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
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057 #ifndef CANDRIVEHARMONICA_INCLUDEDEF_H
00058 #define CANDRIVEHARMONICA_INCLUDEDEF_H
00059
00060
00061 #include <cob_canopen_motor/CanDriveItf.h>
00062 #include <cob_utilities/TimeStamp.h>
00063
00064 #include <cob_canopen_motor/SDOSegmented.h>
00065 #include <cob_canopen_motor/ElmoRecorder.h>
00066
00067
00072 class CanDriveHarmonica : public CanDriveItf
00073 {
00074 public:
00075
00079 struct ParamType
00080 {
00081 int iNumRetryOfSend;
00082 int iDivForRequestStatus;
00083 double dCanTimeout;
00084 };
00085
00089 enum StateHarmonica
00090 {
00091 ST_PRE_INITIALIZED,
00092 ST_OPERATION_ENABLED,
00093 ST_OPERATION_DISABLED,
00094 ST_MOTOR_FAILURE
00095 };
00096
00100 struct ParamCanOpenType
00101 {
00102 int iTxPDO1;
00103 int iTxPDO2;
00104 int iRxPDO2;
00105 int iTxSDO;
00106 int iRxSDO;
00107 };
00108
00109
00113 void setCanItf(CanItf* pCanItf){ m_pCanCtrl = pCanItf; }
00114
00119 bool init();
00120
00126 bool isInitialized() { return m_bIsInitialized; }
00127
00132 bool start();
00133
00138 bool stop();
00143 bool reset();
00144
00148 bool shutdown();
00149
00156 bool disableBrake(bool bDisabled);
00157
00161 bool initHoming();
00162
00166 bool execHoming();
00167
00172 bool endHoming();
00173
00177 double getTimeToLastMsg();
00178
00183 bool getStatusLimitSwitch();
00184
00192 bool startWatchdog(bool bStarted);
00193
00199 bool evalReceivedMsg(CanMsg& msg);
00200
00205 bool evalReceivedMsg() { return true; }
00206
00207
00212 void setGearPosVelRadS(double dPosRad, double dVelRadS);
00213
00218 void setGearVelRadS(double dVelEncRadS);
00219
00223 bool setTypeMotion(int iType);
00224
00228 void getGearPosVelRadS(double* pdAngleGearRad, double* pdVelGearRadS);
00229
00234 void getGearDeltaPosVelRadS(double* pdDeltaAngleGearRad, double* pdVelGearRadS);
00235
00239 void getGearPosRad(double* pdPosGearRad);
00240
00244 void setDriveParam(DriveParam driveParam) { m_DriveParam = driveParam; }
00245
00249 bool isError();
00250
00254 unsigned int getError() { return 0; }
00255
00256
00257
00261 void requestPosVel();
00262
00267 void requestStatus();
00268
00272 void getStatus(int* piStatus, int* piTempCel) { *piStatus = 0; *piTempCel = 0; }
00273
00274
00275
00279 CanDriveHarmonica();
00280
00289 void getData(double* pdPosGearRad, double* pdVelGearRadS,
00290 int* piTorqueCtrl, int* piStatusCtrl);
00291
00300 void setCanOpenParam( int iTxPDO1, int iTxPDO2, int iRxPDO2, int iTxSDO, int iRxSDO);
00301
00305 void IntprtSetInt(int iDataLen, char cCmdChar1, char cCmdChar2, int iIndex, int iData);
00306
00310 void sendHeartbeat();
00311
00312
00313 bool setEMStop() {
00314 std::cout << "The function setEMStop() is not implemented!!!" << std::endl;
00315 return false;
00316 }
00317
00318 bool resetEMStop() {
00319 std::cout << "The function resetEMStop() is not implemented!!!" << std::endl;
00320 return false;
00321 }
00322
00327 void setMotorTorque(double dTorqueNm);
00328
00337 void requestMotorTorque();
00338
00343 void getMotorTorque(double* dTorqueNm);
00344
00355 int setRecorder(int iFlag, int iParam = 0, std::string sParam = "/home/MyLog_");
00356
00357
00358
00359
00360
00364 void IntprtSetFloat(int iDataLen, char cCmdChar1, char cCmdChar2, int iIndex, float fData);
00365
00369 void sendSDOUpload(int iObjIndex, int iObjSub);
00370
00374 void sendSDOAbort(int iObjIndex, int iObjSubIndex, unsigned int iErrorCode);
00375
00379 void sendSDODownload(int iObjIndex, int iObjSub, int iData);
00380
00384 void evalSDO(CanMsg& CMsg, int* pIndex, int* pSubindex);
00385
00389 int getSDODataInt32(CanMsg& CMsg);
00390
00391
00392 protected:
00393
00394 ParamCanOpenType m_ParamCanOpen;
00395 DriveParam m_DriveParam;
00396 bool m_bLimitSwitchEnabled;
00397 ParamType m_Param;
00398
00399
00400 CanItf* m_pCanCtrl;
00401 CanMsg m_CanMsgLast;
00402
00403 ElmoRecorder* ElmoRec;
00404
00405 int m_iTypeMotion;
00406 int m_iStatusCtrl;
00407 int m_iTorqueCtrl;
00408
00409 TimeStamp m_CurrentTime;
00410 TimeStamp m_WatchdogTime;
00411 TimeStamp m_VelCalcTime;
00412 TimeStamp m_FailureStartTime;
00413 TimeStamp m_SendTime;
00414 TimeStamp m_StartTime;
00415
00416 double m_dAngleGearRadMem;
00417 double m_dVelGearMeasRadS;
00418 double m_dPosGearMeasRad;
00419
00420 bool m_bLimSwLeft;
00421 bool m_bLimSwRight;
00422
00423 double m_dOldPos;
00424
00425 std::string m_sErrorMessage;
00426
00427 int m_iMotorState;
00428 int m_iNewMotorState;
00429
00430 int m_iCountRequestDiv;
00431
00432 bool m_bCurrentLimitOn;
00433
00434 int m_iNumAttempsRecFail;
00435
00436 bool m_bOutputOfFailure;
00437
00438 bool m_bIsInitialized;
00439
00440 double m_dMotorCurr;
00441
00442 bool m_bWatchdogActive;
00443
00444 segData seg_Data;
00445
00446
00447
00448 double estimVel(double dPos);
00449
00450 bool evalStatusRegister(int iStatus);
00451 void evalMotorFailure(int iFailure);
00452
00453 int m_iPartnerDriveRatio;
00454 int m_iDistSteerAxisToDriveWheelMM;
00455
00456 bool isBitSet(int iVal, int iNrBit)
00457 {
00458 if( (iVal & (1 << iNrBit)) == 0)
00459 return false;
00460 else
00461 return true;
00462 }
00463
00468 void sendSDOUploadSegmentConfirmation(bool toggleBit);
00469
00478 int receivedSDODataSegment(CanMsg& msg);
00479
00485 int receivedSDOSegmentedInitiation(CanMsg& msg);
00486
00491 void receivedSDOTransferAbort(unsigned int iErrorCode);
00492
00499 void finishedSDOSegmentedTransfer();
00500
00501 };
00502
00503 #endif