SerRelayBoard.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_relayboard
00013  * Description: Class for communication with relayboard. The relayboard is mainly used for reading the Emergencystop and Laserscannerstop states.
00014  *                                                              
00015  * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00016  *                      
00017  * Author: Philipp Koehler
00018  * Supervised by: Christian Connette, email:christian.connette@ipa.fhg.de
00019  *
00020  * Date of creation: March 2010
00021  * ToDo:
00022  *
00023  * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00024  *
00025  * Redistribution and use in source and binary forms, with or without
00026  * modification, are permitted provided that the following conditions are met:
00027  *
00028  *     * Redistributions of source code must retain the above copyright
00029  *       notice, this list of conditions and the following disclaimer.
00030  *     * Redistributions in binary form must reproduce the above copyright
00031  *       notice, this list of conditions and the following disclaimer in the
00032  *       documentation and/or other materials provided with the distribution.
00033  *     * Neither the name of the Fraunhofer Institute for Manufacturing 
00034  *       Engineering and Automation (IPA) nor the names of its
00035  *       contributors may be used to endorse or promote products derived from
00036  *       this software without specific prior written permission.
00037  *
00038  * This program is free software: you can redistribute it and/or modify
00039  * it under the terms of the GNU Lesser General Public License LGPL as 
00040  * published by the Free Software Foundation, either version 3 of the 
00041  * License, or (at your option) any later version.
00042  * 
00043  * This program is distributed in the hope that it will be useful,
00044  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00045  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00046  * GNU Lesser General Public License LGPL for more details.
00047  * 
00048  * You should have received a copy of the GNU Lesser General Public 
00049  * License LGPL along with this program. 
00050  * If not, see <http://www.gnu.org/licenses/>.
00051  *
00052  ****************************************************************/
00053 
00054 #ifndef SerRelayBoard_INCLUDEDEF_H
00055 #define SerRelayBoard_INCLUDEDEF_H
00056 
00057 //-----------------------------------------------
00058 #include <cob_relayboard/SerialIO.h>
00059 #include <cob_relayboard/Mutex.h>
00060 #include <cob_relayboard/CmdRelaisBoard.h>
00061 
00062 //-----------------------------------------------
00063 
00068 class SerRelayBoard
00069 {
00070 public:
00071         
00072         SerRelayBoard(std::string ComPort, int ProtocolVersion = 1);
00073 
00074         ~SerRelayBoard();
00075 
00076         // Main control functions
00077         bool init();
00078         bool reset();
00079         bool shutdown();
00080 
00081         int evalRxBuffer(); //needs to be calles to read new data from relayboard
00082         int sendRequest(); //sends collected data and requests response
00083 
00084         //Services by relayboard
00085         int setDigOut(int iChannel, bool bOn);
00086         int getAnalogIn(int* piAnalogIn);
00087         int getDigIn();
00088         bool isEMStop();
00089         bool isScannerStop();
00090         int getBatteryVoltage()
00091         {
00092                 return m_iRelBoardBattVoltage;
00093         }
00094         int getChargeCurrent()
00095         {
00096                 return m_iChargeCurrent;
00097         }
00098 
00099 
00100         enum RelBoardReturns
00101         {
00102                 NO_ERROR = 0,
00103                 NOT_INITIALIZED = 1,
00104                 GENERAL_SENDING_ERROR = 2,
00105                 TOO_LESS_BYTES_IN_QUEUE = 3,
00106                 NO_MESSAGES = 4, //for a long time, no message have been received, check com port!
00107                 CHECKSUM_ERROR = 5,
00108         };
00109 
00110         enum RelBoardCmd
00111         {
00112                 CMD_SET_CHARGE_RELAY = 1,
00113                 CMD_RESET_POS_CNT = 2,
00114                 CMD_QUICK_STOP = 4,
00115                 CMD_SET_RELAY1 = 8,
00116                 CMD_SET_RELAY2 = 16,
00117                 CMD_SET_RELAY3 = 32,
00118                 CMD_SET_RELAY4 = 64,
00119                 CMD_SET_RELAY5 = 128,
00120                 CMD_SET_RELAY6 = 256,
00121                 CMD_ZERO_GYRO = 512
00122         };
00123 
00124         enum RelBoardConfig
00125         {
00126                 CONFIG_HAS_IOBOARD = 1,
00127                 CONFIG_HAS_USBOARD = 2,
00128                 CONFIG_HAS_GYROBOARD = 4,
00129                 CONFIG_HAS_RADARBOARD1 = 8,
00130                 CONFIG_HAS_RADARBOARD2 = 16,
00131                 CONFIG_HAS_DRIVES = 32,
00132         };
00133 
00134         enum TypeLCD
00135         {
00136                 LCD_20CHAR_TEXT,
00137                 LCD_60CHAR_TEXT,
00138                 RELAY_BOARD_1_4
00139         };
00140 
00141 protected:
00142         
00143 
00144         std::string m_sNumComPort;
00145 
00146         void txCharArray();
00147         void rxCharArray();
00148 
00149         void convDataToSendMsg(unsigned char cMsg[]);
00150         bool convRecMsgToData(unsigned char cMsg[]);
00151 
00152         Mutex m_Mutex;
00153         
00154         int m_iNumBytesSend;
00155         int m_iTypeLCD; 
00156 
00157         unsigned char m_cTextDisplay[60];
00158 
00159         //relayboard 1.4:
00160         int m_iVelCmdMotRearRightEncS;
00161         int m_iVelCmdMotRearLeftEncS;
00162         char m_cSoftEMStop;
00163         char m_cDebugRearRight[4];
00164         int m_iPosMeasMotRearRightEnc;
00165         int m_iVelMeasMotRearRightEncS;
00166         int m_iPosMeasMotRearLeftEnc;
00167         char m_cDebugRearLeft[4];
00168         int m_iVelMeasMotRearLeftEncS;
00169         int m_iMotRearRightStatus;
00170         int m_iMotRearLeftStatus;
00171         double m_dLastPosRearRight;
00172         double m_dLastPosRearLeft;      
00173 
00174         //-----------------------
00175         // send data
00176 
00177         // RelayBoard
00178         int m_iConfigRelayBoard;
00179         int m_iCmdRelayBoard;
00180 
00181         // IOBoard
00182         int m_iIOBoardDigOut;
00183 
00184         // MotCtrlBoards
00185         int m_iVelCmdMotRightEncS;
00186         int m_iVelCmdMotLeftEncS;
00187 
00188         // USBoard
00189         int m_iUSBoardSensorActive;
00190 
00191         //-----------------------
00192         // rec data
00193         int m_iRelBoardStatus;
00194         int m_iChargeCurrent;
00195         int m_iRelBoardBattVoltage;
00196         int m_iRelBoardKeyPad;
00197         int m_iRelBoardAnalogIn[4];
00198         int m_iRelBoardTempSensor;
00199         
00200         int m_iDigIn;
00201         int m_iProtocolVersion;
00202         int m_NUM_BYTE_SEND;
00203 
00204         SerialIO m_SerIO;
00205 
00206         bool m_bComInit;
00207 };
00208 
00209 
00210 //-----------------------------------------------
00211 #endif


cob_relayboard
Author(s): Christian Connette
autogenerated on Sun Oct 5 2014 23:01:10