Go to the documentation of this file.00001 #include "segway_rmp200_driver_node.h"
00002
00003 using namespace segway_rmp200_node;
00004
00005 SegwayRmp200DriverNode::SegwayRmp200DriverNode(ros::NodeHandle &nh) try :
00006 iri_base_driver::IriBaseNodeDriver<SegwayRmp200Driver>(nh)
00007 {
00008 event_server_ = CEventServer::instance();
00009
00010
00011 this->loop_rate_ = 50;
00012
00013
00014 this->status_publisher_ = this->public_node_handle_.advertise<iri_segway_rmp_msgs::SegwayRMP200Status>("status", 100);
00015
00016
00017 this->cmd_platform_subscriber_ = this->public_node_handle_.subscribe("cmd_vel", 100, &SegwayRmp200DriverNode::cmd_platform_callback, this);
00018
00019
00020
00021
00022
00023
00024
00025
00026 }
00027 catch (CException & e)
00028 {
00029 ROS_FATAL("'%s'",e.what().c_str());
00030 }
00031
00032 void SegwayRmp200DriverNode::mainNodeThread(void)
00033 {
00034
00035 this->driver_.lock();
00036
00037 segway_event_id_ = event_server_->wait_first(driver_.getSegwayEvents());
00038
00039 switch(segway_event_id_)
00040 {
00041 case SegwayRmp200Driver::NO_USB:
00042 ROS_WARN("The USB cable has been disconnected");
00043 driver_.goClosed();
00044 break;
00045
00046 case SegwayRmp200Driver::POWER_OFF:
00047 ROS_WARN("The segway platform power is off");
00048 break;
00049
00050 case SegwayRmp200Driver::NO_HEART_BEAT:
00051 ROS_WARN("No heart beat detected");
00052 break;
00053
00054 case SegwayRmp200Driver::NEW_STATUS:
00055
00056 updateSegwayStatus();
00057 this->segway_status_msg_.header.seq = 0;
00058 this->segway_status_msg_.header.stamp = ros::Time::now();
00059 this->segway_status_msg_.header.frame_id = "segway";
00060 status_publisher_.publish(this->segway_status_msg_);
00061 break;
00062 }
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075 this->driver_.unlock();
00076 }
00077
00078 void SegwayRmp200DriverNode::updateSegwayStatus()
00079 {
00080 this->segway_status_msg_ = this->driver_.get_status();
00081 }
00082
00083
00084 void SegwayRmp200DriverNode::cmd_platform_callback(const geometry_msgs::Twist::ConstPtr& msg)
00085 {
00086 ROS_DEBUG("SegwayRmp200DriverNode::cmd_platform_callback");
00087
00088
00089 this->driver_.lock();
00090
00091 if(this->driver_.isRunning())
00092 {
00093 double vT = msg->linear.x;
00094 double vR = msg->angular.z;
00095 ROS_INFO("New Command Received: vT=%f vR=%f", vT, vR);
00096
00097
00098 this->driver_.move_platform(vT, vR);
00099 }
00100 else
00101 {
00102 ROS_WARN("Segway driver has not been started yet");
00103 }
00104
00105
00106 this->driver_.unlock();
00107 }
00108
00109
00110
00111
00112
00113
00114
00115 void SegwayRmp200DriverNode::postNodeOpenHook(void)
00116 {
00117 }
00118
00119 void SegwayRmp200DriverNode::check_configuration(diagnostic_updater::DiagnosticStatusWrapper &stat)
00120 {
00121 switch(segway_event_id_)
00122 {
00123 case SegwayRmp200Driver::NO_USB:
00124 stat.summary(diagnostic_msgs::DiagnosticStatus::ERROR, "USB Cable disconected.");
00125 break;
00126
00127 case SegwayRmp200Driver::POWER_OFF:
00128 stat.summary(diagnostic_msgs::DiagnosticStatus::WARN, "Platform is powered off.");
00129 break;
00130
00131 case SegwayRmp200Driver::NO_HEART_BEAT:
00132 stat.summary(diagnostic_msgs::DiagnosticStatus::WARN, "No heart beat received.");
00133 break;
00134
00135 case SegwayRmp200Driver::NEW_STATUS:
00136 stat.summary(diagnostic_msgs::DiagnosticStatus::OK, "Everything is working properly.");
00137 break;
00138 }
00139 stat.add("Current Segway event: ", driver_.getSegwayEventName(segway_event_id_));
00140 }
00141
00142 void SegwayRmp200DriverNode::ui_battery_check(diagnostic_updater::DiagnosticStatusWrapper &stat)
00143 {
00144 float ui_battery=0.0;
00145
00146 ui_battery = this->driver_.get_ui_battery_voltage();
00147
00148 if(ui_battery>=6.0)
00149 stat.summary(diagnostic_msgs::DiagnosticStatus::OK, "UI battery level is okay.");
00150
00151 else if(ui_battery>4.0 && ui_battery<6.0)
00152 stat.summary(diagnostic_msgs::DiagnosticStatus::WARN, "UI battery level is low.");
00153
00154 else
00155 stat.summary(diagnostic_msgs::DiagnosticStatus::ERROR, "UI battery extremelly low, please recharge it as soon as possible");
00156
00157 stat.add("UI battery level: ", ui_battery);
00158 }
00159
00160 void SegwayRmp200DriverNode::pb_battery_check(diagnostic_updater::DiagnosticStatusWrapper &stat)
00161 {
00162 float pb_battery=0.0;
00163
00164 pb_battery = this->driver_.get_powerbase_battery_voltage();
00165
00166 if(pb_battery>=70.0)
00167 stat.summary(diagnostic_msgs::DiagnosticStatus::OK, "Powerbase battery level is okay.");
00168
00169 else if(pb_battery>60.0 && pb_battery<70.0)
00170 stat.summary(diagnostic_msgs::DiagnosticStatus::WARN, "Powerbase battery level is low.");
00171
00172 else
00173 stat.summary(diagnostic_msgs::DiagnosticStatus::ERROR, "Powerbase battery extremelly low, please recharge it as soon as possible");
00174
00175 stat.add("Powerbase battery level: ", pb_battery);
00176 }
00177
00178 void SegwayRmp200DriverNode::addNodeDiagnostics(void)
00179 {
00180 this->diagnostic_.add("Error event check", this, &SegwayRmp200DriverNode::check_configuration);
00181 this->diagnostic_.add("UI battery level check", this, &SegwayRmp200DriverNode::ui_battery_check);
00182 this->diagnostic_.add("Powerbase battery level check", this, &SegwayRmp200DriverNode::pb_battery_check);
00183 }
00184
00185 void SegwayRmp200DriverNode::addNodeOpenedTests(void)
00186 {
00187 }
00188
00189 void SegwayRmp200DriverNode::addNodeStoppedTests(void)
00190 {
00191 }
00192
00193 void SegwayRmp200DriverNode::addNodeRunningTests(void)
00194 {
00195 }
00196
00197 void SegwayRmp200DriverNode::reconfigureNodeHook(int level)
00198 {
00199 }
00200
00201 SegwayRmp200DriverNode::~SegwayRmp200DriverNode()
00202 {
00203
00204 }
00205
00206
00207 int main(int argc,char *argv[])
00208 {
00209 return driver_base::main<SegwayRmp200DriverNode>(argc,argv,"segway_rmp200_driver_node");
00210 }
00211