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_; }
177 std::vector<double> actuator_reduction_;
178 std::vector<double> joint_reduction_;
179 std::vector<double> joint_offset_;
181 std::vector<JointHandle> joint_position_;
182 std::vector<JointHandle> joint_velocity_;
183 std::vector<JointHandle> joint_effort_;
184 std::vector<JointHandle> joint_torque_;
185 std::vector<JointHandle> joint_force_;
186 std::vector<JointHandle> joint_absolute_position_;
188 std::vector<ActuatorHandle> actuator_position_;
189 std::vector<ActuatorHandle> actuator_velocity_;
190 std::vector<ActuatorHandle> actuator_effort_;
191 std::vector<ActuatorHandle> actuator_torque_;
192 std::vector<ActuatorHandle> actuator_force_;
193 std::vector<ActuatorHandle> actuator_absolute_position_;
197 const std::vector<double> & actuator_reduction,
const std::vector<double> & joint_reduction,
198 const std::vector<double> & joint_offset)
199: actuator_reduction_(actuator_reduction),
200 joint_reduction_(joint_reduction),
201 joint_offset_(joint_offset)
207 throw Exception(
"Reduction and offset vectors must have size 2.");
211 0.0 == actuator_reduction_[0] || 0.0 == actuator_reduction_[1] || 0.0 == joint_reduction_[0] ||
212 0.0 == joint_reduction_[1])
214 throw Exception(
"Transmission reduction ratios cannot be zero.");
219 const std::vector<JointHandle> & joint_handles,
220 const std::vector<ActuatorHandle> & actuator_handles)
222 if (joint_handles.empty())
224 throw Exception(
"No joint handles were passed in");
227 if (actuator_handles.empty())
229 throw Exception(
"No actuator handles were passed in");
232 const auto joint_names = get_names(joint_handles);
233 if (joint_names.size() != 2)
237 FMT_COMPILE(
"There should be exactly two unique joint names but was given '{}'."),
238 to_string(joint_names)));
240 const auto actuator_names = get_names(actuator_handles);
241 if (actuator_names.size() != 2)
245 FMT_COMPILE(
"There should be exactly two unique actuator names but was given '{}'."),
246 to_string(actuator_names)));
256 joint_absolute_position_ =
259 if (!joint_position_.empty() && joint_position_.size() != 2)
263 FMT_COMPILE(
"Not enough valid or required joint position handles were present. \n{}"),
266 if (!joint_velocity_.empty() && joint_velocity_.size() != 2)
270 FMT_COMPILE(
"Not enough valid or required joint velocity handles were present. \n{}"),
273 if (!joint_effort_.empty() && joint_effort_.size() != 2)
277 FMT_COMPILE(
"Not enough valid or required joint effort handles were present. \n{}"),
280 if (!joint_torque_.empty() && joint_torque_.size() != 2)
284 FMT_COMPILE(
"Not enough valid or required joint torque handles were present. \n{}"),
287 if (!joint_force_.empty() && joint_force_.size() != 2)
291 FMT_COMPILE(
"Not enough valid or required joint force handles were present. \n{}"),
294 if (!joint_absolute_position_.empty() && joint_absolute_position_.size() != 2)
299 "Not enough valid or required joint absolute position handles were present. \n{}"),
313 actuator_absolute_position_ =
316 if (!actuator_position_.empty() && actuator_position_.size() != 2)
320 FMT_COMPILE(
"Not enough valid or required actuator position handles were present. \n{}"),
323 if (!actuator_velocity_.empty() && actuator_velocity_.size() != 2)
327 FMT_COMPILE(
"Not enough valid or required actuator velocity handles were present. \n{}"),
330 if (!actuator_effort_.empty() && actuator_effort_.size() != 2)
334 FMT_COMPILE(
"Not enough valid or required actuator effort handles were present. \n{}"),
337 if (!actuator_torque_.empty() && actuator_torque_.size() != 2)
341 FMT_COMPILE(
"Not enough valid or required actuator torque handles were present. \n{}"),
344 if (!actuator_force_.empty() && actuator_force_.size() != 2)
348 FMT_COMPILE(
"Not enough valid or required actuator force handles were present. \n{}"),
351 if (!actuator_absolute_position_.empty() && actuator_absolute_position_.size() != 2)
356 "Not enough valid or required actuator absolute position handles were "
362 !joint_position_.empty() && !actuator_position_.empty() &&
363 joint_position_.size() != actuator_position_.size())
367 FMT_COMPILE(
"Pair-wise mismatch on position interfaces. \n{}"),
get_handles_info()));
370 !joint_velocity_.empty() && !actuator_velocity_.empty() &&
371 joint_velocity_.size() != actuator_velocity_.size())
375 FMT_COMPILE(
"Pair-wise mismatch on velocity interfaces. \n{}"),
get_handles_info()));
378 !joint_effort_.empty() && !actuator_effort_.empty() &&
379 joint_effort_.size() != actuator_effort_.size())
383 FMT_COMPILE(
"Pair-wise mismatch on effort interfaces. \n{}"),
get_handles_info()));
386 !joint_torque_.empty() && !actuator_torque_.empty() &&
387 joint_torque_.size() != actuator_torque_.size())
391 FMT_COMPILE(
"Pair-wise mismatch on torque interfaces. \n{}"),
get_handles_info()));
394 !joint_force_.empty() && !actuator_force_.empty() &&
395 joint_force_.size() != actuator_force_.size())
398 fmt::format(FMT_COMPILE(
"Pair-wise mismatch on force interfaces. \n{}"),
get_handles_info()));
401 !joint_absolute_position_.empty() && !actuator_absolute_position_.empty() &&
402 joint_absolute_position_.size() != actuator_absolute_position_.size())
406 FMT_COMPILE(
"Pair-wise mismatch on absolute position interfaces. \n{}"),
411 if (!((!joint_position_.empty() && !actuator_position_.empty() &&
412 joint_position_.size() == actuator_position_.size()) ||
413 (!joint_velocity_.empty() && !actuator_velocity_.empty() &&
414 joint_velocity_.size() == actuator_velocity_.size()) ||
415 (!joint_effort_.empty() && !actuator_effort_.empty() &&
416 joint_effort_.size() == actuator_effort_.size()) ||
417 (!joint_torque_.empty() && !actuator_torque_.empty() &&
418 joint_torque_.size() == actuator_torque_.size()) ||
419 (!joint_force_.empty() && !actuator_force_.empty() &&
420 joint_force_.size() == actuator_force_.size()) ||
421 (!joint_absolute_position_.empty() && !actuator_absolute_position_.empty() &&
422 joint_absolute_position_.size() == actuator_absolute_position_.size())))
426 FMT_COMPILE(
"No pair-wise interface available between joints and actuators. \n{}"),
433 const auto & ar = actuator_reduction_;
434 const auto & jr = joint_reduction_;
436 auto & act_pos = actuator_position_;
437 auto & joint_pos = joint_position_;
440 assert(act_pos[0] && act_pos[1] && joint_pos[0] && joint_pos[1]);
442 joint_pos[0].set_value(
443 (act_pos[0].get_value() / ar[0] + act_pos[1].get_value() / ar[1]) / (2.0 * jr[0]) +
445 joint_pos[1].set_value(
446 (act_pos[0].get_value() / ar[0] - act_pos[1].get_value() / ar[1]) / (2.0 * jr[1]) +
450 auto & act_vel = actuator_velocity_;
451 auto & joint_vel = joint_velocity_;
454 assert(act_vel[0] && act_vel[1] && joint_vel[0] && joint_vel[1]);
456 joint_vel[0].set_value(
457 (act_vel[0].get_value() / ar[0] + act_vel[1].get_value() / ar[1]) / (2.0 * jr[0]));
458 joint_vel[1].set_value(
459 (act_vel[0].get_value() / ar[0] - act_vel[1].get_value() / ar[1]) / (2.0 * jr[1]));
462 auto & act_eff = actuator_effort_;
463 auto & joint_eff = joint_effort_;
466 assert(act_eff[0] && act_eff[1] && joint_eff[0] && joint_eff[1]);
468 joint_eff[0].set_value(
469 jr[0] * (act_eff[0].get_value() * ar[0] + act_eff[1].get_value() * ar[1]));
470 joint_eff[1].set_value(
471 jr[1] * (act_eff[0].get_value() * ar[0] - act_eff[1].get_value() * ar[1]));
474 auto & act_tor = actuator_torque_;
475 auto & joint_tor = joint_torque_;
478 assert(act_tor[0] && act_tor[1] && joint_tor[0] && joint_tor[1]);
480 joint_tor[0].set_value(
481 jr[0] * (act_tor[0].get_value() * ar[0] + act_tor[1].get_value() * ar[1]));
482 joint_tor[1].set_value(
483 jr[1] * (act_tor[0].get_value() * ar[0] - act_tor[1].get_value() * ar[1]));
486 auto & act_for = actuator_force_;
487 auto & joint_for = joint_force_;
490 assert(act_for[0] && act_for[1] && joint_for[0] && joint_for[1]);
492 joint_for[0].set_value(
493 jr[0] * (act_for[0].get_value() * ar[0] + act_for[1].get_value() * ar[1]));
494 joint_for[1].set_value(
495 jr[1] * (act_for[0].get_value() * ar[0] - act_for[1].get_value() * ar[1]));
498 auto & act_abs_pos = actuator_absolute_position_;
499 auto & joint_abs_pos = joint_absolute_position_;
502 assert(act_abs_pos[0] && act_abs_pos[1] && joint_abs_pos[0] && joint_abs_pos[1]);
504 joint_abs_pos[0].set_value(
505 (act_abs_pos[0].get_value() / ar[0] + act_abs_pos[1].get_value() / ar[1]) / (2.0 * jr[0]) +
507 joint_abs_pos[1].set_value(
508 (act_abs_pos[0].get_value() / ar[0] - act_abs_pos[1].get_value() / ar[1]) / (2.0 * jr[1]) +
515 const auto & ar = actuator_reduction_;
516 const auto & jr = joint_reduction_;
518 auto & act_pos = actuator_position_;
519 auto & joint_pos = joint_position_;
522 assert(act_pos[0] && act_pos[1] && joint_pos[0] && joint_pos[1]);
524 double joints_offset_applied[2] = {
525 joint_pos[0].get_value() - joint_offset_[0], joint_pos[1].get_value() - joint_offset_[1]};
526 act_pos[0].set_value(
527 (joints_offset_applied[0] * jr[0] + joints_offset_applied[1] * jr[1]) * ar[0]);
528 act_pos[1].set_value(
529 (joints_offset_applied[0] * jr[0] - joints_offset_applied[1] * jr[1]) * ar[1]);
532 auto & act_vel = actuator_velocity_;
533 auto & joint_vel = joint_velocity_;
536 assert(act_vel[0] && act_vel[1] && joint_vel[0] && joint_vel[1]);
538 act_vel[0].set_value(
539 (joint_vel[0].get_value() * jr[0] + joint_vel[1].get_value() * jr[1]) * ar[0]);
540 act_vel[1].set_value(
541 (joint_vel[0].get_value() * jr[0] - joint_vel[1].get_value() * jr[1]) * ar[1]);
544 auto & act_eff = actuator_effort_;
545 auto & joint_eff = joint_effort_;
548 assert(act_eff[0] && act_eff[1] && joint_eff[0] && joint_eff[1]);
550 act_eff[0].set_value(
551 (joint_eff[0].get_value() / jr[0] + joint_eff[1].get_value() / jr[1]) / (2.0 * ar[0]));
552 act_eff[1].set_value(
553 (joint_eff[0].get_value() / jr[0] - joint_eff[1].get_value() / jr[1]) / (2.0 * ar[1]));
556 auto & act_tor = actuator_torque_;
557 auto & joint_tor = joint_torque_;
560 assert(act_tor[0] && act_tor[1] && joint_tor[0] && joint_tor[1]);
562 act_tor[0].set_value(
563 (joint_tor[0].get_value() / jr[0] + joint_tor[1].get_value() / jr[1]) / (2.0 * ar[0]));
564 act_tor[1].set_value(
565 (joint_tor[0].get_value() / jr[0] - joint_tor[1].get_value() / jr[1]) / (2.0 * ar[1]));
568 auto & act_for = actuator_force_;
569 auto & joint_for = joint_force_;
572 assert(act_for[0] && act_for[1] && joint_for[0] && joint_for[1]);
574 act_for[0].set_value(
575 (joint_for[0].get_value() / jr[0] + joint_for[1].get_value() / jr[1]) / (2.0 * ar[0]));
576 act_for[1].set_value(
577 (joint_for[0].get_value() / jr[0] - joint_for[1].get_value() / jr[1]) / (2.0 * ar[1]));
585 "Got the following handles:\n"
586 "Joint position: {}, Actuator position: {}\n"
587 "Joint velocity: {}, Actuator velocity: {}\n"
588 "Joint effort: {}, Actuator effort: {}\n"
589 "Joint torque: {}, Actuator torque: {}\n"
590 "Joint force: {}, Actuator force: {}\n"
591 "Joint absolute position: {}, Actuator absolute position: {}"),
592 to_string(get_names(joint_position_)), to_string(get_names(actuator_position_)),
593 to_string(get_names(joint_velocity_)), to_string(get_names(actuator_velocity_)),
594 to_string(get_names(joint_effort_)), to_string(get_names(actuator_effort_)),
595 to_string(get_names(joint_torque_)), to_string(get_names(actuator_torque_)),
596 to_string(get_names(joint_force_)), to_string(get_names(actuator_force_)),
597 to_string(get_names(joint_absolute_position_)),
598 to_string(get_names(actuator_absolute_position_)));