Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef CANDRIVEHARMONICA_INCLUDEDEF_H
00019 #define CANDRIVEHARMONICA_INCLUDEDEF_H
00020
00021
00022 #include <cob_canopen_motor/CanDriveItf.h>
00023 #include <cob_utilities/TimeStamp.h>
00024
00025 #include <cob_canopen_motor/SDOSegmented.h>
00026 #include <cob_canopen_motor/ElmoRecorder.h>
00027
00028
00033 class CanDriveHarmonica : public CanDriveItf
00034 {
00035 public:
00036
00040 struct ParamType
00041 {
00042 int iNumRetryOfSend;
00043 int iDivForRequestStatus;
00044 double dCanTimeout;
00045 };
00046
00050 enum StateHarmonica
00051 {
00052 ST_PRE_INITIALIZED,
00053 ST_OPERATION_ENABLED,
00054 ST_OPERATION_DISABLED,
00055 ST_MOTOR_FAILURE
00056 };
00057
00061 struct ParamCanOpenType
00062 {
00063 int iTxPDO1;
00064 int iTxPDO2;
00065 int iRxPDO2;
00066 int iTxSDO;
00067 int iRxSDO;
00068 };
00069
00070
00074 void setCanItf(CanItf* pCanItf){ m_pCanCtrl = pCanItf; }
00075
00080 bool init();
00081
00087 bool isInitialized() { return m_bIsInitialized; }
00088
00093 bool start();
00094
00099 bool stop();
00104 bool reset();
00105
00109 bool shutdown();
00110
00117 bool disableBrake(bool bDisabled);
00118
00122 bool initHoming();
00123
00127 bool execHoming();
00128
00133 bool endHoming();
00134
00138 double getTimeToLastMsg();
00139
00144 bool getStatusLimitSwitch();
00145
00153 bool startWatchdog(bool bStarted);
00154
00160 bool evalReceivedMsg(CanMsg& msg);
00161
00166 bool evalReceivedMsg() { return true; }
00167
00168
00173 void setGearPosVelRadS(double dPosRad, double dVelRadS);
00174
00179 void setGearVelRadS(double dVelEncRadS);
00180
00184 bool setTypeMotion(int iType);
00185
00189 void getGearPosVelRadS(double* pdAngleGearRad, double* pdVelGearRadS);
00190
00195 void getGearDeltaPosVelRadS(double* pdDeltaAngleGearRad, double* pdVelGearRadS);
00196
00200 void getGearPosRad(double* pdPosGearRad);
00201
00205 void setDriveParam(DriveParam driveParam) { m_DriveParam = driveParam; }
00206
00210 bool isError();
00211
00215 unsigned int getError() { return 0; }
00216
00217
00218
00222 void requestPosVel();
00223
00228 void requestStatus();
00229
00233 void getStatus(int* piStatus, int* piTempCel) { *piStatus = 0; *piTempCel = 0; }
00234
00235
00236
00240 CanDriveHarmonica();
00241
00250 void getData(double* pdPosGearRad, double* pdVelGearRadS,
00251 int* piTorqueCtrl, int* piStatusCtrl);
00252
00261 void setCanOpenParam( int iTxPDO1, int iTxPDO2, int iRxPDO2, int iTxSDO, int iRxSDO);
00262
00266 void IntprtSetInt(int iDataLen, char cCmdChar1, char cCmdChar2, int iIndex, int iData);
00267
00271 void sendHeartbeat();
00272
00273
00274 bool setEMStop() {
00275 std::cout << "The function setEMStop() is not implemented!!!" << std::endl;
00276 return false;
00277 }
00278
00279 bool resetEMStop() {
00280 std::cout << "The function resetEMStop() is not implemented!!!" << std::endl;
00281 return false;
00282 }
00283
00288 void setMotorTorque(double dTorqueNm);
00289
00298 void requestMotorTorque();
00299
00304 void getMotorTorque(double* dTorqueNm);
00305
00316 int setRecorder(int iFlag, int iParam = 0, std::string sParam = "/home/MyLog_");
00317
00318
00319
00320
00321
00325 void IntprtSetFloat(int iDataLen, char cCmdChar1, char cCmdChar2, int iIndex, float fData);
00326
00330 void sendSDOUpload(int iObjIndex, int iObjSub);
00331
00335 void sendSDOAbort(int iObjIndex, int iObjSubIndex, unsigned int iErrorCode);
00336
00340 void sendSDODownload(int iObjIndex, int iObjSub, int iData);
00341
00345 void evalSDO(CanMsg& CMsg, int* pIndex, int* pSubindex);
00346
00350 int getSDODataInt32(CanMsg& CMsg);
00351
00352
00353 protected:
00354
00355 ParamCanOpenType m_ParamCanOpen;
00356 DriveParam m_DriveParam;
00357 bool m_bLimitSwitchEnabled;
00358 ParamType m_Param;
00359
00360
00361 CanItf* m_pCanCtrl;
00362 CanMsg m_CanMsgLast;
00363
00364 ElmoRecorder* ElmoRec;
00365
00366 int m_iTypeMotion;
00367 int m_iStatusCtrl;
00368 int m_iTorqueCtrl;
00369
00370 TimeStamp m_CurrentTime;
00371 TimeStamp m_WatchdogTime;
00372 TimeStamp m_VelCalcTime;
00373 TimeStamp m_FailureStartTime;
00374 TimeStamp m_SendTime;
00375 TimeStamp m_StartTime;
00376
00377 double m_dAngleGearRadMem;
00378 double m_dVelGearMeasRadS;
00379 double m_dPosGearMeasRad;
00380
00381 bool m_bLimSwLeft;
00382 bool m_bLimSwRight;
00383
00384 double m_dOldPos;
00385
00386 std::string m_sErrorMessage;
00387
00388 int m_iMotorState;
00389 int m_iNewMotorState;
00390
00391 int m_iCountRequestDiv;
00392
00393 bool m_bCurrentLimitOn;
00394
00395 int m_iNumAttempsRecFail;
00396
00397 bool m_bOutputOfFailure;
00398
00399 bool m_bIsInitialized;
00400
00401 double m_dMotorCurr;
00402
00403 bool m_bWatchdogActive;
00404
00405 segData seg_Data;
00406
00407
00408
00409 double estimVel(double dPos);
00410
00411 bool evalStatusRegister(int iStatus);
00412 void evalMotorFailure(int iFailure);
00413
00414 int m_iPartnerDriveRatio;
00415 int m_iDistSteerAxisToDriveWheelMM;
00416
00417 bool isBitSet(int iVal, int iNrBit)
00418 {
00419 if( (iVal & (1 << iNrBit)) == 0)
00420 return false;
00421 else
00422 return true;
00423 }
00424
00429 void sendSDOUploadSegmentConfirmation(bool toggleBit);
00430
00439 int receivedSDODataSegment(CanMsg& msg);
00440
00446 int receivedSDOSegmentedInitiation(CanMsg& msg);
00447
00452 void receivedSDOTransferAbort(unsigned int iErrorCode);
00453
00460 void finishedSDOSegmentedTransfer();
00461
00462 };
00463
00464 #endif