46045-syslab/syslab-python/syslab/physical/Dumpload.py

113 lines
4.0 KiB
Python

from ..core.SyslabUnit import SyslabUnit
import warnings
class Dumpload(SyslabUnit):
"""The Dumpload class represents a dumpload in SYSLAB.
The Dumpload class is instantiated using a string with the unique name of the dumpload, ie. 'which'
A full list of available dumploads can be found by calling 'Dumpload.getAvailableDumpLoads()'
Alternatively, the user may specify a host and port to connect to via the *host* and *port* arguments.
"""
__DUMPLOADS = {
'mobload1': ('syslab-16.syslab.dk', '8080', 'mobload1'),
'mobload2': ('syslab-17.syslab.dk', '8080', 'mobload2'),
'mobload3': ('syslab-18.syslab.dk', '8080', 'mobload3'),
'load1': ('syslab-05.syslab.dk', '8080', 'load1'),
'vmobload1': ('simlab-16', '8080', 'mobload1'),
'vmobload2': ('simlab-17', '8080', 'mobload2'),
'vmobload3': ('simlab-18', '8080', 'mobload3'),
'vload1': ('simlab-05', '8080', 'load1'),
'simlab-05': ('192.168.0.105', '8080', 'mobload2'),
'simlab-11': ('192.168.0.111', '8080', 'mobload1'),
'simlab-12': ('192.168.0.112', '8080', 'load1'),
}
def __init__(self, which=None, host=None, port=None, unitname=None):
baseurl = 'http://{host}:{port}/typebased_WebService_Load/GenericLoadWebService/{unit_name}/'
super().__init__(
baseurl=baseurl,
which=which,
units=self.__DUMPLOADS,
host=host,
port=port,
unit_name=unitname,
unit_type="Battery")
def startLoad(self):
return self._request_resource('startLoad', (), 'put')
def stopLoad(self):
return self._request_resource('stopLoad', (), 'put')
def getPowerSetPoint(self):
return self._request_resource('getConstantP')
def setPowerSetPoint(self, setPoint):
"""
Set the active power setpoint for the load.
Inputs:
setPoint (float): Requested power setpoint
Outputs:
Ack (bool): Acknowledgement of receiver
"""
P_UpperLimit = 15.0
P_LowerLimit = 0
return self._request_resource('setConstantP', max(P_LowerLimit, min(setPoint, P_UpperLimit)), 'put')
def getActivePower(self):
return self._request_resource('getActivePower')
def getReactivePower(self):
"""
Get the reactive power draw from the load.
Outputs:
Q (CompositeMeasurement): Current reactive power draw, calculated from active power draw (see note)
NOTE: This is a theoretical value calculated from the relation
Q = Q_r * sin (pi * P /P_r)
where P_r and Q_r are the rated active and reactive power draw.
For control purposes, use the measured value from the switchboard
instead to get an actual measurement.
"""
warnings.warn("The output of getReactivePower from the Dumpload class is calculated from the active power draw rather than a measured value. For control purposes, use the measured power draw on the switchboard.")
return self._request_resource('getReactivePower')
def getRatedPower(self):
return self._request_resource('getRatedP')
def getRatedReactivePower(self):
return self._request_resource('getRatedQ')
def getName(self):
return self._request_resource('getLoadName')
def isLoadOn(self):
return self._request_resource('isLoadOn')
@staticmethod
def getAvailableDumploads():
return list(Dumpload.__DUMPLOADS.keys())
class MobileLoad1(Dumpload):
def __init__(self):
super(MobileLoad1, self).__init__("mobload1")
class MobileLoad2(Dumpload):
def __init__(self):
super(MobileLoad2, self).__init__("mobload2")
class MobileLoad3(Dumpload):
def __init__(self):
super(MobileLoad3, self).__init__("mobload3")