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 00061 //----------------------------------------------- 00062 00067 class SerRelayBoard 00068 { 00069 public: 00070 00071 SerRelayBoard(std::string ComPort, int ProtocolVersion = 1); 00072 00073 ~SerRelayBoard(); 00074 00075 // Main control functions 00076 bool init(); 00077 bool reset(); 00078 bool shutdown(); 00079 00080 int evalRxBuffer(); //needs to be calles to read new data from relayboard 00081 int sendRequest(); //sends collected data and requests response 00082 00083 //Services by relayboard 00084 int setDigOut(int iChannel, bool bOn); 00085 int getAnalogIn(int* piAnalogIn); 00086 int getDigIn(); 00087 bool isEMStop(); 00088 bool isScannerStop(); 00089 00090 00091 enum RelBoardReturns 00092 { 00093 NO_ERROR = 0, 00094 NOT_INITIALIZED = 1, 00095 GENERAL_SENDING_ERROR = 2, 00096 TOO_LESS_BYTES_IN_QUEUE = 3, 00097 NO_MESSAGES = 4, //for a long time, no message have been received, check com port! 00098 CHECKSUM_ERROR = 5, 00099 }; 00100 00101 protected: 00102 enum RelBoardCmd 00103 { 00104 CMD_SET_CHARGE_RELAY = 1, 00105 CMD_RESET_POS_CNT = 2, 00106 CMD_QUICK_STOP = 4, 00107 CMD_SET_RELAY1 = 8, 00108 CMD_SET_RELAY2 = 16, 00109 CMD_SET_RELAY3 = 32, 00110 CMD_SET_RELAY4 = 64, 00111 CMD_SET_RELAY5 = 128, 00112 CMD_SET_RELAY6 = 256, 00113 CMD_ZERO_GYRO = 512 00114 }; 00115 00116 enum RelBoardConfig 00117 { 00118 CONFIG_HAS_IOBOARD = 1, 00119 CONFIG_HAS_USBOARD = 2, 00120 CONFIG_HAS_GYROBOARD = 4, 00121 CONFIG_HAS_RADARBOARD1 = 8, 00122 CONFIG_HAS_RADARBOARD2 = 16, 00123 CONFIG_HAS_DRIVES = 32, 00124 }; 00125 00126 std::string m_sNumComPort; 00127 00128 void txCharArray(); 00129 void rxCharArray(); 00130 00131 void convDataToSendMsg(unsigned char cMsg[]); 00132 bool convRecMsgToData(unsigned char cMsg[]); 00133 00134 Mutex m_Mutex; 00135 00136 //----------------------- 00137 // send data 00138 int m_iConfigRelayBoard; 00139 int m_iCmdRelayBoard; 00140 00141 //----------------------- 00142 // rec data 00143 int m_iRelBoardStatus; 00144 int m_iChargeCurrent; 00145 int m_iRelBoardBattVoltage; 00146 int m_iRelBoardKeyPad; 00147 int m_iRelBoardAnalogIn[4]; 00148 int m_iRelBoardTempSensor; 00149 00150 int m_iDigIn; 00151 int m_iProtocolVersion; 00152 int m_NUM_BYTE_SEND; 00153 00154 SerialIO m_SerIO; 00155 00156 bool m_bComInit; 00157 }; 00158 00159 00160 //----------------------------------------------- 00161 #endif