@@ -87,6 +87,12 @@ void QuadrupedRobot::parse_code_run()
87
87
case 3 :
88
88
bot_walk ();
89
89
break ;
90
+ case 4 :
91
+ bot_turn_left ();
92
+ break ;
93
+ case 5 :
94
+ bot_turn_right ();
95
+ break ;
90
96
case 0 :
91
97
switch_off ();
92
98
break ;
@@ -181,6 +187,9 @@ void QuadrupedRobot::body_xyz(float x, float y, float z)
181
187
servo_move (joint_angs_new);
182
188
}
183
189
190
+ /* *
191
+ * Moving Body from current position
192
+ */
184
193
void QuadrupedRobot::body_move_xyz (float dx, float dy, float dz)
185
194
{
186
195
for (size_t i = 0 ; i < 4 ; i++)
@@ -193,6 +202,26 @@ void QuadrupedRobot::body_move_xyz(float dx, float dy, float dz)
193
202
servo_move (joint_angs_new);
194
203
}
195
204
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
+
196
225
/* *
197
226
* Move ith foot with one step, in the same hight work plane
198
227
*/
@@ -203,6 +232,19 @@ void QuadrupedRobot::foot_step(int i, float x, float z)
203
232
foot_move_xyz (i, 0 , -50 , 0 ); // leg placement
204
233
}
205
234
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
+ */
206
248
void QuadrupedRobot::foot_move_xyz (int i, float dx, float dy, float dz)
207
249
{
208
250
foot_pos[3 * i] += dx;
@@ -213,6 +255,32 @@ void QuadrupedRobot::foot_move_xyz(int i, float dx, float dy, float dz)
213
255
delay (200 );
214
256
}
215
257
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
+
216
284
217
285
/* *
218
286
* Calculate the joint angles by foot positions
@@ -361,18 +429,18 @@ void QuadrupedRobot::bot_rest()
361
429
void QuadrupedRobot::bot_walk ()
362
430
{
363
431
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
366
434
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);
368
436
while (command_code == 3 )
369
437
{
370
438
foot_step (2 , steplen, 0 ); // move RR
371
439
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 );
373
441
foot_step (3 , steplen, 0 ); // move RL
374
442
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);
376
444
interrupt ();
377
445
}
378
446
foot_step (2 , steplen / 2 , 0 );
@@ -381,6 +449,38 @@ void QuadrupedRobot::bot_walk()
381
449
delay (500 );
382
450
}
383
451
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
+
384
484
QuadrupedRobot::~QuadrupedRobot ()
385
485
{
386
486
for (size_t i = 0 ; i < DOF; i++)
0 commit comments