38 const Duration& expected_dt,
const Time& t, ReferenceTrajectoryInterface* sref)
40 assert(
x.rows() == expected_xref.getDimension() &&
"Dimension mismatch in controller: current state x and reference");
48 SignalTargetInterface* signal_target, ReferenceTrajectoryInterface* sref, ReferenceTrajectoryInterface* xinit,
49 ReferenceTrajectoryInterface* uinit,
const std::string& ns)
55 xref.getReference(t, xref_vec);
57 uref.getReference(t, uref_vec);
59 if (
_V.rows() > 0 &&
_V.cols() > 0)
61 u = -
_K *
x +
_V * xref_vec;
65 signal_target->sendMeasurement(ns +
"controller/error_norml2", t.toSec(), {x.norm()});
72 u =
_K * state_error + uref_vec;
76 signal_target->sendMeasurement(ns +
"controller/error_norml2", t.toSec(), {state_error.norm()});
82 u_sequence->add(0.0, u);
83 x_sequence->add(0.0,
x);
92 signal_target.registerMeasurement(ns +
"controller/error_norml2", 1);
98 #ifdef MESSAGE_SUPPORT
99 void SimpleStateController::toMessage(corbo::messages::Controller& message)
const
102 message.mutable_simple_state_controller()->mutable_k()->Resize(
_K.rows() *
_K.cols(), 0);
107 message.mutable_simple_state_controller()->mutable_v()->Resize(
_V.rows() *
_V.cols(), 0);
114 message.mutable_simple_state_controller()->set_publish_error(
_publish_error);
117 void SimpleStateController::fromMessage(
const corbo::messages::Controller& message, std::stringstream* issues)
123 if (message.simple_state_controller().v_size() == 0)
126 state_dim = message.simple_state_controller().state_dim();
127 output_dim = state_dim;
128 control_dim = message.simple_state_controller().k_size() / state_dim;
129 if (message.simple_state_controller().output_dim() != output_dim && issues)
131 *issues <<
"SimpleStateController: output_dim must match state_dim since no prefilter matrix V is specified.\n";
136 output_dim = message.simple_state_controller().output_dim();
137 control_dim = message.simple_state_controller().v_size() / output_dim;
138 state_dim = message.simple_state_controller().state_dim();
139 if (control_dim != message.simple_state_controller().k_size() / state_dim && issues)
141 *issues <<
"SimpleStateController: dimension mismatch. cols(K) must be equal to cols(V).\n";
144 if (output_dim * control_dim == message.simple_state_controller().v_size())
147 control_dim, output_dim));
150 *issues <<
"SimpleStateController: invalid size of filter matrix V.\n";
152 if (state_dim * control_dim == message.simple_state_controller().k_size())
158 *issues <<
"SimpleStateController: invalid size of feedback gain matrix K.\n";
161 _publish_error = message.simple_state_controller().publish_error();