40 assert(x.rows() == expected_xref.
getDimension() &&
"Dimension mismatch in controller: current state x and reference");
59 if (
_V.rows() > 0 &&
_V.cols() > 0)
61 u = -
_K * x +
_V * xref_vec;
72 u =
_K * state_error + uref_vec;
82 u_sequence->add(0.0, u);
83 x_sequence->add(0.0, x);
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();
Eigen::VectorXd ControlVector
void reset() override
Reset internal controller state and caches.
void getAvailableSignals(SignalTargetInterface &signal_target, const std::string &ns="") const override
Retrieve available signals from the controller.
void setFilterMatrixV(const Eigen::Ref< const Eigen::MatrixXd > &V)
Set reference filter matrix V [control input dimension x output dimension].
A matrix or vector expression mapping an existing array of data.
virtual int getDimension() const =0
virtual void sendMeasurement(Measurement::ConstPtr measurement)=0
Send a measurement to the target.
void setGainMatrixK(const Eigen::Ref< const Eigen::MatrixXd > &K)
Set feedback gain matrix K [control input dimension x state dimension].
Interface class for signal targets.
Representation of time stamps.
virtual void registerMeasurement(const std::string &unique_name, int value_dimension, const std::vector< std::string > &value_labels={}, bool zero_order_hold=false)=0
Register a measurement type at current target.
Eigen::VectorXd OutputVector
A matrix or vector expression mapping an existing expression.
constexpr const int INHERITED
Inherit property.
double toSec() const
Cast time stamp to seconds.
Interface class for reference trajectories.
Eigen::VectorXd StateVector
bool initialize(const StateVector &x, ReferenceTrajectoryInterface &expected_xref, ReferenceTrajectoryInterface &expected_uref, const Duration &expected_dt, const Time &t, ReferenceTrajectoryInterface *sref=nullptr) override
Initialize the controller.
virtual void getReference(const Time &t, OutputVector &ref) const =0
std::shared_ptr< TimeSeries > Ptr
The matrix class, also used for vectors and row-vectors.
Representation of time durations.
bool step(const StateVector &x, ReferenceTrajectoryInterface &xref, ReferenceTrajectoryInterface &uref, const Duration &dt, const Time &t, TimeSeries::Ptr u_sequence, TimeSeries::Ptr x_sequence, SignalTargetInterface *signal_target=nullptr, ReferenceTrajectoryInterface *sref=nullptr, ReferenceTrajectoryInterface *xinit=nullptr, ReferenceTrajectoryInterface *uinit=nullptr, const std::string &ns="") override
int getStateDimension() const override
Return the dimension of the required plant state/output.