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 "
348 !joint_position_.empty() && !actuator_position_.empty() &&
349 joint_position_.size() != actuator_position_.size())
353 FMT_COMPILE(
"Pair-wise mismatch on position interfaces. \n{}"),
get_handles_info()));
356 !joint_velocity_.empty() && !actuator_velocity_.empty() &&
357 joint_velocity_.size() != actuator_velocity_.size())
361 FMT_COMPILE(
"Pair-wise mismatch on velocity interfaces. \n{}"),
get_handles_info()));
364 !joint_effort_.empty() && !actuator_effort_.empty() &&
365 joint_effort_.size() != actuator_effort_.size())
369 FMT_COMPILE(
"Pair-wise mismatch on effort interfaces. \n{}"),
get_handles_info()));
372 !joint_torque_.empty() && !actuator_torque_.empty() &&
373 joint_torque_.size() != actuator_torque_.size())
377 FMT_COMPILE(
"Pair-wise mismatch on torque interfaces. \n{}"),
get_handles_info()));
380 !joint_force_.empty() && !actuator_force_.empty() &&
381 joint_force_.size() != actuator_force_.size())
384 fmt::format(FMT_COMPILE(
"Pair-wise mismatch on force interfaces. \n{}"),
get_handles_info()));
387 !joint_absolute_position_.empty() && !actuator_absolute_position_.empty() &&
388 joint_absolute_position_.size() != actuator_absolute_position_.size())
392 FMT_COMPILE(
"Pair-wise mismatch on absolute position interfaces. \n{}"),
397 if (!((!joint_position_.empty() && !actuator_position_.empty() &&
398 joint_position_.size() == actuator_position_.size()) ||
399 (!joint_velocity_.empty() && !actuator_velocity_.empty() &&
400 joint_velocity_.size() == actuator_velocity_.size()) ||
401 (!joint_effort_.empty() && !actuator_effort_.empty() &&
402 joint_effort_.size() == actuator_effort_.size()) ||
403 (!joint_torque_.empty() && !actuator_torque_.empty() &&
404 joint_torque_.size() == actuator_torque_.size()) ||
405 (!joint_force_.empty() && !actuator_force_.empty() &&
406 joint_force_.size() == actuator_force_.size()) ||
407 (!joint_absolute_position_.empty() && !actuator_absolute_position_.empty() &&
408 joint_absolute_position_.size() == actuator_absolute_position_.size())))
412 FMT_COMPILE(
"No pair-wise interface available between joints and actuators. \n{}"),
419 const auto & ar = actuator_reduction_;
420 const auto & jr = joint_reduction_;
422 auto & act_pos = actuator_position_;
423 auto & joint_pos = joint_position_;
426 assert(act_pos[0] && act_pos[1] && joint_pos[0] && joint_pos[1]);
428 joint_pos[0].set_value(
429 (act_pos[0].get_value() / ar[0] + act_pos[1].get_value() / ar[1]) / (2.0 * jr[0]) +
431 joint_pos[1].set_value(
432 (act_pos[0].get_value() / ar[0] - act_pos[1].get_value() / ar[1]) / (2.0 * jr[1]) +
436 auto & act_vel = actuator_velocity_;
437 auto & joint_vel = joint_velocity_;
440 assert(act_vel[0] && act_vel[1] && joint_vel[0] && joint_vel[1]);
442 joint_vel[0].set_value(
443 (act_vel[0].get_value() / ar[0] + act_vel[1].get_value() / ar[1]) / (2.0 * jr[0]));
444 joint_vel[1].set_value(
445 (act_vel[0].get_value() / ar[0] - act_vel[1].get_value() / ar[1]) / (2.0 * jr[1]));
448 auto & act_eff = actuator_effort_;
449 auto & joint_eff = joint_effort_;
452 assert(act_eff[0] && act_eff[1] && joint_eff[0] && joint_eff[1]);
454 joint_eff[0].set_value(
455 jr[0] * (act_eff[0].get_value() * ar[0] + act_eff[1].get_value() * ar[1]));
456 joint_eff[1].set_value(
457 jr[1] * (act_eff[0].get_value() * ar[0] - act_eff[1].get_value() * ar[1]));
460 auto & act_tor = actuator_torque_;
461 auto & joint_tor = joint_torque_;
464 assert(act_tor[0] && act_tor[1] && joint_tor[0] && joint_tor[1]);
466 joint_tor[0].set_value(
467 jr[0] * (act_tor[0].get_value() * ar[0] + act_tor[1].get_value() * ar[1]));
468 joint_tor[1].set_value(
469 jr[1] * (act_tor[0].get_value() * ar[0] - act_tor[1].get_value() * ar[1]));
472 auto & act_for = actuator_force_;
473 auto & joint_for = joint_force_;
476 assert(act_for[0] && act_for[1] && joint_for[0] && joint_for[1]);
478 joint_for[0].set_value(
479 jr[0] * (act_for[0].get_value() * ar[0] + act_for[1].get_value() * ar[1]));
480 joint_for[1].set_value(
481 jr[1] * (act_for[0].get_value() * ar[0] - act_for[1].get_value() * ar[1]));
484 auto & act_abs_pos = actuator_absolute_position_;
485 auto & joint_abs_pos = joint_absolute_position_;
488 assert(act_abs_pos[0] && act_abs_pos[1] && joint_abs_pos[0] && joint_abs_pos[1]);
490 joint_abs_pos[0].set_value(
491 (act_abs_pos[0].get_value() / ar[0] + act_abs_pos[1].get_value() / ar[1]) / (2.0 * jr[0]) +
493 joint_abs_pos[1].set_value(
494 (act_abs_pos[0].get_value() / ar[0] - act_abs_pos[1].get_value() / ar[1]) / (2.0 * jr[1]) +
501 const auto & ar = actuator_reduction_;
502 const auto & jr = joint_reduction_;
504 auto & act_pos = actuator_position_;
505 auto & joint_pos = joint_position_;
508 assert(act_pos[0] && act_pos[1] && joint_pos[0] && joint_pos[1]);
510 double joints_offset_applied[2] = {
511 joint_pos[0].get_value() - joint_offset_[0], joint_pos[1].get_value() - joint_offset_[1]};
512 act_pos[0].set_value(
513 (joints_offset_applied[0] * jr[0] + joints_offset_applied[1] * jr[1]) * ar[0]);
514 act_pos[1].set_value(
515 (joints_offset_applied[0] * jr[0] - joints_offset_applied[1] * jr[1]) * ar[1]);
518 auto & act_vel = actuator_velocity_;
519 auto & joint_vel = joint_velocity_;
522 assert(act_vel[0] && act_vel[1] && joint_vel[0] && joint_vel[1]);
524 act_vel[0].set_value(
525 (joint_vel[0].get_value() * jr[0] + joint_vel[1].get_value() * jr[1]) * ar[0]);
526 act_vel[1].set_value(
527 (joint_vel[0].get_value() * jr[0] - joint_vel[1].get_value() * jr[1]) * ar[1]);
530 auto & act_eff = actuator_effort_;
531 auto & joint_eff = joint_effort_;
534 assert(act_eff[0] && act_eff[1] && joint_eff[0] && joint_eff[1]);
536 act_eff[0].set_value(
537 (joint_eff[0].get_value() / jr[0] + joint_eff[1].get_value() / jr[1]) / (2.0 * ar[0]));
538 act_eff[1].set_value(
539 (joint_eff[0].get_value() / jr[0] - joint_eff[1].get_value() / jr[1]) / (2.0 * ar[1]));
542 auto & act_tor = actuator_torque_;
543 auto & joint_tor = joint_torque_;
546 assert(act_tor[0] && act_tor[1] && joint_tor[0] && joint_tor[1]);
548 act_tor[0].set_value(
549 (joint_tor[0].get_value() / jr[0] + joint_tor[1].get_value() / jr[1]) / (2.0 * ar[0]));
550 act_tor[1].set_value(
551 (joint_tor[0].get_value() / jr[0] - joint_tor[1].get_value() / jr[1]) / (2.0 * ar[1]));
554 auto & act_for = actuator_force_;
555 auto & joint_for = joint_force_;
558 assert(act_for[0] && act_for[1] && joint_for[0] && joint_for[1]);
560 act_for[0].set_value(
561 (joint_for[0].get_value() / jr[0] + joint_for[1].get_value() / jr[1]) / (2.0 * ar[0]));
562 act_for[1].set_value(
563 (joint_for[0].get_value() / jr[0] - joint_for[1].get_value() / jr[1]) / (2.0 * ar[1]));
571 "Got the following handles:\n"
572 "Joint position: {}, Actuator position: {}\n"
573 "Joint velocity: {}, Actuator velocity: {}\n"
574 "Joint effort: {}, Actuator effort: {}\n"
575 "Joint torque: {}, Actuator torque: {}\n"
576 "Joint force: {}, Actuator force: {}\n"
577 "Joint absolute position: {}, Actuator absolute position: {}"),
578 to_string(get_names(joint_position_)), to_string(get_names(actuator_position_)),
579 to_string(get_names(joint_velocity_)), to_string(get_names(actuator_velocity_)),
580 to_string(get_names(joint_effort_)), to_string(get_names(actuator_effort_)),
581 to_string(get_names(joint_torque_)), to_string(get_names(actuator_torque_)),
582 to_string(get_names(joint_force_)), to_string(get_names(actuator_force_)),
583 to_string(get_names(joint_absolute_position_)),
584 to_string(get_names(actuator_absolute_position_)));