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

Committer:
symbiotic
Date:
Fri May 23 19:27:12 2014 +0000
Revision:
2:17c7a02f8401
Parent:
1:d3abc0577ebc
Child:
3:8e7471af3453
Added support for continuous units

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