robot_stroke_converter.cpp
Go to the documentation of this file.
2 
3 using namespace noid;
4 using namespace common;
5 
6 namespace typef
7 {
9 void Angle2Stroke
10  (std::vector<int16_t>& _strokes, const std::vector<double> _angles)
11 {
12  float rad2Deg = 180.0 / M_PI;
13  float scale = 100.0;
14  dualJoint right_wrist =
15  WristRollPitchTable(rad2Deg * _angles[22],
16  rad2Deg * _angles[23]);
17  dualJoint left_wrist =
18  WristRollPitchTable(rad2Deg * _angles[8],
19  -rad2Deg * _angles[9]);
20  dualJoint waist =
21  WaistRollPitchTable(-rad2Deg * _angles[2],
22  rad2Deg * _angles[1]);
23  dualJoint neck =
24  NeckRollPitchTable(rad2Deg * _angles[16],
25  rad2Deg * _angles[15]);
26 
27  // ros_order -> can_order
28  _strokes[0] = scale * rad2Deg * _angles[14];
29  _strokes[1] = scale * neck.one;
30  _strokes[2] = scale * neck.two;
31 
32  _strokes[3] =
33  scale * ShoulderPitchTable(-rad2Deg * _angles[17]);
34  _strokes[4] =
35  scale * ShoulderRollTable(-rad2Deg * _angles[18]);
36  _strokes[5] = -scale * rad2Deg * _angles[19];
37  _strokes[6] = scale * ElbowPitchTable(-rad2Deg * _angles[20]);
38  _strokes[7] = -scale * rad2Deg * _angles[21];
39  _strokes[8] = scale * right_wrist.one;
40  _strokes[9] = scale * right_wrist.two;
41  _strokes[10] = -scale * (rad2Deg * _angles[27] - 50.0) * 0.18;
42 
43  _strokes[11] =
44  scale * ShoulderPitchTable(-rad2Deg * _angles[3]);
45  _strokes[12] =
46  scale * ShoulderRollTable(rad2Deg * _angles[4]);
47  _strokes[13] = -scale * rad2Deg * _angles[5];
48  _strokes[14] = scale * ElbowPitchTable(-rad2Deg * _angles[6]);
49  _strokes[15] = -scale * rad2Deg * _angles[7];
50  _strokes[16] = scale * left_wrist.one;
51  _strokes[17] = scale * left_wrist.two;
52  _strokes[18] = scale * (rad2Deg * _angles[13] + 50.0) * 0.18;
53 
54  _strokes[19] = scale * waist.two;
55  _strokes[20] = scale * waist.one;
56  _strokes[21] = scale * rad2Deg * _angles[0];
57 
58  _strokes[22] = scale * LegTable( rad2Deg * _angles[29]);
59  _strokes[23] = scale * LegTable(- rad2Deg * _angles[28]);
60 }
61 
63 void Stroke2Angle
64  (std::vector<double>& _angles, const std::vector<int16_t> _strokes)
65 {
66  float scale = 0.01;
67  float left_wrist_roll_stroke =
68  (scale * _strokes[16] + scale * _strokes[17]) * 0.5;
69  float right_wrist_roll_stroke =
70  (scale * _strokes[8] + scale * _strokes[9]) * 0.5;
71  float waist_pitch_stroke =
72  (scale * _strokes[19] + scale * _strokes[20]) * 0.5;
73  float neck_pitch_stroke =
74  (scale * _strokes[1] + scale * _strokes[2]) * 0.5;
75  float deg2Rad = M_PI / 180.0;
76  float knee_angle = - deg2Rad * LegInvTable(scale * _strokes[23]);
77  float ankle_angle = deg2Rad * LegInvTable(scale * _strokes[22]);
78 
79  // can_order -> ros_order
80  _angles[0] =
81  deg2Rad * scale * _strokes[21];
82  _angles[1] =
83  deg2Rad * WaistPitchInvTable(waist_pitch_stroke);
84  _angles[2] =
85  deg2Rad * WaistRollInvTable(scale * _strokes[19] - waist_pitch_stroke);
86 
87  _angles[3] =
88  -deg2Rad * ShoulderPitchInvTable(scale * _strokes[11]);
89  _angles[4] =
90  deg2Rad * ShoulderRollInvTable(scale * _strokes[12]);
91  _angles[5] =
92  -deg2Rad * scale * _strokes[13];
93  _angles[6] =
94  -deg2Rad * ElbowPitchInvTable(scale * _strokes[14]);
95  _angles[7] =
96  -deg2Rad * scale * _strokes[15];
97  _angles[8] =
98  deg2Rad * WristPitchInvTable(scale * _strokes[16] - left_wrist_roll_stroke);
99  _angles[9] =
100  -deg2Rad * WristRollInvTable(left_wrist_roll_stroke);
101  _angles[10] =
102  -deg2Rad * (scale * _strokes[18] * 5.556 - 50.0);
103  _angles[11] = 0;
104  _angles[12] = 0;
105  _angles[13] =
106  deg2Rad * (scale * _strokes[18] * 5.556 - 50.0);
107 
108  _angles[14] =
109  deg2Rad * scale * _strokes[0];
110  _angles[15] =
111  deg2Rad * NeckPitchInvTable(neck_pitch_stroke);
112  _angles[16] =
113  -deg2Rad * NeckRollInvTable(scale * _strokes[1] - neck_pitch_stroke);
114 
115  _angles[17] =
116  -deg2Rad * ShoulderPitchInvTable(scale * _strokes[3]);
117  _angles[18] =
118  -deg2Rad * ShoulderRollInvTable(scale * _strokes[4]);
119  _angles[19] =
120  -deg2Rad * scale * _strokes[5];
121  _angles[20] =
122  -deg2Rad * ElbowPitchInvTable(scale * _strokes[6]);
123  _angles[21] =
124  -deg2Rad * scale * _strokes[7];
125  _angles[22] =
126  deg2Rad * WristPitchInvTable(scale * _strokes[8] - right_wrist_roll_stroke);
127  _angles[23] =
128  deg2Rad * WristRollInvTable(right_wrist_roll_stroke);
129  _angles[24] =
130  deg2Rad * (scale * _strokes[10] * 5.556 - 50.0);
131  _angles[25] = 0;
132  _angles[26] = 0;
133  _angles[27] =
134  -deg2Rad * (scale * _strokes[10] * 5.556 - 50.0);
135 
136  _angles[28] = knee_angle;
137  _angles[29] = ankle_angle;
138 }
139 
140 }
141 
142 
143 
144 
145 
146 
float ShoulderRollInvTable(float _stroke)
float ElbowPitchTable(float _angle)
void Angle2Stroke(std::vector< int16_t > &_strokes, const std::vector< double > _angles)
float WristPitchInvTable(float _stroke)
float WristRollInvTable(float _stroke)
float WaistPitchInvTable(float _stroke)
float ShoulderPitchTable(float _angle)
float NeckPitchInvTable(float _stroke)
float ElbowPitchInvTable(float _stroke)
dualJoint WaistRollPitchTable(float _angle1, float _angle2)
void Stroke2Angle(std::vector< double > &_angles, const std::vector< int16_t > _strokes)
float ShoulderPitchInvTable(float _stroke)
float ShoulderRollTable(float _angle)
float NeckRollInvTable(float _stroke)
float LegTable(float _angle)
float WaistRollInvTable(float _stroke)
dualJoint NeckRollPitchTable(float _angle1, float _angle2)
float LegInvTable(float _stroke)
dualJoint WristRollPitchTable(float _angle1, float _angle2)


noid_robot_interface
Author(s):
autogenerated on Sat Jul 20 2019 03:44:26