00001
00002
00004
00005 #ifndef BHAND_DRIVER_H
00006 #define BHAND_DRIVER_H
00007
00021 #include "BHandCommands.h"
00022
00023 #include <stdio.h>
00024
00025
00026
00027 #ifdef LINUX
00028 #define THREAD_PRIORITY_TIME_CRITICAL 15
00029 #define THREAD_PRIORITY_HIGHEST 10
00030 #define THREAD_PRIORITY_ABOVE_NORMAL 9
00031 #define THREAD_PRIORITY_NORMAL 8
00032 #define THREAD_PRIORITY_BELOW_NORMAL 7
00033 #define THREAD_PRIORITY_LOWEST 6
00034 #define THREAD_PRIORITY_IDLE 1
00035 #endif
00036
00037
00039
00040 enum BHCommunication {
00041 BH_SERIAL_COMMUNICATION = 0,
00042 BH_CAN_COMMUNICATION
00043 };
00044
00045
00046 class BHand;
00047 class BHandSupervisoryRealtime;
00048 class BHandSupervisoryCommand;
00049 class BHandSupervisoryResult;
00050
00051
00053
00054 typedef void (*BHCallback)(class BHand *);
00055
00056
00057 class BHandDriver
00058 {
00059 public:
00060
00062
00064
00065 BHandDriver(BHand *bhand, BHandSupervisoryRealtime *moduleSuperReal, BHCommunication comm) :
00066 m_bhand(bhand), m_moduleSuperReal(moduleSuperReal), m_Comm(comm), m_open(false), m_activeSupervisoryCommand(NULL), m_supervisoryCommandResult(NULL) {}
00067 virtual ~BHandDriver()
00068 {
00069
00070 if (m_supervisoryCommandResult != NULL)
00071 {
00072
00073 delete m_supervisoryCommandResult;
00074 m_supervisoryCommandResult = NULL;
00075
00076 }
00077 }
00078
00079
00081
00083
00084 BHCommunication getComm() { return m_Comm; }
00085
00086 void setActiveSupervisoryCommand(BHandSupervisoryCommand *activeSupervisoryCommand) { m_activeSupervisoryCommand = activeSupervisoryCommand; }
00087
00088
00090
00092
00093
00094 virtual int Initialize() = 0;
00095 virtual void Close() = 0;
00096 bool IsOpen() { return m_open; }
00097
00098
00099 int ExecuteSupervisoryCall();
00100 virtual int ExecuteRealtimeCall() = 0;
00101
00102 virtual void SetWaitCallbackFunc(BHCallback waitCallbackFunc) = 0;
00103
00104 BHandSupervisoryResult *GetResult() { return m_supervisoryCommandResult; }
00105
00106
00108
00110
00111
00112 int InitHand(const char *motor);
00113 int Reset(bool *responseReceived = 0);
00114
00115
00116 int Close(const char *motor);
00117 int Open(const char *motor);
00118
00119 int GoToDefault(const char *motor);
00120 int GoToDifferentPositions(const int *encoderPositons, unsigned int numEncoderPositions);
00121 int GoToHome(const char *motor = "");
00122 int GoToPosition(const char *motor, int value);
00123
00124 int StepClose(const char *motor, bool valueIncluded = false, int stepAmount = 0);
00125 int StepOpen(const char *motor, bool valueIncluded = false, int stepAmount = 0);
00126
00127 int StopMotor(const char *motor);
00128
00129 int TorqueClose(const char *motor);
00130 int TorqueOpen(const char *motor);
00131
00132
00133 int Get(const char *motor, const char *parameter, int *result);
00134 int Set(const char *motor, const char *parameter, int value);
00135
00136 int PGet(const char *parameter, int *result);
00137 int PSet(const char *parameter, int value);
00138
00139 int Default(const char *motor);
00140 int Load(const char *motor);
00141 int Save(const char *motor);
00142
00143 int Temperature(int *temperature);
00144
00145
00146 int Delay(unsigned int msec);
00147
00148 int Command(const char *send);
00149 int Command(const char *send, char *receive);
00150
00151 int Baud(unsigned int baud);
00152
00153
00155
00157
00158
00159 virtual int RTStart(const char *motor, BHMotorProtection motorProtection = BHMotorTSTOPProtect) = 0;
00160 virtual int RTUpdate(bool control = true, bool feedback = true) = 0;
00161 virtual int RTAbort() = 0;
00162
00163
00164 virtual int RTSetFlags(const char *motor, bool LCV, int LCVC, bool LCPG,
00165 bool LFV, int LFVC, bool LFS, bool LFAP, bool LFDP, int LFDPC) = 0;
00166 virtual int RTSetFlags(const char *motor, bool LCV, int LCVC, bool LCPG, bool LCT,
00167 bool LFV, int LFVC, bool LFS, bool LFAP, bool LFDP, int LFDPC,
00168 bool LFBP, bool LFAIN, bool LFDPD, bool LFT) = 0;
00169
00170 virtual int RTUpdate(const char *motor, const char *property, int *values) = 0;
00171
00172
00173 virtual int RTSetVelocity(const char motor, int velocity) = 0;
00174 virtual int RTSetGain(const char motor, int gain) = 0;
00175 virtual int RTSetTorque(const char motor, int torque) = 0;
00176 virtual int RTSetPosition(const char motor, int position) = 0;
00177
00178
00179 virtual char RTGetVelocity(const char motor) = 0;
00180 virtual unsigned char RTGetStrain(const char motor) = 0;
00181 virtual int RTGetPosition(const char motor) = 0;
00182 virtual char RTGetDeltaPos(const char motor) = 0;
00183 virtual int RTGetBreakawayPosition(const char motor) = 0;
00184 virtual int RTGetTemp() = 0;
00185 virtual unsigned char RTGetAIN(const char motor) = 0;
00186 virtual void RTGetPPS(const char motor, int *pps, int ppsElements) = 0;
00187
00188
00189 protected:
00190
00192
00194
00195
00196 virtual int HandInit(BHMotors bhMotors) = 0;
00197 virtual int HandReset(BHMotors bhMotors, bool *responseReceived) = 0;
00198
00199
00200 virtual int HandClose(BHMotors bhMotors) = 0;
00201 virtual int HandOpen(BHMotors bhMotors) = 0;
00202
00203 virtual int HandGoToDefault(BHMotors bhMotors, bool valueIncluded = false, int defaultPosition = 0) = 0;
00204 virtual int HandGoToDifferentPositionsHand(const int *encoderPositions, unsigned int numEncoderPositions) = 0;
00205 virtual int HandGoToHome(BHMotors bhMotors) = 0;
00206 virtual int HandGoToPosition(BHMotors bhMotors, unsigned int encoderPositionTickCount) = 0;
00207
00208 virtual int HandStepClose(BHMotors bhMotors, bool valueIncluded = false, int stepAmount = 0) = 0;
00209 virtual int HandStepOpen(BHMotors bhMotors, bool valueIncluded = false, int stepAmount = 0) = 0;
00210
00211 virtual int HandTorqueClose(BHMotors bhMotors) = 0;
00212 virtual int HandTorqueOpen(BHMotors bhMotors) = 0;
00213
00214
00215
00216
00217 virtual int HandGet(BHMotors bhMotors, const char *property, int *propertyResult, int *nresults = 0) = 0;
00218 virtual int HandSet(BHMotors bhMotors, const char *property, int value) = 0;
00219
00220 virtual int HandPGet(const char *property, int *propertyResult) = 0;
00221 virtual int HandPSet(const char *property, int value) = 0;
00222
00223 virtual int HandDefault(BHMotors bhMotors) = 0;
00224 virtual int HandLoad(BHMotors bhMotors) = 0;
00225 virtual int HandSave(BHMotors bhMotors) = 0;
00226
00227 virtual int HandTemperature(BHMotors bhMotors, int *temperature, unsigned int numTemperatures) = 0;
00228
00229
00230 virtual int HandDelay(unsigned int milliSeconds) = 0;
00231
00232 virtual int HandStopMotor(BHMotors bhMotors) = 0;
00233
00234 virtual char * HandCommand(const char *send, int *errorCode) = 0;
00235
00236
00237 virtual int HandBaud(unsigned int newBaud) = 0;
00238
00240
00242
00243 virtual int HandleSupervisoryCall() = 0;
00244
00245 int runSupervisoryCommand(BHandSupervisoryCommand *command);
00246
00247 BHand *m_bhand;
00248 BHandSupervisoryRealtime *m_moduleSuperReal;
00249
00250 BHCommunication m_Comm;
00251
00252 bool m_open;
00253
00254 BHandSupervisoryCommand *m_activeSupervisoryCommand;
00255 BHandSupervisoryResult *m_supervisoryCommandResult;
00256
00257 };
00258
00259 #endif