Skip to content

Commit

Permalink
Adding some smoothing to hybrid controller (#40)
Browse files Browse the repository at this point in the history
* Adding some smoothing to hybrid controller

* Updating test that wasn't passing

* Update supervisory controller test to be more intuitive.

---------

Co-authored-by: Starke <gstarke@gstarke-41230s.nrel.gov>
Co-authored-by: Genevieve Starke <gstarke@kl2.head.cm.kestrel.hpc.nrel.gov>
Co-authored-by: misi9170 <michael.sinner@nrel.gov>
  • Loading branch information
4 people authored Nov 19, 2024
1 parent bae938a commit 5eb45e1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
24 changes: 21 additions & 3 deletions tests/controller_library_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,27 @@ def test_HybridSupervisoryControllerBaseline():
interface=test_interface, input_dict=test_hercules_dict
)

solar_current = 800
wind_current = [600, 300]
power_ref = 1000

# Simply test the supervisory_control method, for the time being
test_hercules_dict["external_signals"]["plant_power_reference"] = 1000
test_hercules_dict["hercules_comms"]["amr_wind"]["test_farm"]["turbine_powers"] = [500, 500]
test_hercules_dict["external_signals"]["plant_power_reference"] = power_ref
test_hercules_dict["hercules_comms"]["amr_wind"]["test_farm"]["turbine_powers"] = wind_current
test_hercules_dict["py_sims"]["test_solar"]["outputs"]["power_mw"] = solar_current / 1e3
test_controller.prev_solar_power = solar_current # To override filtering
test_controller.prev_wind_power = sum(wind_current) # To override filtering

test_controller.step(test_hercules_dict) # Run the controller once to update measurements
supervisory_control_output = test_controller.supervisory_control()
assert np.allclose(supervisory_control_output, [10500.0, 10500.0, 1000.0]) # To charge battery

# Expected outputs
wind_solar_current = sum(wind_current)+solar_current
wind_power_cmd = 20000/2 + sum(wind_current)-(wind_solar_current - power_ref)/2
solar_power_cmd = 20000/2 + solar_current-(wind_solar_current - power_ref)/2
battery_power_cmd = wind_solar_current - power_ref

assert np.allclose(
supervisory_control_output,
[wind_power_cmd, solar_power_cmd, battery_power_cmd]
) # To charge battery
6 changes: 6 additions & 0 deletions whoc/controllers/hybrid_supervisory_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ def supervisory_control(self):
solar_aoi = self.measurements_dict["solar_aoi"] # angle of incidence # noqa: F841
reference_power = self.measurements_dict["plant_power_reference"]

# Filter the wind and solar power measurements to reduce noise and improve closed-loop
# controller damping
a = 0.1
wind_power = (1-a)*self.prev_wind_power + a*wind_power
solar_power = (1-a)*self.prev_solar_power + a*solar_power

# Temporary print statements (note that negative battery indicates discharging)
print("Measured powers (wind, solar, battery):", wind_power, solar_power, battery_power)
print("Reference power:", reference_power)
Expand Down

0 comments on commit 5eb45e1

Please sign in to comment.