neo_relayboard_node.h
Go to the documentation of this file.
00001 // ROS includes
00002 #include <ros/ros.h>
00003 #include <iostream>
00004 #include <SerRelayBoard.h>
00005 
00006 // ROS message includes
00007 
00008 #include <std_msgs/Bool.h>
00009 #include <std_msgs/Int16.h>
00010 #include <std_msgs/Empty.h>
00011 #include <sensor_msgs/JointState.h>
00012 #include <trajectory_msgs/JointTrajectory.h>
00013 #include <neo_msgs/EmergencyStopState.h>
00014 #include <neo_msgs/Keypad.h>
00015 #include <neo_msgs/LCDOutput.h>
00016 #include <neo_msgs/IRSensors.h>
00017 #include <neo_msgs/GyroBoard.h>
00018 #include <neo_msgs/RadarBoard.h>
00019 #include <neo_msgs/USBoard.h>
00020 #include <neo_msgs/IOOut.h>
00021 #include <neo_msgs/IOAnalogIn.h>
00022 #include <neo_msgs/PowerState.h>
00023 #include <neo_msgs/PowerBoardState.h>
00024 
00025 // ROS service includes
00026 //--
00027 
00028 // external includes
00029 //--
00030 
00031 //####################
00032 //#### node class ####
00033 class neo_relayboard_node
00034 {
00035         //
00036         public:
00037                 // create a handle for this node, initialize node
00038                 ros::NodeHandle n;
00039                 
00040                 // topics:
00041                 //basic topics:
00042                 ros::Publisher topicPub_isEmergencyStop;
00043                 ros::Publisher topicPub_batVoltage;
00044                 ros::Publisher topicPub_temperatur;
00045                 ros::Publisher topicPub_keypad;
00046                 ros::Publisher topicPub_IRSensor;
00047                 ros::Publisher topicPub_boardState;
00048 
00049                 ros::Publisher topicPub_SendRelayStates;
00050                 ros::Subscriber topicSub_SetRelayStates;
00051                 //optional topics:
00052                 enum Modules {
00053                         DRIVE1=0,
00054                         DRIVE2=1,
00055                         US_BOARD=2,
00056                         RADAR_BOARD=3,
00057                         IO_BOARD=4,
00058                         GYRO_BOARD=5,
00059                         DRIVE3=6,
00060                         DRIVE4=7
00061                 };
00062                 //drives:
00063                 ros::Publisher topicPub_drives;                 //both motors are connected: motor callback
00064                 ros::Subscriber topicSub_drives;                //set velocity of both drives
00065                 //ultrasonic board:
00066                 ros::Publisher topicPub_usBoard;
00067                 ros::Subscriber topicSub_startUSBoard;
00068                 ros::Subscriber topicSub_stopUSBoard;           
00069                 //radar board:
00070                 ros::Publisher topicPub_radarBoard;
00071                 //io board:
00072                 ros::Publisher topicPub_ioDigIn;
00073                 ros::Publisher topicPub_ioDigOut;
00074                 ros::Publisher topicPub_analogIn;
00075                 ros::Subscriber topicSub_lcdDisplay;
00076                 ros::Subscriber topicSub_setDigOut;
00077                 //gyro board:
00078                 ros::Publisher topicPub_gyroBoard;
00079                 ros::Subscriber topicSub_zeroGyro;
00080 
00081                 // Constructor
00082                 neo_relayboard_node()
00083                 {
00084                         //topics which allways get published
00085                         topicPub_isEmergencyStop = n.advertise<neo_msgs::EmergencyStopState>("/emergency_stop_state", 1);
00086                         topicPub_batVoltage = n.advertise<neo_msgs::PowerState>("/power_state", 1);
00087                         topicPub_temperatur = n.advertise<std_msgs::Int16>("/temperature", 1);
00088                         topicPub_boardState = n.advertise<neo_msgs::PowerBoardState>("/power_board/state",1);
00089                         // Make sure member variables have a defined state at the beginning
00090                         EM_stop_status_ = ST_EM_FREE;
00091                         relayboard_available = false;
00092                         relayboard_online = false;
00093                         relayboard_timeout_ = 2.0;
00094                         protocol_version_ = 1;
00095                         duration_for_EM_free_ = ros::Duration(1);
00096                 }
00097         
00098                 // Destructor
00099                 ~neo_relayboard_node() 
00100                 {
00101                         delete m_SerRelayBoard;
00102                 }
00103                 //basic:
00104                 void sendEmergencyStopStates();
00105                 void sendAnalogIn();
00106                 void setRelayBoardDigOut(const neo_msgs::IOOut&);
00107                 void sendRelayBoardDigOut();
00108                 //IOBoard
00109                 void getNewLCDOutput(const neo_msgs::LCDOutput&); //output on a 20 char lcd display
00110                 void sendIOBoardDigIn();
00111                 void sendIOBoardDigOut();
00112                 void getIOBoardDigOut(const neo_msgs::IOOut&);
00113                 void sendIOBoardAnalogIn();
00114                 //motor:
00115                 void sendDriveStates();
00116                 void getNewDriveStates(const trajectory_msgs::JointTrajectory jt);
00117                 //gyroBoard:
00118                 void sendGyroBoard();
00119                 void zeroGyro(const std_msgs::Bool& b);
00120                 //radarBoard:
00121                 void sendRadarBoard();
00122                 //usBoard:
00123                 void sendUSBoard();
00124                 void startUSBoard(const std_msgs::Int16& configuration);
00125                 void stopUSBoard(const std_msgs::Empty& empty);
00126                 
00127                 int init();
00128                 int requestBoardStatus();
00129                 double getRequestRate();
00130                 void readConfig(int protocol_version_);
00131 
00132         private:
00133                 int activeModule[8]; //are the modules available (else ther won't be any datastreaming);
00134                 std::string sComPort;
00135                 SerRelayBoard * m_SerRelayBoard;
00136 
00137                 int EM_stop_status_;
00138                 ros::Duration duration_for_EM_free_;
00139                 ros::Time time_of_EM_confirmed_;
00140                 double relayboard_timeout_;
00141                 int protocol_version_;
00142                 double requestRate;
00143 
00144                 ros::Time time_last_message_received_;
00145                 bool relayboard_online; //the relayboard is sending messages at regular time
00146                 bool relayboard_available; //the relayboard has sent at least one message -> publish topic
00147 
00148                 //log
00149                 bool log;  //enables or disables the log for neo_relayboard
00150 
00151                 // possible states of emergency stop
00152                 enum
00153                 {
00154                         ST_EM_FREE = 0,
00155                         ST_EM_ACTIVE = 1,
00156                         ST_EM_CONFIRMED = 2
00157                 };
00158                 int motorCanIdent[4];
00159                 std::string joint_names[4];
00160                 int hasKeyPad, hasIRSensors, hasLCDOut;
00161                 double voltage_min_, voltage_max_, charge_nominal_, voltage_nominal_, current_voltage;
00162 };
00163 


neo_relayboard
Author(s): Jan-Niklas Nieland
autogenerated on Thu Jun 6 2019 21:37:07