qb_move_transmission_interface.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_MOVE_TRANSMISSION_H
29 #define QB_MOVE_TRANSMISSION_H
30 
33 
41  public:
54  : qbMoveTransmission(true, std::vector<double>(3, M_PI/std::pow(2, 15-1)), 1./3000, 0.2, 0.001) {}
55 
65  qbMoveTransmission(const bool &command_with_position_and_preset, const std::vector<double> &position_factor, const double &preset_factor, const double &velocity_factor, const double &effort_factor)
66  : Transmission(),
67  command_with_position_and_preset_(command_with_position_and_preset),
68  position_factor_(position_factor),
69  preset_factor_(preset_factor),
70  velocity_factor_(velocity_factor),
71  effort_factor_(effort_factor) {}
72 
82  ROS_ASSERT(numActuators() == actuator.effort.size() && numJoints() == joint.effort.size());
83  ROS_ASSERT(actuator.effort[0] && actuator.effort[1] && actuator.effort[2] && joint.effort[0] && joint.effort[1] && joint.effort[2] && joint.effort[3]);
84 
85  *joint.effort[0] = *actuator.effort[0] * effort_factor_; // motor_1_joint [A]
86  *joint.effort[1] = *actuator.effort[1] * effort_factor_; // motor_2_joint [A]
87  *joint.effort[2] = (*actuator.effort[0] + *actuator.effort[1]) * effort_factor_ / 2; // sort of current average [A]
88  *joint.effort[3] = 0.0; // meaningless
89  }
90 
100  ROS_ASSERT(numActuators() == actuator.velocity.size() && numJoints() == joint.velocity.size());
101  ROS_ASSERT(actuator.velocity[0] && actuator.velocity[1] && actuator.velocity[2] && joint.velocity[0] && joint.velocity[1] && joint.velocity[2] && joint.velocity[3]);
102 
103  // note: be aware that this method _misuses_ actuator.velocity to store the current measured velocity
104  // - *actuator.velocity[i] is the current measured velocity of the motor i in [ticks/s]
105  // - *joint.velocity[i] is the previous step velocity in [radians/s] or [percent/s]
106  *joint.velocity[0] = filters::exponentialSmoothing(*actuator.velocity[0] * position_factor_.at(0), *joint.velocity[0], velocity_factor_); // motor_1_joint [radians/s]
107  *joint.velocity[1] = filters::exponentialSmoothing(*actuator.velocity[1] * position_factor_.at(1), *joint.velocity[1], velocity_factor_); // motor_2_joint [radians/s]
108  *joint.velocity[2] = filters::exponentialSmoothing(*actuator.velocity[2] * position_factor_.at(2), *joint.velocity[2], velocity_factor_); // shaft_joint [radians/s]
109  *joint.velocity[3] = (*joint.velocity[0] - *joint.velocity[1]) / 2; // stiffness preset [percent/s]
110  }
111 
121  ROS_ASSERT(numActuators() == actuator.position.size() && numJoints() == joint.position.size());
122  ROS_ASSERT(actuator.position[0] && actuator.position[1] && actuator.position[2] && joint.position[0] && joint.position[1] && joint.position[2] && joint.position[3]);
123 
124  *joint.position[0] = *actuator.position[0] * position_factor_.at(0); // motor_1_joint [radians]
125  *joint.position[1] = *actuator.position[1] * position_factor_.at(1); // motor_2_joint [radians]
126  *joint.position[2] = *actuator.position[2] * position_factor_.at(2); // shaft_joint [radians]
127  *joint.position[3] = std::abs(*actuator.position[0] - *actuator.position[1]) * preset_factor_ / 2; // stiffness_preset = abs(motor_1 - motor_2)/2 [percent 0,1]
128  }
129 
134 
138  inline const std::vector<double> getPositionFactor() const { return position_factor_; }
139 
143  inline const double getPresetFactor() const { return preset_factor_; }
144 
148  inline const double getPresetPercentToRadians() const { return position_factor_.front()/preset_factor_; }
149 
153  inline const double getVelocityFactor() const { return velocity_factor_; }
154 
158  inline const double getEffortFactor() const { return effort_factor_; }
159 
169  ROS_ASSERT(numActuators() == actuator.effort.size() && numJoints() == joint.effort.size());
170  ROS_ASSERT(actuator.effort[0] && actuator.effort[1] && actuator.effort[2] && joint.effort[0] && joint.effort[1] && joint.effort[2] && joint.effort[3]);
171 
173  // the qbmove cannot be controlled in current from shaft and preset info
174  *actuator.effort[0] = 0.0;
175  *actuator.effort[1] = 0.0;
176  *actuator.effort[2] = 0.0;
177  }
178  else { // direct motors control
179  // not used yet, but this could help in the near future
180  *actuator.effort[0] = *joint.effort[0] / effort_factor_;
181  *actuator.effort[1] = *joint.effort[1] / effort_factor_;
182  *actuator.effort[2] = 0.0;
183  }
184  }
185 
195  ROS_ASSERT(numActuators() == actuator.velocity.size() && numJoints() == joint.velocity.size());
196  ROS_ASSERT(actuator.velocity[0] && actuator.velocity[1] && actuator.velocity[2] && joint.velocity[0] && joint.velocity[1] && joint.velocity[2] && joint.velocity[3]);
197 
198  // the qbmove cannot be controlled in velocity
199  *actuator.velocity[0] = 0.0;
200  *actuator.velocity[1] = 0.0;
201  *actuator.velocity[2] = 0.0;
202  }
203 
213  ROS_ASSERT(numActuators() == actuator.position.size() && numJoints() == joint.position.size());
214  ROS_ASSERT(actuator.position[0] && actuator.position[1] && actuator.position[2] && joint.position[0] && joint.position[1] && joint.position[2] && joint.position[3]);
215 
217  *actuator.position[0] = *joint.position[2] / position_factor_.at(2) + *joint.position[3] / preset_factor_; // motor_1 = shaft + preset [ticks]
218  *actuator.position[1] = *joint.position[2] / position_factor_.at(2) - *joint.position[3] / preset_factor_; // motor_2 = shaft - preset [ticks]
219  *actuator.position[2] = *joint.position[2] / position_factor_.at(2);
220  }
221  else { // direct motors control
222  *actuator.position[0] = *joint.position[0] / position_factor_.at(0); // motor_1 = motor_1_command [ticks]
223  *actuator.position[1] = *joint.position[1] / position_factor_.at(1); // motor_2 = motor_2_command [ticks]
224  *actuator.position[2] = (*joint.position[0] / position_factor_.at(0) + *joint.position[1] / position_factor_.at(1))/2;
225  }
226  }
227 
231  inline std::size_t numActuators() const { return 3; }
232 
236  inline std::size_t numJoints() const { return 4; }
237 
241  inline void setCommandWithPoistionAndPreset(const bool &command_with_position_and_preset) { command_with_position_and_preset_ = command_with_position_and_preset; }
242 
246  inline void setPositionFactor(const std::vector<int> &encoder_resolutions) {
247  ROS_ASSERT(numActuators() == position_factor_.size() && numActuators() == encoder_resolutions.size());
248  ROS_ASSERT(encoder_resolutions[0] == encoder_resolutions[1]);
249  for (int i=0; i< position_factor_.size(); i++) {
250  position_factor_.at(i) = M_PI/std::pow(2, 15-encoder_resolutions.at(i));
251  }
252  }
253 
257  inline void setPresetFactor(const int &stiffness_preset_limit) { preset_factor_ = 1./stiffness_preset_limit; }
258 
259  private:
261  std::vector<double> position_factor_;
265 };
266 } // namespace qb_move_transmission_interface
267 
268 #endif // QB_MOVE_TRANSMISSION_H
std::vector< double * > velocity
void actuatorToJointVelocity(const transmission_interface::ActuatorData &actuator, transmission_interface::JointData &joint)
Transform velocity variables from actuator to joint space.
void jointToActuatorPosition(const transmission_interface::JointData &joint, transmission_interface::ActuatorData &actuator)
Transform position variables from joint to actuator space.
void actuatorToJointPosition(const transmission_interface::ActuatorData &actuator, transmission_interface::JointData &joint)
Transform position variables from actuator to joint space.
std::vector< double * > position
qbMoveTransmission(const bool &command_with_position_and_preset, const std::vector< double > &position_factor, const double &preset_factor, const double &velocity_factor, const double &effort_factor)
Build the qbmove transmission with the given scale factors.
void actuatorToJointEffort(const transmission_interface::ActuatorData &actuator, transmission_interface::JointData &joint)
Transform effort variables from actuator to joint space.
void setPositionFactor(const std::vector< int > &encoder_resolutions)
void jointToActuatorVelocity(const transmission_interface::JointData &joint, transmission_interface::ActuatorData &actuator)
Transform velocity variables from joint to actuator space.
qbMoveTransmission()
Build the qbmove transmission with default velocity and effort scale factors (respectively 0...
void jointToActuatorEffort(const transmission_interface::JointData &joint, transmission_interface::ActuatorData &actuator)
Transform effort variables from joint to actuator space.
INLINE Rall1d< T, V, S > pow(const Rall1d< T, V, S > &arg, double m)
static double exponentialSmoothing(double current_raw_value, double last_smoothed_value, double alpha)
std::vector< double * > velocity
std::vector< double * > position
void setCommandWithPoistionAndPreset(const bool &command_with_position_and_preset)
std::vector< double * > effort
std::vector< double * > effort
#define ROS_ASSERT(cond)
The qbrobotics qbmove Transmission interface implements the specific transmission_interface::Transmis...


qb_move_hardware_interface
Author(s): qbrobotics®
autogenerated on Thu Oct 10 2019 03:30:57