asterx1_driver_node.cpp
Go to the documentation of this file.
00001 #include "asterx1_driver_node.h"
00002 
00003 Asterx1DriverNode::Asterx1DriverNode(ros::NodeHandle &nh) :
00004   iri_base_driver::IriBaseNodeDriver<Asterx1Driver>(nh),
00005   is_auto_home_position_set_(0)
00006 {
00007         
00008   //string for port names
00009   std::string port_name;
00010         
00011   //init class attributes if necessary
00012   this->loop_rate_ = 10;//in [Hz]. Driver does not necessarily iterates at the same rate
00013   
00014   // [init publishers]
00015   port_name = ros::names::append(ros::this_node::getName(), "gpsStandard"); 
00016   this->gpsStandard = this->public_node_handle_.advertise<sensor_msgs::NavSatFix>(port_name, 100);
00017 
00018   //port_name = ros::names::append(ros::this_node::getName(), "gpsExtended"); 
00019   //this->gpsExtended = this->public_node_handle_.advertise<iri_common_msgs::gpsExtended>(port_name, 100);
00020  
00021   // [init subscribers]
00022   
00023   // [init services]
00024   
00025   // [init clients]
00026   
00027   // [init action servers]
00028   
00029   // [init action clients]
00030 }
00031 
00032 void Asterx1DriverNode::mainNodeThread(void)
00033 {
00034         
00035   ros::Time driverTS;
00036   
00037   //lock access to driver if necessary
00038   this->driver_.lock();
00039 
00040   //read device data. Blocks here (with timeout) if no data avaiolable.
00041   driver_.readDataFromDevice();
00042   
00043   // [fill msg Header if necessary]
00044   driverTS.fromSec( driver_.getTimeStamp() ); //time stamp provided by the driver process
00045   gpsStandardMsg.header.stamp = driverTS; //ros::Time::now();
00046   gpsStandardMsg.header.frame_id = driver_.config_.frame_id;
00047   
00048   // [fill msg structures]
00049   if (driver_.getStatus() == ALL_OK)
00050   {
00051           gpsStandardMsg.status.status = sensor_msgs::NavSatStatus::STATUS_FIX;
00052     if((driver_.config_.autoHome && !is_auto_home_position_set_) || (driver_.config_.autoHome && driver_.config_.resetHome))
00053     {
00054       driver_.setMapOrigin(driver_.getLat(inDEGREES),driver_.getLon(inDEGREES),driver_.getAlt(),0);
00055       is_auto_home_position_set_ = true;
00056       driver_.config_.resetHome = false;
00057       ROS_INFO("Map origin has been set to: %f %f %f",driver_.getLat(inDEGREES),driver_.getLon(inDEGREES),driver_.getAlt());
00058     }
00059   }
00060   else
00061   {
00062           gpsStandardMsg.status.status = sensor_msgs::NavSatStatus::STATUS_NO_FIX;
00063     ROS_DEBUG("Status: %d",driver_.getStatus());
00064   }
00065   gpsStandardMsg.status.service = sensor_msgs::NavSatStatus::SERVICE_GPS;
00066   
00067   //geodetic position
00068   gpsStandardMsg.latitude = driver_.getLat(inDEGREES);
00069   gpsStandardMsg.longitude = driver_.getLon(inDEGREES);
00070   gpsStandardMsg.altitude = driver_.getAlt();
00071   
00072   //fill ENU covariance matrix row by row 
00073   gpsStandardMsg.position_covariance[0] = driver_.getCxxEnu(); 
00074   gpsStandardMsg.position_covariance[1] = driver_.getCxyEnu();
00075   gpsStandardMsg.position_covariance[2] = driver_.getCxzEnu(); 
00076   gpsStandardMsg.position_covariance[3] = driver_.getCxyEnu(); //cyx = cxy
00077   gpsStandardMsg.position_covariance[4] = driver_.getCyyEnu();
00078   gpsStandardMsg.position_covariance[5] = driver_.getCyzEnu();
00079   gpsStandardMsg.position_covariance[6] = driver_.getCxzEnu(); //czx = cxz
00080   gpsStandardMsg.position_covariance[7] = driver_.getCyzEnu(); //czy = cyz
00081   gpsStandardMsg.position_covariance[8] = driver_.getCzzEnu();
00082   gpsStandardMsg.position_covariance_type = gpsStandardMsg.COVARIANCE_TYPE_KNOWN; //to do ....
00083 
00084   ROS_DEBUG("T: %f N: %u",driver_.getTimeStamp(),driver_.getNumSatellites());
00085   if(driver_.getStatus() == ALL_OK)
00086   {
00087     ROS_DEBUG("WGS: pos %f %f %f vel: %f %f %f",driver_.getXWgs(),driver_.getYWgs(),driver_.getZWgs(),driver_.getVxWgs(),driver_.getVyWgs(),driver_.getVzWgs());
00088     ROS_DEBUG("Map: pos %f %f %f vel: %f %f %f",driver_.getXMap(),driver_.getYMap(),driver_.getZMap(),driver_.getVxMap(),driver_.getVyMap(),driver_.getVzMap());
00089   }
00090 
00091   // [fill srv structure and make request to the server]
00092   
00093   // [fill action structure and make request to the action server]
00094 
00095   // [publish messages]
00096   gpsStandard.publish(gpsStandardMsg);
00097 
00098   //unlock access to driver if previously blocked
00099   this->driver_.unlock();
00100 }
00101 
00102 /*  [subscriber callbacks] */
00103 
00104 /*  [service callbacks] */
00105 
00106 /*  [action callbacks] */
00107 
00108 /*  [action requests] */
00109 
00110 void Asterx1DriverNode::postNodeOpenHook(void)
00111 {
00112 }
00113 
00114 void Asterx1DriverNode::addNodeDiagnostics(void)
00115 {
00116 }
00117 
00118 void Asterx1DriverNode::addNodeOpenedTests(void)
00119 {
00120 }
00121 
00122 void Asterx1DriverNode::addNodeStoppedTests(void)
00123 {
00124 }
00125 
00126 void Asterx1DriverNode::addNodeRunningTests(void)
00127 {
00128 }
00129 
00130 void Asterx1DriverNode::reconfigureNodeHook(int level)
00131 {
00132 }
00133 
00134 Asterx1DriverNode::~Asterx1DriverNode()
00135 {
00136   //[free dynamic memory]
00137 }
00138 
00139 /* main function */
00140 int main(int argc,char *argv[])
00141 {
00142   return driver_base::main<Asterx1DriverNode>(argc,argv,"asterx1_driver_node");
00143 }


iri_asterx1
Author(s): andreu, acorominas@iri.upc.edu
autogenerated on Fri Dec 6 2013 22:38:17