$search
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 int getBatteryVoltage() 00090 { 00091 return m_iRelBoardBattVoltage; 00092 } 00093 int getChargeCurrent() 00094 { 00095 return m_iChargeCurrent; 00096 } 00097 00098 00099 enum RelBoardReturns 00100 { 00101 NO_ERROR = 0, 00102 NOT_INITIALIZED = 1, 00103 GENERAL_SENDING_ERROR = 2, 00104 TOO_LESS_BYTES_IN_QUEUE = 3, 00105 NO_MESSAGES = 4, //for a long time, no message have been received, check com port! 00106 CHECKSUM_ERROR = 5, 00107 }; 00108 00109 protected: 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 std::string m_sNumComPort; 00135 00136 void txCharArray(); 00137 void rxCharArray(); 00138 00139 void convDataToSendMsg(unsigned char cMsg[]); 00140 bool convRecMsgToData(unsigned char cMsg[]); 00141 00142 Mutex m_Mutex; 00143 00144 //----------------------- 00145 // send data 00146 int m_iConfigRelayBoard; 00147 int m_iCmdRelayBoard; 00148 00149 //----------------------- 00150 // rec data 00151 int m_iRelBoardStatus; 00152 int m_iChargeCurrent; 00153 int m_iRelBoardBattVoltage; 00154 int m_iRelBoardKeyPad; 00155 int m_iRelBoardAnalogIn[4]; 00156 int m_iRelBoardTempSensor; 00157 00158 int m_iDigIn; 00159 int m_iProtocolVersion; 00160 int m_NUM_BYTE_SEND; 00161 00162 SerialIO m_SerIO; 00163 00164 bool m_bComInit; 00165 }; 00166 00167 00168 //----------------------------------------------- 00169 #endif