15#ifndef TRANSMISSION_INTERFACE__SIMPLE_TRANSMISSION_HPP_
16#define TRANSMISSION_INTERFACE__SIMPLE_TRANSMISSION_HPP_
24#include "hardware_interface/types/hardware_interface_type_values.hpp"
25#include "transmission_interface/exception.hpp"
26#include "transmission_interface/transmission.hpp"
94 const double joint_to_actuator_reduction,
const double joint_offset = 0.0);
104 const std::vector<JointHandle> & joint_handles,
105 const std::vector<ActuatorHandle> & actuator_handles)
override;
126 double get_actuator_reduction()
const {
return reduction_; }
127 double get_joint_offset()
const {
return jnt_offset_; }
148 JointHandle joint_velocity_ = {
"",
"",
nullptr};
149 JointHandle joint_effort_ = {
"",
"",
nullptr};
150 JointHandle joint_torque_ = {
"",
"",
nullptr};
151 JointHandle joint_force_ = {
"",
"",
nullptr};
152 JointHandle joint_absolute_position_ = {
"",
"",
nullptr};
154 ActuatorHandle actuator_position_ = {
"",
"",
nullptr};
155 ActuatorHandle actuator_velocity_ = {
"",
"",
nullptr};
156 ActuatorHandle actuator_effort_ = {
"",
"",
nullptr};
157 ActuatorHandle actuator_torque_ = {
"",
"",
nullptr};
158 ActuatorHandle actuator_force_ = {
"",
"",
nullptr};
159 ActuatorHandle actuator_absolute_position_ = {
"",
"",
nullptr};
163 const double joint_to_actuator_reduction,
const double joint_offset)
164: reduction_(joint_to_actuator_reduction), jnt_offset_(joint_offset)
166 if (reduction_ == 0.0)
168 throw Exception(
"Transmission reduction ratio cannot be zero.");
172template <
class HandleType>
173HandleType get_by_interface(
174 const std::vector<HandleType> & handles,
const std::string & interface_name)
176 const auto result = std::find_if(
177 handles.cbegin(), handles.cend(),
178 [&interface_name](
const auto handle) { return handle.get_interface_name() == interface_name; });
179 if (result == handles.cend())
181 return HandleType(handles.cbegin()->get_prefix_name(), interface_name,
nullptr);
187bool are_names_identical(
const std::vector<T> & handles)
189 std::vector<std::string> names;
191 handles.cbegin(), handles.cend(), std::back_inserter(names),
192 [](
const auto & handle) { return handle.get_prefix_name(); });
193 return std::equal(names.cbegin() + 1, names.cend(), names.cbegin());
197 const std::vector<JointHandle> & joint_handles,
198 const std::vector<ActuatorHandle> & actuator_handles)
200 if (joint_handles.empty())
202 throw Exception(
"No joint handles were passed in");
205 if (actuator_handles.empty())
207 throw Exception(
"No actuator handles were passed in");
210 if (!are_names_identical(joint_handles))
212 throw Exception(
"Joint names given to transmissions should be identical");
215 if (!are_names_identical(actuator_handles))
217 throw Exception(
"Actuator names given to transmissions should be identical");
225 joint_absolute_position_ = get_by_interface(joint_handles, HW_IF_ABSOLUTE_POSITION);
228 !joint_position_ && !joint_velocity_ && !joint_effort_ && !joint_torque_ && !joint_force_ &&
229 !joint_absolute_position_)
231 throw Exception(
"None of the provided joint handles are valid or from the required interfaces");
239 actuator_absolute_position_ = get_by_interface(actuator_handles, HW_IF_ABSOLUTE_POSITION);
242 !actuator_position_ && !actuator_velocity_ && !actuator_effort_ && !actuator_torque_ &&
243 !actuator_force_ && !actuator_absolute_position_)
246 "None of the provided actuator handles are valid or from the required interfaces");
252 if (joint_effort_ && actuator_effort_)
254 joint_effort_.set_value(actuator_effort_.get_value() * reduction_);
257 if (joint_velocity_ && actuator_velocity_)
259 joint_velocity_.set_value(actuator_velocity_.get_value() / reduction_);
262 if (joint_position_ && actuator_position_)
264 joint_position_.set_value(actuator_position_.get_value() / reduction_ + jnt_offset_);
267 if (joint_torque_ && actuator_torque_)
269 joint_torque_.set_value(actuator_torque_.get_value() * reduction_);
272 if (joint_force_ && actuator_force_)
274 joint_force_.set_value(actuator_force_.get_value() * reduction_);
277 if (joint_absolute_position_ && actuator_absolute_position_)
279 joint_absolute_position_.set_value(
280 actuator_absolute_position_.get_value() / reduction_ + jnt_offset_);
286 if (joint_effort_ && actuator_effort_)
288 actuator_effort_.set_value(joint_effort_.get_value() / reduction_);
291 if (joint_velocity_ && actuator_velocity_)
293 actuator_velocity_.set_value(joint_velocity_.get_value() * reduction_);
296 if (joint_position_ && actuator_position_)
298 actuator_position_.set_value((joint_position_.get_value() - jnt_offset_) * reduction_);
301 if (joint_torque_ && actuator_torque_)
303 actuator_torque_.set_value(joint_torque_.get_value() / reduction_);
306 if (joint_force_ && actuator_force_)
308 actuator_force_.set_value(joint_force_.get_value() / reduction_);
Definition exception.hpp:23
Implementation of a simple reducer transmission.
Definition simple_transmission.hpp:86
SimpleTransmission(const double joint_to_actuator_reduction, const double joint_offset=0.0)
Definition simple_transmission.hpp:162
std::size_t num_actuators() const override
Definition simple_transmission.hpp:123
void actuator_to_joint() override
Transform variables from actuator to joint space.
Definition simple_transmission.hpp:250
void joint_to_actuator() override
Transform variables from joint to actuator space.
Definition simple_transmission.hpp:284
std::vector< std::string > get_supported_joint_interfaces() const override
Definition simple_transmission.hpp:136
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:196
std::vector< std::string > get_supported_actuator_interfaces() const override
Definition simple_transmission.hpp:129
std::size_t num_joints() const override
Definition simple_transmission.hpp:124
Abstract base class for representing mechanical transmissions.
Definition transmission.hpp:50
constexpr char HW_IF_EFFORT[]
Constant defining effort interface name.
Definition hardware_interface_type_values.hpp:27
constexpr char HW_IF_FORCE[]
Constant defining force interface name.
Definition mujoco_system_interface.hpp:61
constexpr char HW_IF_TORQUE[]
Constant defining torque interface name.
Definition mujoco_system_interface.hpp:59
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:26