Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <ros/ros.h>
00020
00021
00022 #include <cob_msgs/PowerState.h>
00023 #include <cob_msgs/EmergencyStopState.h>
00024 #include <std_msgs/Bool.h>
00025 #include <std_msgs/Float64.h>
00026
00027 #include <cob_voltage_control_common.cpp>
00028 #include <cob_phidgets/AnalogSensor.h>
00029 #include <cob_phidgets/DigitalSensor.h>
00030
00031 class cob_voltage_control_ros
00032 {
00033 private:
00034 int EM_stop_status_;
00035
00036 public:
00037 ros::NodeHandle n_;
00038
00039 ros::Publisher topicPub_em_stop_state_;
00040 ros::Publisher topicPub_power_state_;
00041
00042 ros::Publisher topicPub_Current_;
00043 ros::Publisher topicPub_Voltage_;
00044
00045 ros::Subscriber topicSub_AnalogInputs;
00046 ros::Subscriber topicSub_DigitalInputs;
00047
00048 cob_voltage_control_data component_data_;
00049 cob_voltage_control_config component_config_;
00050 cob_voltage_control_impl component_implementation_;
00051
00052
00053 bool last_rear_em_state;
00054 bool last_front_em_state;
00055
00056
00057 enum
00058 {
00059 ST_EM_FREE = 0,
00060 ST_EM_ACTIVE = 1,
00061 ST_EM_CONFIRMED = 2
00062 };
00063
00064 cob_voltage_control_ros()
00065 {
00066 topicPub_power_state_ = n_.advertise<cob_msgs::PowerState>("power_state", 1);
00067 topicPub_em_stop_state_ = n_.advertise<cob_msgs::EmergencyStopState>("em_stop_state", 1);
00068
00069 topicPub_Current_ = n_.advertise<std_msgs::Float64>("current", 10);
00070 topicPub_Voltage_ = n_.advertise<std_msgs::Float64>("voltage", 10);
00071
00072 topicSub_AnalogInputs = n_.subscribe("input/analog_sensors", 10, &cob_voltage_control_ros::analogPhidgetSignalsCallback, this);
00073 topicSub_DigitalInputs = n_.subscribe("input/digital_sensors", 10, &cob_voltage_control_ros::digitalPhidgetSignalsCallback, this);
00074
00075 n_.param("battery_max_voltage", component_config_.max_voltage, 48.5);
00076 n_.param("battery_min_voltage", component_config_.min_voltage, 44.0);
00077 n_.param("robot_max_voltage", component_config_.max_voltage_res, 70.0);
00078 n_.param("voltage_analog_port", component_config_.num_voltage_port, 1);
00079 n_.param("em_stop_dio_port", component_config_.num_em_stop_port, 0);
00080 n_.param("scanner_stop_dio_port", component_config_.num_scanner_em_port, 1);
00081
00082 last_rear_em_state = false;
00083 last_front_em_state = false;
00084
00085 EM_stop_status_ = ST_EM_ACTIVE;
00086 component_data_.out_pub_em_stop_state_.scanner_stop = false;
00087 }
00088
00089 void configure()
00090 {
00091 component_implementation_.configure();
00092 }
00093
00094 void update()
00095 {
00096 component_implementation_.update(component_data_, component_config_);
00097 topicPub_Voltage_.publish(component_data_.out_pub_voltage_);
00098 topicPub_Current_.publish(component_data_.out_pub_current_);
00099 topicPub_power_state_.publish(component_data_.out_pub_power_state_);
00100 topicPub_em_stop_state_.publish(component_data_.out_pub_em_stop_state_);
00101 }
00102
00103 void analogPhidgetSignalsCallback(const cob_phidgets::AnalogSensorConstPtr &msg)
00104 {
00105 for(int i = 0; i < msg->uri.size(); i++)
00106 {
00107 if( msg->uri[i] == "voltage")
00108 {
00109 component_data_.in_phidget_voltage = msg->value[i];
00110 }
00111 if( msg->uri[i] == "current")
00112 {
00113 component_data_.in_phidget_current = msg->value[i];
00114 }
00115 }
00116 }
00117
00118 void digitalPhidgetSignalsCallback(const cob_phidgets::DigitalSensorConstPtr &msg)
00119 {
00120 bool front_em_active = false;
00121 bool rear_em_active = false;
00122 static bool em_caused_by_button = false;
00123 cob_msgs::EmergencyStopState EM_msg;
00124 bool EM_signal = false;
00125 bool got_message = false;
00126
00127 for(int i = 0; i < msg->uri.size(); i++)
00128 {
00129 if( msg->uri[i] == "em_stop_laser_rear")
00130 {
00131 rear_em_active = !((bool)msg->state[i]);
00132 got_message = true;
00133 }
00134 else if( msg->uri[i] == "em_stop_laser_front")
00135 {
00136 front_em_active = !((bool)msg->state[i]);
00137 got_message = true;
00138 }
00139 }
00140 if(got_message)
00141 {
00142 if( (front_em_active && rear_em_active) && (!last_front_em_state && !last_rear_em_state))
00143 {
00144 component_data_.out_pub_em_stop_state_.emergency_button_stop = true;
00145 em_caused_by_button = true;
00146 }
00147 else if((!front_em_active && !rear_em_active) && (last_front_em_state && last_rear_em_state))
00148 {
00149 component_data_.out_pub_em_stop_state_.emergency_button_stop = false;
00150 em_caused_by_button = false;
00151 }
00152 else if((front_em_active != rear_em_active) && em_caused_by_button)
00153 {
00154 component_data_.out_pub_em_stop_state_.emergency_button_stop = false;
00155 em_caused_by_button = false;
00156 component_data_.out_pub_em_stop_state_.scanner_stop = (bool)(front_em_active | rear_em_active);
00157 }
00158 else
00159 {
00160 component_data_.out_pub_em_stop_state_.scanner_stop = (bool)(front_em_active | rear_em_active);
00161 }
00162
00163 EM_signal = component_data_.out_pub_em_stop_state_.scanner_stop | component_data_.out_pub_em_stop_state_.emergency_button_stop;
00164
00165 switch (EM_stop_status_)
00166 {
00167 case ST_EM_FREE:
00168 {
00169 if (EM_signal == true)
00170 {
00171 ROS_INFO("Emergency stop was issued");
00172 EM_stop_status_ = EM_msg.EMSTOP;
00173 }
00174 break;
00175 }
00176 case ST_EM_ACTIVE:
00177 {
00178 if (EM_signal == false)
00179 {
00180 ROS_INFO("Emergency stop was confirmed");
00181 EM_stop_status_ = EM_msg.EMCONFIRMED;
00182 }
00183 break;
00184 }
00185 case ST_EM_CONFIRMED:
00186 {
00187 if (EM_signal == true)
00188 {
00189 ROS_INFO("Emergency stop was issued");
00190 EM_stop_status_ = EM_msg.EMSTOP;
00191 }
00192 else
00193 {
00194 ROS_INFO("Emergency stop released");
00195 EM_stop_status_ = EM_msg.EMFREE;
00196 }
00197 break;
00198 }
00199 };
00200
00201 component_data_.out_pub_em_stop_state_.emergency_state = EM_stop_status_;
00202
00203 last_front_em_state = front_em_active;
00204 last_rear_em_state = rear_em_active;
00205 }
00206 }
00207 };
00208
00209 int main(int argc, char** argv)
00210 {
00211 ros::init(argc, argv, "cob_voltage_control");
00212
00213 cob_voltage_control_ros node;
00214 node.configure();
00215
00216 ros::Rate loop_rate(20);
00217
00218 while(node.n_.ok())
00219 {
00220 node.update();
00221 loop_rate.sleep();
00222 ros::spinOnce();
00223 }
00224 return 0;
00225 }