Skip to content

Commit 2d06daf

Browse files
committed
fixed roll dir bug. Left turn test
1 parent bd102ea commit 2d06daf

File tree

4 files changed

+596
-8
lines changed

4 files changed

+596
-8
lines changed

hardware_test/LabRobot/StableGait/QuadrupedRobot.cpp

Lines changed: 105 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@ void QuadrupedRobot::parse_code_run()
8787
case 3:
8888
bot_walk();
8989
break;
90+
case 4:
91+
bot_turn_left();
92+
break;
93+
case 5:
94+
bot_turn_right();
95+
break;
9096
case 0:
9197
switch_off();
9298
break;
@@ -181,6 +187,9 @@ void QuadrupedRobot::body_xyz(float x, float y, float z)
181187
servo_move(joint_angs_new);
182188
}
183189

190+
/**
191+
* Moving Body from current position
192+
*/
184193
void QuadrupedRobot::body_move_xyz(float dx, float dy, float dz)
185194
{
186195
for (size_t i = 0; i < 4; i++)
@@ -193,6 +202,26 @@ void QuadrupedRobot::body_move_xyz(float dx, float dy, float dz)
193202
servo_move(joint_angs_new);
194203
}
195204

205+
/**
206+
* Turn body
207+
*/
208+
void QuadrupedRobot::body_turn_left()
209+
{
210+
// FL pose
211+
foot_pos[0] = - step_turn[0];
212+
foot_pos[2] = - step_turn[2];
213+
// RL pose
214+
foot_pos[9] = - step_turn[9];
215+
foot_pos[11] = - step_turn[11];
216+
// FR pose
217+
foot_pos[3] = 0;
218+
foot_pos[5] = 0;
219+
// RR pose
220+
foot_pos[6] = 0;
221+
foot_pos[8] = 0;
222+
body_move_xyz(0, 0, 2 * toe_out0);
223+
}
224+
196225
/**
197226
* Move ith foot with one step, in the same hight work plane
198227
*/
@@ -203,6 +232,19 @@ void QuadrupedRobot::foot_step(int i, float x, float z)
203232
foot_move_xyz(i, 0, -50, 0); // leg placement
204233
}
205234

235+
/**
236+
* Move ith foot with a turn angle
237+
*/
238+
void QuadrupedRobot::foot_step_ang(int i)
239+
{
240+
foot_move_xyz(i, 0, 50, 0); // leg lifting
241+
foot_move_xyz(i, step_turn[3 * i], 0, step_turn[3 * i + 2]);
242+
foot_move_xyz(i, 0, -50, 0); // leg placement
243+
}
244+
245+
/**
246+
* Moving foot from current position
247+
*/
206248
void QuadrupedRobot::foot_move_xyz(int i, float dx, float dy, float dz)
207249
{
208250
foot_pos[3 * i] += dx;
@@ -213,6 +255,32 @@ void QuadrupedRobot::foot_move_xyz(int i, float dx, float dy, float dz)
213255
delay(200);
214256
}
215257

258+
/**
259+
* Calculate step_turn
260+
* foot sequence: FL FR RR RL
261+
* index: ith (foot) * <0(x) | 1(y) | 2(z)>
262+
*/
263+
void QuadrupedRobot::turn_pose(float ang)
264+
{
265+
step_turn[0] = body_radius * cos(body_phi0 + ang * M_PI / 180) - feet_dist_x / 2;
266+
step_turn[2] = feet_dist_z / 2 - body_radius * sin(body_phi0 + ang * M_PI / 180);
267+
step_turn[3] = body_radius * cos(body_phi0 - ang * M_PI / 180) - feet_dist_x / 2;
268+
step_turn[5] = body_radius * sin(body_phi0 - ang * M_PI / 180) - feet_dist_z / 2;
269+
step_turn[6] = feet_dist_x / 2 - body_radius * cos(body_phi0 + ang * M_PI / 180);
270+
step_turn[8] = body_radius * sin(body_phi0 + ang * M_PI / 180) - feet_dist_z / 2;
271+
step_turn[9] = feet_dist_x / 2 - body_radius * cos(body_phi0 - ang * M_PI / 180);
272+
step_turn[11] = feet_dist_z / 2 - body_radius * sin(body_phi0 - ang * M_PI / 180);
273+
274+
// Serial.println(step_turn[0]);
275+
// Serial.println(step_turn[2]);
276+
// Serial.println(step_turn[3]);
277+
// Serial.println(step_turn[5]);
278+
// Serial.println(step_turn[6]);
279+
// Serial.println(step_turn[8]);
280+
// Serial.println(step_turn[9]);
281+
// Serial.println(step_turn[11]);
282+
}
283+
216284

