Go to the documentation of this file.00001 #include "compass_odom_alg_node.h"
00002
00003 CompassOdomAlgNode::CompassOdomAlgNode(void)
00004 {
00005
00006
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
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
00019 this->compass_subscriber_ = this->public_node_handle_.subscribe("compass", 100, &CompassOdomAlgNode::compass_callback, this);
00020
00021
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
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
00037
00038
00039
00040
00041
00042
00043
00044
00045 }
00046
00047 CompassOdomAlgNode::~CompassOdomAlgNode(void)
00048 {
00049
00050 }
00051
00052 void CompassOdomAlgNode::mainNodeThread(void)
00053 {
00054
00055
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
00064
00065
00066
00067
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
00078 void CompassOdomAlgNode::compass_callback(const iri_common_drivers_msgs::compass3axis & msg)
00079 {
00080
00081
00082
00083
00084 this->compass_mutex_.enter();
00085
00086
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
00098
00099
00100
00101
00102 alg_.unlock();
00103
00104
00105
00106 this->compass_mutex_.exit();
00107 }
00108
00109
00110
00111
00112
00113
00114
00115 void CompassOdomAlgNode::node_config_update(Config &config, uint32_t level)
00116 {
00117 }
00118
00119 void CompassOdomAlgNode::addNodeDiagnostics(void)
00120 {
00121 }
00122
00123
00124 int main(int argc,char *argv[])
00125 {
00126 return algorithm_base::main<CompassOdomAlgNode>(argc, argv, "compass_odom_alg_node");
00127 }