compass_odom_alg_node.cpp
Go to the documentation of this file.
00001 #include "compass_odom_alg_node.h"
00002 
00003 CompassOdomAlgNode::CompassOdomAlgNode(void)
00004 {
00005   //init class attributes if necessary
00006   //this->loop_rate_ = 2;//in [Hz]
00007 
00008   this->public_node_handle_.param<std::string>("parent_id", parent_id_, "odom");
00009   alg_.parent_id_ = parent_id_;
00010   this->public_node_handle_.param<bool>("publish_tf", publish_tf_, false);
00011   this->public_node_handle_.param<bool>("publish_imu", publish_imu_, false);
00012 
00013   // [init publishers]
00014   this->compass_odom_publisher_ = this->public_node_handle_.advertise<nav_msgs::Odometry>("compass_odom", 100);
00015   if(publish_imu_)
00016     this->compass_imu_publisher_ = this->public_node_handle_.advertise<sensor_msgs::Imu>("compass_imu", 100);
00017 
00018   // [init subscribers]
00019   this->compass_subscriber_ = this->public_node_handle_.subscribe("compass", 100, &CompassOdomAlgNode::compass_callback, this);
00020 
00021   // Events
00022   ES = CEventServer::instance();
00023   std::stringstream const_time;
00024   const_time << ros::Time::now();
00025   TCM3_IN = "compass3axis_in_" + const_time.str();
00026   ES->create_event(TCM3_IN);
00027   SUBS_LIST.push_back(TCM3_IN);
00028   compass_arrived_ = false;
00029 
00030   // UI
00031 
00032   ROS_WARN("Mounting Position MUST BE 6, otherwise changes in transformation are required!");
00033   ROS_INFO("Publish TF: %d",publish_tf_);
00034   ROS_INFO("Publish IMU: %d",publish_imu_);
00035   ROS_INFO("Parent ID: %s", parent_id_.c_str());
00036   //ROS_INFO("Frame ID: %s",  frame_id_);
00037 
00038   // [init services]
00039 
00040   // [init clients]
00041 
00042   // [init action servers]
00043 
00044   // [init action clients]
00045 }
00046 
00047 CompassOdomAlgNode::~CompassOdomAlgNode(void)
00048 {
00049   // [free dynamic memory]
00050 }
00051 
00052 void CompassOdomAlgNode::mainNodeThread(void)
00053 {
00054   // [fill msg structures]
00055   //this->Odometry_msg.data = my_var;
00056 
00057   ES->wait_all(SUBS_LIST);
00058   alg_.getOdometry(Odometry_msg_,Transform_msg_);
00059 
00060   if(publish_imu_)
00061     alg_.getImuMessage(Odometry_msg_,Imu_msg_);
00062 
00063   // [fill srv structure and make request to the server]
00064 
00065   // [fill action structure and make request to the action server]
00066 
00067   // [publish messages]
00068   this->compass_odom_publisher_.publish(Odometry_msg_);
00069 
00070   if(publish_imu_)
00071     this->compass_imu_publisher_.publish(Imu_msg_);
00072 
00073   if(publish_tf_)
00074     compass_odom_broadcaster_.sendTransform(Transform_msg_);
00075 }
00076 
00077 /*  [subscriber callbacks] */
00078 void CompassOdomAlgNode::compass_callback(const iri_common_drivers_msgs::compass3axis & msg)
00079 {
00080   //ROS_INFO("CompassOdomAlgNode::compass_callback: New Message Received");
00081 
00082   //use appropiate mutex to shared variables if necessary
00083 
00084   this->compass_mutex_.enter();
00085 
00086   //ROS_INFO("compass msg: %f %f %f",msg.angles[0],msg.angles[1],msg.angles[2]);
00087 
00088   alg_.lock();
00089     if(compass_arrived_){
00090       alg_.old_compass_ = alg_.new_compass_;
00091       alg_.new_compass_ = msg;
00092       ES->set_event(TCM3_IN);
00093     }else{
00094       alg_.new_compass_ = msg;
00095       compass_arrived_ = true;
00096     }
00097     // NOMES PER EXPERIMENT USANT CONFIGURACIO 5 !
00098     //     alg_.new_compass_.angles[0] -= 90;
00099     //     double pitch = -alg_.new_compass_.angles[1];
00100     //     alg_.new_compass_.angles[1] = alg_.new_compass_.angles[2];
00101     //     alg_.new_compass_.angles[2] = pitch;
00102   alg_.unlock();
00103 
00104   //unlock previously blocked shared variables
00105 
00106   this->compass_mutex_.exit();
00107 }
00108 
00109 /*  [service callbacks] */
00110 
00111 /*  [action callbacks] */
00112 
00113 /*  [action requests] */
00114 
00115 void CompassOdomAlgNode::node_config_update(Config &config, uint32_t level)
00116 {
00117 }
00118 
00119 void CompassOdomAlgNode::addNodeDiagnostics(void)
00120 {
00121 }
00122 
00123 /* main function */
00124 int main(int argc,char *argv[])
00125 {
00126   return algorithm_base::main<CompassOdomAlgNode>(argc, argv, "compass_odom_alg_node");
00127 }


iri_msg_to_odom
Author(s): Marti Morta, mmorta at iri.upc.edu
autogenerated on Fri Dec 6 2013 22:08:38