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_absolute_position_;
173 std::vector<ActuatorHandle> actuator_position_;
174 std::vector<ActuatorHandle> actuator_velocity_;
175 std::vector<ActuatorHandle> actuator_effort_;
176 std::vector<ActuatorHandle> actuator_torque_;
177 std::vector<ActuatorHandle> actuator_absolute_position_;
181 const std::vector<double> & actuator_reduction,
const std::vector<double> & joint_reduction,
182 const std::vector<double> & joint_offset)
183: actuator_reduction_(actuator_reduction),
184 joint_reduction_(joint_reduction),
185 joint_offset_(joint_offset)
191 throw Exception(
"Reduction and offset vectors must have size 2.");
195 0.0 == actuator_reduction_[0] || 0.0 == actuator_reduction_[1] || 0.0 == joint_reduction_[0] ||
196 0.0 == joint_reduction_[1])
198 throw Exception(
"Transmission reduction ratios cannot be zero.");
203 const std::vector<JointHandle> & joint_handles,
204 const std::vector<ActuatorHandle> & actuator_handles)
206 if (joint_handles.empty())
208 throw Exception(
"No joint handles were passed in");
211 if (actuator_handles.empty())
213 throw Exception(
"No actuator handles were passed in");
216 const auto joint_names = get_names(joint_handles);
217 if (joint_names.size() != 2)
221 FMT_COMPILE(
"There should be exactly two unique joint names but was given '{}'."),
222 to_string(joint_names)));
224 const auto actuator_names = get_names(actuator_handles);
225 if (actuator_names.size() != 2)
229 FMT_COMPILE(
"There should be exactly two unique actuator names but was given '{}'."),
230 to_string(actuator_names)));
239 joint_absolute_position_ =
243 joint_position_.size() != 2 && joint_velocity_.size() != 2 && joint_effort_.size() != 2 &&
244 joint_torque_.size() != 2 && joint_absolute_position_.size() != 2)
246 throw Exception(
"Not enough valid or required joint handles were presented.");
257 actuator_absolute_position_ =
261 actuator_position_.size() != 2 && actuator_velocity_.size() != 2 &&
262 actuator_effort_.size() != 2 && actuator_torque_.size() != 2 &&
263 actuator_absolute_position_.size() != 2)
267 FMT_COMPILE(
"Not enough valid or required actuator handles were presented. \n{}"),
272 joint_position_.size() != actuator_position_.size() &&
273 joint_velocity_.size() != actuator_velocity_.size() &&
274 joint_effort_.size() != actuator_effort_.size() &&
275 joint_torque_.size() != actuator_torque_.size() &&
276 joint_absolute_position_.size() != actuator_absolute_position_.size())
279 fmt::format(FMT_COMPILE(
"Pair-wise mismatch on interfaces. \n{}"),
get_handles_info()));
285 const auto & ar = actuator_reduction_;
286 const auto & jr = joint_reduction_;
288 auto & act_pos = actuator_position_;
289 auto & joint_pos = joint_position_;
292 assert(act_pos[0] && act_pos[1] && joint_pos[0] && joint_pos[1]);
294 joint_pos[0].set_value(
295 (act_pos[0].get_value() / ar[0] + act_pos[1].get_value() / ar[1]) / (2.0 * jr[0]) +
297 joint_pos[1].set_value(
298 (act_pos[0].get_value() / ar[0] - act_pos[1].get_value() / ar[1]) / (2.0 * jr[1]) +
302 auto & act_vel = actuator_velocity_;
303 auto & joint_vel = joint_velocity_;
306 assert(act_vel[0] && act_vel[1] && joint_vel[0] && joint_vel[1]);
308 joint_vel[0].set_value(
309 (act_vel[0].get_value() / ar[0] + act_vel[1].get_value() / ar[1]) / (2.0 * jr[0]));
310 joint_vel[1].set_value(
311 (act_vel[0].get_value() / ar[0] - act_vel[1].get_value() / ar[1]) / (2.0 * jr[1]));
314 auto & act_eff = actuator_effort_;
315 auto & joint_eff = joint_effort_;
318 assert(act_eff[0] && act_eff[1] && joint_eff[0] && joint_eff[1]);
320 joint_eff[0].set_value(
321 jr[0] * (act_eff[0].get_value() * ar[0] + act_eff[1].get_value() * ar[1]));
322 joint_eff[1].set_value(
323 jr[1] * (act_eff[0].get_value() * ar[0] - act_eff[1].get_value() * ar[1]));
326 auto & act_tor = actuator_torque_;
327 auto & joint_tor = joint_torque_;
330 assert(act_tor[0] && act_tor[1] && joint_tor[0] && joint_tor[1]);
332 joint_tor[0].set_value(
333 jr[0] * (act_tor[0].get_value() * ar[0] + act_tor[1].get_value() * ar[1]));
334 joint_tor[1].set_value(
335 jr[1] * (act_tor[0].get_value() * ar[0] - act_tor[1].get_value() * ar[1]));
338 auto & act_abs_pos = actuator_absolute_position_;
339 auto & joint_abs_pos = joint_absolute_position_;
342 assert(act_abs_pos[0] && act_abs_pos[1] && joint_abs_pos[0] && joint_abs_pos[1]);
344 joint_abs_pos[0].set_value(
345 (act_abs_pos[0].get_value() / ar[0] + act_abs_pos[1].get_value() / ar[1]) / (2.0 * jr[0]) +
347 joint_abs_pos[1].set_value(
348 (act_abs_pos[0].get_value() / ar[0] - act_abs_pos[1].get_value() / ar[1]) / (2.0 * jr[1]) +
355 const auto & ar = actuator_reduction_;
356 const auto & jr = joint_reduction_;
358 auto & act_pos = actuator_position_;
359 auto & joint_pos = joint_position_;
362 assert(act_pos[0] && act_pos[1] && joint_pos[0] && joint_pos[1]);
364 double joints_offset_applied[2] = {
365 joint_pos[0].get_value() - joint_offset_[0], joint_pos[1].get_value() - joint_offset_[1]};
366 act_pos[0].set_value(
367 (joints_offset_applied[0] * jr[0] + joints_offset_applied[1] * jr[1]) * ar[0]);
368 act_pos[1].set_value(
369 (joints_offset_applied[0] * jr[0] - joints_offset_applied[1] * jr[1]) * ar[1]);
372 auto & act_vel = actuator_velocity_;
373 auto & joint_vel = joint_velocity_;
376 assert(act_vel[0] && act_vel[1] && joint_vel[0] && joint_vel[1]);
378 act_vel[0].set_value(
379 (joint_vel[0].get_value() * jr[0] + joint_vel[1].get_value() * jr[1]) * ar[0]);
380 act_vel[1].set_value(
381 (joint_vel[0].get_value() * jr[0] - joint_vel[1].get_value() * jr[1]) * ar[1]);
384 auto & act_eff = actuator_effort_;
385 auto & joint_eff = joint_effort_;
388 assert(act_eff[0] && act_eff[1] && joint_eff[0] && joint_eff[1]);
390 act_eff[0].set_value(
391 (joint_eff[0].get_value() / jr[0] + joint_eff[1].get_value() / jr[1]) / (2.0 * ar[0]));
392 act_eff[1].set_value(
393 (joint_eff[0].get_value() / jr[0] - joint_eff[1].get_value() / jr[1]) / (2.0 * ar[1]));
396 auto & act_tor = actuator_torque_;
397 auto & joint_tor = joint_torque_;
400 assert(act_tor[0] && act_tor[1] && joint_tor[0] && joint_tor[1]);
402 act_tor[0].set_value(
403 (joint_tor[0].get_value() / jr[0] + joint_tor[1].get_value() / jr[1]) / (2.0 * ar[0]));
404 act_tor[1].set_value(
405 (joint_tor[0].get_value() / jr[0] - joint_tor[1].get_value() / jr[1]) / (2.0 * ar[1]));
413 "Got the following handles:\n"
414 "Joint position: {}, Actuator position: {}\n"
415 "Joint velocity: {}, Actuator velocity: {}\n"
416 "Joint effort: {}, Actuator effort: {}\n"
417 "Joint torque: {}, Actuator torque: {}\n"
418 "Joint absolute position: {}, Actuator absolute position: {}"),
419 to_string(get_names(joint_position_)), to_string(get_names(actuator_position_)),
420 to_string(get_names(joint_velocity_)), to_string(get_names(actuator_velocity_)),
421 to_string(get_names(joint_effort_)), to_string(get_names(actuator_effort_)),
422 to_string(get_names(joint_torque_)), to_string(get_names(actuator_torque_)),
423 to_string(get_names(joint_absolute_position_)),
424 to_string(get_names(actuator_absolute_position_)));
DifferentialTransmission(const std::vector< double > &actuator_reduction, const std::vector< double > &joint_reduction, const std::vector< double > &joint_offset={0.0, 0.0})
Definition differential_transmission.hpp:180