124 const std::vector<double> & actuator_reduction,
const std::vector<double> & joint_reduction,
125 const std::vector<double> & joint_offset = {0.0, 0.0});
133 const std::vector<JointHandle> & joint_handles,
134 const std::vector<ActuatorHandle> & actuator_handles)
override;
155 const std::vector<double> & get_actuator_reduction()
const {
return actuator_reduction_; }
156 const std::vector<double> & get_joint_reduction()
const {
return joint_reduction_; }
157 const std::vector<double> & get_joint_offset()
const {
return joint_offset_; }
163 std::vector<double> actuator_reduction_;
164 std::vector<double> joint_reduction_;
165 std::vector<double> joint_offset_;
167 std::vector<JointHandle> joint_position_;
168 std::vector<JointHandle> joint_velocity_;
169 std::vector<JointHandle> joint_effort_;
170 std::vector<JointHandle> joint_torque_;
171 std::vector<JointHandle> joint_force_;
172 std::vector<JointHandle> joint_absolute_position_;
174 std::vector<ActuatorHandle> actuator_position_;
175 std::vector<ActuatorHandle> actuator_velocity_;
176 std::vector<ActuatorHandle> actuator_effort_;
177 std::vector<ActuatorHandle> actuator_torque_;
178 std::vector<ActuatorHandle> actuator_force_;
179 std::vector<ActuatorHandle> actuator_absolute_position_;
183 const std::vector<double> & actuator_reduction,
const std::vector<double> & joint_reduction,
184 const std::vector<double> & joint_offset)
185: actuator_reduction_(actuator_reduction),
186 joint_reduction_(joint_reduction),
187 joint_offset_(joint_offset)
193 throw Exception(
"Reduction and offset vectors must have size 2.");
197 0.0 == actuator_reduction_[0] || 0.0 == actuator_reduction_[1] || 0.0 == joint_reduction_[0] ||
198 0.0 == joint_reduction_[1])
200 throw Exception(
"Transmission reduction ratios cannot be zero.");
205 const std::vector<JointHandle> & joint_handles,
206 const std::vector<ActuatorHandle> & actuator_handles)
208 if (joint_handles.empty())
210 throw Exception(
"No joint handles were passed in");
213 if (actuator_handles.empty())
215 throw Exception(
"No actuator handles were passed in");
218 const auto joint_names = get_names(joint_handles);
219 if (joint_names.size() != 2)
223 FMT_COMPILE(
"There should be exactly two unique joint names but was given '{}'."),
224 to_string(joint_names)));
226 const auto actuator_names = get_names(actuator_handles);
227 if (actuator_names.size() != 2)
231 FMT_COMPILE(
"There should be exactly two unique actuator names but was given '{}'."),
232 to_string(actuator_names)));
242 joint_absolute_position_ =
245 if (!joint_position_.empty() && joint_position_.size() != 2)
249 FMT_COMPILE(
"Not enough valid or required joint position handles were present. \n{}"),
252 if (!joint_velocity_.empty() && joint_velocity_.size() != 2)
256 FMT_COMPILE(
"Not enough valid or required joint velocity handles were present. \n{}"),
259 if (!joint_effort_.empty() && joint_effort_.size() != 2)
263 FMT_COMPILE(
"Not enough valid or required joint effort handles were present. \n{}"),
266 if (!joint_torque_.empty() && joint_torque_.size() != 2)
270 FMT_COMPILE(
"Not enough valid or required joint torque handles were present. \n{}"),
273 if (!joint_force_.empty() && joint_force_.size() != 2)
277 FMT_COMPILE(
"Not enough valid or required joint force handles were present. \n{}"),
280 if (!joint_absolute_position_.empty() && joint_absolute_position_.size() != 2)
285 "Not enough valid or required joint absolute position handles were present. \n{}"),
299 actuator_absolute_position_ =
302 if (!actuator_position_.empty() && actuator_position_.size() != 2)
306 FMT_COMPILE(
"Not enough valid or required actuator position handles were present. \n{}"),
309 if (!actuator_velocity_.empty() && actuator_velocity_.size() != 2)
313 FMT_COMPILE(
"Not enough valid or required actuator velocity handles were present. \n{}"),
316 if (!actuator_effort_.empty() && actuator_effort_.size() != 2)
320 FMT_COMPILE(
"Not enough valid or required actuator effort handles were present. \n{}"),
323 if (!actuator_torque_.empty() && actuator_torque_.size() != 2)
327 FMT_COMPILE(
"Not enough valid or required actuator torque handles were present. \n{}"),
330 if (!actuator_force_.empty() && actuator_force_.size() != 2)
334 FMT_COMPILE(
"Not enough valid or required actuator force handles were present. \n{}"),
337 if (!actuator_absolute_position_.empty() && actuator_absolute_position_.size() != 2)
342 "Not enough valid or required actuator absolute position handles were "
347 if (joint_position_.size() != actuator_position_.size())
351 FMT_COMPILE(
"Pair-wise mismatch on position interfaces. \n{}"),
get_handles_info()));
353 if (joint_velocity_.size() != actuator_velocity_.size())
357 FMT_COMPILE(
"Pair-wise mismatch on velocity interfaces. \n{}"),
get_handles_info()));
359 if (joint_effort_.size() != actuator_effort_.size())
363 FMT_COMPILE(
"Pair-wise mismatch on effort interfaces. \n{}"),
get_handles_info()));
365 if (joint_torque_.size() != actuator_torque_.size())
369 FMT_COMPILE(
"Pair-wise mismatch on torque interfaces. \n{}"),
get_handles_info()));
371 if (joint_force_.size() != actuator_force_.size())
374 fmt::format(FMT_COMPILE(
"Pair-wise mismatch on force interfaces. \n{}"),
get_handles_info()));
376 if (joint_absolute_position_.size() != actuator_absolute_position_.size())
380 FMT_COMPILE(
"Pair-wise mismatch on absolute position interfaces. \n{}"),
387 const auto & ar = actuator_reduction_;
388 const auto & jr = joint_reduction_;
390 auto & act_pos = actuator_position_;
391 auto & joint_pos = joint_position_;
394 assert(act_pos[0] && act_pos[1] && joint_pos[0] && joint_pos[1]);
396 joint_pos[0].set_value(
397 (act_pos[0].get_value() / ar[0] + act_pos[1].get_value() / ar[1]) / (2.0 * jr[0]) +
399 joint_pos[1].set_value(
400 (act_pos[0].get_value() / ar[0] - act_pos[1].get_value() / ar[1]) / (2.0 * jr[1]) +
404 auto & act_vel = actuator_velocity_;
405 auto & joint_vel = joint_velocity_;
408 assert(act_vel[0] && act_vel[1] && joint_vel[0] && joint_vel[1]);
410 joint_vel[0].set_value(
411 (act_vel[0].get_value() / ar[0] + act_vel[1].get_value() / ar[1]) / (2.0 * jr[0]));
412 joint_vel[1].set_value(
413 (act_vel[0].get_value() / ar[0] - act_vel[1].get_value() / ar[1]) / (2.0 * jr[1]));
416 auto & act_eff = actuator_effort_;
417 auto & joint_eff = joint_effort_;
420 assert(act_eff[0] && act_eff[1] && joint_eff[0] && joint_eff[1]);
422 joint_eff[0].set_value(
423 jr[0] * (act_eff[0].get_value() * ar[0] + act_eff[1].get_value() * ar[1]));
424 joint_eff[1].set_value(
425 jr[1] * (act_eff[0].get_value() * ar[0] - act_eff[1].get_value() * ar[1]));
428 auto & act_tor = actuator_torque_;
429 auto & joint_tor = joint_torque_;
432 assert(act_tor[0] && act_tor[1] && joint_tor[0] && joint_tor[1]);
434 joint_tor[0].set_value(
435 jr[0] * (act_tor[0].get_value() * ar[0] + act_tor[1].get_value() * ar[1]));
436 joint_tor[1].set_value(
437 jr[1] * (act_tor[0].get_value() * ar[0] - act_tor[1].get_value() * ar[1]));
440 auto & act_for = actuator_force_;
441 auto & joint_for = joint_force_;
444 assert(act_for[0] && act_for[1] && joint_for[0] && joint_for[1]);
446 joint_for[0].set_value(
447 jr[0] * (act_for[0].get_value() * ar[0] + act_for[1].get_value() * ar[1]));
448 joint_for[1].set_value(
449 jr[1] * (act_for[0].get_value() * ar[0] - act_for[1].get_value() * ar[1]));
452 auto & act_abs_pos = actuator_absolute_position_;
453 auto & joint_abs_pos = joint_absolute_position_;
456 assert(act_abs_pos[0] && act_abs_pos[1] && joint_abs_pos[0] && joint_abs_pos[1]);
458 joint_abs_pos[0].set_value(
459 (act_abs_pos[0].get_value() / ar[0] + act_abs_pos[1].get_value() / ar[1]) / (2.0 * jr[0]) +
461 joint_abs_pos[1].set_value(
462 (act_abs_pos[0].get_value() / ar[0] - act_abs_pos[1].get_value() / ar[1]) / (2.0 * jr[1]) +
469 const auto & ar = actuator_reduction_;
470 const auto & jr = joint_reduction_;
472 auto & act_pos = actuator_position_;
473 auto & joint_pos = joint_position_;
476 assert(act_pos[0] && act_pos[1] && joint_pos[0] && joint_pos[1]);
478 double joints_offset_applied[2] = {
479 joint_pos[0].get_value() - joint_offset_[0], joint_pos[1].get_value() - joint_offset_[1]};
480 act_pos[0].set_value(
481 (joints_offset_applied[0] * jr[0] + joints_offset_applied[1] * jr[1]) * ar[0]);
482 act_pos[1].set_value(
483 (joints_offset_applied[0] * jr[0] - joints_offset_applied[1] * jr[1]) * ar[1]);
486 auto & act_vel = actuator_velocity_;
487 auto & joint_vel = joint_velocity_;
490 assert(act_vel[0] && act_vel[1] && joint_vel[0] && joint_vel[1]);
492 act_vel[0].set_value(
493 (joint_vel[0].get_value() * jr[0] + joint_vel[1].get_value() * jr[1]) * ar[0]);
494 act_vel[1].set_value(
495 (joint_vel[0].get_value() * jr[0] - joint_vel[1].get_value() * jr[1]) * ar[1]);
498 auto & act_eff = actuator_effort_;
499 auto & joint_eff = joint_effort_;
502 assert(act_eff[0] && act_eff[1] && joint_eff[0] && joint_eff[1]);
504 act_eff[0].set_value(
505 (joint_eff[0].get_value() / jr[0] + joint_eff[1].get_value() / jr[1]) / (2.0 * ar[0]));
506 act_eff[1].set_value(
507 (joint_eff[0].get_value() / jr[0] - joint_eff[1].get_value() / jr[1]) / (2.0 * ar[1]));
510 auto & act_tor = actuator_torque_;
511 auto & joint_tor = joint_torque_;
514 assert(act_tor[0] && act_tor[1] && joint_tor[0] && joint_tor[1]);
516 act_tor[0].set_value(
517 (joint_tor[0].get_value() / jr[0] + joint_tor[1].get_value() / jr[1]) / (2.0 * ar[0]));
518 act_tor[1].set_value(
519 (joint_tor[0].get_value() / jr[0] - joint_tor[1].get_value() / jr[1]) / (2.0 * ar[1]));
522 auto & act_for = actuator_force_;
523 auto & joint_for = joint_force_;
526 assert(act_for[0] && act_for[1] && joint_for[0] && joint_for[1]);
528 act_for[0].set_value(
529 (joint_for[0].get_value() / jr[0] + joint_for[1].get_value() / jr[1]) / (2.0 * ar[0]));
530 act_for[1].set_value(
531 (joint_for[0].get_value() / jr[0] - joint_for[1].get_value() / jr[1]) / (2.0 * ar[1]));
539 "Got the following handles:\n"
540 "Joint position: {}, Actuator position: {}\n"
541 "Joint velocity: {}, Actuator velocity: {}\n"
542 "Joint effort: {}, Actuator effort: {}\n"
543 "Joint torque: {}, Actuator torque: {}\n"
544 "Joint force: {}, Actuator force: {}\n"
545 "Joint absolute position: {}, Actuator absolute position: {}"),
546 to_string(get_names(joint_position_)), to_string(get_names(actuator_position_)),
547 to_string(get_names(joint_velocity_)), to_string(get_names(actuator_velocity_)),
548 to_string(get_names(joint_effort_)), to_string(get_names(actuator_effort_)),
549 to_string(get_names(joint_torque_)), to_string(get_names(actuator_torque_)),
550 to_string(get_names(joint_force_)), to_string(get_names(actuator_force_)),
551 to_string(get_names(joint_absolute_position_)),
552 to_string(get_names(actuator_absolute_position_)));