talos-torque-control  1.1.0
Collection of dynamic-graph entities aiming at the implementation of torque control on TALOS.
talos-common.hh
Go to the documentation of this file.
1 /*
2  * Copyright 2014, Oscar E. Ramos Ponce, LAAS-CNRS
3  *
4  */
5 
6 #ifndef __sot_torque_control_talos_common_H__
7 #define __sot_torque_control_talos_common_H__
8 
9 /* --------------------------------------------------------------------- */
10 /* --- API ------------------------------------------------------------- */
11 /* --------------------------------------------------------------------- */
12 
13 #if defined (WIN32)
14 # if defined (talos_common_EXPORTS)
15 # define TALOSCOMMON_EXPORT __declspec(dllexport)
16 # else
17 # define TALOSCOMMON_EXPORT __declspec(dllimport)
18 # endif
19 #else
20 # define TALOSCOMMON_EXPORT
21 #endif
22 
23 
24 /* --------------------------------------------------------------------- */
25 /* --- INCLUDE --------------------------------------------------------- */
26 /* --------------------------------------------------------------------- */
27 
28 #include <map>
29 #include <initializer_list>
30 #include "boost/assign.hpp"
31 /* HELPER */
32 #include <dynamic-graph/signal-helper.h>
33 #include <sot/core/matrix-geometry.hh>
34 
35 namespace dynamicgraph {
36 namespace sot {
37 namespace torque_control {
38 
39 #define N_JOINTS 32
40 
41 #define RIGHT_FOOT_FRAME_NAME "RLEG_JOINT5"
42 #define LEFT_FOOT_FRAME_NAME "LLEG_JOINT5"
43 
44 const double DEFAULT_MAX_DELTA_Q = 0.1;
45 
46 const double DEFAULT_MAX_CURRENT = 5;
47 
48 // Information on the location of the IMU and F/T sensors of HRP-2
49 // copied from the urdf file (in stacks/hrp2/hrp2_14_description/urdf):
50 // <joint name="AccelerometerJoint" type="fixed">
51 // <origin xyz="-0.13 0.0 0.118" rpy="0.0 0.0 0.0"/>
52 // <joint name="RightFootForceSensorJoint" type="fixed">
53 // <origin xyz="0.0 0.0 -0.105" rpy="0.0 0.0 0.0"/>
54 // <joint name="LeftFootForceSensorJoint" type="fixed">
55 // <origin xyz="0.0 0.0 -0.105" rpy="0.0 0.0 0.0"/>
56 // <joint name="RightHandForceSensorJoint" type="fixed">
57 // <origin xyz="0.005 0.0 -0.05925" rpy="0.0 0.0 0.0"/>
58 // <joint name="LeftHandForceSensorJoint" type="fixed">
59 // <origin xyz="0.005 0.0 -0.05925" rpy="0.0 0.0 0.0"/>
60 
62 const double IMU_XYZ[3] = { -0.13, 0.0, 0.118}; // not updated for talos/talos
63 
65 const double RIGHT_FOOT_FORCE_SENSOR_XYZ[3] = {0.0, 0.0, -0.0}; // not updated for talos/talos
66 const double LEFT_FOOT_FORCE_SENSOR_XYZ[3] = {0.0, 0.0, -0.0}; // not updated for talos/talos
67 const double RIGHT_HAND_FORCE_SENSOR_XYZ[3] = {0.0, 0.0, -0.051};
68 const double LEFT_HAND_FORCE_SENSOR_XYZ[3] = {0.005, 0.0, -0.051};
69 
71 const double RIGHT_HAND_FORCE_SENSOR_Z_ROTATION = -0.5 * M_PI; // not updated for talos/talos
72 const double LEFT_HAND_FORCE_SENSOR_Z_ROTATION = -0.5 * M_PI; // not updated for talos/talos
73 
75 const double RIGHT_FOOT_SOLE_XYZ[3] = {0.0, 0.0, -0.107};
76 const double LEFT_FOOT_SOLE_XYZ[3] = {0.0, 0.0, -0.107};
77 
79 const double RIGHT_HAND_GRIPPER_XYZ[3] = {0.0, 0.0, -0.02875};
80 const double LEFT_HAND_GRIPPER_XYZ[3] = {0.0, 0.0, 0.02025};
81 
83 const double RIGHT_FOOT_FORCE_SENSOR_MASS_PERCENTAGE = 0.65; // not updated for talos/talos
84 const double LEFT_FOOT_FORCE_SENSOR_MASS_PERCENTAGE = 0.65; // not updated for talos/talos
85 const double RIGHT_HAND_FORCE_SENSOR_MASS_PERCENTAGE = 0.75; // not updated for talos/talos
86 const double LEFT_HAND_FORCE_SENSOR_MASS_PERCENTAGE = 0.75; // not updated for talos/talos
87 
88 struct JointLimits {
89  double upper;
90  double lower;
91 
93  upper(0.0),
94  lower(0.0)
95  {}
96 
97  JointLimits(double l, double u):
98  upper(u),
99  lower(l)
100  {}
101 };
102 
104 struct JointUtil {
105  static std::map<unsigned int, JointLimits> create_id_2_limits_map() {
106  std::map<unsigned int, JointLimits> m;
107  m[0] = JointLimits(-0.349065850399, 1.57079632679); // left leg 1
108  m[1] = JointLimits(-0.5236, 0.5236); // left leg 2
109  m[2] = JointLimits(-2.095, 0.7); // left leg 3
110  m[3] = JointLimits(0.0, 2.618); // left leg 4
111  m[4] = JointLimits(-1.309, 0.768); // left leg 5
112  m[5] = JointLimits(-0.5236, 0.5236); // left leg 6
113  m[6] = JointLimits(-1.57079632679, 0.349065850399); // right leg 1
114  m[7] = JointLimits(-0.5236, 0.5236); // right leg 2
115  m[8] = JointLimits(-2.095, 0.7); // right leg 3
116  m[9] = JointLimits(0.0, 2.618); // right leg 4
117  m[10] = JointLimits(-1.309, 0.768); // right leg 5
118  m[11] = JointLimits(-0.5236, 0.5236); // right leg 6
119  m[12] = JointLimits(-1.308996939, 1.308996939); // torso 1
120  m[13] = JointLimits(-0.261799387799, 0.785398163397); // torso 2
121  m[14] = JointLimits(-1.57079632679, 0.523598775598); // left arm 1 shoulder
122  m[15] = JointLimits(0.0, 2.87979326579); // left arm 2 shoulder
123  m[16] = JointLimits(-2.44346095279, 2.44346095279); // left arm 3 shoulder
124  m[17] = JointLimits(-2.35619449019, 0.0); // left arm 4 elbow
125  m[18] = JointLimits(-2.53072741539, 2.53072741539); // left arm 5 wrist
126  m[19] = JointLimits(-1.3962634016, 1.3962634016); // left arm 6 wrist
127  m[20] = JointLimits(-0.698131700798, 0.698131700798); // left arm 7 wrist
128  m[21] = JointLimits(-1.0471975512, 0.0); // left gripper
129  m[22] = JointLimits(-0.523598775598, 1.57079632679); // right arm 1 shoulder
130  m[23] = JointLimits(-2.87979326579, 0.0); // right arm 2 shoulder
131  m[24] = JointLimits(-2.44346095279, 2.44346095279); // right arm 3 shoulder
132  m[25] = JointLimits(-2.35619449019, 0.0); // right arm 4 elbow
133  m[26] = JointLimits(-2.53072741539, 2.53072741539); // right arm 5 wrist
134  m[27] = JointLimits(-1.3962634016, 1.3962634016); // right arm 6 wrist
135  m[28] = JointLimits(-0.698131700798, 0.698131700798); // right arm 7 wrist
136  m[29] = JointLimits(-1.0471975512, 0.0); // right gripper
137  m[30] = JointLimits(-0.261799387799, 0.785398163397); // head 1
138  m[31] = JointLimits(-1.308996939, 1.308996939); // head 2
139  return m;
140  }
141 
142  static std::map<std::string, unsigned int> create_name_2_id_map() {
143  std::map<std::string, unsigned int> m;
144  m["lhy"] = 0; // left hip yaw
145  m["lhr"] = 1; // left hip roll
146  m["lhp"] = 2; // left hip pitch
147  m["lk"] = 3; // left knee
148  m["lap"] = 4; // left ankle pitch
149  m["lar"] = 5; // left ankle roll
150  m["rhy"] = 6; // right hip yaw
151  m["rhr"] = 7; // right hip roll
152  m["rhp"] = 8; // right hip pitch
153  m["rk"] = 9; // right knee
154  m["rap"] = 10; // right ankle pitch
155  m["rar"] = 11; // right ankle roll
156  m["ty"] = 12; // torso yaw
157  m["tp"] = 13; // torso pitch
158  m["lsy"] = 14; // left shoulder yaw
159  m["lsr"] = 15; // left shoulder roll
160  m["lay"] = 16; // left arm yaw
161  m["le"] = 17; // left elbow
162  m["lwy"] = 18; // left wrist yaw
163  m["lwp"] = 19; // left wrist pitch
164  m["lwr"] = 20; // left wrist roll
165  m["lh"] = 21; // left hand
166  m["rsy"] = 22; // right shoulder yaw
167  m["rsr"] = 23; // right shoulder roll
168  m["ray"] = 24; // right arm yaw
169  m["re"] = 25; // right elbow
170  m["rwy"] = 26; // right wrist yaw
171  m["rwp"] = 27; // right wrist pitch
172  m["rwr"] = 28; // right wrist roll
173  m["rh"] = 29; // right hand
174  m["hp"] = 30; // head pitch
175  m["hy"] = 31; // head yaw
176  return m;
177  }
178 
179  static std::map<unsigned int, std::string> create_id_2_name_map(
180  const std::map<std::string, unsigned int>& name_2_id_map) {
181  std::map<unsigned int, std::string> m;
182  std::map<std::string, unsigned int>::const_iterator it;
183  for (it = name_2_id_map.begin(); it != name_2_id_map.end(); it++)
184  m[it->second] = it->first;
185  return m;
186  }
187 
192  static int get_id_from_name(std::string name) {
193  std::map<std::string, unsigned int>::const_iterator iter = name_2_id.find(name);
194  if (iter == name_2_id.end())
195  return -1;
196  return iter->second;
197  }
198 
203  static std::string get_name_from_id(unsigned int id) {
204  std::map<unsigned int, std::string>::const_iterator iter = id_2_name.find(id);
205  if (iter == id_2_name.end())
206  return "Joint name not found";
207  return iter->second;
208  }
209 
214  static JointLimits get_limits_from_id(unsigned int id) {
215  std::map<unsigned int, JointLimits>::const_iterator iter = id_2_limits.find(id);
216  if (iter == id_2_limits.end())
217  return JointLimits(0.0, 0.0);
218  return iter->second;
219  }
220 
221  static const std::map<std::string, unsigned int> name_2_id;
222  static const std::map<unsigned int, std::string> id_2_name;
223  static const std::map<unsigned int, JointLimits> id_2_limits;
224 };
225 const std::map<std::string, unsigned int> JointUtil::name_2_id = JointUtil::create_name_2_id_map();
226 const std::map<unsigned int, std::string> JointUtil::id_2_name = JointUtil::create_id_2_name_map(JointUtil::name_2_id);
227 const std::map<unsigned int, JointLimits> JointUtil::id_2_limits = JointUtil::create_id_2_limits_map();
228 
229 
230 
231 struct ForceLimits {
232  Eigen::VectorXd upper;
233  Eigen::VectorXd lower;
234 
236  upper(dynamicgraph::sot::Vector6d::Zero()),
237  lower(dynamicgraph::sot::Vector6d::Zero())
238  {}
239 
240  ForceLimits(const Eigen::VectorXd& l, const Eigen::VectorXd& u):
241  upper(u),
242  lower(l)
243  {}
244 };
245 
246 enum ForceID {
251 };
252 
254 struct ForceUtil {
255  static std::map<unsigned int, ForceLimits> create_id_2_limits_map() {
256  dynamicgraph::sot::Vector6d fMax, fMin;
257  fMax << 100.0, 100.0, 300.0, 80.0, 80.0, 30.0;
258  fMin = -fMax;
259  std::map<unsigned int, ForceLimits> m;
260  m[0] = ForceLimits(fMin, fMax); // right foot
261  m[1] = ForceLimits(fMin, fMax); // left foot
262  m[2] = ForceLimits(fMin, fMax); // right hand
263  m[3] = ForceLimits(fMin, fMax); // left hand
264  return m;
265  }
266 
267  static std::map<std::string, unsigned int> create_name_2_id_map() {
268  std::map<std::string, unsigned int> m;
269  m["rf"] = 0; // right foot
270  m["lf"] = 1; // left foot
271  m["rh"] = 2; // right hand
272  m["lh"] = 3; // left hand
273  return m;
274  }
275 
276  static std::map<unsigned int, std::string> create_id_2_name_map(
277  const std::map<std::string, unsigned int>& name_2_id_map) {
278  std::map<unsigned int, std::string> m;
279  std::map<std::string, unsigned int>::const_iterator it;
280  for (it = name_2_id_map.begin(); it != name_2_id_map.end(); it++)
281  m[it->second] = it->first;
282  return m;
283  }
284 
289  static int get_id_from_name(std::string name) {
290  std::map<std::string, unsigned int>::const_iterator iter = name_2_id.find(name);
291  if (iter == name_2_id.end())
292  return -1;
293  return iter->second;
294  }
295 
300  static std::string get_name_from_id(unsigned int id) {
301  std::map<unsigned int, std::string>::const_iterator iter = id_2_name.find(id);
302  if (iter == id_2_name.end())
303  return "Force name not found";
304  return iter->second;
305  }
306 
311  static ForceLimits get_limits_from_id(unsigned int id) {
312  std::map<unsigned int, ForceLimits>::const_iterator iter = id_2_limits.find(id);
313  if (iter == id_2_limits.end())
314  return ForceLimits();
315  return iter->second;
316  }
317 
318  static const std::map<std::string, unsigned int> name_2_id;
319  static const std::map<unsigned int, std::string> id_2_name;
320  static const std::map<unsigned int, ForceLimits> id_2_limits;
321 };
322 const std::map<std::string, unsigned int> ForceUtil::name_2_id = ForceUtil::create_name_2_id_map();
323 const std::map<unsigned int, std::string> ForceUtil::id_2_name = ForceUtil::create_id_2_name_map(ForceUtil::name_2_id);
324 const std::map<unsigned int, ForceLimits> ForceUtil::id_2_limits = ForceUtil::create_id_2_limits_map();
325 
326 bool base_se3_to_sot(dynamicgraph::sot::ConstRefVector pos,
327  dynamicgraph::sot::ConstRefMatrix R,
328  dynamicgraph::sot::RefVector q_sot);
329 bool base_urdf_to_sot(dynamicgraph::sot::ConstRefVector q_urdf, dynamicgraph::sot::RefVector q_sot);
330 bool base_sot_to_urdf(dynamicgraph::sot::ConstRefVector q_sot, dynamicgraph::sot::RefVector q_urdf);
331 bool config_urdf_to_sot(dynamicgraph::sot::ConstRefVector q_urdf, dynamicgraph::sot::RefVector q_sot);
332 bool config_sot_to_urdf(dynamicgraph::sot::ConstRefVector q_sot, dynamicgraph::sot::RefVector q_urdf);
333 bool velocity_urdf_to_sot(dynamicgraph::sot::ConstRefVector v_urdf, dynamicgraph::sot::RefVector v_sot);
334 bool velocity_sot_to_urdf(dynamicgraph::sot::ConstRefVector v_sot, dynamicgraph::sot::RefVector v_urdf);
335 bool joints_urdf_to_sot(dynamicgraph::sot::ConstRefVector q_urdf, dynamicgraph::sot::RefVector q_sot);
336 bool joints_sot_to_urdf(dynamicgraph::sot::ConstRefVector q_sot, dynamicgraph::sot::RefVector q_urdf);
337 
338 } // namespace torque_control
339 } // namespace sot
340 } // namespace dynamicgraph
341 
342 
343 
344 #endif // #ifndef __sot_torque_control_talos_common_H__
static const std::map< unsigned int, ForceLimits > id_2_limits
static std::map< unsigned int, std::string > create_id_2_name_map(const std::map< std::string, unsigned int > &name_2_id_map)
static const std::map< std::string, unsigned int > name_2_id
static int get_id_from_name(std::string name)
const double RIGHT_FOOT_FORCE_SENSOR_MASS_PERCENTAGE
Percentage of mass of the link that is measured by the F/T sensors.
Definition: talos-common.hh:83
bool config_sot_to_urdf(dynamicgraph::sot::ConstRefVector q_sot, dynamicgraph::sot::RefVector q_urdf)
const double LEFT_HAND_FORCE_SENSOR_XYZ[3]
Definition: talos-common.hh:68
static std::map< std::string, unsigned int > create_name_2_id_map()
const double LEFT_FOOT_FORCE_SENSOR_XYZ[3]
Definition: talos-common.hh:66
const double LEFT_HAND_FORCE_SENSOR_MASS_PERCENTAGE
Definition: talos-common.hh:86
bool base_se3_to_sot(dynamicgraph::sot::ConstRefVector pos, dynamicgraph::sot::ConstRefMatrix R, dynamicgraph::sot::RefVector q_sot)
bool base_urdf_to_sot(dynamicgraph::sot::ConstRefVector q_urdf, dynamicgraph::sot::RefVector q_sot)
bool velocity_sot_to_urdf(dynamicgraph::sot::ConstRefVector v_sot, dynamicgraph::sot::RefVector v_urdf)
ForceLimits(const Eigen::VectorXd &l, const Eigen::VectorXd &u)
const double LEFT_HAND_FORCE_SENSOR_Z_ROTATION
Definition: talos-common.hh:72
const double RIGHT_FOOT_SOLE_XYZ[3]
Position of the foot soles w.r.t. the frame of the foot.
Definition: talos-common.hh:75
static const std::map< std::string, unsigned int > name_2_id
const double DEFAULT_MAX_CURRENT
max joint position tracking error [rad]
Definition: talos-common.hh:46
static JointLimits get_limits_from_id(unsigned int id)
static std::map< std::string, unsigned int > create_name_2_id_map()
bool velocity_urdf_to_sot(dynamicgraph::sot::ConstRefVector v_urdf, dynamicgraph::sot::RefVector v_sot)
bool joints_sot_to_urdf(dynamicgraph::sot::ConstRefVector q_sot, dynamicgraph::sot::RefVector q_urdf)
const double RIGHT_HAND_FORCE_SENSOR_XYZ[3]
Definition: talos-common.hh:67
bool config_urdf_to_sot(dynamicgraph::sot::ConstRefVector q_urdf, dynamicgraph::sot::RefVector q_sot)
const double RIGHT_HAND_FORCE_SENSOR_MASS_PERCENTAGE
Definition: talos-common.hh:85
static const std::map< unsigned int, std::string > id_2_name
const double RIGHT_FOOT_FORCE_SENSOR_XYZ[3]
Position of the force/torque sensors w.r.t. the frame of the hosting link.
Definition: talos-common.hh:65
const double RIGHT_HAND_FORCE_SENSOR_Z_ROTATION
Rotation angle around Z axis of the force/torque sensors w.r.t. the frame of the hosting link...
Definition: talos-common.hh:71
static std::map< unsigned int, std::string > create_id_2_name_map(const std::map< std::string, unsigned int > &name_2_id_map)
const double RIGHT_HAND_GRIPPER_XYZ[3]
Position of the hand grippers w.r.t. the frame of the hand.
Definition: talos-common.hh:79
bool joints_urdf_to_sot(dynamicgraph::sot::ConstRefVector q_urdf, dynamicgraph::sot::RefVector q_sot)
static std::map< unsigned int, ForceLimits > create_id_2_limits_map()
static ForceLimits get_limits_from_id(unsigned int id)
static int get_id_from_name(std::string name)
static std::map< unsigned int, JointLimits > create_id_2_limits_map()
static std::string get_name_from_id(unsigned int id)
static const std::map< unsigned int, std::string > id_2_name
const double IMU_XYZ[3]
max CURRENT (double in [0 Amp, 20 Amp])
Definition: talos-common.hh:62
bool base_sot_to_urdf(dynamicgraph::sot::ConstRefVector q_sot, dynamicgraph::sot::RefVector q_urdf)
static std::string get_name_from_id(unsigned int id)
Map from joint names to joint ids.
Map from force names to force ids.
static const std::map< unsigned int, JointLimits > id_2_limits
const double LEFT_FOOT_FORCE_SENSOR_MASS_PERCENTAGE
Definition: talos-common.hh:84