00001 /********************************************************************* 00002 * Software License Agreement (BSD License) 00003 * 00004 * Copyright (c) 2015, Neobotix GmbH 00005 * All rights reserved. 00006 * 00007 * Redistribution and use in source and binary forms, with or without 00008 * modification, are permitted provided that the following conditions 00009 * are met: 00010 * 00011 * * Redistributions of source code must retain the above copyright 00012 * notice, this list of conditions and the following disclaimer. 00013 * * Redistributions in binary form must reproduce the above 00014 * copyright notice, this list of conditions and the following 00015 * disclaimer in the documentation and/or other materials provided 00016 * with the distribution. 00017 * * Neither the name of the Neobotix nor the names of its 00018 * contributors may be used to endorse or promote products derived 00019 * from this software without specific prior written permission. 00020 * 00021 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00022 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00023 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00024 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00025 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00026 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00027 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00028 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00029 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00030 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00031 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00032 * POSSIBILITY OF SUCH DAMAGE. 00033 *********************************************************************/ 00034 00035 // ROS includes 00036 #include <ros/ros.h> 00037 #include <iostream> 00038 #include <RelayBoardV2.h> 00039 00040 // ROS message includes 00041 00042 #include <std_msgs/Bool.h> 00043 #include <std_msgs/Int16.h> 00044 #include <std_msgs/Empty.h> 00045 #include <sensor_msgs/JointState.h> 00046 #include <trajectory_msgs/JointTrajectory.h> 00047 #include <neo_msgs/EmergencyStopState.h> 00048 #include <neo_msgs/Keypad.h> 00049 #include <neo_msgs/LCDOutput.h> 00050 #include <neo_msgs/USBoard.h> 00051 #include <neo_msgs/IOOut.h> 00052 #include <neo_msgs/IOAnalogIn.h> 00053 #include <neo_msgs/PowerState.h> 00054 00055 // ROS service includes 00056 //-- 00057 00058 // external includes 00059 //-- 00060 00061 //#################### 00062 //#### node class #### 00063 class neo_relayboardV2_node 00064 { 00065 public: 00066 // create a handle for this node, initialize node 00067 ros::NodeHandle n; 00068 00069 // topics: 00070 //basic topics: 00071 ros::Publisher topicPub_RelayBoardState; 00072 ros::Publisher topicPub_isEmergencyStop; 00073 ros::Publisher topicPub_batVoltage; 00074 ros::Publisher topicPub_chargeCurrent; 00075 ros::Publisher topicPub_chargeState; 00076 ros::Publisher topicPub_temperatur; 00077 ros::Publisher topicPub_keypad; 00078 ros::Subscriber topicSub_startCharging; 00079 ros::Subscriber topicSub_stopCharging; 00080 00081 ros::Publisher topicPub_SendRelayStates; 00082 ros::Subscriber topicSub_SetRelayStates; 00083 //drives: 00084 ros::Publisher topicPub_drives; // 00085 ros::Subscriber topicSub_drives; // 00086 //ultrasonic board: 00087 ros::Publisher topicPub_usBoard; 00088 ros::Subscriber topicSub_startUSBoard; 00089 ros::Subscriber topicSub_stopUSBoard; 00090 //io board: 00091 ros::Publisher topicPub_ioDigIn; 00092 ros::Publisher topicPub_ioDigOut; 00093 ros::Publisher topicPub_analogIn; 00094 ros::Subscriber topicSub_lcdDisplay; 00095 ros::Subscriber topicSub_setDigOut; 00096 00097 00098 // Constructor 00099 neo_relayboardV2_node() 00100 { 00101 // Make sure member variables have a defined state at the beginning 00102 m_iEM_stop_state = ST_EM_FREE; 00103 m_iRelayBoard_available = 0; 00104 m_dRelayBoard_timeout = 2.0; 00105 m_duration_for_EM_free = ros::Duration(1); 00106 m_iactive_motors = 0; 00107 m_imotor_count = 0; 00108 m_ihoming_motors = 0; 00109 m_iext_hardware = 0; 00110 m_ihasIOBoard = 0; 00111 m_ihasUSBoard = 0; 00112 } 00113 00114 // Destructor 00115 ~neo_relayboardV2_node() 00116 { 00117 delete m_SerRelayBoard; 00118 } 00119 00120 //Comm Handler 00121 int init(); 00122 void HandleCommunication(); 00123 00124 // Topic Callbacks 00125 void getNewVelocitiesFomTopic(const trajectory_msgs::JointTrajectory jt); 00126 void startUSBoard(const std_msgs::Int16& configuration); 00127 void stopUSBoard(const std_msgs::Empty& empty); 00128 void getRelayBoardDigOut(const neo_msgs::IOOut& setOut); 00129 void getNewLCDMsg(const neo_msgs::LCDOutput& msg); 00130 void getIOBoardDigOut(const neo_msgs::IOOut& setOut); 00131 00132 void startCharging(const std_msgs::Empty& empty); 00133 void stopCharging(const std_msgs::Empty& empty); 00134 00135 // Pubisher functions 00136 //RelayBoard 00137 void PublishRelayBoardState(); 00138 void PublishTemperature(); 00139 void PublishBattVoltage(); 00140 void PublishChargingCurrent(); 00141 void PublishChargingState(); 00142 void PublishEmergencyStopStates(); 00143 void PublishRelayBoardDigOut(); 00144 void PublishKeyPad(); 00145 //Motors 00146 void PublishJointStates(); 00147 //USBoard 00148 void PublishUSBoardData(); 00149 //IOBoard 00150 void PublishIOBoardAnalogIn(); 00151 void PublishIOBoardDigIn(); 00152 void PublishIOBoardDigOut(); 00153 00154 double getRequestRate(); 00155 private: 00156 00157 //----Configuration-------- 00158 int m_iactive_motors; 00159 int m_imotor_count; 00160 int m_ihoming_motors; 00161 int m_iext_hardware; 00162 int m_ihasIOBoard; 00163 int m_ihasUSBoard; 00164 int m_iRelayBoard_available; //the RelayBoard has confirmed the configuration and is ready 00165 std::string m_sComPort; 00166 RelayBoardV2 * m_SerRelayBoard; 00167 00168 DriveParam m_Drives[8]; 00169 00170 //----EM Stop Handling------ 00171 int m_iEM_stop_state; 00172 ros::Duration m_duration_for_EM_free; 00173 ros::Time m_time_of_EM_confirmed; 00174 // possible states of emergency stop 00175 enum 00176 { 00177 ST_EM_FREE = 0, 00178 ST_EM_ACTIVE = 1, 00179 ST_EM_CONFIRMED = 2 00180 }; 00181 //----Msg Handling------------ 00182 double m_dRelayBoard_timeout; 00183 double m_dRequestRate; 00184 ros::Time m_time_last_message_received; 00185 00186 00187 //log 00188 int m_ilog; //enables or disables the log for neo_relayboard 00189 }; 00190