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

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers LegInterface.h Source File

LegInterface.h

00001 #ifndef LEGINTERFACE_H
00002 #define LEGINTERFACE_H
00003 #include "I2CTransaction.h"
00004 #include "leg_packets.h"
00005 #include "robot_config.h"
00006 
00007 
00008 
00009 
00010 
00011 class LegInterface
00012 {
00013 public:
00014     // Indices for the different legs
00015     enum Leg {LEG_W=0, LEG_E, LEG_S, NUM_LEGS};
00016 
00017     // An array of I2C addresses indexable by enum Leg
00018     static const int LegAddress[];
00019 
00020     // Encoder to wheel
00021     static const float TICKS_PER_METER = 52633.97;
00022 
00023     // Angle between front legs
00024     static const float FRONT_LEG_ANGLE = 130;  // Degrees
00025 
00026     // Distance from center of robot to wheel
00027     //static const float ROBOT_RADIUS = 0.4702;  // m
00028 
00029     // Number of A2D ticks per meter.  TODO: is 4096 right?
00030     static const float LIFT_TICKS_PER_METER = 4096 / 0.1;
00031 
00032     // Offset between measured height and true height (m)
00033     //static const float LIFT_OFFSET = 0.01;
00034 #if (ROBOT_CONFIG_LEG_SYMMETRY == 0)
00035     static const float LIFT_OFFSET = 0.015;
00036 #else
00037     static const float LIFT_OFFSET = -0.005;
00038 #endif
00039 
00040     LegInterface(Serial *pc = NULL);
00041 
00042     bool sendEstop(bool estop);
00043     bool queryStateInitiate();
00044     bool queryStateCompleted();
00045     bool queryStateSuccess();
00046     void queryStateReportMagic();
00047     bool queryEstopCompleted();
00048     bool queryEstopSuccess();
00049     bool queryStateWaitForCompletion(int timeout = 1000);
00050     bool queryStateCopy(LegState_t legState[NUM_LEGS]);
00051     bool queryStateCopy(float liftPosition[NUM_LEGS], float liftVelocity[NUM_LEGS], float wheelPosition[NUM_LEGS], float wheelVelocity[NUM_LEGS], bool cliff[NUM_LEGS], bool limit[NUM_LEGS], bool estop[NUM_LEGS], uint8_t magic[NUM_LEGS]);
00052     void displayLegState(LegState_t *legState);
00053     void queryStateTest(Serial *pc);
00054     bool queryLegParams(Leg leg, LegControlParams_t *liftParams, LegControlParams_t *wheelParams);
00055     void displayParams(LegControlParams_t *params);
00056     bool setLegParams(Leg leg, LegControlParams_t *liftParams, LegControlParams_t *wheelParams);
00057     bool setLegGoal(int32_t liftPos[NUM_LEGS], int32_t wheelVel[NUM_LEGS]);
00058     bool setLegGoal(float liftPos[NUM_LEGS], float wheelVel[NUM_LEGS]);
00059     bool getLegGoalCompleted();
00060     bool getLegGoalSuccess();
00061     void displayStatus();
00062     //bool getLegGoalStatus();
00063     void clearLegSetGoalStatus();
00064     void clearQueryTransactions();
00065     void clearSetGoalTransactions();
00066     static void reset();
00067     static void resetBus();
00068     static void cycleBus();
00069     static void initI2C(PinName sda, PinName scl);
00070 
00071 private:
00072     I2CTransaction *transactionEstop[NUM_LEGS];
00073     LegPacket_t legPacketEstop;
00074 
00075     I2CTransaction *transactionQueryState[NUM_LEGS];
00076     LegPacket_t legPacketQuery;
00077     LegState_t legState[NUM_LEGS];
00078 
00079     I2CTransaction *transactionQueryLiftParams[NUM_LEGS];
00080     I2CTransaction *transactionQueryWheelParams[NUM_LEGS];
00081     LegPacket_t legPacketQueryLiftParams;
00082     LegPacket_t legPacketQueryWheelParams;
00083     LegControlParams_t legLiftParams;
00084     LegControlParams_t legWheelParams;
00085 
00086     I2CTransaction *transactionSetLiftParams[NUM_LEGS];
00087     I2CTransaction *transactionSetWheelParams[NUM_LEGS];
00088     LegPacket_t legPacketSetLiftParams;
00089     LegPacket_t legPacketSetWheelParams;
00090 
00091     I2CTransaction *transactionSetGoal[NUM_LEGS];
00092     LegPacket_t legPacketSetGoal[NUM_LEGS];
00093     Serial *pc;
00094 
00095 };
00096 
00097 #endif