Class to drive a Hexapod Robot using two PCA9685 PWM Driver boards.
Dependencies: Gait Hexapod_Leg PCA9685 Tripod
Hexapod.cpp@3:82ac75ea08a7, 2016-05-11 (annotated)
- Committer:
- el13cj
- Date:
- Wed May 11 15:47:09 2016 +0000
- Revision:
- 3:82ac75ea08a7
- Parent:
- 2:e83b4acfcb36
Ready
Who changed what in which revision?
User | Revision | Line number | New 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 | Hexapod::Hexapod(I2C i2c) : |
el13cj | 0:c15ca34340a7 | 7 | |
el13cj | 0:c15ca34340a7 | 8 | board_1(I2C_ADDR_1, i2c, 50), |
el13cj | 0:c15ca34340a7 | 9 | board_2(I2C_ADDR_2, i2c, 50), |
el13cj | 0:c15ca34340a7 | 10 | |
el13cj | 0:c15ca34340a7 | 11 | //*GROUP 1* |
el13cj | 0:c15ca34340a7 | 12 | leg_1(board_1, leg_cent[1], leg_step[1], leg_out[0], true), |
el13cj | 0:c15ca34340a7 | 13 | leg_5(board_2, leg_cent[5], leg_step[5], leg_out[1], false), |
el13cj | 0:c15ca34340a7 | 14 | leg_3(board_1, leg_cent[3], leg_step[3], leg_out[2], true), |
el13cj | 0:c15ca34340a7 | 15 | |
el13cj | 1:24ba9327c9ee | 16 | group_1(board_1, leg_1, leg_5, leg_3, 1, 0), |
el13cj | 0:c15ca34340a7 | 17 | //** |
el13cj | 0:c15ca34340a7 | 18 | |
el13cj | 0:c15ca34340a7 | 19 | //*GROUP 2* |
el13cj | 0:c15ca34340a7 | 20 | leg_4(board_2, leg_cent[4], leg_step[4], leg_out[0], false), |
el13cj | 0:c15ca34340a7 | 21 | leg_2(board_1, leg_cent[2], leg_step[2], leg_out[1], true), |
el13cj | 0:c15ca34340a7 | 22 | leg_6(board_2, leg_cent[6], leg_step[6], leg_out[2], false), |
el13cj | 0:c15ca34340a7 | 23 | |
el13cj | 1:24ba9327c9ee | 24 | group_2(board_2, leg_4, leg_2, leg_6, 2, 3), |
el13cj | 0:c15ca34340a7 | 25 | //** |
el13cj | 0:c15ca34340a7 | 26 | |
el13cj | 0:c15ca34340a7 | 27 | gait(group_1, group_2) |
el13cj | 0:c15ca34340a7 | 28 | |
el13cj | 0:c15ca34340a7 | 29 | { |
el13cj | 0:c15ca34340a7 | 30 | |
el13cj | 0:c15ca34340a7 | 31 | } |
el13cj | 0:c15ca34340a7 | 32 | |
el13cj | 0:c15ca34340a7 | 33 | void Hexapod::init(void) |
el13cj | 0:c15ca34340a7 | 34 | { |
el13cj | 0:c15ca34340a7 | 35 | |
el13cj | 0:c15ca34340a7 | 36 | board_1.init(); |
el13cj | 0:c15ca34340a7 | 37 | board_2.init(); |
el13cj | 0:c15ca34340a7 | 38 | |
el13cj | 1:24ba9327c9ee | 39 | /* |
el13cj | 1:24ba9327c9ee | 40 | group_1.set_gait_start(0); |
el13cj | 1:24ba9327c9ee | 41 | group_2.set_gait_start(5); |
el13cj | 1:24ba9327c9ee | 42 | */ |
el13cj | 0:c15ca34340a7 | 43 | |
el13cj | 0:c15ca34340a7 | 44 | stand(); |
el13cj | 0:c15ca34340a7 | 45 | |
el13cj | 0:c15ca34340a7 | 46 | } |
el13cj | 0:c15ca34340a7 | 47 | |
el13cj | 0:c15ca34340a7 | 48 | void Hexapod::stand(void) |
el13cj | 0:c15ca34340a7 | 49 | { |
el13cj | 0:c15ca34340a7 | 50 | leg_1.set_joint_angles(0, 0, -90); |
el13cj | 0:c15ca34340a7 | 51 | leg_2.set_joint_angles(0, 0, -90); |
el13cj | 0:c15ca34340a7 | 52 | leg_3.set_joint_angles(0, 0, -90); |
el13cj | 0:c15ca34340a7 | 53 | board_1.update(); |
el13cj | 0:c15ca34340a7 | 54 | |
el13cj | 0:c15ca34340a7 | 55 | leg_4.set_joint_angles(0, 0, -90); |
el13cj | 0:c15ca34340a7 | 56 | leg_5.set_joint_angles(0, 0, -90); |
el13cj | 0:c15ca34340a7 | 57 | leg_6.set_joint_angles(0, 0, -90); |
el13cj | 0:c15ca34340a7 | 58 | board_2.update(); |
el13cj | 0:c15ca34340a7 | 59 | } |
el13cj | 0:c15ca34340a7 | 60 | |
el13cj | 2:e83b4acfcb36 | 61 | void Hexapod::walk(int Dir) |
el13cj | 0:c15ca34340a7 | 62 | { |
el13cj | 2:e83b4acfcb36 | 63 | gait.stop(); |
el13cj | 2:e83b4acfcb36 | 64 | |
el13cj | 2:e83b4acfcb36 | 65 | direction = Dir; |
el13cj | 0:c15ca34340a7 | 66 | |
el13cj | 0:c15ca34340a7 | 67 | gait.start(1); |
el13cj | 0:c15ca34340a7 | 68 | |
el13cj | 0:c15ca34340a7 | 69 | } |
el13cj | 0:c15ca34340a7 | 70 | |
el13cj | 0:c15ca34340a7 | 71 | void Hexapod::halt(void) |
el13cj | 0:c15ca34340a7 | 72 | { |
el13cj | 0:c15ca34340a7 | 73 | |
el13cj | 0:c15ca34340a7 | 74 | gait.stop(); |
el13cj | 0:c15ca34340a7 | 75 | |
el13cj | 0:c15ca34340a7 | 76 | } |