122 const std::vector<double> & actuator_reduction,
const std::vector<double> & joint_reduction,
123 const std::vector<double> & joint_offset = {0.0, 0.0});
131 const std::vector<JointHandle> & joint_handles,
132 const std::vector<ActuatorHandle> & actuator_handles)
override;
153 const std::vector<double> & get_actuator_reduction()
const {
return actuator_reduction_; }
154 const std::vector<double> & get_joint_reduction()
const {
return joint_reduction_; }
155 const std::vector<double> & get_joint_offset()
const {
return joint_offset_; }
175 std::vector<double> actuator_reduction_;
176 std::vector<double> joint_reduction_;
177 std::vector<double> joint_offset_;
179 std::vector<JointHandle> joint_position_;
180 std::vector<JointHandle> joint_velocity_;
181 std::vector<JointHandle> joint_effort_;
182 std::vector<JointHandle> joint_torque_;
183 std::vector<JointHandle> joint_force_;
184 std::vector<JointHandle> joint_absolute_position_;
186 std::vector<ActuatorHandle> actuator_position_;
187 std::vector<ActuatorHandle> actuator_velocity_;
188 std::vector<ActuatorHandle> actuator_effort_;
189 std::vector<ActuatorHandle> actuator_torque_;
190 std::vector<ActuatorHandle> actuator_force_;
191 std::vector<ActuatorHandle> actuator_absolute_position_;
195 const std::vector<double> & actuator_reduction,
const std::vector<double> & joint_reduction,
196 const std::vector<double> & joint_offset)
197: actuator_reduction_(actuator_reduction),
198 joint_reduction_(joint_reduction),
199 joint_offset_(joint_offset)
205 throw Exception(
"Reduction and offset vectors must have size 2.");
209 0.0 == actuator_reduction_[0] || 0.0 == actuator_reduction_[1] || 0.0 == joint_reduction_[0] ||
210 0.0 == joint_reduction_[1])
212 throw Exception(
"Transmission reduction ratios cannot be zero.");
217 const std::vector<JointHandle> & joint_handles,
218 const std::vector<ActuatorHandle> & actuator_handles)
220 if (joint_handles.empty())
222 throw Exception(
"No joint handles were passed in");
225 if (actuator_handles.empty())
227 throw Exception(
"No actuator handles were passed in");
230 const auto joint_names = get_names(joint_handles);
231 if (joint_names.size() != 2)
235 FMT_COMPILE(
"There should be exactly two unique joint names but was given '{}'."),
236 to_string(joint_names)));
238 const auto actuator_names = get_names(actuator_handles);
239 if (actuator_names.size() != 2)
243 FMT_COMPILE(
"There should be exactly two unique actuator names but was given '{}'."),
244 to_string(actuator_names)));
254 joint_absolute_position_ =
255 get_ordered_handles(joint_handles, joint_names, HW_IF_ABSOLUTE_POSITION);
257 if (!joint_position_.empty() && joint_position_.size() != 2)
261 FMT_COMPILE(
"Not enough valid or required joint position handles were present. \n{}"),
264 if (!joint_velocity_.empty() && joint_velocity_.size() != 2)
268 FMT_COMPILE(
"Not enough valid or required joint velocity handles were present. \n{}"),
271 if (!joint_effort_.empty() && joint_effort_.size() != 2)
275 FMT_COMPILE(
"Not enough valid or required joint effort handles were present. \n{}"),
278 if (!joint_torque_.empty() && joint_torque_.size() != 2)
282 FMT_COMPILE(
"Not enough valid or required joint torque handles were present. \n{}"),
285 if (!joint_force_.empty() && joint_force_.size() != 2)
289 FMT_COMPILE(
"Not enough valid or required joint force handles were present. \n{}"),
292 if (!joint_absolute_position_.empty() && joint_absolute_position_.size() != 2)
297 "Not enough valid or required joint absolute position handles were present. \n{}"),
311 actuator_absolute_position_ =
312 get_ordered_handles(actuator_handles, actuator_names, HW_IF_ABSOLUTE_POSITION);
314 if (!actuator_position_.empty() && actuator_position_.size() != 2)
318 FMT_COMPILE(
"Not enough valid or required actuator position handles were present. \n{}"),
321 if (!actuator_velocity_.empty() && actuator_velocity_.size() != 2)
325 FMT_COMPILE(
"Not enough valid or required actuator velocity handles were present. \n{}"),
328 if (!actuator_effort_.empty() && actuator_effort_.size() != 2)
332 FMT_COMPILE(
"Not enough valid or required actuator effort handles were present. \n{}"),
335 if (!actuator_torque_.empty() && actuator_torque_.size() != 2)
339 FMT_COMPILE(
"Not enough valid or required actuator torque handles were present. \n{}"),
342 if (!actuator_force_.empty() && actuator_force_.size() != 2)
346 FMT_COMPILE(
"Not enough valid or required actuator force handles were present. \n{}"),
349 if (!actuator_absolute_position_.empty() && actuator_absolute_position_.size() != 2)
354 "Not enough valid or required actuator absolute position handles were "
360 !joint_position_.empty() && !actuator_position_.empty() &&
361 joint_position_.size() != actuator_position_.size())
365 FMT_COMPILE(
"Pair-wise mismatch on position interfaces. \n{}"),
get_handles_info()));
368 !joint_velocity_.empty() && !actuator_velocity_.empty() &&
369 joint_velocity_.size() != actuator_velocity_.size())
373 FMT_COMPILE(
"Pair-wise mismatch on velocity interfaces. \n{}"),
get_handles_info()));
376 !joint_effort_.empty() && !actuator_effort_.empty() &&
377 joint_effort_.size() != actuator_effort_.size())
381 FMT_COMPILE(
"Pair-wise mismatch on effort interfaces. \n{}"),
get_handles_info()));
384 !joint_torque_.empty() && !actuator_torque_.empty() &&
385 joint_torque_.size() != actuator_torque_.size())
389 FMT_COMPILE(
"Pair-wise mismatch on torque interfaces. \n{}"),
get_handles_info()));
392 !joint_force_.empty() && !actuator_force_.empty() &&
393 joint_force_.size() != actuator_force_.size())
396 fmt::format(FMT_COMPILE(
"Pair-wise mismatch on force interfaces. \n{}"),
get_handles_info()));
399 !joint_absolute_position_.empty() && !actuator_absolute_position_.empty() &&
400 joint_absolute_position_.size() != actuator_absolute_position_.size())
404 FMT_COMPILE(
"Pair-wise mismatch on absolute position interfaces. \n{}"),
409 if (!((!joint_position_.empty() && !actuator_position_.empty() &&
410 joint_position_.size() == actuator_position_.size()) ||
411 (!joint_velocity_.empty() && !actuator_velocity_.empty() &&
412 joint_velocity_.size() == actuator_velocity_.size()) ||
413 (!joint_effort_.empty() && !actuator_effort_.empty() &&
414 joint_effort_.size() == actuator_effort_.size()) ||
415 (!joint_torque_.empty() && !actuator_torque_.empty() &&
416 joint_torque_.size() == actuator_torque_.size()) ||
417 (!joint_force_.empty() && !actuator_force_.empty() &&
418 joint_force_.size() == actuator_force_.size()) ||
419 (!joint_absolute_position_.empty() && !actuator_absolute_position_.empty() &&
420 joint_absolute_position_.size() == actuator_absolute_position_.size())))
424 FMT_COMPILE(
"No pair-wise interface available between joints and actuators. \n{}"),
431 const auto & ar = actuator_reduction_;
432 const auto & jr = joint_reduction_;
434 auto & act_pos = actuator_position_;
435 auto & joint_pos = joint_position_;
438 assert(act_pos[0] && act_pos[1] && joint_pos[0] && joint_pos[1]);
440 joint_pos[0].set_value(
441 (act_pos[0].get_value() / ar[0] + act_pos[1].get_value() / ar[1]) / (2.0 * jr[0]) +
443 joint_pos[1].set_value(
444 (act_pos[0].get_value() / ar[0] - act_pos[1].get_value() / ar[1]) / (2.0 * jr[1]) +
448 auto & act_vel = actuator_velocity_;
449 auto & joint_vel = joint_velocity_;
452 assert(act_vel[0] && act_vel[1] && joint_vel[0] && joint_vel[1]);
454 joint_vel[0].set_value(
455 (act_vel[0].get_value() / ar[0] + act_vel[1].get_value() / ar[1]) / (2.0 * jr[0]));
456 joint_vel[1].set_value(
457 (act_vel[0].get_value() / ar[0] - act_vel[1].get_value() / ar[1]) / (2.0 * jr[1]));
460 auto & act_eff = actuator_effort_;
461 auto & joint_eff = joint_effort_;
464 assert(act_eff[0] && act_eff[1] && joint_eff[0] && joint_eff[1]);
466 joint_eff[0].set_value(
467 jr[0] * (act_eff[0].get_value() * ar[0] + act_eff[1].get_value() * ar[1]));
468 joint_eff[1].set_value(
469 jr[1] * (act_eff[0].get_value() * ar[0] - act_eff[1].get_value() * ar[1]));
472 auto & act_tor = actuator_torque_;
473 auto & joint_tor = joint_torque_;
476 assert(act_tor[0] && act_tor[1] && joint_tor[0] && joint_tor[1]);
478 joint_tor[0].set_value(
479 jr[0] * (act_tor[0].get_value() * ar[0] + act_tor[1].get_value() * ar[1]));
480 joint_tor[1].set_value(
481 jr[1] * (act_tor[0].get_value() * ar[0] - act_tor[1].get_value() * ar[1]));
484 auto & act_for = actuator_force_;
485 auto & joint_for = joint_force_;
488 assert(act_for[0] && act_for[1] && joint_for[0] && joint_for[1]);
490 joint_for[0].set_value(
491 jr[0] * (act_for[0].get_value() * ar[0] + act_for[1].get_value() * ar[1]));
492 joint_for[1].set_value(
493 jr[1] * (act_for[0].get_value() * ar[0] - act_for[1].get_value() * ar[1]));
496 auto & act_abs_pos = actuator_absolute_position_;
497 auto & joint_abs_pos = joint_absolute_position_;
500 assert(act_abs_pos[0] && act_abs_pos[1] && joint_abs_pos[0] && joint_abs_pos[1]);
502 joint_abs_pos[0].set_value(
503 (act_abs_pos[0].get_value() / ar[0] + act_abs_pos[1].get_value() / ar[1]) / (2.0 * jr[0]) +
505 joint_abs_pos[1].set_value(
506 (act_abs_pos[0].get_value() / ar[0] - act_abs_pos[1].get_value() / ar[1]) / (2.0 * jr[1]) +
513 const auto & ar = actuator_reduction_;
514 const auto & jr = joint_reduction_;
516 auto & act_pos = actuator_position_;
517 auto & joint_pos = joint_position_;
520 assert(act_pos[0] && act_pos[1] && joint_pos[0] && joint_pos[1]);
522 double joints_offset_applied[2] = {
523 joint_pos[0].get_value() - joint_offset_[0], joint_pos[1].get_value() - joint_offset_[1]};
524 act_pos[0].set_value(
525 (joints_offset_applied[0] * jr[0] + joints_offset_applied[1] * jr[1]) * ar[0]);
526 act_pos[1].set_value(
527 (joints_offset_applied[0] * jr[0] - joints_offset_applied[1] * jr[1]) * ar[1]);
530 auto & act_vel = actuator_velocity_;
531 auto & joint_vel = joint_velocity_;
534 assert(act_vel[0] && act_vel[1] && joint_vel[0] && joint_vel[1]);
536 act_vel[0].set_value(
537 (joint_vel[0].get_value() * jr[0] + joint_vel[1].get_value() * jr[1]) * ar[0]);
538 act_vel[1].set_value(
539 (joint_vel[0].get_value() * jr[0] - joint_vel[1].get_value() * jr[1]) * ar[1]);
542 auto & act_eff = actuator_effort_;
543 auto & joint_eff = joint_effort_;
546 assert(act_eff[0] && act_eff[1] && joint_eff[0] && joint_eff[1]);
548 act_eff[0].set_value(
549 (joint_eff[0].get_value() / jr[0] + joint_eff[1].get_value() / jr[1]) / (2.0 * ar[0]));
550 act_eff[1].set_value(
551 (joint_eff[0].get_value() / jr[0] - joint_eff[1].get_value() / jr[1]) / (2.0 * ar[1]));
554 auto & act_tor = actuator_torque_;
555 auto & joint_tor = joint_torque_;
558 assert(act_tor[0] && act_tor[1] && joint_tor[0] && joint_tor[1]);
560 act_tor[0].set_value(
561 (joint_tor[0].get_value() / jr[0] + joint_tor[1].get_value() / jr[1]) / (2.0 * ar[0]));
562 act_tor[1].set_value(
563 (joint_tor[0].get_value() / jr[0] - joint_tor[1].get_value() / jr[1]) / (2.0 * ar[1]));
566 auto & act_for = actuator_force_;
567 auto & joint_for = joint_force_;
570 assert(act_for[0] && act_for[1] && joint_for[0] && joint_for[1]);
572 act_for[0].set_value(
573 (joint_for[0].get_value() / jr[0] + joint_for[1].get_value() / jr[1]) / (2.0 * ar[0]));
574 act_for[1].set_value(
575 (joint_for[0].get_value() / jr[0] - joint_for[1].get_value() / jr[1]) / (2.0 * ar[1]));
583 "Got the following handles:\n"
584 "Joint position: {}, Actuator position: {}\n"
585 "Joint velocity: {}, Actuator velocity: {}\n"
586 "Joint effort: {}, Actuator effort: {}\n"
587 "Joint torque: {}, Actuator torque: {}\n"
588 "Joint force: {}, Actuator force: {}\n"
589 "Joint absolute position: {}, Actuator absolute position: {}"),
590 to_string(get_names(joint_position_)), to_string(get_names(actuator_position_)),
591 to_string(get_names(joint_velocity_)), to_string(get_names(actuator_velocity_)),
592 to_string(get_names(joint_effort_)), to_string(get_names(actuator_effort_)),
593 to_string(get_names(joint_torque_)), to_string(get_names(actuator_torque_)),
594 to_string(get_names(joint_force_)), to_string(get_names(actuator_force_)),
595 to_string(get_names(joint_absolute_position_)),
596 to_string(get_names(actuator_absolute_position_)));