-
Notifications
You must be signed in to change notification settings - Fork 3
/
hexapod.cc
169 lines (143 loc) · 6.55 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
#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
namespace robot {
void Hexapod::_build(Environment_hexa& env, const Eigen::Vector3d& pos)
{
/// Definition of robot's params
// length in meter
// mass in KG
static const double body_mass = 1.6; // with 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;
/// creation of robot's body
_main_body = Object::ptr_t(new Box(env, pos + Eigen::Vector3d(0, 0, legP3_length + 0.01),
body_mass, body_length, body_width, body_height));
_bodies.push_back(_main_body);
for (int i = 0; i < 6; ++i) // for each legs
{
for (size_t 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 = 0;
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 CappedCyl(env, pos
+ Eigen::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(Eigen::Vector3d(cos(-angle), sin(-angle), 0),
Eigen::Vector3d(0, 0, -1));
_bodies.push_back(l1);
env.add_leg_object(i, *l1);
Mx28::ptr_t s1(new Mx28(env, pos + Eigen::Vector3d(xStart,
yStart,
/*legP2_length+*/ legP3_length + 0.01),
*_main_body, *l1));
//s1->set_axis(0, Eigen::Vector3d(cos(-angle), sin(-angle), 0));
s1->set_axis(0, Eigen::Vector3d(0, 0, 1));
//s1->set_axis(2, Eigen::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 CappedCyl(env, pos + Eigen::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(Eigen::Vector3d(cos(-angle), sin(-angle), 0),
Eigen::Vector3d(sin(-angle), -cos(-angle), 0));*/
l2->set_rotation(Eigen::Vector3d(cos(-angle), sin(-angle), 0),
Eigen::Vector3d(0, 0, -1));
_bodies.push_back(l2);
env.add_leg_object(i, *l2);
Mx28::ptr_t s2(new Mx28(env, pos + Eigen::Vector3d(xStart + sin(angle) * (legP1_length),
yStart + cos(angle) * (legP1_length),
legP3_length + 0.01),
*l1, *l2));
s2->set_axis(0, Eigen::Vector3d(cos(-angle), sin(-angle), 0));
s2->set_axis(2, Eigen::Vector3d(sin(-angle), -cos(-angle), 0));
s2->set_lim(0, -M_PI / 4, M_PI / 4);
_servos.push_back(s2);
/// third part
Object::ptr_t l3(
new CappedCyl(env, pos + Eigen::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(Eigen::Vector3d(cos(-angle), sin(-angle), 0),
Eigen::Vector3d(sin(-angle), -cos(-angle), 0));
_bodies.push_back(l3);
env.add_leg_object(i, *l3);
Mx28::ptr_t s3(new Mx28(env, pos + Eigen::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, Eigen::Vector3d(cos(-angle), sin(-angle), 0));
s3->set_axis(2, Eigen::Vector3d(sin(-angle), -cos(-angle), 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 = 1; j < 3; ++j)
_servos[i]->set_lim(j, 0, 0 );
}*/
}
}