15#ifndef TRANSMISSION_INTERFACE__SIMPLE_TRANSMISSION_HPP_
16#define TRANSMISSION_INTERFACE__SIMPLE_TRANSMISSION_HPP_
23#include "hardware_interface/types/hardware_interface_type_values.hpp"
24#include "transmission_interface/exception.hpp"
25#include "transmission_interface/transmission.hpp"
95 const double joint_to_actuator_reduction,
const double joint_offset = 0.0);
105 const std::vector<JointHandle> & joint_handles,
106 const std::vector<ActuatorHandle> & actuator_handles)
override;
127 double get_actuator_reduction()
const {
return reduction_; }
128 double get_joint_offset()
const {
return jnt_offset_; }
134 JointHandle joint_position_ = {
"",
"",
nullptr};
135 JointHandle joint_velocity_ = {
"",
"",
nullptr};
136 JointHandle joint_effort_ = {
"",
"",
nullptr};
137 JointHandle joint_torque_ = {
"",
"",
nullptr};
138 JointHandle joint_absolute_position_ = {
"",
"",
nullptr};
140 ActuatorHandle actuator_position_ = {
"",
"",
nullptr};
141 ActuatorHandle actuator_velocity_ = {
"",
"",
nullptr};
142 ActuatorHandle actuator_effort_ = {
"",
"",
nullptr};
143 ActuatorHandle actuator_torque_ = {
"",
"",
nullptr};
144 ActuatorHandle actuator_absolute_position_ = {
"",
"",
nullptr};
148 const double joint_to_actuator_reduction,
const double joint_offset)
149: reduction_(joint_to_actuator_reduction), jnt_offset_(joint_offset)
151 if (reduction_ == 0.0)
153 throw Exception(
"Transmission reduction ratio cannot be zero.");
157template <
class HandleType>
158HandleType get_by_interface(
159 const std::vector<HandleType> & handles,
const std::string & interface_name)
161 const auto result = std::find_if(
162 handles.cbegin(), handles.cend(),
163 [&interface_name](
const auto handle) { return handle.get_interface_name() == interface_name; });
164 if (result == handles.cend())
166 return HandleType(handles.cbegin()->get_prefix_name(), interface_name,
nullptr);
172bool are_names_identical(
const std::vector<T> & handles)
174 std::vector<std::string> names;
176 handles.cbegin(), handles.cend(), std::back_inserter(names),
177 [](
const auto & handle) { return handle.get_prefix_name(); });
178 return std::equal(names.cbegin() + 1, names.cend(), names.cbegin());
182 const std::vector<JointHandle> & joint_handles,
183 const std::vector<ActuatorHandle> & actuator_handles)
185 if (joint_handles.empty())
187 throw Exception(
"No joint handles were passed in");
190 if (actuator_handles.empty())
192 throw Exception(
"No actuator handles were passed in");
195 if (!are_names_identical(joint_handles))
197 throw Exception(
"Joint names given to transmissions should be identical");
200 if (!are_names_identical(actuator_handles))
202 throw Exception(
"Actuator names given to transmissions should be identical");
212 !joint_position_ && !joint_velocity_ && !joint_effort_ && !joint_torque_ &&
213 !joint_absolute_position_)
215 throw Exception(
"None of the provided joint handles are valid or from the required interfaces");
225 !actuator_position_ && !actuator_velocity_ && !actuator_effort_ && !actuator_torque_ &&
226 !actuator_absolute_position_)
228 throw Exception(
"None of the provided joint handles are valid or from the required interfaces");
234 if (joint_effort_ && actuator_effort_)
236 joint_effort_.set_value(actuator_effort_.get_value() * reduction_);
239 if (joint_velocity_ && actuator_velocity_)
241 joint_velocity_.set_value(actuator_velocity_.get_value() / reduction_);
244 if (joint_position_ && actuator_position_)
246 joint_position_.set_value(actuator_position_.get_value() / reduction_ + jnt_offset_);
249 if (joint_torque_ && actuator_torque_)
251 joint_torque_.set_value(actuator_torque_.get_value() * reduction_);
254 if (joint_absolute_position_ && actuator_absolute_position_)
256 joint_absolute_position_.set_value(
257 actuator_absolute_position_.get_value() / reduction_ + jnt_offset_);
263 if (joint_effort_ && actuator_effort_)
265 actuator_effort_.set_value(joint_effort_.get_value() / reduction_);
268 if (joint_velocity_ && actuator_velocity_)
270 actuator_velocity_.set_value(joint_velocity_.get_value() * reduction_);
273 if (joint_position_ && actuator_position_)
275 actuator_position_.set_value((joint_position_.get_value() - jnt_offset_) * reduction_);
278 if (joint_torque_ && actuator_torque_)
280 actuator_torque_.set_value(joint_torque_.get_value() / reduction_);
Definition exception.hpp:23
Definition simple_transmission.hpp:87
SimpleTransmission(const double joint_to_actuator_reduction, const double joint_offset=0.0)
Definition simple_transmission.hpp:147
std::size_t num_actuators() const override
Definition simple_transmission.hpp:124
void actuator_to_joint() override
Transform variables from actuator to joint space.
Definition simple_transmission.hpp:232
void joint_to_actuator() override
Transform variables from joint to actuator space.
Definition simple_transmission.hpp:261
void configure(const std::vector< JointHandle > &joint_handles, const std::vector< ActuatorHandle > &actuator_handles) override
Set up the data the transmission operates on.
Definition simple_transmission.hpp:181
std::size_t num_joints() const override
Definition simple_transmission.hpp:125
Abstract base class for representing mechanical transmissions.
Definition transmission.hpp:46
constexpr char HW_IF_EFFORT[]
Constant defining effort interface name.
Definition hardware_interface_type_values.hpp:27
constexpr char HW_IF_TORQUE[]
Constant defining torque interface name.
Definition hardware_interface_type_values.hpp:29
constexpr char HW_IF_VELOCITY[]
Constant defining velocity interface name.
Definition hardware_interface_type_values.hpp:23
constexpr char HW_IF_POSITION[]
Constant defining position interface name.
Definition hardware_interface_type_values.hpp:21
Definition accessor.hpp:25
constexpr auto HW_IF_ABSOLUTE_POSITION
Implementation of a differential transmission.
Definition differential_transmission.hpp:112