four_bar_linkage_transmission.h
Go to the documentation of this file.
1 
3 // Copyright (C) 2013, PAL Robotics S.L.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are met:
7 // * Redistributions of source code must retain the above copyright notice,
8 // this list of conditions and the following disclaimer.
9 // * Redistributions in binary form must reproduce the above copyright
10 // notice, this list of conditions and the following disclaimer in the
11 // documentation and/or other materials provided with the distribution.
12 // * Neither the name of PAL Robotics S.L. nor the names of its
13 // contributors may be used to endorse or promote products derived from
14 // this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 // POSSIBILITY OF SUCH DAMAGE.
28 
30 
31 #pragma once
32 
33 
34 #include <cassert>
35 #include <string>
36 #include <vector>
37 
40 
41 namespace transmission_interface
42 {
43 
118 {
119 public:
126  FourBarLinkageTransmission(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) override;
139 
147  void actuatorToJointVelocity(const ActuatorData& act_data,
148  JointData& jnt_data) override;
149 
157  void actuatorToJointPosition(const ActuatorData& act_data,
158  JointData& jnt_data) override;
159 
167  void actuatorToJointAbsolutePosition(const ActuatorData& act_data,
168  JointData& jnt_data) override;
169 
176  void actuatorToJointTorqueSensor(const ActuatorData& act_data,
177  JointData& jnt_data) override;
178 
186  void jointToActuatorEffort(const JointData& jnt_data,
187  ActuatorData& act_data) override;
188 
196  void jointToActuatorVelocity(const JointData& jnt_data,
197  ActuatorData& act_data) override;
198 
206  void jointToActuatorPosition(const JointData& jnt_data,
207  ActuatorData& act_data) override;
208 
209  std::size_t numActuators() const override {return 2;}
210  std::size_t numJoints() const override {return 2;}
211  bool hasActuatorToJointAbsolutePosition() const override {return true;}
212  bool hasActuatorToJointTorqueSensor() const override {return true;}
213 
214  const std::vector<double>& getActuatorReduction() const {return act_reduction_;}
215  const std::vector<double>& getJointReduction() const {return jnt_reduction_;}
216  const std::vector<double>& getJointOffset() const {return jnt_offset_;}
217 
218 protected:
219  std::vector<double> act_reduction_;
220  std::vector<double> jnt_reduction_;
221  std::vector<double> jnt_offset_;
222 };
223 
224 inline FourBarLinkageTransmission::FourBarLinkageTransmission(const std::vector<double>& actuator_reduction,
225  const std::vector<double>& joint_reduction,
226  const std::vector<double>& joint_offset)
227  : act_reduction_(actuator_reduction),
228  jnt_reduction_(joint_reduction),
229  jnt_offset_(joint_offset)
230 {
231  if (numActuators() != act_reduction_.size() ||
232  numJoints() != jnt_reduction_.size() ||
233  numJoints() != jnt_offset_.size())
234  {
235  throw TransmissionInterfaceException("Reduction and offset vectors of a four-bar linkage transmission must have size 2.");
236  }
237  if (0.0 == act_reduction_[0] ||
238  0.0 == act_reduction_[1] ||
239  0.0 == jnt_reduction_[0] ||
240  0.0 == jnt_reduction_[1])
241  {
242  throw TransmissionInterfaceException("Transmission reduction ratios cannot be zero.");
243  }
244 }
245 
247  JointData& jnt_data)
248 {
249  assert(numActuators() == act_data.effort.size() && numJoints() == jnt_data.effort.size());
250  assert(act_data.effort[0] && act_data.effort[1] && jnt_data.effort[0] && jnt_data.effort[1]);
251 
252  std::vector<double>& ar = act_reduction_;
253  std::vector<double>& jr = jnt_reduction_;
254 
255  *jnt_data.effort[0] = jr[0] * (*act_data.effort[0] * ar[0]);
256  *jnt_data.effort[1] = jr[1] * (*act_data.effort[1] * ar[1] - *act_data.effort[0] * ar[0] * jr[0]);
257 }
258 
260  JointData& jnt_data)
261 {
262  assert(numActuators() == act_data.velocity.size() && numJoints() == jnt_data.velocity.size());
263  assert(act_data.velocity[0] && act_data.velocity[1] && jnt_data.velocity[0] && jnt_data.velocity[1]);
264 
265  std::vector<double>& ar = act_reduction_;
266  std::vector<double>& jr = jnt_reduction_;
267 
268  *jnt_data.velocity[0] = *act_data.velocity[0] / (jr[0] * ar[0]);
269  *jnt_data.velocity[1] = (*act_data.velocity[1] / ar[1] - *act_data.velocity[0] / (jr[0] * ar[0])) / jr[1];
270 }
271 
273  JointData& jnt_data)
274 {
275  assert(numActuators() == act_data.position.size() && numJoints() == jnt_data.position.size());
276  assert(act_data.position[0] && act_data.position[1] && jnt_data.position[0] && jnt_data.position[1]);
277 
278  std::vector<double>& ar = act_reduction_;
279  std::vector<double>& jr = jnt_reduction_;
280 
281  *jnt_data.position[0] = *act_data.position[0] /(jr[0] * ar[0]) + jnt_offset_[0];
282  *jnt_data.position[1] = (*act_data.position[1] / ar[1] - *act_data.position[0] / (jr[0] * ar[0])) / jr[1]
283  + jnt_offset_[1];
284 }
285 
287  JointData& jnt_data)
288 {
289 
290  assert(numActuators() == act_data.absolute_position.size() && numJoints() == jnt_data.absolute_position.size());
291  assert(act_data.absolute_position[0] && act_data.absolute_position[1] && jnt_data.absolute_position[0] && jnt_data.absolute_position[1]);
292 
293  const std::vector<double>& ar = act_reduction_;
294  const std::vector<double>& jr = jnt_reduction_;
295 
296  *jnt_data.absolute_position[0] = *act_data.absolute_position[0] /(jr[0] * ar[0]) + jnt_offset_[0];
297  *jnt_data.absolute_position[1] = (*act_data.absolute_position[1] / ar[1] - *act_data.absolute_position[0] / (jr[0] * ar[0])) /
298  jr[1] + jnt_offset_[1];
299 }
300 
302  JointData& jnt_data)
303 {
304 
305  assert(numActuators() == act_data.torque_sensor.size() && numJoints() == jnt_data.torque_sensor.size());
306  assert(act_data.torque_sensor[0] && act_data.torque_sensor[1] && jnt_data.torque_sensor[0] && jnt_data.torque_sensor[1]);
307 
308  const std::vector<double>& ar = act_reduction_;
309  const std::vector<double>& jr = jnt_reduction_;
310 
311  *jnt_data.torque_sensor[0] = jr[0] * (*act_data.torque_sensor[0] * ar[0]);
312  *jnt_data.torque_sensor[1] = jr[1] * (*act_data.torque_sensor[1] * ar[1] - *act_data.torque_sensor[0] * ar[0] * jr[0]);
313 }
314 
315 
317  ActuatorData& act_data)
318 {
319  assert(numActuators() == act_data.effort.size() && numJoints() == jnt_data.effort.size());
320  assert(act_data.effort[0] && act_data.effort[1] && jnt_data.effort[0] && jnt_data.effort[1]);
321 
322  std::vector<double>& ar = act_reduction_;
323  std::vector<double>& jr = jnt_reduction_;
324 
325  *act_data.effort[0] = *jnt_data.effort[0] / (ar[0] * jr[0]);
326  *act_data.effort[1] = (*jnt_data.effort[0] + *jnt_data.effort[1] / jr[1]) / ar[1];
327 }
328 
330  ActuatorData& act_data)
331 {
332  assert(numActuators() == act_data.velocity.size() && numJoints() == jnt_data.velocity.size());
333  assert(act_data.velocity[0] && act_data.velocity[1] && jnt_data.velocity[0] && jnt_data.velocity[1]);
334 
335  std::vector<double>& ar = act_reduction_;
336  std::vector<double>& jr = jnt_reduction_;
337 
338  *act_data.velocity[0] = *jnt_data.velocity[0] * jr[0] * ar[0];
339  *act_data.velocity[1] = (*jnt_data.velocity[0] + *jnt_data.velocity[1] * jr[1]) * ar[1];
340 }
341 
343  ActuatorData& act_data)
344 {
345  assert(numActuators() == act_data.position.size() && numJoints() == jnt_data.position.size());
346  assert(act_data.position[0] && act_data.position[1] && jnt_data.position[0] && jnt_data.position[1]);
347 
348  std::vector<double>& ar = act_reduction_;
349  std::vector<double>& jr = jnt_reduction_;
350 
351  double jnt_pos_off[2] = {*jnt_data.position[0] - jnt_offset_[0], *jnt_data.position[1] - jnt_offset_[1]};
352 
353  *act_data.position[0] = jnt_pos_off[0] * jr[0] * ar[0];
354  *act_data.position[1] = (jnt_pos_off[0] + jnt_pos_off[1] * jr[1]) * ar[1];
355 }
356 
357 } // transmission_interface
void actuatorToJointEffort(const ActuatorData &act_data, JointData &jnt_data) override
Transform effort variables from actuator to joint space.
std::vector< double * > absolute_position
Definition: transmission.h:68
std::vector< double * > velocity
Definition: transmission.h:66
std::vector< double * > absolute_position
Definition: transmission.h:55
Contains pointers to raw data representing the position, velocity and acceleration of a transmission&#39;...
Definition: transmission.h:63
std::vector< double * > position
Definition: transmission.h:52
void actuatorToJointAbsolutePosition(const ActuatorData &act_data, JointData &jnt_data) override
Transform absolute encoder values from actuator to joint space.
std::vector< double * > torque_sensor
Definition: transmission.h:69
FourBarLinkageTransmission(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 actuatorToJointTorqueSensor(const ActuatorData &act_data, JointData &jnt_data) override
Transform torque sensor values from actuator to joint space.
void jointToActuatorPosition(const JointData &jnt_data, ActuatorData &act_data) override
Transform position variables from joint to actuator space.
std::vector< double * > torque_sensor
Definition: transmission.h:56
Implementation of a four-bar-linkage transmission.
Contains pointers to raw data representing the position, velocity and acceleration of a transmission&#39;...
Definition: transmission.h:50
void jointToActuatorEffort(const JointData &jnt_data, ActuatorData &act_data) override
Transform effort variables from joint to actuator space.
std::vector< double * > velocity
Definition: transmission.h:53
std::vector< double * > position
Definition: transmission.h:65
std::vector< double * > effort
Definition: transmission.h:67
void jointToActuatorVelocity(const JointData &jnt_data, ActuatorData &act_data) override
Transform velocity variables from joint to actuator space.
std::vector< double * > effort
Definition: transmission.h:54
void actuatorToJointVelocity(const ActuatorData &act_data, JointData &jnt_data) override
Transform velocity variables from actuator to joint space.
Abstract base class for representing mechanical transmissions.
Definition: transmission.h:91
void actuatorToJointPosition(const ActuatorData &act_data, JointData &jnt_data) override
Transform position variables from actuator to joint space.


transmission_interface
Author(s): Adolfo Rodriguez Tsouroukdissian
autogenerated on Mon Feb 28 2022 23:30:26