Example use of I2CTransaction class. In this example, the master mbed is talking to 3 legs of the SIPPC3B robot.
LegInterface.h@3:8e7471af3453, 2014-05-26 (annotated)
- Committer:
- symbiotic
- Date:
- Mon May 26 20:07:53 2014 +0000
- Revision:
- 3:8e7471af3453
- Parent:
- 2:17c7a02f8401
- Child:
- 4:5f7d38d0e22d
updated to support transaction resetting (not clear that this is a good idea).;
Who changed what in which revision?
User | Revision | Line number | New 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 | 3:8e7471af3453 | 37 | void queryStateTest(Serial *pc); |
symbiotic | 0:346370254254 | 38 | bool queryLegParams(Leg leg, LegControlParams_t *liftParams, LegControlParams_t *wheelParams); |
symbiotic | 0:346370254254 | 39 | void displayParams(LegControlParams_t *params); |
symbiotic | 0:346370254254 | 40 | bool setLegParams(Leg leg, LegControlParams_t *liftParams, LegControlParams_t *wheelParams); |
symbiotic | 0:346370254254 | 41 | bool setLegGoal(int32_t liftPos[NUM_LEGS], int32_t wheelVel[NUM_LEGS]); |
symbiotic | 1:d3abc0577ebc | 42 | bool setLegGoal(float liftPos[NUM_LEGS], float wheelVel[NUM_LEGS]); |
symbiotic | 0:346370254254 | 43 | void displayStatus(); |
symbiotic | 0:346370254254 | 44 | |
symbiotic | 0:346370254254 | 45 | private: |
symbiotic | 0:346370254254 | 46 | I2CTransaction *transactionEstop[NUM_LEGS]; |
symbiotic | 0:346370254254 | 47 | LegPacket_t legPacketEstop; |
symbiotic | 0:346370254254 | 48 | |
symbiotic | 0:346370254254 | 49 | I2CTransaction *transactionQueryState[NUM_LEGS]; |
symbiotic | 0:346370254254 | 50 | LegPacket_t legPacketQuery; |
symbiotic | 0:346370254254 | 51 | LegState_t legState[NUM_LEGS]; |
symbiotic | 0:346370254254 | 52 | |
symbiotic | 0:346370254254 | 53 | I2CTransaction *transactionQueryLiftParams[NUM_LEGS]; |
symbiotic | 0:346370254254 | 54 | I2CTransaction *transactionQueryWheelParams[NUM_LEGS]; |
symbiotic | 0:346370254254 | 55 | LegPacket_t legPacketQueryLiftParams; |
symbiotic | 0:346370254254 | 56 | LegPacket_t legPacketQueryWheelParams; |
symbiotic | 0:346370254254 | 57 | LegControlParams_t legLiftParams; |
symbiotic | 0:346370254254 | 58 | LegControlParams_t legWheelParams; |
symbiotic | 0:346370254254 | 59 | |
symbiotic | 0:346370254254 | 60 | I2CTransaction *transactionSetLiftParams[NUM_LEGS]; |
symbiotic | 0:346370254254 | 61 | I2CTransaction *transactionSetWheelParams[NUM_LEGS]; |
symbiotic | 0:346370254254 | 62 | LegPacket_t legPacketSetLiftParams; |
symbiotic | 0:346370254254 | 63 | LegPacket_t legPacketSetWheelParams; |
symbiotic | 0:346370254254 | 64 | |
symbiotic | 0:346370254254 | 65 | I2CTransaction *transactionSetGoal[NUM_LEGS]; |
symbiotic | 0:346370254254 | 66 | LegPacket_t legPacketSetGoal[NUM_LEGS]; |
symbiotic | 0:346370254254 | 67 | Serial *pc; |
symbiotic | 0:346370254254 | 68 | |
symbiotic | 0:346370254254 | 69 | }; |
symbiotic | 0:346370254254 | 70 | |
symbiotic | 0:346370254254 | 71 | #endif |