00001 #include "leuze_laser_driver_node.h" 00002 00003 LeuzeLaserDriverNode::LeuzeLaserDriverNode(ros::NodeHandle &nh) : iri_base_driver::IriBaseNodeDriver<LeuzeLaserDriver>(nh) 00004 { 00005 //init class attributes if necessary 00006 //this->loop_rate_ = 2;//in [Hz] 00007 00008 // [init publishers] 00009 this->status_publisher_ = this->public_node_handle_.advertise<iri_common_drivers_msgs::leuze_status>("status", 10); 00010 scan_publisher_ = public_node_handle_.advertise<sensor_msgs::LaserScan>("scan", 100); 00011 00012 // [init subscribers] 00013 00014 // [init services] 00015 this->change_wp_pair_server_ = this->public_node_handle_.advertiseService("change_wp_pair", &LeuzeLaserDriverNode::change_wp_pairCallback, this); 00016 00017 // [init clients] 00018 00019 // [init action servers] 00020 00021 // [init action clients] 00022 00023 event_server_ = CEventServer::instance(); 00024 events_.push_back(driver_.getNewScanEventId()); 00025 events_.push_back(driver_.getNoLaserEventId()); 00026 } 00027 00028 void LeuzeLaserDriverNode::mainNodeThread(void) 00029 { 00030 // [fill msg Header if necessary] 00031 //<publisher_name>.header.stamp = ros::Time::now(); 00032 //<publisher_name>.header.frame_id = "<publisher_topic_name>"; 00033 00034 // [fill msg structures] 00035 //this->leuze_status_msg_.data = my_var; 00036 //this->LaserScan_msg.data = my_var; 00037 00038 // [fill srv structure and make request to the server] 00039 00040 // [fill action structure and make request to the action server] 00041 00042 // [publish messages] 00043 this->status_publisher_.publish(this->leuze_status_msg_); 00044 00045 // wait for new laser scan event 00046 int event_id = event_server_->wait_first(events_); 00047 00048 switch(event_id) 00049 { 00050 //New Scan Event 00051 case 0: 00052 //ROS_INFO("New Laser Scan!"); 00053 00054 driver_.lock(); 00055 LaserScan_msg_ = driver_.getScan(); 00056 leuze_status_msg_ = driver_.getStatus(); 00057 driver_.unlock(); 00058 00059 scan_publisher_.publish(LaserScan_msg_); 00060 status_publisher_.publish(leuze_status_msg_); 00061 break; 00062 00063 //No Laser Detected 00064 case 1: 00065 ROS_ERROR("Laser NOT detected, please check either the serial port or the power supply"); 00066 break; 00067 } 00068 } 00069 00070 /* [subscriber callbacks] */ 00071 00072 /* [service callbacks] */ 00073 bool LeuzeLaserDriverNode::change_wp_pairCallback(iri_common_drivers_msgs::change_wp_pair::Request &req, iri_common_drivers_msgs::change_wp_pair::Response &res) 00074 { 00075 ROS_INFO("LeuzeLaserDriverNode::change_wp_pairCallback: New Request Received!"); 00076 00077 //use appropiate mutex to shared variables if necessary 00078 this->driver_.lock(); 00079 //this->change_wp_pair_mutex_.enter(); 00080 00081 if(this->driver_.isRunning()) 00082 { 00083 if(driver_.changePair(req.new_pair)) 00084 res.success=true; 00085 else 00086 res.success=false; 00087 //ROS_INFO("LeuzeLaserDriverNode::change_wp_pairCallback: Processin New Request!"); 00088 //do operations with req and output on res 00089 //res.data2 = req.data1 + my_var; 00090 } 00091 else 00092 { 00093 //ROS_INFO("LeuzeLaserDriverNode::change_wp_pairCallback: ERROR: driver is not on run mode yet."); 00094 res.success=false; 00095 } 00096 00097 //unlock previously blocked shared variables 00098 this->driver_.unlock(); 00099 //this->change_wp_pair_mutex_.exit(); 00100 00101 return true; 00102 } 00103 00104 /* [action callbacks] */ 00105 00106 /* [action requests] */ 00107 00108 void LeuzeLaserDriverNode::postNodeOpenHook(void) 00109 { 00110 } 00111 00112 void LeuzeLaserDriverNode::addNodeDiagnostics(void) 00113 { 00114 } 00115 00116 void LeuzeLaserDriverNode::addNodeOpenedTests(void) 00117 { 00118 } 00119 00120 void LeuzeLaserDriverNode::addNodeStoppedTests(void) 00121 { 00122 } 00123 00124 void LeuzeLaserDriverNode::addNodeRunningTests(void) 00125 { 00126 } 00127 00128 void LeuzeLaserDriverNode::reconfigureNodeHook(int level) 00129 { 00130 } 00131 00132 LeuzeLaserDriverNode::~LeuzeLaserDriverNode() 00133 { 00134 // [free dynamic memory] 00135 } 00136 00137 /* main function */ 00138 int main(int argc,char *argv[]) 00139 { 00140 return driver_base::main<LeuzeLaserDriverNode>(argc, argv, "leuze_laser_driver_node"); 00141 }