OpenDSS CtrlQueue Interface PDF
OpenDSS CtrlQueue Interface PDF
OpenDSS CtrlQueue Interface PDF
CtrlQueue Interface
Sept 2012
Updated Mar 2015
The CtrlQueue interface contains properties and methods for interactions between
internal DSS control objects and control algorithms written in programs driving the
OpenDSS program through its interface.
Continuous controls generally act directly on variables within the program and any delay
is accomplished through time integration. Continuous controls are primarily used in
dynamics simulations while discrete controls are mainly for sequential power flow
simulations. They are often implemented by user-written DLLs.
The Control Queue gets populated after a converged solution is achieved. All of the
control objects currently enabled in the circuit are polled. If they determine that they need
to make a delayed change, they will push a control action onto the Control Queue using
codes that are unique to each class of control object. When it comes time to execute the
action, the OpenDSS pops the appropriate control actions off the Control Queue and
dispatches each of them to the appropriate control handler (a virtual function called
DoPendingAction in the module that pushed the action code onto the control queue).
1
algorithms should check this List and execute the requested action, if it is still appropriate
to do so.
The Action List dispatches control requests using a Device Handle and an Action Code.
Controls implemented in external languages via the COM interface should be associated
with a particular user-assigned Device Handle for dispatching by the COM Control Proxy
object. At this time, Device Handles and Action Codes are defined in the external user-
written code, but a future version may also employ handles and codes managed by the
simulator.
Typically, an external control would step through the solution one step at a time. After
achieving a converged circuit solution, the control would execute the functions that
sample the quantities of interest. It could then Push any control actions onto the
OpenDSS Control Queue and rely on the OpenDSS to dispatch the control. The
OpenDSS would know the action request came from the COM Control Proxy and
dispatch any actions back to the Proxy where they are accumulated in the Action Queue.
The user-written control would then be responsible for checking the Action List, setting
the Active Action (directly or by popping off the list in sequence), and then dispatching
the action code to the proper control algorithm.
All discrete external controls with time-delayed actions should employ the OpenDSS
Control Queue for proper synchronization with other active controllers in the circuit.
When the time comes to execute an action, external controls may act directly upon circuit
objects through the COM interface. For example, if a user-written relay control
determines that a device terminal needs to be opened, it can do so through either the text
interface or the CktElement interface.
Note that accessing most of these properties and methods without an active circuit
defined will result in no action.
2
COM Interface Control Proxy Operation
COM Interface
COM CONTROL
Proxy
DoPendingAction
POP CONTROL
USER CODE Action List
DISPATCHER
PUSH
POP
CONTROL OBJECT
ACTION 1
DoPendingAction
ALL PUSHES
ACTION 2
ARE SORTED
BY TIME ACTION 3
...
CONTROL OBJECT
ACTION N
DoPendingAction
DSS Control Queue
Time
Action Code
Proxy Handle
Control Addr
Figure 1. Illustration of how the COM Control Proxy interacts with the DSS Control Queue
3
Properties
Methods
Function ClearQueue: HResult;
This clears all actions from the DSS Control Queue. The return value is always zero.
4
control action to the proper control device managed by the user-written code when the
Action is popped off the Control Queue. The DSS will automatically return this handle to
the control proxy in the COM interface when the action is popped.
The actual internal DSS Control Queue Push function passes one more argument not
shown in this COM interface method. For internal control objects, it is the Self variable;
for any control model coming through the COM interface, it is the address of the
COMControlProxyObj variable. When an action destined for the user-written code is
popped off the DSS Control Queue, the COMControlProxyObj.DoPendingAction
function is called. This dispatches the action message to the Action List in the user-
written code. Then the user-written code must decipher it.
When this command is complete the Result property of the Text interface contains the
name of the file, which you may use for further processing. (The Result property must be
accessed before doing anything else or it will disappear.)
Example 1
DSSText.Command='Set MaxControlIter=30';
5
end
DSSText.Command='Export Voltages';
disp(DSSText.Result)
DSSSolution.SampleControlDevices;
DSSCircuit.CtrlQueue.Show; % show the contents of the control queue
disp(DSSText.Result)
DSSSolution.DoControlActions; % execute the control actions
DSSCircuit.CtrlQueue.Show; % see what is left on the queue
else
a = 'DSS Did Not Start'
disp(a)
end
6
Set DSSMonitors = DSSCircuit.Monitors
End Sub
' Example of implementing a simple voltage control for Capacitors via the COM interface
' Run simple capacitor interface test and execute local cap control that emulates
CapControl
' with these settings:
' PT=125.09 Type=voltage onsetting=118.8 offsetting=121.2
' this test case has a four-step capacitor bank named "cap" and can be found in the
Test Folder
DSSText.Command = "Compile
(C:\Users\prdu001\OpenDSS\Test\Master_TestCapInterface.DSS)"
' Each message we push onto the queue will get a 5 s delay
hour = 0
secDelay = 5 ' delay
' now, we'll crank the load up in 10% steps, checking the voltage at each step
' until all cap steps are on (no more available)
i = 0
Do While DSSCapacitors.AvailableSteps > 0
7
i = i + 1
DSSSolution.LoadMult = 1# + i * 0.1 ' 10% more each time
DSSSolution.InitSnap
DSSSolution.SolveNoControl
DSSSolution.SampleControlDevices ' sample all other controls
' Emulate the cap control Sample Routine and get the bus voltage
DSSCircuit.SetActiveBus "feedbus"
V = DSSBus.VMagAngle
' check the first phase magnitude
Vreg = V(0) / PTratio
Debug.Print "Step "; i; " Voltage="; Vreg; " LoadMult="; DSSSolution.LoadMult
If Vreg < ONsetting Then ' push a message to bump up the number of steps
DSSControlQueue.Push hour, secDelay, ActionCodeAdd, DeviceHandle
End If
Case 201
DSSCapacitors.AddStep
Case 202
DSSCapacitors.SubtractStep
End Select
Loop
End If
Loop
' Emulate the cap control Sample Routine and get the bus voltage
DSSCircuit.SetActiveBus "feedbus"
V = DSSBus.VMagAngle
' check the first phase magnitude
Vreg = V(0) / PTratio
Debug.Print "Step "; i; " Voltage="; Vreg; " LoadMult="; DSSSolution.LoadMult
If Vreg > OFFsetting Then ' push a message to bump down the number of steps
DSSControlQueue.Push hour, secDelay, ActionCodeSub, DeviceHandle
End If
8
Case 123
iCap = DSSCapacitors.First ' Sets designated capacitor active
End Select
Case 201
DSSCapacitors.AddStep
Case 202
DSSCapacitors.SubtractStep
End Select
Loop
End If
Loop
End Sub
The DSS script for the circuit (from the Test folder).
Clear
New Circuit.CapInterface
~ basekv=161 pu=1.05 angle=0.0 freq=60.0 phases=3