Skip to content

Commit

Permalink
Comments (#150)
Browse files Browse the repository at this point in the history
* cleanup api change table

* Update comments to describe zmq modules and functions better

* comment and cleanup controller-related moduels

* cleanup and comments for turbine modules

* psuedo functions for weird interpolation steps

* minor sim cleanup

* More comments for robust tuning procedures

* add descriptions and comments for robust scheduling

* Add some comments

* Add Ct_max comment

Co-authored-by: dzalkind <dzalkind@nrel.gov>
  • Loading branch information
nikhar-abbas and dzalkind authored Jul 22, 2022
1 parent 601ca8f commit 61b6039
Show file tree
Hide file tree
Showing 7 changed files with 253 additions and 130 deletions.
44 changes: 36 additions & 8 deletions ROSCO_toolbox/control_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ def init_discon(self):
# Torque initial condition
self.avrSWAP[22] = 0


# Code this as first call
self.avrSWAP[0] = 0

Expand All @@ -98,15 +97,14 @@ def init_discon(self):
# Initialize DISCON and related
self.aviFAIL = c_int32() # 1
self.accINFILE = self.param_name.encode('utf-8')
# self.avcOUTNAME = create_string_buffer(1000) # 'DEMO'.encode('utf-8')
self.avcOUTNAME = (self.sim_name + '.RO.dbg').encode('utf-8')
self.avcMSG = create_string_buffer(1000)
self.discon.DISCON.argtypes = [POINTER(c_float), POINTER(c_int32), c_char_p, c_char_p, c_char_p] # (all defined by ctypes)

# Run DISCON
self.call_discon()

# Code as not first run
# Code as not first run now that DISCON has been initialized
self.avrSWAP[0] = 1


Expand Down Expand Up @@ -173,7 +171,6 @@ def call_controller(self, turbine_state, end=False):
except KeyError:
self.avrSWAP[82] = 0


# call controller
self.call_discon()

Expand All @@ -182,9 +179,6 @@ def call_controller(self, turbine_state, end=False):
self.torque = self.avrSWAP[46]
self.nac_yawrate = self.avrSWAP[47]

# if turbine_state['iStatus'] == -1:
# self.avrSWAP[0] = -1

return(self.torque,self.pitch,self.nac_yawrate)

def show_control_values(self):
Expand Down Expand Up @@ -304,14 +298,28 @@ def __init__(self, network_addresses=["tcp://*:5555", "tcp://*:5556"],
verbose=verbose)

def get_measurements(self):
'''
Get measurements from zmq servers
'''
measurements = [None for _ in range(self.nturbs)]
for ti in range(self.nturbs):
measurements[ti] = self.zmq_servers[ti].get_measurements()
return measurements

def send_setpoints(self, genTorques=None, nacelleHeadings=None,
bladePitchAngles=None):
'''
Send setpoints to DLL via zmq server for farm level controls
Parameters:
-----------
genTorques: List
List of generator torques of length self.nturbs
nacelleHeadings: List
List of nacelle headings of length self.nturbs
bladePitchAngles: List
List of blade pitch angles of length self.nturbs
'''
# Default choices if unspecified
if genTorques is None:
genTorques = [0.0] * self.nturbs
Expand Down Expand Up @@ -357,6 +365,9 @@ def __init__(self, network_address="tcp://*:5555", identifier="0",
self._connect()

def _connect(self):
'''
Connect to zmq server
'''
address = self.network_address

# Connect socket
Expand All @@ -369,11 +380,17 @@ def _connect(self):
print("[%s] Successfully established connection with %s" % (self.identifier, address))

def _disconnect(self):
'''
Disconnect from zmq server
'''
self.socket.close()
context = zmq.Context()
context.term()

def get_measurements(self):
'''
Receive measurements from ROSCO .dll
'''
if self.verbose:
print("[%s] Waiting to receive measurements from ROSCO..." % (self.identifier))

Expand All @@ -390,7 +407,6 @@ def get_measurements(self):

# Convert to individual strings and then to floats
measurements = message_in
# measurements = bytes.decode(message_in)
measurements = measurements.replace('\x00', '').split(',')
measurements = [float(m) for m in measurements]

Expand Down Expand Up @@ -421,6 +437,18 @@ def get_measurements(self):

def send_setpoints(self, genTorque=0.0, nacelleHeading=0.0,
bladePitch=[0.0, 0.0, 0.0]):
'''
Send setpoints to ROSCO .dll ffor individual turbine control
Parameters:
-----------
genTorques: float
Generator torque setpoint
nacelleHeadings: float
Nacelle heading setpoint
bladePitchAngles: List (len=3)
Blade pitch angle setpoint
'''
# Create a message with setpoints to send to ROSCO
message_out = b"%016.5f, %016.5f, %016.5f, %016.5f, %016.5f" % (
genTorque, nacelleHeading, bladePitch[0], bladePitch[1],
Expand Down
Loading

0 comments on commit 61b6039

Please sign in to comment.