15#ifndef TRANSMISSION_INTERFACE__DIFFERENTIAL_TRANSMISSION_HPP_
16#define TRANSMISSION_INTERFACE__DIFFERENTIAL_TRANSMISSION_HPP_
23#include "hardware_interface/types/hardware_interface_type_values.hpp"
24#include "transmission_interface/accessor.hpp"
25#include "transmission_interface/exception.hpp"
26#include "transmission_interface/transmission.hpp"
114 const std::vector<double> & actuator_reduction,
const std::vector<double> & joint_reduction,
115 const std::vector<double> & joint_offset = {0.0, 0.0});
123 const std::vector<JointHandle> & joint_handles,
124 const std::vector<ActuatorHandle> & actuator_handles)
override;
143 const std::vector<double> & get_actuator_reduction()
const {
return actuator_reduction_; }
144 const std::vector<double> & get_joint_reduction()
const {
return joint_reduction_; }
145 const std::vector<double> & get_joint_offset()
const {
return joint_offset_; }
151 std::vector<double> actuator_reduction_;
152 std::vector<double> joint_reduction_;
153 std::vector<double> joint_offset_;
155 std::vector<JointHandle> joint_position_;
156 std::vector<JointHandle> joint_velocity_;
157 std::vector<JointHandle> joint_effort_;
159 std::vector<ActuatorHandle> actuator_position_;
160 std::vector<ActuatorHandle> actuator_velocity_;
161 std::vector<ActuatorHandle> actuator_effort_;
165 const std::vector<double> & actuator_reduction,
const std::vector<double> & joint_reduction,
166 const std::vector<double> & joint_offset)
167: actuator_reduction_(actuator_reduction),
168 joint_reduction_(joint_reduction),
169 joint_offset_(joint_offset)
175 throw Exception(
"Reduction and offset vectors must have size 2.");
179 0.0 == actuator_reduction_[0] || 0.0 == actuator_reduction_[1] || 0.0 == joint_reduction_[0] ||
180 0.0 == joint_reduction_[1])
182 throw Exception(
"Transmission reduction ratios cannot be zero.");
187 const std::vector<JointHandle> & joint_handles,
188 const std::vector<ActuatorHandle> & actuator_handles)
190 if (joint_handles.empty())
192 throw Exception(
"No joint handles were passed in");
195 if (actuator_handles.empty())
197 throw Exception(
"No actuator handles were passed in");
200 const auto joint_names = get_names(joint_handles);
201 if (joint_names.size() != 2)
204 "There should be exactly two unique joint names but was given " + to_string(joint_names));
206 const auto actuator_names = get_names(actuator_handles);
207 if (actuator_names.size() != 2)
210 "There should be exactly two unique actuator names but was given " +
211 to_string(actuator_names));
220 if (joint_position_.size() != 2 && joint_velocity_.size() != 2 && joint_effort_.size() != 2)
222 throw Exception(
"Not enough valid or required joint handles were presented.");
233 actuator_position_.size() != 2 && actuator_velocity_.size() != 2 &&
234 actuator_effort_.size() != 2)
237 "Not enough valid or required actuator handles were presented. \n" +
get_handles_info());
241 joint_position_.size() != actuator_position_.size() &&
242 joint_velocity_.size() != actuator_velocity_.size() &&
243 joint_effort_.size() != actuator_effort_.size())
251 const auto & ar = actuator_reduction_;
252 const auto & jr = joint_reduction_;
254 auto & act_pos = actuator_position_;
255 auto & joint_pos = joint_position_;
258 assert(act_pos[0] && act_pos[1] && joint_pos[0] && joint_pos[1]);
260 joint_pos[0].set_value(
261 (act_pos[0].get_value() / ar[0] + act_pos[1].get_value() / ar[1]) / (2.0 * jr[0]) +
263 joint_pos[1].set_value(
264 (act_pos[0].get_value() / ar[0] - act_pos[1].get_value() / ar[1]) / (2.0 * jr[1]) +
268 auto & act_vel = actuator_velocity_;
269 auto & joint_vel = joint_velocity_;
272 assert(act_vel[0] && act_vel[1] && joint_vel[0] && joint_vel[1]);
274 joint_vel[0].set_value(
275 (act_vel[0].get_value() / ar[0] + act_vel[1].get_value() / ar[1]) / (2.0 * jr[0]));
276 joint_vel[1].set_value(
277 (act_vel[0].get_value() / ar[0] - act_vel[1].get_value() / ar[1]) / (2.0 * jr[1]));
280 auto & act_eff = actuator_effort_;
281 auto & joint_eff = joint_effort_;
284 assert(act_eff[0] && act_eff[1] && joint_eff[0] && joint_eff[1]);
286 joint_eff[0].set_value(
287 jr[0] * (act_eff[0].get_value() * ar[0] + act_eff[1].get_value() * ar[1]));
288 joint_eff[1].set_value(
289 jr[1] * (act_eff[0].get_value() * ar[0] - act_eff[1].get_value() * ar[1]));
295 const auto & ar = actuator_reduction_;
296 const auto & jr = joint_reduction_;
298 auto & act_pos = actuator_position_;
299 auto & joint_pos = joint_position_;
302 assert(act_pos[0] && act_pos[1] && joint_pos[0] && joint_pos[1]);
304 double joints_offset_applied[2] = {
305 joint_pos[0].get_value() - joint_offset_[0], joint_pos[1].get_value() - joint_offset_[1]};
306 act_pos[0].set_value(
307 (joints_offset_applied[0] * jr[0] + joints_offset_applied[1] * jr[1]) * ar[0]);
308 act_pos[1].set_value(
309 (joints_offset_applied[0] * jr[0] - joints_offset_applied[1] * jr[1]) * ar[1]);
312 auto & act_vel = actuator_velocity_;
313 auto & joint_vel = joint_velocity_;
316 assert(act_vel[0] && act_vel[1] && joint_vel[0] && joint_vel[1]);
318 act_vel[0].set_value(
319 (joint_vel[0].get_value() * jr[0] + joint_vel[1].get_value() * jr[1]) * ar[0]);
320 act_vel[1].set_value(
321 (joint_vel[0].get_value() * jr[0] - joint_vel[1].get_value() * jr[1]) * ar[1]);
324 auto & act_eff = actuator_effort_;
325 auto & joint_eff = joint_effort_;
328 assert(act_eff[0] && act_eff[1] && joint_eff[0] && joint_eff[1]);
330 act_eff[0].set_value(
331 (joint_eff[0].get_value() / jr[0] + joint_eff[1].get_value() / jr[1]) / (2.0 * ar[0]));
332 act_eff[1].set_value(
333 (joint_eff[0].get_value() / jr[0] - joint_eff[1].get_value() / jr[1]) / (2.0 * ar[1]));
339 return std::string(
"Got the following handles:\n") +
340 "Joint position: " + to_string(get_names(joint_position_)) +
341 ", Actuator position: " + to_string(get_names(actuator_position_)) +
"\n" +
342 "Joint velocity: " + to_string(get_names(joint_velocity_)) +
343 ", Actuator velocity: " + to_string(get_names(actuator_velocity_)) +
"\n" +
344 "Joint effort: " + to_string(get_names(joint_effort_)) +
345 ", Actuator effort: " + to_string(get_names(actuator_effort_));
Implementation of a differential transmission.
Definition differential_transmission.hpp:105
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:164
std::size_t num_joints() const override
Definition differential_transmission.hpp:141
void joint_to_actuator() override
Transform variables from joint to actuator space.
Definition differential_transmission.hpp:293
void actuator_to_joint() override
Transform variables from actuator to joint space.
Definition differential_transmission.hpp:249
std::string get_handles_info() const
Get human-friendly report of handles.
Definition differential_transmission.hpp:337
void configure(const std::vector< JointHandle > &joint_handles, const std::vector< ActuatorHandle > &actuator_handles) override
Definition differential_transmission.hpp:186
std::size_t num_actuators() const override
Definition differential_transmission.hpp:140
Definition exception.hpp:23
Abstract base class for representing mechanical transmissions.
Definition transmission.hpp:46
constexpr char HW_IF_EFFORT[]
Constant defining effort interface.
Definition hardware_interface_type_values.hpp:27
constexpr char HW_IF_VELOCITY[]
Constant defining velocity interface.
Definition hardware_interface_type_values.hpp:23
constexpr char HW_IF_POSITION[]
Constant defining position interface.
Definition hardware_interface_type_values.hpp:21
Definition accessor.hpp:24