217285
/**
218286
* Calculate the joint angles by foot positions
@@ -361,18 +429,18 @@ void QuadrupedRobot::bot_rest()
361429
void QuadrupedRobot::bot_walk()
362430
{
363431
Serial.println("walk");
364-
body_move_xyz(steplen / 4, 0, -toe_out0);
365-
foot_step(3, steplen / 2, 0); // move RL
432+
body_move_xyz(steplen / 4, 0, toe_out0);
433+
foot_step(3, steplen / 2, 0); // move FL
366434
foot_step(0, steplen / 2, 0); // move FL
367-
body_move_xyz(steplen / 4, 0, 2 * toe_out0);
435+
body_move_xyz(steplen / 4, 0, -2 * toe_out0);
368436
while (command_code == 3)
369437
{
370438
foot_step(2, steplen, 0); // move RR
371439
foot_step(1, steplen, 0); // move FR
372-
body_move_xyz(steplen / 2, 0, -2 * toe_out0 );
440+
body_move_xyz(steplen / 2, 0, 2 * toe_out0 );
373441
foot_step(3, steplen, 0); // move RL
374442
foot_step(0, steplen, 0); // move FL
375-
body_move_xyz(steplen / 2, 0, 2 * toe_out0);
443+
body_move_xyz(steplen / 2, 0, -2 * toe_out0);
376444
interrupt();
377445
}
378446
foot_step(2, steplen / 2, 0);
@@ -381,6 +449,38 @@ void QuadrupedRobot::bot_walk()
381449
delay(500);
382450
}
383451

452+
void QuadrupedRobot::bot_turn_left()
453+
{
454+
Serial.println("turn right");
455+
turn_pose(turn_phi);
456+
body_xyz(toe_out0 / 2, 0, -toe_out0); // Lean left
457+
foot_step_ang(2); // move RR
458+
foot_step_ang(1); // move FR
459+
body_turn_left(); // move body
460+
foot_step_ang(0); // move FL
461+
// foot_step_ang(3); // move RL
462+
463+
pause();
464+
}
465+
466+
void QuadrupedRobot::bot_turn_right()
467+
{
468+
Serial.println("turn left");
469+
while (command_code == 5)
470+
{
471+
;
472+
}
473+
474+
}
475+
476+
void QuadrupedRobot::pause()
477+
{
478+
while(!interrupt())
479+
{
480+
delay(1000);
481+
}
482+
}
483+
384484
QuadrupedRobot::~QuadrupedRobot()
385485
{
386486
for (size_t i = 0; i < DOF; i++)

hardware_test/LabRobot/StableGait/QuadrupedRobot.h

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,19 @@ class QuadrupedRobot
4141
* Real servo coord to calibrated coord: X-roll, Y-yaw, Z-pitch
4242
*/
4343
const float init_servo_deg[12]{35, 90, 180, 125, 83, 5, 40, 85, 180, 127, 83, 0};
44-
const int8_t servo_dir[12]{-1, -1, -1, -1, 1, 1, 1, 1, 1, 1, -1, -1};
44+
const int8_t servo_dir[12]{1, -1, -1, 1, 1, 1, -1, 1, 1, -1, -1, -1};
4545
const float toe_out0{30}; // outward distance of toe during stand, in mm
4646
const float dist_ag{30}; // distance between alfa and gamma axis, in mm
4747
const float thigh{107};
4848
const float calf{90};
49+
/**
50+
* Body configs
51+
*/
52+
const float feet_dist_z{70}; // distance between feet in z axis, in mm
53+
const float feet_dist_x{220}; // distance between feet in x axis, in mm
54+
// distance from center to the foot
55+
const float body_radius{sqrt(pow(feet_dist_z / 2, 2) + pow(feet_dist_x / 2, 2))};
56+
const float body_phi0{atan(feet_dist_z / feet_dist_x)};
4957
/**
5058
* vleg_len: virtual leg length (composite with 2 limbs)
5159
* alfa, gamma, beta is conresponding to angles on HipZ, Knee, HipX axises
@@ -64,14 +72,15 @@ class QuadrupedRobot
6472
float joint_angs_new[12]{};
6573
float vlegs_len[4]{};
6674
float foot_pos[12] {};
75+
float step_turn[12] {}; // foot step in case of turn
6776
/**
6877
* Configed States
6978
* Angles in callibrated coordinate
7079
*/
7180
const float stand_angs[12]{0, -30, 60, 0, -30, 60, 0, 30, -60, 0, 30, -60};
7281
const float rest_angs[12]{0, -55, 130, 0, -55, 130, 0, 55, -130, 0, 55, -130};
73-
const float adjust_angs[12] {};
74-
82+
const float adjust_angs[12]{};
83+
const float turn_phi{20};
7584
//
7685
// X points to forward, Z points to upward
7786

@@ -84,8 +93,12 @@ class QuadrupedRobot
8493

8594
void body_xyz(float x, float y, float z);
8695
void body_move_xyz(float dx, float dy, float dz);
96+
void body_turn_left();
97+
void body_turn_right();
8798
void foot_step(int i, float x, float z);
99+
void foot_step_ang(int i);
88100
void foot_move_xyz(int i, float dx, float dy, float dz);
101+
void turn_pose(float ang);
89102

90103
void inverse_kinematics();
91104
float gamma_left(float dy, float dz);
@@ -97,6 +110,8 @@ class QuadrupedRobot
97110
float alfa_front(float dx, float beta, float vleg_len);
98111
float alfa_rear(float dx, float beta, float vleg_len);
99112

113+
void pause();
114+
100115
public:
101116
~QuadrupedRobot();
102117
bool interrupt();
@@ -109,6 +124,8 @@ class QuadrupedRobot
109124
void bot_rest();
110125
void bot_stand();
111126
void bot_walk();
127+
void bot_turn_right();
128+
void bot_turn_left();
112129
};
113130

114131
#endif

hardware_test/LabRobot/StableGait/StableGait.ino

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ void setup() {
1515
" 1. switch on\n"
1616
" 2. stand\n"
1717
" 3. walk\n"
18+
" 4. turn left\n"
19+
" 5. turn right\n"
1820
" 0. switch off\n"
1921
" 998. adjust angles\n"
2022
);

0 commit comments

Comments
 (0)