CanDriveHarmonica.h
Go to the documentation of this file.
00001 /****************************************************************
00002  *
00003  * Copyright (c) 2010
00004  *
00005  * Fraunhofer Institute for Manufacturing Engineering   
00006  * and Automation (IPA)
00007  *
00008  * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00009  *
00010  * Project name: care-o-bot
00011  * ROS stack name: cob_driver
00012  * ROS package name: cob_canopen_motor
00013  * Description:
00014  *                                                              
00015  * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00016  *                      
00017  * Author: Christian Connette, email:christian.connette@ipa.fhg.de
00018  * Supervised by: Christian Connette, email:christian.connette@ipa.fhg.de
00019  *
00020  * Date of creation: Feb 2009
00021  * ToDo: - Assign Adsress of digital input for homing switch "iHomeDigIn" via parameters (in evalReceived Message, Line 116).
00022  *       - Homing Event should be defined by a parameterfile and handed to CanDrive... e.g. via the DriveParam.h (in inithoming, Line 531).
00023  *               - Check whether "requestStatus" can/should be done in the class implementing the component
00024  *
00025  * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00026  *
00027  * Redistribution and use in source and binary forms, with or without
00028  * modification, are permitted provided that the following conditions are met:
00029  *
00030  *     * Redistributions of source code must retain the above copyright
00031  *       notice, this list of conditions and the following disclaimer.
00032  *     * Redistributions in binary form must reproduce the above copyright
00033  *       notice, this list of conditions and the following disclaimer in the
00034  *       documentation and/or other materials provided with the distribution.
00035  *     * Neither the name of the Fraunhofer Institute for Manufacturing 
00036  *       Engineering and Automation (IPA) nor the names of its
00037  *       contributors may be used to endorse or promote products derived from
00038  *       this software without specific prior written permission.
00039  *
00040  * This program is free software: you can redistribute it and/or modify
00041  * it under the terms of the GNU Lesser General Public License LGPL as 
00042  * published by the Free Software Foundation, either version 3 of the 
00043  * License, or (at your option) any later version.
00044  * 
00045  * This program is distributed in the hope that it will be useful,
00046  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00047  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00048  * GNU Lesser General Public License LGPL for more details.
00049  * 
00050  * You should have received a copy of the GNU Lesser General Public 
00051  * License LGPL along with this program. 
00052  * If not, see <http://www.gnu.org/licenses/>.
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         // ------------------------- Types
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         // ------------------------- Interface
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         // ------ Dummy implementations for completing the interface
00257 
00261         void requestPosVel();
00262 
00267         void requestStatus();
00268 
00272         void getStatus(int* piStatus, int* piTempCel) { *piStatus = 0; *piTempCel = 0; }
00273 
00274 
00275         // ------------------------- Interface: Harmonica specific
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         //CanDriveHarmonica specific functions (not from CanDriveItf)
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         // ------------------------- Parameters
00394         ParamCanOpenType m_ParamCanOpen;
00395         DriveParam m_DriveParam;
00396         bool m_bLimitSwitchEnabled;
00397         ParamType m_Param;
00398 
00399         // ------------------------- Variables
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         // ------------------------- Member functions
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


cob_canopen_motor
Author(s): Christian Connette
autogenerated on Sun Oct 5 2014 23:02:12