79 "stiffness", Eigen::MatrixXd::Identity(dimensions, dimensions))), damping_(
81 "damping", Eigen::MatrixXd::Identity(dimensions, dimensions))), inertia_(
83 "inertia", Eigen::MatrixXd::Identity(dimensions, dimensions))), feed_forward_force_(
85 state_representation::make_shared_parameter<Eigen::VectorXd>(
"force_limit")), dimensions_(dimensions) {
110 const std::shared_ptr<state_representation::ParameterInterface>& parameter
112 if (parameter->get_name() ==
"stiffness") {
113 this->stiffness_->set_value(this->gain_matrix_from_parameter(parameter));
114 }
else if (parameter->get_name() ==
"damping") {
115 this->damping_->set_value(this->gain_matrix_from_parameter(parameter));
116 }
else if (parameter->get_name() ==
"inertia") {
117 this->inertia_->set_value(this->gain_matrix_from_parameter(parameter));
118 }
else if (parameter->get_name() ==
"feed_forward_force") {
119 this->feed_forward_force_->set_value(parameter->get_parameter_value<
bool>());
120 }
else if (parameter->get_name() ==
"force_limit") {
121 if (parameter->get_parameter_type() == state_representation::ParameterType::MATRIX) {
123 "Parameter " + parameter->get_name() +
" has incorrect type");
125 auto limit_matrix = this->gain_matrix_from_parameter(parameter);
126 this->force_limit_->set_value(limit_matrix.diagonal());
129 "No parameter with name '" + parameter->get_name() +
"' found"
136 const std::shared_ptr<state_representation::ParameterInterface>& parameter
138 Eigen::MatrixXd matrix;
139 if (parameter->get_parameter_type() == state_representation::ParameterType::DOUBLE) {
140 auto gain = std::static_pointer_cast<state_representation::Parameter<double>>(parameter);
141 matrix = gain->get_value() * Eigen::MatrixXd::Identity(this->dimensions_, this->dimensions_);
142 }
else if (parameter->get_parameter_type() == state_representation::ParameterType::DOUBLE_ARRAY) {
143 auto gain = std::static_pointer_cast<state_representation::Parameter<std::vector<double>>>(parameter);
144 if (gain->get_value().size() == 1) {
145 matrix = gain->get_value().at(0) * Eigen::MatrixXd::Identity(this->dimensions_, this->dimensions_);
146 }
else if (gain->get_value().size() == this->dimensions_) {
147 Eigen::VectorXd diagonal = Eigen::VectorXd::Map(gain->get_value().data(), this->dimensions_);
148 matrix = diagonal.asDiagonal();
151 "The provided diagonal coefficients do not match the dimensionality of the controller ("
152 + std::to_string(this->dimensions_) +
")");
154 }
else if (parameter->get_parameter_type() == state_representation::ParameterType::VECTOR) {
155 auto gain = std::static_pointer_cast<state_representation::Parameter<Eigen::VectorXd>>(parameter);
156 if (gain->get_value().size() == 1) {
157 matrix = gain->get_value()(0) * Eigen::MatrixXd::Identity(this->dimensions_, this->dimensions_);
158 }
else if (gain->get_value().size() == this->dimensions_) {
159 matrix = gain->get_value().asDiagonal();
162 "The provided diagonal coefficients do not match the dimensionality of the controller ("
163 + std::to_string(this->dimensions_) +
")");
165 }
else if (parameter->get_parameter_type() == state_representation::ParameterType::MATRIX) {
166 auto gain = std::static_pointer_cast<state_representation::Parameter<Eigen::MatrixXd>>(parameter);
167 if (gain->get_value().rows() != this->dimensions_ || gain->get_value().cols() != this->dimensions_) {
168 auto dim = std::to_string(this->dimensions_);
170 "The provided matrix does not have the expected size (" + dim +
"x" + dim +
")");
172 matrix = gain->get_value();
175 "Parameter " + parameter->get_name() +
" has incorrect type");
177 if ((matrix.array() < 0).any()) {
179 "Parameter " + parameter->get_name() +
" cannot have negative elements");