differential_transmission.h
Go to the documentation of this file.
1 // Copyright (C) 2013, PAL Robotics S.L.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are met:
6 // * Redistributions of source code must retain the above copyright notice,
7 // this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above copyright
9 // notice, this list of conditions and the following disclaimer in the
10 // documentation and/or other materials provided with the distribution.
11 // * Neither the name of PAL Robotics S.L. nor the names of its
12 // contributors may be used to endorse or promote products derived from
13 // this software without specific prior written permission.
14 //
15 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 // POSSIBILITY OF SUCH DAMAGE.
27 
29 
30 #ifndef TRANSMISSION_INTERFACE_DIFFERENTIAL_TRANSMISSION_H
31 #define TRANSMISSION_INTERFACE_DIFFERENTIAL_TRANSMISSION_H
32 
33 #include <cassert>
34 #include <string>
35 #include <vector>
36 
39 
40 namespace transmission_interface
41 {
42 
118 {
119 public:
126  DifferentialTransmission(const std::vector<double>& actuator_reduction,
127  const std::vector<double>& joint_reduction,
128  const std::vector<double>& joint_offset = std::vector<double>(2, 0.0));
129 
137  void actuatorToJointEffort(const ActuatorData& act_data,
138  JointData& jnt_data);
139 
147  void actuatorToJointVelocity(const ActuatorData& act_data,
148  JointData& jnt_data);
149 
157  void actuatorToJointPosition(const ActuatorData& act_data,
158  JointData& jnt_data);
159 
167  void jointToActuatorEffort(const JointData& jnt_data,
168  ActuatorData& act_data);
169 
177  void jointToActuatorVelocity(const JointData& jnt_data,
178  ActuatorData& act_data);
179 
187  void jointToActuatorPosition(const JointData& jnt_data,
188  ActuatorData& act_data);
189 
190  std::size_t numActuators() const {return 2;}
191  std::size_t numJoints() const {return 2;}
192 
193  const std::vector<double>& getActuatorReduction() const {return act_reduction_;}
194  const std::vector<double>& getJointReduction() const {return jnt_reduction_;}
195  const std::vector<double>& getJointOffset() const {return jnt_offset_;}
196 
197 protected:
198  std::vector<double> act_reduction_;
199  std::vector<double> jnt_reduction_;
200  std::vector<double> jnt_offset_;
201 };
202 
203 inline DifferentialTransmission::DifferentialTransmission(const std::vector<double>& actuator_reduction,
204  const std::vector<double>& joint_reduction,
205  const std::vector<double>& joint_offset)
206  : Transmission(),
207  act_reduction_(actuator_reduction),
208  jnt_reduction_(joint_reduction),
209  jnt_offset_(joint_offset)
210 {
211  if (numActuators() != act_reduction_.size() ||
212  numJoints() != jnt_reduction_.size() ||
213  numJoints() != jnt_offset_.size())
214  {
215  throw TransmissionInterfaceException("Reduction and offset vectors of a differential transmission must have size 2.");
216  }
217 
218  if (0.0 == act_reduction_[0] ||
219  0.0 == act_reduction_[1] ||
220  0.0 == jnt_reduction_[0] ||
221  0.0 == jnt_reduction_[1]
222  )
223  {
224  throw TransmissionInterfaceException("Transmission reduction ratios cannot be zero.");
225  }
226 }
227 
229  JointData& jnt_data)
230 {
231  assert(numActuators() == act_data.effort.size() && numJoints() == jnt_data.effort.size());
232  assert(act_data.effort[0] && act_data.effort[1] && jnt_data.effort[0] && jnt_data.effort[1]);
233 
234  std::vector<double>& ar = act_reduction_;
235  std::vector<double>& jr = jnt_reduction_;
236 
237  *jnt_data.effort[0] = jr[0] * (*act_data.effort[0] * ar[0] + *act_data.effort[1] * ar[1]);
238  *jnt_data.effort[1] = jr[1] * (*act_data.effort[0] * ar[0] - *act_data.effort[1] * ar[1]);
239 }
240 
242  JointData& jnt_data)
243 {
244  assert(numActuators() == act_data.velocity.size() && numJoints() == jnt_data.velocity.size());
245  assert(act_data.velocity[0] && act_data.velocity[1] && jnt_data.velocity[0] && jnt_data.velocity[1]);
246 
247  std::vector<double>& ar = act_reduction_;
248  std::vector<double>& jr = jnt_reduction_;
249 
250  *jnt_data.velocity[0] = (*act_data.velocity[0] / ar[0] + *act_data.velocity[1] / ar[1]) / (2.0 * jr[0]);
251  *jnt_data.velocity[1] = (*act_data.velocity[0] / ar[0] - *act_data.velocity[1] / ar[1]) / (2.0 * jr[1]);
252 }
253 
255  JointData& jnt_data)
256 {
257  assert(numActuators() == act_data.position.size() && numJoints() == jnt_data.position.size());
258  assert(act_data.position[0] && act_data.position[1] && jnt_data.position[0] && jnt_data.position[1]);
259 
260  std::vector<double>& ar = act_reduction_;
261  std::vector<double>& jr = jnt_reduction_;
262 
263  *jnt_data.position[0] = (*act_data.position[0] / ar[0] + *act_data.position[1] / ar[1]) / (2.0 * jr[0]) + jnt_offset_[0];
264  *jnt_data.position[1] = (*act_data.position[0] / ar[0] - *act_data.position[1] / ar[1]) / (2.0 * jr[1]) + jnt_offset_[1];
265 }
266 
268  ActuatorData& act_data)
269 {
270  assert(numActuators() == act_data.effort.size() && numJoints() == jnt_data.effort.size());
271  assert(act_data.effort[0] && act_data.effort[1] && jnt_data.effort[0] && jnt_data.effort[1]);
272 
273  std::vector<double>& ar = act_reduction_;
274  std::vector<double>& jr = jnt_reduction_;
275 
276  *act_data.effort[0] = (*jnt_data.effort[0] / jr[0] + *jnt_data.effort[1] / jr[1]) / (2.0 * ar[0]);
277  *act_data.effort[1] = (*jnt_data.effort[0] / jr[0] - *jnt_data.effort[1] / jr[1]) / (2.0 * ar[1]);
278 }
279 
281  ActuatorData& act_data)
282 {
283  assert(numActuators() == act_data.velocity.size() && numJoints() == jnt_data.velocity.size());
284  assert(act_data.velocity[0] && act_data.velocity[1] && jnt_data.velocity[0] && jnt_data.velocity[1]);
285 
286  std::vector<double>& ar = act_reduction_;
287  std::vector<double>& jr = jnt_reduction_;
288 
289  *act_data.velocity[0] = (*jnt_data.velocity[0] * jr[0] + *jnt_data.velocity[1] * jr[1]) * ar[0];
290  *act_data.velocity[1] = (*jnt_data.velocity[0] * jr[0] - *jnt_data.velocity[1] * jr[1]) * ar[1];
291 }
292 
294  ActuatorData& act_data)
295 {
296  assert(numActuators() == act_data.position.size() && numJoints() == jnt_data.position.size());
297  assert(act_data.position[0] && act_data.position[1] && jnt_data.position[0] && jnt_data.position[1]);
298 
299  std::vector<double>& ar = act_reduction_;
300  std::vector<double>& jr = jnt_reduction_;
301 
302  double jnt_pos_off[2] = {*jnt_data.position[0] - jnt_offset_[0], *jnt_data.position[1] - jnt_offset_[1]};
303 
304  *act_data.position[0] = (jnt_pos_off[0] * jr[0] + jnt_pos_off[1] * jr[1]) * ar[0];
305  *act_data.position[1] = (jnt_pos_off[0] * jr[0] - jnt_pos_off[1] * jr[1]) * ar[1];
306 }
307 
308 } // transmission_interface
309 
310 #endif // TRANSMISSION_INTERFACE_DIFFERENTIAL_TRANSMISSION_H
void jointToActuatorVelocity(const JointData &jnt_data, ActuatorData &act_data)
Transform velocity variables from joint to actuator space.
std::vector< double * > velocity
Definition: transmission.h:64
Contains pointers to raw data representing the position, velocity and acceleration of a transmission&#39;...
Definition: transmission.h:61
std::vector< double * > position
Definition: transmission.h:52
void jointToActuatorEffort(const JointData &jnt_data, ActuatorData &act_data)
Transform effort variables from joint to actuator space.
const std::vector< double > & getActuatorReduction() const
const std::vector< double > & getJointReduction() const
const std::vector< double > & getJointOffset() const
DifferentialTransmission(const std::vector< double > &actuator_reduction, const std::vector< double > &joint_reduction, const std::vector< double > &joint_offset=std::vector< double >(2, 0.0))
void actuatorToJointPosition(const ActuatorData &act_data, JointData &jnt_data)
Transform position variables from actuator to joint space.
Contains pointers to raw data representing the position, velocity and acceleration of a transmission&#39;...
Definition: transmission.h:50
std::vector< double * > velocity
Definition: transmission.h:53
void actuatorToJointVelocity(const ActuatorData &act_data, JointData &jnt_data)
Transform velocity variables from actuator to joint space.
void jointToActuatorPosition(const JointData &jnt_data, ActuatorData &act_data)
Transform position variables from joint to actuator space.
std::vector< double * > position
Definition: transmission.h:63
void actuatorToJointEffort(const ActuatorData &act_data, JointData &jnt_data)
Transform effort variables from actuator to joint space.
std::vector< double * > effort
Definition: transmission.h:65
std::vector< double * > effort
Definition: transmission.h:54
Abstract base class for representing mechanical transmissions.
Definition: transmission.h:87
Implementation of a differential transmission.


transmission_interface
Author(s): Adolfo Rodriguez Tsouroukdissian
autogenerated on Mon Apr 20 2020 03:52:15