-
Notifications
You must be signed in to change notification settings - Fork 2
/
hexapod.cc
299 lines (231 loc) · 10.4 KB
/
hexapod.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
//| This file is a part of the ERC ResiBots project.
//| Copyright 2015, ISIR / Universite Pierre et Marie Curie (UPMC)
//| Main contributor(s): Jean-Baptiste Mouret, [email protected]
//| Antoine Cully, [email protected]
//|
//| This software is governed by the CeCILL license under French law
//| and abiding by the rules of distribution of free software. You
//| can use, modify and/ or redistribute the software under the terms
//| of the CeCILL license as circulated by CEA, CNRS and INRIA at the
//| following URL "http://www.cecill.info".
//|
//| As a counterpart to the access to the source code and rights to
//| copy, modify and redistribute granted by the license, users are
//| provided only with a limited warranty and the software's author,
//| the holder of the economic rights, and the successive licensors
//| have only limited liability.
//|
//| In this respect, the user's attention is drawn to the risks
//| associated with loading, using, modifying and/or developing or
//| reproducing the software by the user in light of its specific
//| status of free software, that may mean that it is complicated to
//| manipulate, and that also therefore means that it is reserved for
//| developers and experienced professionals having in-depth computer
//| knowledge. Users are therefore encouraged to load and test the
//| software's suitability as regards their requirements in conditions
//| enabling the security of their systems and/or data to be ensured
//| and, more generally, to use and operate it in the same conditions
//| as regards security.
//|
//| The fact that you are presently reading this means that you have
//| had knowledge of the CeCILL license and that you accept its terms.
#include "hexapod.hh"
#include "ode/box.hh"
#include "ode/capped_cyl.hh"
#include "ode/sphere.hh"
#include "ode/motor.hh"
#include "ode/mx28.hh"
#include "ode/ax12.hh"
using namespace ode;
//USING_PART_OF_NAMESPACE_EIGEN
using namespace Eigen;
namespace robot
{
static int sign(float x)
{
return x > 0 ? 1 : -1;
}
void Hexapod :: _build(Environment_hexa& env, const Vector3d& pos)
{
/// Definition of robot's params
// length in meter
// mass in KG
// Robot -- PARIS
/*
static const double body_mass = 1.6; // with the new Mx 28
static const double body_length = 0.20;
static const double body_width = 0.24;
static const double body_height =0.04;
static const double legP1_w = 0.02;
static const double legP1_length = 0.06;
static const double legP1_dist = 0.2;
static const double legP1_mass = 0.020;
static const double legP2_w = 0.02;
static const double legP2_length = 0.085;
static const double legP2_dist = 0.2;
static const double legP2_mass = 0.180;
static const double legP3_w = 0.025;
static const double legP3_length = 0.145;
static const double legP3_dist = 0.2;
static const double legP3_mass = 0.060;
*/
static const double battery = 0.292;// white LiPo
static const double computer = 0.277;// cf documentation
static const double body_mass = 1.6 - battery - computer; // with the new Mx 28
static const double body_length = 0.20;
static const double body_width = 0.24;
static const double body_height = 0.04;
static const double legP1_w = 0.02;
static const double legP1_length = 0.06;
static const double legP1_dist = 0.2;
static const double legP1_mass = 0.020;
static const double legP2_w = 0.02;
static const double legP2_length = 0.085;
static const double legP2_dist = 0.2;
static const double legP2_mass = 0.184;
static const double legP3_w = 0.025;
static const double legP3_length = 0.095;
static const double legP3_dist = 0.2;
static const double legP3_mass = 0.040;
/// creation of robot's body
_main_body = Object::ptr_t(new Box(env, pos + Vector3d(0, 0, legP3_length+0.01),
body_mass, body_length, body_width, body_height));
_bodies.push_back(_main_body);
for (size_t i = 0; i <6; ++i) // for each legs
{
for(int j=0;j<_brokenLegs.size();j++)
{
if(i==_brokenLegs[j])
{
i++;
if(_brokenLegs.size()>j+1 && _brokenLegs[j+1]!=i)
break;
}
}
if(i>=6)
return;
// selecting an angle corresponding to number of the leg
// float angle = i<3 ? M_PI / 2.0f : -M_PI / 2.0f;// + M_PI / 6;
float angle;
float xStart=0; // selection of the start of the first joint
float yStart=0;
switch(i)
{
case 0:
case 5:
{
xStart=i<3 ? 0.06 : -0.06;
yStart=0.12;
angle=i<3? 3*M_PI/8:-3*M_PI/8;
break;
}
case 1:
case 4:
{
xStart=i<3 ? 0.10 : -0.10;
yStart=0;
angle=i<3? M_PI/2:-M_PI/2;
break;
}
case 2:
case 3:
{
xStart=i<3 ? 0.06 : -0.06;
yStart=-0.12;
angle=i<3? 5*M_PI/8:-5*M_PI/8;
break;
}
}
/// first part
Object::ptr_t l1(
/* new Box(env, pos
+ Vector3d(xStart+sin(angle) * (legP1_length / 2),
yStart+cos(angle) * (legP1_length / 2),
legP3_length+0.01),
legP1_mass,0.04, legP1_w, legP1_length));
*/
new CappedCyl(env, pos
+ Vector3d(xStart+sin(angle) * (legP1_length / 2),
yStart+cos(angle) * (legP1_length / 2),
legP3_length+0.01),
legP1_mass, legP1_w, legP1_length));
l1->set_rotation(Vector3d(cos(-angle), sin(-angle), 0),
Vector3d(0, 0, 1));
_bodies.push_back(l1);
env.add_leg_object(i,*l1);
Mx28::ptr_t s1(new Mx28(env, pos +
Vector3d(xStart,
yStart,
/*legP2_length+*/legP3_length+0.01),
*_main_body, *l1));
//s1->set_axis(0, Vector3d(cos(-angle), sin(-angle), 0));
s1->set_axis(0, Vector3d(0,0, 1));
s1->set_axis(2, Vector3d(1,0, 0));
//s1->set_hinge_axis(Vector3d(0,0, 1));
//s1->set_axis(2, Vector3d(0, 0, -1));
s1->set_lim(0, -M_PI/8, M_PI/8 );
_servos.push_back(s1);
/// second part
Object::ptr_t l2(
/* new Box(env, pos +
Vector3d(xStart+sin(angle) * (legP1_length+legP2_length/2),
yStart+cos(angle) * (legP1_length+legP2_length/2),
legP3_length+0.01),
legP2_mass,0.04, legP2_w, legP2_length));*/
new CappedCyl(env, pos +
Vector3d(xStart+sin(angle) * (legP1_length+legP2_length/2),
yStart+cos(angle) * (legP1_length+legP2_length/2),
legP3_length+0.01),
legP2_mass, legP2_w, legP2_length));
/*l2->set_rotation(Vector3d(cos(-angle), sin(-angle), 0),
Vector3d(sin(-angle), -cos(-angle), 0));*/
l2->set_rotation(Vector3d(cos(-angle), sin(-angle), 0),
Vector3d(0, 0, 1));
_bodies.push_back(l2);
env.add_leg_object(i,*l2);
Mx28::ptr_t s2(new Mx28(env, pos +
Vector3d(xStart+sin(angle) * (legP1_length),
yStart+cos(angle) * (legP1_length),
legP3_length+0.01),
*l1, *l2));
s2->set_axis(0, Vector3d(cos(-angle), sin(-angle), 0));
//s2->set_axis(2, Vector3d(sin(-angle), -cos(-angle), 0));
//s2->set_axis(0, Vector3d(0, 1, 0));
//s2->set_axis(2, Vector3d(0, 0, 1));
s2->set_lim(0, -M_PI/4, M_PI/4 );
_servos.push_back(s2);
/// third part
Object::ptr_t l3(
new CappedCyl(env, pos +
Vector3d(xStart+sin(angle) * (legP1_length+legP2_length),
yStart+cos(angle) * (legP1_length+legP2_length),
legP3_length/2+0.01),
legP3_mass, legP3_w, legP3_length));
//l3->set_rotation(Vector3d(cos(-angle), sin(-angle), 0),
// Vector3d(sin(-angle), -cos(-angle), 0));
_bodies.push_back(l3);
env.add_leg_object(i,*l3);
Mx28::ptr_t s3(new Mx28(env, pos +
Vector3d(xStart+sin(angle) * (legP1_length+legP2_length),
yStart+cos(angle) * (legP1_length+legP2_length),
legP3_length+0.01),
*l2, *l3));
s3->set_axis(0, Vector3d(cos(-angle), sin(-angle), 0));
s3->set_axis(2, Vector3d(sin(-angle), -cos(-angle), 0));
//s3->set_axis(0, Vector3d(1, 0, 0));
//s3->set_axis(2, Vector3d(0, 1, 0));
// dBodyVectorToWorld(l2->get_body(),1,0,0,axis);
//s3->set_hinge_axis(Vector3d(axis[0],axis[1],axis[2]));//Vector3d(0,1,0));
s3->set_lim(0, -M_PI/4, M_PI/4 );
_servos.push_back(s3);
}
for (size_t i = 0; i < _servos.size(); ++i)
for (size_t j = 0; j < 3; ++j)
_servos[i]->set_lim(j, -M_PI/2, M_PI/2 );
/*for (size_t i = 0; i < _servos.size(); i++)
{
for (size_t j = 0; j < 3; ++j)
_servos[i]->set_lim(j, 0, 0 );
}*/
}
}