teo_battery_monitor_driver_node.cpp
Go to the documentation of this file.
00001 #include "teo_battery_monitor_driver_node.h"
00002 #include <iostream>
00003 
00004 TeoBatteryMonitorDriverNode::TeoBatteryMonitorDriverNode(ros::NodeHandle &nh) : 
00005   iri_base_driver::IriBaseNodeDriver<TeoBatteryMonitorDriver>(nh)
00006 {
00007   //init class attributes if necessary
00008   this->loop_rate_ = 0.5;//in [Hz]
00009 
00010   // [init publishers]
00011   this->battery_status_publisher_ = this->public_node_handle_.advertise<iri_common_drivers_msgs::lifebatt_status>("battery_status", 100);
00012   
00013   // [init subscribers]
00014   this->segway_status_subscriber_ = this->public_node_handle_.subscribe("segway_status", 100, &TeoBatteryMonitorDriverNode::segway_status_callback, this);
00015   
00016   // [init services]
00017   
00018   // [init clients]
00019   
00020   // [init action servers]
00021   
00022   // [init action clients]
00023 }
00024 
00025 void TeoBatteryMonitorDriverNode::mainNodeThread(void)
00026 {
00027   TBatteryInfo info;
00028 
00029   //lock access to driver if necessary
00030   this->driver_.lock();
00031 
00032   this->driver_.get_battery_info(&info);
00033   // [fill msg Header if necessary]
00034   //<publisher_name>.header.stamp = ros::Time::now();
00035   //<publisher_name>.header.frame_id = "<publisher_topic_name>";
00036   this->battery_status_msg_.voltage=info.battery_voltage;
00037   this->battery_status_msg_.temperature=(info.temperature1+info.temperature2)/2.0;
00038   this->battery_status_msg_.status=info.status;
00039   this->battery_status_msg_.input_current=info.current_in;
00040   this->battery_status_msg_.output_current=info.current_out;
00041   this->battery_status_msg_.remaining_capacity=info.rem_capacity;
00042   this->battery_status_msg_.time_to_charged=info.time_to_charged;
00043   this->battery_status_msg_.time_to_discharged=info.time_to_discharged;
00044 
00045   if(driver_.config_.print_info)
00046   {
00047     ROS_DEBUG_STREAM("LifeBatt voltage: " << this->battery_status_msg_.voltage << " mV");
00048     ROS_DEBUG_STREAM("LifeBatt temperature: " << this->battery_status_msg_.temperature << " *C");
00049     ROS_DEBUG_STREAM("LifeBatt status: " << (unsigned int)this->battery_status_msg_.status << "");
00050     ROS_DEBUG_STREAM("LifeBatt input_current: " << this->battery_status_msg_.input_current << "");
00051     ROS_DEBUG_STREAM("LifeBatt output_current: " << this->battery_status_msg_.output_current << "");
00052     ROS_DEBUG_STREAM("LifeBatt remaining_capacity: " << this->battery_status_msg_.remaining_capacity << " mAh");
00053     ROS_DEBUG_STREAM("LifeBatt time_to_charged: " << this->battery_status_msg_.time_to_charged << " m");
00054     ROS_DEBUG_STREAM("LifeBatt time_to_discharged: " << this->battery_status_msg_.time_to_discharged << " m");
00055     ROS_DEBUG_STREAM("Segways ui_battery: " << this->ui_0_ << " / " << this->ui_1_ << " V");
00056     ROS_DEBUG_STREAM("Segways powerbase_battery: " << this->powerbase_0_ << " / " << this->powerbase_1_ << " V");
00057   }
00058 
00059   // [fill msg structures]
00060   //this->battery_status_msg_.data = my_var;
00061   
00062   // [fill srv structure and make request to the server]
00063   
00064   // [fill action structure and make request to the action server]
00065 
00066   // [publish messages]
00067   this->battery_status_publisher_.publish(this->battery_status_msg_);
00068 
00069   //unlock access to driver if previously blocked
00070   this->driver_.unlock();
00071 }
00072 
00073 /*  [subscriber callbacks] */
00074 void TeoBatteryMonitorDriverNode::segway_status_callback(const iri_segway_rmp_msgs::SegwayRMP400Status::ConstPtr& msg) 
00075 { 
00076   //ROS_INFO("TeoBatteryMonitorDriverNode::segway_status_callback: New Message Received"); 
00077 
00078   //use appropiate mutex to shared variables if necessary 
00079   //this->driver_.lock(); 
00080   //this->segway_status_mutex_.enter(); 
00081 
00082   //std::cout << msg->data << std::endl;
00083   this->ui_0_ = msg->rmp200[0].ui_battery;
00084   this->ui_1_ = msg->rmp200[1].ui_battery;
00085   this->powerbase_0_ = msg->rmp200[0].powerbase_battery;
00086   this->powerbase_1_ = msg->rmp200[1].powerbase_battery;
00087 
00088   //unlock previously blocked shared variables 
00089   //this->driver_.unlock(); 
00090   //this->segway_status_mutex_.exit(); 
00091 }
00092 
00093 /*  [service callbacks] */
00094 
00095 /*  [action callbacks] */
00096 
00097 /*  [action requests] */
00098 
00099 void TeoBatteryMonitorDriverNode::postNodeOpenHook(void)
00100 {
00101 }
00102 
00103 void TeoBatteryMonitorDriverNode::addNodeDiagnostics(void)
00104 {
00105 }
00106 
00107 void TeoBatteryMonitorDriverNode::addNodeOpenedTests(void)
00108 {
00109 }
00110 
00111 void TeoBatteryMonitorDriverNode::addNodeStoppedTests(void)
00112 {
00113 }
00114 
00115 void TeoBatteryMonitorDriverNode::addNodeRunningTests(void)
00116 {
00117 }
00118 
00119 void TeoBatteryMonitorDriverNode::reconfigureNodeHook(int level)
00120 {
00121 }
00122 
00123 TeoBatteryMonitorDriverNode::~TeoBatteryMonitorDriverNode(void)
00124 {
00125   // [free dynamic memory]
00126 }
00127 
00128 /* main function */
00129 int main(int argc,char *argv[])
00130 {
00131   return driver_base::main<TeoBatteryMonitorDriverNode>(argc, argv, "teo_battery_monitor_driver_node");
00132 }


teo_battery_monitor
Author(s): Sergi Hernandez Juan
autogenerated on Fri Dec 6 2013 23:09:52