Example use of I2CTransaction class. In this example, the master mbed is talking to 3 legs of the SIPPC3B robot.
LegInterface.h@4:5f7d38d0e22d, 2014-06-10 (annotated)
- Committer:
- symbiotic
- Date:
- Tue Jun 10 19:21:21 2014 +0000
- Revision:
- 4:5f7d38d0e22d
- Parent:
- 3:8e7471af3453
- Child:
- 5:86f1cd6657de
Added I2C bus resetting capability
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 | 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 | 0:346370254254 | 32 | |
symbiotic | 0:346370254254 | 33 | LegInterface(Serial *pc = NULL); |
symbiotic | 0:346370254254 | 34 | |
symbiotic | 0:346370254254 | 35 | bool sendEstop(bool estop); |
symbiotic | 0:346370254254 | 36 | bool queryStateInitiate(); |
symbiotic | 2:17c7a02f8401 | 37 | bool queryStateCompleted(); |
symbiotic | 2:17c7a02f8401 | 38 | bool queryStateWaitForCompletion(int timeout = 1000); |
symbiotic | 0:346370254254 | 39 | bool queryStateCopy(LegState_t legState[NUM_LEGS]); |
symbiotic | 2:17c7a02f8401 | 40 | bool queryStateCopy(float liftPosition[NUM_LEGS], float liftVelocity[NUM_LEGS], float wheelPosition[NUM_LEGS], float wheelVelocity[NUM_LEGS]); |
symbiotic | 0:346370254254 | 41 | void displayLegState(LegState_t *legState); |
symbiotic | 3:8e7471af3453 | 42 | void queryStateTest(Serial *pc); |
symbiotic | 0:346370254254 | 43 | bool queryLegParams(Leg leg, LegControlParams_t *liftParams, LegControlParams_t *wheelParams); |
symbiotic | 0:346370254254 | 44 | void displayParams(LegControlParams_t *params); |
symbiotic | 0:346370254254 | 45 | bool setLegParams(Leg leg, LegControlParams_t *liftParams, LegControlParams_t *wheelParams); |
symbiotic | 0:346370254254 | 46 | bool setLegGoal(int32_t liftPos[NUM_LEGS], int32_t wheelVel[NUM_LEGS]); |
symbiotic | 1:d3abc0577ebc | 47 | bool setLegGoal(float liftPos[NUM_LEGS], float wheelVel[NUM_LEGS]); |
symbiotic | 0:346370254254 | 48 | void displayStatus(); |
symbiotic | 4:5f7d38d0e22d | 49 | static void reset(); |
symbiotic | 4:5f7d38d0e22d | 50 | static void resetBus(); |
symbiotic | 4:5f7d38d0e22d | 51 | static void cycleBus(); |
symbiotic | 0:346370254254 | 52 | |
symbiotic | 0:346370254254 | 53 | private: |
symbiotic | 0:346370254254 | 54 | I2CTransaction *transactionEstop[NUM_LEGS]; |
symbiotic | 0:346370254254 | 55 | LegPacket_t legPacketEstop; |
symbiotic | 0:346370254254 | 56 | |
symbiotic | 0:346370254254 | 57 | I2CTransaction *transactionQueryState[NUM_LEGS]; |
symbiotic | 0:346370254254 | 58 | LegPacket_t legPacketQuery; |
symbiotic | 0:346370254254 | 59 | LegState_t legState[NUM_LEGS]; |
symbiotic | 0:346370254254 | 60 | |
symbiotic | 0:346370254254 | 61 | I2CTransaction *transactionQueryLiftParams[NUM_LEGS]; |
symbiotic | 0:346370254254 | 62 | I2CTransaction *transactionQueryWheelParams[NUM_LEGS]; |
symbiotic | 0:346370254254 | 63 | LegPacket_t legPacketQueryLiftParams; |
symbiotic | 0:346370254254 | 64 | LegPacket_t legPacketQueryWheelParams; |
symbiotic | 0:346370254254 | 65 | LegControlParams_t legLiftParams; |
symbiotic | 0:346370254254 | 66 | LegControlParams_t legWheelParams; |
symbiotic | 0:346370254254 | 67 | |
symbiotic | 0:346370254254 | 68 | I2CTransaction *transactionSetLiftParams[NUM_LEGS]; |
symbiotic | 0:346370254254 | 69 | I2CTransaction *transactionSetWheelParams[NUM_LEGS]; |
symbiotic | 0:346370254254 | 70 | LegPacket_t legPacketSetLiftParams; |
symbiotic | 0:346370254254 | 71 | LegPacket_t legPacketSetWheelParams; |
symbiotic | 0:346370254254 | 72 | |
symbiotic | 0:346370254254 | 73 | I2CTransaction *transactionSetGoal[NUM_LEGS]; |
symbiotic | 0:346370254254 | 74 | LegPacket_t legPacketSetGoal[NUM_LEGS]; |
symbiotic | 0:346370254254 | 75 | Serial *pc; |
symbiotic | 0:346370254254 | 76 | |
symbiotic | 0:346370254254 | 77 | }; |
symbiotic | 0:346370254254 | 78 | |
symbiotic | 0:346370254254 | 79 | #endif |