Class to drive a Hexapod Robot using two PCA9685 PWM Driver boards.

Dependencies:   Gait Hexapod_Leg PCA9685 Tripod

Committer:
el13cj
Date:
Tue May 10 12:15:20 2016 +0000
Revision:
1:24ba9327c9ee
Parent:
0:c15ca34340a7
Child:
2:e83b4acfcb36
About to add directions

Who changed what in which revision?

UserRevisionLine numberNew contents of line
el13cj 0:c15ca34340a7 1 #include "Hexapod.h"
el13cj 0:c15ca34340a7 2
el13cj 0:c15ca34340a7 3 #define I2C_ADDR_1 0x82
el13cj 0:c15ca34340a7 4 #define I2C_ADDR_2 0x84
el13cj 0:c15ca34340a7 5
el13cj 0:c15ca34340a7 6
el13cj 0:c15ca34340a7 7
el13cj 0:c15ca34340a7 8
el13cj 0:c15ca34340a7 9
el13cj 0:c15ca34340a7 10 Hexapod::Hexapod(I2C i2c) :
el13cj 0:c15ca34340a7 11
el13cj 0:c15ca34340a7 12
el13cj 0:c15ca34340a7 13 board_1(I2C_ADDR_1, i2c, 50),
el13cj 0:c15ca34340a7 14 board_2(I2C_ADDR_2, i2c, 50),
el13cj 0:c15ca34340a7 15
el13cj 0:c15ca34340a7 16 //*GROUP 1*
el13cj 0:c15ca34340a7 17 leg_1(board_1, leg_cent[1], leg_step[1], leg_out[0], true),
el13cj 0:c15ca34340a7 18 leg_5(board_2, leg_cent[5], leg_step[5], leg_out[1], false),
el13cj 0:c15ca34340a7 19 leg_3(board_1, leg_cent[3], leg_step[3], leg_out[2], true),
el13cj 0:c15ca34340a7 20
el13cj 1:24ba9327c9ee 21 group_1(board_1, leg_1, leg_5, leg_3, 1, 0),
el13cj 0:c15ca34340a7 22 //**
el13cj 0:c15ca34340a7 23
el13cj 0:c15ca34340a7 24 //*GROUP 2*
el13cj 0:c15ca34340a7 25 leg_4(board_2, leg_cent[4], leg_step[4], leg_out[0], false),
el13cj 0:c15ca34340a7 26 leg_2(board_1, leg_cent[2], leg_step[2], leg_out[1], true),
el13cj 0:c15ca34340a7 27 leg_6(board_2, leg_cent[6], leg_step[6], leg_out[2], false),
el13cj 0:c15ca34340a7 28
el13cj 1:24ba9327c9ee 29 group_2(board_2, leg_4, leg_2, leg_6, 2, 3),
el13cj 0:c15ca34340a7 30 //**
el13cj 0:c15ca34340a7 31
el13cj 0:c15ca34340a7 32 gait(group_1, group_2)
el13cj 0:c15ca34340a7 33
el13cj 0:c15ca34340a7 34 {
el13cj 0:c15ca34340a7 35
el13cj 0:c15ca34340a7 36 }
el13cj 0:c15ca34340a7 37
el13cj 0:c15ca34340a7 38
el13cj 0:c15ca34340a7 39 void Hexapod::init(void)
el13cj 0:c15ca34340a7 40 {
el13cj 0:c15ca34340a7 41
el13cj 0:c15ca34340a7 42 board_1.init();
el13cj 0:c15ca34340a7 43 board_2.init();
el13cj 0:c15ca34340a7 44
el13cj 1:24ba9327c9ee 45 /*
el13cj 1:24ba9327c9ee 46 group_1.set_gait_start(0);
el13cj 1:24ba9327c9ee 47 group_2.set_gait_start(5);
el13cj 1:24ba9327c9ee 48 */
el13cj 0:c15ca34340a7 49
el13cj 0:c15ca34340a7 50 stand();
el13cj 0:c15ca34340a7 51
el13cj 0:c15ca34340a7 52 }
el13cj 0:c15ca34340a7 53
el13cj 0:c15ca34340a7 54
el13cj 0:c15ca34340a7 55
el13cj 0:c15ca34340a7 56 void Hexapod::stand(void)
el13cj 0:c15ca34340a7 57 {
el13cj 0:c15ca34340a7 58 leg_1.set_joint_angles(0, 0, -90);
el13cj 0:c15ca34340a7 59 leg_2.set_joint_angles(0, 0, -90);
el13cj 0:c15ca34340a7 60 leg_3.set_joint_angles(0, 0, -90);
el13cj 0:c15ca34340a7 61 board_1.update();
el13cj 0:c15ca34340a7 62
el13cj 0:c15ca34340a7 63 leg_4.set_joint_angles(0, 0, -90);
el13cj 0:c15ca34340a7 64 leg_5.set_joint_angles(0, 0, -90);
el13cj 0:c15ca34340a7 65 leg_6.set_joint_angles(0, 0, -90);
el13cj 0:c15ca34340a7 66 board_2.update();
el13cj 0:c15ca34340a7 67 }
el13cj 0:c15ca34340a7 68
el13cj 0:c15ca34340a7 69 void Hexapod::walk(void)
el13cj 0:c15ca34340a7 70 {
el13cj 0:c15ca34340a7 71
el13cj 0:c15ca34340a7 72 gait.start(1);
el13cj 0:c15ca34340a7 73
el13cj 0:c15ca34340a7 74 }
el13cj 0:c15ca34340a7 75
el13cj 0:c15ca34340a7 76 void Hexapod::halt(void)
el13cj 0:c15ca34340a7 77 {
el13cj 0:c15ca34340a7 78
el13cj 0:c15ca34340a7 79 gait.stop();
el13cj 0:c15ca34340a7 80
el13cj 0:c15ca34340a7 81 }