Example use of I2CTransaction class. In this example, the master mbed is talking to 3 legs of the SIPPC3B robot.

Committer:
symbiotic
Date:
Fri Jun 20 06:10:34 2014 +0000
Revision:
5:86f1cd6657de
Parent:
4:5f7d38d0e22d
Child:
6:a52ded837184
???

Who changed what in which revision?

UserRevisionLine numberNew contents of line
symbiotic 0:346370254254 1 #ifndef LEGINTERFACE_H
symbiotic 0:346370254254 2 #define LEGINTERFACE_H
symbiotic 0:346370254254 3 #include "I2CTransaction.h"
symbiotic 0:346370254254 4 #include "leg_packets.h"
symbiotic 0:346370254254 5
symbiotic 4:5f7d38d0e22d 6
symbiotic 4:5f7d38d0e22d 7
symbiotic 4:5f7d38d0e22d 8
symbiotic 4:5f7d38d0e22d 9
symbiotic 4:5f7d38d0e22d 10
symbiotic 0:346370254254 11 class LegInterface
symbiotic 0:346370254254 12 {
symbiotic 0:346370254254 13 public:
symbiotic 0:346370254254 14 // Indices for the different legs
symbiotic 0:346370254254 15 enum Leg {LEG_W=0, LEG_E, LEG_S, NUM_LEGS};
symbiotic 0:346370254254 16
symbiotic 0:346370254254 17 // An array of I2C addresses indexable by enum Leg
symbiotic 0:346370254254 18 static const int LegAddress[];
symbiotic 2:17c7a02f8401 19
symbiotic 2:17c7a02f8401 20 // Encoder to wheel
symbiotic 2:17c7a02f8401 21 static const float TICKS_PER_METER = 52633.97;
symbiotic 2:17c7a02f8401 22
symbiotic 2:17c7a02f8401 23 // Angle between front legs
symbiotic 2:17c7a02f8401 24 static const float FRONT_LEG_ANGLE = 130; // Degrees
symbiotic 2:17c7a02f8401 25
symbiotic 2:17c7a02f8401 26 // Distance from center of robot to wheel
symbiotic 2:17c7a02f8401 27 static const float ROBOT_RADIUS = 0.4702; // m
symbiotic 2:17c7a02f8401 28
symbiotic 2:17c7a02f8401 29 // Number of A2D ticks per meter. TODO: is 4096 right?
symbiotic 2:17c7a02f8401 30 static const float LIFT_TICKS_PER_METER = 4096 / 0.1;
symbiotic 0:346370254254 31
symbiotic 5:86f1cd6657de 32 // Offset between measured height and true height (m)
symbiotic 5:86f1cd6657de 33 static const float LIFT_OFFSET = 0.01;
symbiotic 0:346370254254 34
symbiotic 0:346370254254 35 LegInterface(Serial *pc = NULL);
symbiotic 0:346370254254 36
symbiotic 0:346370254254 37 bool sendEstop(bool estop);
symbiotic 0:346370254254 38 bool queryStateInitiate();
symbiotic 2:17c7a02f8401 39 bool queryStateCompleted();
symbiotic 2:17c7a02f8401 40 bool queryStateWaitForCompletion(int timeout = 1000);
symbiotic 0:346370254254 41 bool queryStateCopy(LegState_t legState[NUM_LEGS]);
symbiotic 2:17c7a02f8401 42 bool queryStateCopy(float liftPosition[NUM_LEGS], float liftVelocity[NUM_LEGS], float wheelPosition[NUM_LEGS], float wheelVelocity[NUM_LEGS]);
symbiotic 0:346370254254 43 void displayLegState(LegState_t *legState);
symbiotic 3:8e7471af3453 44 void queryStateTest(Serial *pc);
symbiotic 0:346370254254 45 bool queryLegParams(Leg leg, LegControlParams_t *liftParams, LegControlParams_t *wheelParams);
symbiotic 0:346370254254 46 void displayParams(LegControlParams_t *params);
symbiotic 0:346370254254 47 bool setLegParams(Leg leg, LegControlParams_t *liftParams, LegControlParams_t *wheelParams);
symbiotic 0:346370254254 48 bool setLegGoal(int32_t liftPos[NUM_LEGS], int32_t wheelVel[NUM_LEGS]);
symbiotic 1:d3abc0577ebc 49 bool setLegGoal(float liftPos[NUM_LEGS], float wheelVel[NUM_LEGS]);
symbiotic 0:346370254254 50 void displayStatus();
symbiotic 4:5f7d38d0e22d 51 static void reset();
symbiotic 4:5f7d38d0e22d 52 static void resetBus();
symbiotic 4:5f7d38d0e22d 53 static void cycleBus();
symbiotic 0:346370254254 54
symbiotic 0:346370254254 55 private:
symbiotic 0:346370254254 56 I2CTransaction *transactionEstop[NUM_LEGS];
symbiotic 0:346370254254 57 LegPacket_t legPacketEstop;
symbiotic 0:346370254254 58
symbiotic 0:346370254254 59 I2CTransaction *transactionQueryState[NUM_LEGS];
symbiotic 0:346370254254 60 LegPacket_t legPacketQuery;
symbiotic 0:346370254254 61 LegState_t legState[NUM_LEGS];
symbiotic 0:346370254254 62
symbiotic 0:346370254254 63 I2CTransaction *transactionQueryLiftParams[NUM_LEGS];
symbiotic 0:346370254254 64 I2CTransaction *transactionQueryWheelParams[NUM_LEGS];
symbiotic 0:346370254254 65 LegPacket_t legPacketQueryLiftParams;
symbiotic 0:346370254254 66 LegPacket_t legPacketQueryWheelParams;
symbiotic 0:346370254254 67 LegControlParams_t legLiftParams;
symbiotic 0:346370254254 68 LegControlParams_t legWheelParams;
symbiotic 0:346370254254 69
symbiotic 0:346370254254 70 I2CTransaction *transactionSetLiftParams[NUM_LEGS];
symbiotic 0:346370254254 71 I2CTransaction *transactionSetWheelParams[NUM_LEGS];
symbiotic 0:346370254254 72 LegPacket_t legPacketSetLiftParams;
symbiotic 0:346370254254 73 LegPacket_t legPacketSetWheelParams;
symbiotic 0:346370254254 74
symbiotic 0:346370254254 75 I2CTransaction *transactionSetGoal[NUM_LEGS];
symbiotic 0:346370254254 76 LegPacket_t legPacketSetGoal[NUM_LEGS];
symbiotic 0:346370254254 77 Serial *pc;
symbiotic 0:346370254254 78
symbiotic 0:346370254254 79 };
symbiotic 0:346370254254 80
symbiotic 0:346370254254 81 #endif