Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finish Improve WFC #367

Merged
merged 5 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions Examples/17a_zeromq_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,28 @@ def run_zmq(logfile=None):
network_address = "tcp://*:5555"
server = wfc_zmq_server(network_address, timeout=60.0, verbose=False, logfile=logfile)

# Provide the wind farm control algorithm as the wfc_controller method of the server
server.wfc_controller = wfc_controller
# Provide the wind farm control algorithm as the wfc_controller subclass of the server
server.wfc_controller = wfc_controller()

# Run the server to receive measurements and send setpoints
server.runserver()

def wfc_controller(id,current_time,measurements):
class wfc_controller():
"""
Users needs to define this class to implement wind farm controller.
This class should contain a method named update_setpoints that
should take as argument the turbine id, the current time and current
measurements and return the setpoints for the particular turbine for
the current time. It should ouput the setpoints as a dictionary whose
keys should be as defined in wfc_zmq_server.wfc_interface.
The wfc_controller subclass of the wfc_zmq_server should be overwriten
with this class, otherwise, an exception is raised and the simulation stops.
"""

def __init__(self):
return None

def update_setpoints(self, id,current_time,measurements):
if current_time <= 10.0:
yaw_setpoint = 0.0
else:
Expand All @@ -62,8 +77,10 @@ def wfc_controller(id,current_time,measurements):
setpoints['ZMQ_PitOffset(1)'] = col_pitch_command
setpoints['ZMQ_PitOffset(2)'] = col_pitch_command
setpoints['ZMQ_PitOffset(3)'] = col_pitch_command

return setpoints


def sim_rosco():
# Load yaml file
this_dir = os.path.dirname(os.path.abspath(__file__))
Expand Down
59 changes: 32 additions & 27 deletions Examples/17b_zeromq_multi_openfast.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,41 +22,46 @@ def run_zmq(logfile=None):
network_address = "tcp://*:5555"
server = wfc_zmq_server(network_address, timeout=60.0, verbose=False, logfile = logfile)

# Provide the wind farm control algorithm as the wfc_controller method of the server
server.wfc_controller = wfc_controller
# Provide the wind farm control algorithm as the wfc_controller subclass of the server
server.wfc_controller = wfc_controller()

# Run the server to receive measurements and send setpoints
server.runserver()


def wfc_controller(id, current_time, measurements):
class wfc_controller():
"""
Users needs to define this function to implement wind farm controller.
The user defined function should take as argument the turbine id, the
current time and current measurements and return the setpoints
for the particular turbine for the current time. It should ouput the
setpoints as a dictionary whose keys should be as defined in
wfc_zmq_server.wfc_interface. The wfc_controller method of the wfc_zmq_server
should be overwriten with this fuction, otherwise, an exception is raised and
the simulation stops.
Users needs to define this class to implement wind farm controller.
This class should contain a method named update_setpoints that
should take as argument the turbine id, the current time and current
measurements and return the setpoints for the particular turbine for
the current time. It should ouput the setpoints as a dictionary whose
keys should be as defined in wfc_zmq_server.wfc_interface.
The wfc_controller subclass of the wfc_zmq_server should be overwriten
with this class, otherwise, an exception is raised and the simulation stops.
"""
if current_time <= 10.0:
YawOffset = 0.0
col_pitch_command = 0.0
else:
col_pitch_command = np.deg2rad(2) * np.sin(0.1 * current_time) + np.deg2rad(2) # Implement dynamic induction control
if id == 1:
YawOffset = DESIRED_YAW_OFFSET[0]

def __init__(self):
return None

def update_setpoints(self, id, current_time, measurements):
if current_time <= 10.0:
YawOffset = 0.0
col_pitch_command = 0.0
else:
YawOffset = DESIRED_YAW_OFFSET[1]


setpoints = {}
setpoints["ZMQ_YawOffset"] = YawOffset
setpoints['ZMQ_PitOffset(1)'] = col_pitch_command
setpoints['ZMQ_PitOffset(2)'] = col_pitch_command
setpoints['ZMQ_PitOffset(3)'] = col_pitch_command
return setpoints
col_pitch_command = np.deg2rad(2) * np.sin(0.1 * current_time) + np.deg2rad(2) # Implement dynamic induction control
if id == 1:
YawOffset = DESIRED_YAW_OFFSET[0]
else:
YawOffset = DESIRED_YAW_OFFSET[1]


setpoints = {}
setpoints["ZMQ_YawOffset"] = YawOffset
setpoints['ZMQ_PitOffset(1)'] = col_pitch_command
setpoints['ZMQ_PitOffset(2)'] = col_pitch_command
setpoints['ZMQ_PitOffset(3)'] = col_pitch_command
return setpoints


def sim_openfast_1():
Expand Down
2 changes: 1 addition & 1 deletion rosco/toolbox/control_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ def _get_setpoints(self, id, measurements):
logger.debug(
f"Asking wfc_controller for setpoints at time = {current_time} for id = {id}"
)
setpoints = self.wfc_controller(id, current_time, measurements)
setpoints = self.wfc_controller.update_setpoints(id, current_time, measurements)
logger.info(f"Received setpoints {setpoints} from wfc_controller for time = {current_time} and id = {id}")

for s in self.wfc_interface["setpoints"]:
Expand Down
Loading