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_; }
149 JointHandle joint_velocity_ = {
"",
"",
nullptr};
150 JointHandle joint_effort_ = {
"",
"",
nullptr};
151 JointHandle joint_torque_ = {
"",
"",
nullptr};
152 JointHandle joint_force_ = {
"",
"",
nullptr};
153 JointHandle joint_absolute_position_ = {
"",
"",
nullptr};
155 ActuatorHandle actuator_position_ = {
"",
"",
nullptr};
156 ActuatorHandle actuator_velocity_ = {
"",
"",
nullptr};
157 ActuatorHandle actuator_effort_ = {
"",
"",
nullptr};
158 ActuatorHandle actuator_torque_ = {
"",
"",
nullptr};
159 ActuatorHandle actuator_force_ = {
"",
"",
nullptr};
160 ActuatorHandle actuator_absolute_position_ = {
"",
"",
nullptr};
164 const double joint_to_actuator_reduction,
const double joint_offset)
165: reduction_(joint_to_actuator_reduction), jnt_offset_(joint_offset)
167 if (reduction_ == 0.0)
169 throw Exception(
"Transmission reduction ratio cannot be zero.");
173template <
class HandleType>
174HandleType get_by_interface(
175 const std::vector<HandleType> & handles,
const std::string & interface_name)
177 const auto result = std::find_if(
178 handles.cbegin(), handles.cend(),
179 [&interface_name](
const auto handle) { return handle.get_interface_name() == interface_name; });
180 if (result == handles.cend())
182 return HandleType(handles.cbegin()->get_prefix_name(), interface_name,
nullptr);
188bool are_names_identical(
const std::vector<T> & handles)
190 std::vector<std::string> names;
192 handles.cbegin(), handles.cend(), std::back_inserter(names),
193 [](
const auto & handle) { return handle.get_prefix_name(); });
194 return std::equal(names.cbegin() + 1, names.cend(), names.cbegin());
198 const std::vector<JointHandle> & joint_handles,
199 const std::vector<ActuatorHandle> & actuator_handles)
201 if (joint_handles.empty())
203 throw Exception(
"No joint handles were passed in");
206 if (actuator_handles.empty())
208 throw Exception(
"No actuator handles were passed in");
211 if (!are_names_identical(joint_handles))
213 throw Exception(
"Joint names given to transmissions should be identical");
216 if (!are_names_identical(actuator_handles))
218 throw Exception(
"Actuator names given to transmissions should be identical");
229 !joint_position_ && !joint_velocity_ && !joint_effort_ && !joint_torque_ && !joint_force_ &&
230 !joint_absolute_position_)
232 throw Exception(
"None of the provided joint handles are valid or from the required interfaces");
243 !actuator_position_ && !actuator_velocity_ && !actuator_effort_ && !actuator_torque_ &&
244 !actuator_force_ && !actuator_absolute_position_)
247 "None of the provided actuator handles are valid or from the required interfaces");
253 if (joint_effort_ && actuator_effort_)
255 joint_effort_.set_value(actuator_effort_.get_value() * reduction_);
258 if (joint_velocity_ && actuator_velocity_)
260 joint_velocity_.set_value(actuator_velocity_.get_value() / reduction_);
263 if (joint_position_ && actuator_position_)
265 joint_position_.set_value(actuator_position_.get_value() / reduction_ + jnt_offset_);
268 if (joint_torque_ && actuator_torque_)
270 joint_torque_.set_value(actuator_torque_.get_value() * reduction_);
273 if (joint_force_ && actuator_force_)
275 joint_force_.set_value(actuator_force_.get_value() * reduction_);
278 if (joint_absolute_position_ && actuator_absolute_position_)
280 joint_absolute_position_.set_value(
281 actuator_absolute_position_.get_value() / reduction_ + jnt_offset_);
287 if (joint_effort_ && actuator_effort_)
289 actuator_effort_.set_value(joint_effort_.get_value() / reduction_);
292 if (joint_velocity_ && actuator_velocity_)
294 actuator_velocity_.set_value(joint_velocity_.get_value() * reduction_);
297 if (joint_position_ && actuator_position_)
299 actuator_position_.set_value((joint_position_.get_value() - jnt_offset_) * reduction_);
302 if (joint_torque_ && actuator_torque_)
304 actuator_torque_.set_value(joint_torque_.get_value() / reduction_);
307 if (joint_force_ && actuator_force_)
309 actuator_force_.set_value(joint_force_.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:163
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:251
void joint_to_actuator() override
Transform variables from joint to actuator space.
Definition simple_transmission.hpp:285
std::vector< std::string > get_supported_joint_interfaces() const override
Definition simple_transmission.hpp:137
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:197
std::vector< std::string > get_supported_actuator_interfaces() const override
Definition simple_transmission.hpp:130
std::size_t num_joints() const override
Definition simple_transmission.hpp:125
Abstract base class for representing mechanical transmissions.
Definition transmission.hpp:48
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:73
constexpr char HW_IF_TORQUE[]
Constant defining torque interface name.
Definition mujoco_system_interface.hpp:71
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