I'm working through some basic tutorials and I've come across an issue. I have a simple LeafSystem connected to a PidController, and I want to make my own output port that sends the state to the controller (I know I can use a DeclareStateOutputPort to get a state output automatically, but I'd like to learn more about how things work and maybe change the outputs in customized ways). When I try to wire things up like this, I get an algebraic loop warning, which makes sense since I haven't told it that my output doesn't depend on the input from the controller yet. Searching the docs, I found that I need to specify the prerequisites_to_calc parameter by giving, in this case, a ticket indicating that I only depend on the states.
However, I can't figure out how to pass that ticket in. I assumed I would just use the LeafSystem.all_state_ticket() dependency ticket for the prerequisites_to_calc parameter, but that doesn't work. The errors are mostly referencing the C++ code, which I don't feel as confident parsing.
class MassSpringDamper(LeafSystem):
def __init__(self, m, k1, k2, b1, b2, mu_d, mu_s):
super().__init__()
state_index = self.DeclareContinuousState(2)
self._F_port = self.DeclareVectorInputPort(name='F', size=1)
self.DeclareStateOutputPort("x", state_index)
# This is the problem spot: what does the prerequisites_to_calc parameter expect?
self.DeclareVectorOutputPort("y", size=2, calc=self.get_custom_output, prerequisites_to_calc=self.all_state_ticket())
self.m = m
self.k1 = k1
self.k2 = k2
self.b1 = b1
self.b2 = b2
self.mu_d = mu_d
self.mu_s = mu_s
Any help is appreciated!
The prerequisites_of_calc
is a set of tickets, not just one ticket. Either prerequisites_of_calc={self.all_state_ticket()}
or prerequisites_of_calc=set([self.all_state_ticket()])
should work.
Also note its spelled prerequisites_of_calc
not prerequisites_to_calc
.