Skip to content

Commit

Permalink
Test/hercules wind battery controller (NREL#28)
Browse files Browse the repository at this point in the history
* hercules_wind_battery_controller test

* Rename to just WindBatteryController

* reorder imports to appease ruff

* Cleaning up outdated output files.

---------

Co-authored-by: Zachary <[email protected]>
Co-authored-by: misi9170 <[email protected]>
  • Loading branch information
3 people authored Feb 6, 2024
1 parent 6f1a27e commit 9ccf067
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 16 deletions.
41 changes: 35 additions & 6 deletions tests/controller_library_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
import numpy as np
import pandas as pd
from whoc.controllers import (
HerculesWindBatteryController,
LookupBasedWakeSteeringController,
WindBatteryController,
)
from whoc.interfaces import HerculesADYawInterface
from whoc.interfaces import HerculesADYawInterface, HerculesWindBatteryInterface
from whoc.interfaces.interface_base import InterfaceBase


Expand Down Expand Up @@ -63,7 +63,7 @@ def test_controller_instantiation():
test_interface = StandinInterface()

_ = LookupBasedWakeSteeringController(interface=test_interface, input_dict=test_hercules_dict)
_ = HerculesWindBatteryController(interface=test_interface, input_dict=test_hercules_dict)
_ = WindBatteryController(interface=test_interface, input_dict=test_hercules_dict)


def test_LookupBasedWakeSteeringController():
Expand Down Expand Up @@ -111,6 +111,35 @@ def test_LookupBasedWakeSteeringController():
)
assert np.allclose(test_angles, wind_directions - test_offsets)

def test_HerculesWindBatteryController():
# TODO: write this test, possibly clean up HerculesWindBatteryController class
pass
def test_WindBatteryController():
# TODO: possibly clean up HerculesWindBatteryController class

test_interface = HerculesWindBatteryInterface(test_hercules_dict)
test_controller = WindBatteryController(test_interface, test_hercules_dict)


# Check the low level methods behave as expected
test_controller._receive_measurements(test_hercules_dict)

wind_setpoints = test_controller.calc_wind_setpoints()
assert not wind_setpoints # wind setpoints should be empty

battery_setpoints = test_controller.calc_battery_setpoints()
assert battery_setpoints["signal"] == -500 # battery setpoints should not be empty

test_controller.compute_controls()
assert test_controller.setpoints_dict == {"wind": wind_setpoints, "battery": battery_setpoints}

# Test step
# We will need to change these cases when the wind_battery_controller has more general behavior
test_hercules_dict["hercules_comms"]["amr_wind"]["test_farm"]["turbine_powers"] = [450, 450]
hercules_dict_out = test_controller.step(test_hercules_dict)
assert hercules_dict_out["setpoints"]["battery"]["signal"] == 900

test_hercules_dict["hercules_comms"]["amr_wind"]["test_farm"]["turbine_powers"] = [550, 550]
hercules_dict_out = test_controller.step(test_hercules_dict)
assert hercules_dict_out["setpoints"]["battery"]["signal"] == -500




2 changes: 1 addition & 1 deletion whoc/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from whoc.controllers.hercules_wind_battery_controller import HerculesWindBatteryController
from whoc.controllers.lookup_based_wake_steering_controller import LookupBasedWakeSteeringController
from whoc.controllers.wake_steering_rosco_standin import WakeSteeringROSCOStandin
from whoc.controllers.wind_battery_controller import WindBatteryController
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from whoc.controllers.controller_base import ControllerBase


class HerculesWindBatteryController(ControllerBase):
class WindBatteryController(ControllerBase):
def __init__(self, interface, input_dict, verbose=True):
super().__init__(interface, verbose)

Expand All @@ -26,29 +26,23 @@ def __init__(self, interface, input_dict, verbose=True):

def send_controls(self, hercules_dict):
self._s.check_controls(self.setpoints_dict)
dict = self._s.send_controls(hercules_dict, self.setpoints_dict)
hercules_dict = self._s.send_controls(hercules_dict, self.setpoints_dict)

return dict # or main_dict, or what?
return hercules_dict

def step(self, hercules_dict=None):
self._receive_measurements(hercules_dict)
# receive measurements sets self.measurements_dict
self.compute_controls()
hercules_dict = self.send_controls(hercules_dict)

return hercules_dict

def compute_controls(self):
# set self.controls_dict

# calc wind setpoints
wind_setpoints = self.calc_wind_setpoints()
battery_setpoints = self.calc_battery_setpoints()

self.setpoints_dict = {"wind": wind_setpoints, "battery": battery_setpoints}

return None

def calc_wind_setpoints(self):
wind_setpoints = {}
return wind_setpoints
Expand Down

0 comments on commit 9ccf067

Please sign in to comment.