qb_device_transmission_resources.h
Go to the documentation of this file.
1 /***
2  * Software License Agreement: BSD 3-Clause License
3  *
4  * Copyright (c) 2016-2018, qbrobotics®
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
8  * following conditions are met:
9  *
10  * * Redistributions of source code must retain the above copyright notice, this list of conditions and the
11  * following disclaimer.
12  *
13  * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
14  * following disclaimer in the documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote
17  * products derived from this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
20  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
25  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #ifndef QB_DEVICE_TRANSMISSION_RESOURCES_H
29 #define QB_DEVICE_TRANSMISSION_RESOURCES_H
30 
32 typedef std::shared_ptr<transmission_interface::Transmission> TransmissionPtr;
40  public:
45 
50  qbDeviceTransmissionResources(TransmissionPtr &transmission) {
51  transmission_ = transmission;
52  }
53 
58 
62  const TransmissionPtr& getTransmission() { return transmission_; }
63 
77  setHandleData<transmission_interface::ActuatorData>(actuator_states_, actuator_commands_, actuators);
78  setHandleData<transmission_interface::JointData>(joint_states_, joint_commands_, joints);
79  actuator_to_joint_state.registerHandle(transmission_interface::ActuatorToJointStateHandle(transmission_name, transmission_.get(), actuator_states_.at(0), joint_states_.at(0)));
80  joint_to_actuator_position.registerHandle(transmission_interface::JointToActuatorPositionHandle(transmission_name, transmission_.get(), actuator_commands_.at(0), joint_commands_.at(0)));
81  }
82 
83  // the transmission interface is used just to convert from actuator values [ticks] to joint states [radians] or [0,1]
86 
87  protected:
88  std::vector<transmission_interface::ActuatorData> actuator_states_;
89  std::vector<transmission_interface::ActuatorData> actuator_commands_;
90  std::vector<transmission_interface::JointData> joint_states_;
91  std::vector<transmission_interface::JointData> joint_commands_;
92  TransmissionPtr transmission_;
93 
94  private:
103  template<class T>
104  void setHandleData(std::vector<T> &states, std::vector<T> &commands, qb_device_hardware_interface::qbDeviceHWResources &resource) {
105  T joint_state;
106  T joint_command;
107  for (int i=0; i<resource.names.size(); i++) {
108  joint_state.position.push_back(&resource.positions.at(i));
109  joint_state.velocity.push_back(&resource.velocities.at(i));
110  joint_state.effort.push_back(&resource.efforts.at(i));
111  joint_command.position.push_back(&resource.commands.at(i));
112  }
113  states.push_back(joint_state);
114  commands.push_back(joint_command);
115  }
116 };
117 } // namespace qb_device_transmission_interface
118 
119 #endif // QB_DEVICE_TRANSMISSION_RESOURCES_H
std::shared_ptr< transmission_interface::Transmission > TransmissionPtr
qbDeviceTransmissionResources(TransmissionPtr &transmission)
Initialize the transmission Resource.
void setHandleData(std::vector< T > &states, std::vector< T > &commands, qb_device_hardware_interface::qbDeviceHWResources &resource)
Build the states and commands transmission handle data for the given device HW Resource.
void initialize(const std::string &transmission_name, qb_device_hardware_interface::qbDeviceHWResources &actuators, qb_device_hardware_interface::qbDeviceHWResources &joints)
Initialize the Device Transmission Resources interfaces.
The qbrobotics Device HardWare Resources contains vectors of named joints.
std::vector< transmission_interface::ActuatorData > actuator_commands_
transmission_interface::JointToActuatorPositionInterface joint_to_actuator_position
std::vector< transmission_interface::ActuatorData > actuator_states_
transmission_interface::ActuatorToJointStateInterface actuator_to_joint_state
The qbrobotics Device Transmission Resources is a simple class aimed to group all the transmission_in...


qb_device_hardware_interface
Author(s): qbrobotics®
autogenerated on Thu Jun 6 2019 19:46:29