odom_proxy_node.cpp
Go to the documentation of this file.
00001 #include <ros/ros.h>
00002 #include "rosabridge_msgs/Odometry.h"
00003 #include "rosabridge_msgs/OdometryCovariances.h"
00004 #include "rosabridge_msgs/RequestOdometryCovariances.h"
00005 #include <tf/transform_broadcaster.h>
00006 #include <nav_msgs/Odometry.h>
00007 #include <signal.h>
00008 #include <string>
00009 
00010 // CBA Define following to enable service for obtaining covariances
00011 // (not currently supported by rosserial on Arduino)
00012 //#define _ODOM_COVAR
00013 
00014 void mySigintHandler(int sig)
00015 {
00016   ROS_INFO("Received SIGINT signal, shutting down...");
00017   ros::shutdown();
00018 }
00019 
00020 class OdomProxyNode
00021 {
00022 
00023 public:
00024   OdomProxyNode();
00025 
00026 public:
00027   void odom_callback(const rosabridge_msgs::Odometry::ConstPtr& odomMsg);
00028   int run();
00029 
00030 protected:
00031   ros::NodeHandle nh;
00032   tf::TransformBroadcaster odom_broadcaster;
00033   ros::Publisher odom_pub;
00034   ros::Subscriber odom_sub;
00035   geometry_msgs::TransformStamped trans_msg;
00036   nav_msgs::Odometry odom_msg;
00037 
00038 #ifdef _ODOM_COVAR
00039   ros::ServiceClient odom_client;
00040 #endif
00041 
00042   bool pub_odom_tf;
00043   std::string odom_frame;
00044   std::string base_frame;
00045   std::string odom_topic;
00046 
00047 };
00048 
00049 OdomProxyNode::OdomProxyNode()
00050 {
00051 
00052   // CBA Read local params (from launch file)
00053   ros::NodeHandle nhLocal("~");
00054   nhLocal.param("pub_odom_tf", pub_odom_tf, true);
00055   ROS_INFO_STREAM("pub_odom_tf: " << pub_odom_tf);
00056   nhLocal.param<std::string>("odom_frame", odom_frame, "");
00057   ROS_INFO_STREAM("odom_frame: " << odom_frame);
00058   nhLocal.param<std::string>("base_frame", base_frame, "");
00059   ROS_INFO_STREAM("base_frame: " << base_frame);
00060   nhLocal.param<std::string>("odom_topic", odom_topic, "odom");
00061   ROS_INFO_STREAM("odom_topic: " << odom_topic);
00062 
00063   // CBA Initially zero out covariances
00064   odom_msg.pose.covariance.assign(0);
00065   odom_msg.twist.covariance.assign(0);
00066 
00067 }
00068 
00069 void OdomProxyNode::odom_callback(const rosabridge_msgs::Odometry::ConstPtr& odomMsg)
00070 {
00071   if ( pub_odom_tf )
00072   {
00073   trans_msg.header.stamp = odomMsg->header.stamp;
00074   if ( !odom_frame.empty() )
00075     trans_msg.header.frame_id = odom_frame;
00076   else
00077     trans_msg.header.frame_id = odomMsg->header.frame_id;
00078   if ( !base_frame.empty() )
00079     trans_msg.child_frame_id = base_frame;
00080   else
00081     trans_msg.child_frame_id = odomMsg->child_frame_id;
00082   trans_msg.transform.translation.x = odomMsg->pose.position.x;
00083   trans_msg.transform.translation.y = odomMsg->pose.position.y;
00084   trans_msg.transform.translation.z = odomMsg->pose.position.z;
00085   trans_msg.transform.rotation.x = odomMsg->pose.orientation.x;
00086   trans_msg.transform.rotation.y = odomMsg->pose.orientation.y;
00087   trans_msg.transform.rotation.z = odomMsg->pose.orientation.z;
00088   trans_msg.transform.rotation.w = odomMsg->pose.orientation.w;
00089   odom_broadcaster.sendTransform(trans_msg);
00090   }
00091 
00092   odom_msg.header.stamp = odomMsg->header.stamp;
00093   if ( !odom_frame.empty() )
00094     odom_msg.header.frame_id = odom_frame;
00095   else
00096     odom_msg.header.frame_id = odomMsg->header.frame_id;
00097   if ( !base_frame.empty() )
00098     odom_msg.child_frame_id = base_frame;
00099   else
00100     odom_msg.child_frame_id = odomMsg->child_frame_id;
00101   odom_msg.pose.pose.position.x = odomMsg->pose.position.x;
00102   odom_msg.pose.pose.position.y = odomMsg->pose.position.y;
00103   odom_msg.pose.pose.position.z = odomMsg->pose.position.z;
00104   odom_msg.pose.pose.orientation.x = odomMsg->pose.orientation.x;
00105   odom_msg.pose.pose.orientation.y = odomMsg->pose.orientation.y;
00106   odom_msg.pose.pose.orientation.z = odomMsg->pose.orientation.z;
00107   odom_msg.pose.pose.orientation.w = odomMsg->pose.orientation.w;
00108   odom_msg.twist.twist.linear.x = odomMsg->twist.linear.x;
00109   odom_msg.twist.twist.linear.y = odomMsg->twist.linear.y;
00110   odom_msg.twist.twist.linear.z = odomMsg->twist.linear.z;
00111   odom_msg.twist.twist.angular.x = odomMsg->twist.angular.x;
00112   odom_msg.twist.twist.angular.y = odomMsg->twist.angular.y;
00113   odom_msg.twist.twist.angular.z = odomMsg->twist.angular.z;
00114   odom_msg.pose.covariance[0] = odomMsg->pose_covariance[0];
00115   odom_msg.pose.covariance[7] = odomMsg->pose_covariance[1];
00116   odom_msg.pose.covariance[14] = odomMsg->pose_covariance[2];
00117   odom_msg.pose.covariance[21] = odomMsg->pose_covariance[3];
00118   odom_msg.pose.covariance[28] = odomMsg->pose_covariance[4];
00119   odom_msg.pose.covariance[35] = odomMsg->pose_covariance[5];
00120   odom_msg.twist.covariance[0] = odomMsg->twist_covariance[0];
00121   odom_msg.twist.covariance[7] = odomMsg->twist_covariance[1];
00122   odom_msg.twist.covariance[14] = odomMsg->twist_covariance[2];
00123   odom_msg.twist.covariance[21] = odomMsg->twist_covariance[3];
00124   odom_msg.twist.covariance[28] = odomMsg->twist_covariance[4];
00125   odom_msg.twist.covariance[35] = odomMsg->twist_covariance[5];
00126   odom_pub.publish(odom_msg);
00127 }
00128 
00129 int OdomProxyNode::run()
00130 {
00131 
00132 #ifdef _ODOM_COVAR
00133   ROS_INFO("Requesting Odometry Covariances");
00134   odom_client = nh.serviceClient<rosabridge_msgs::RequestOdometryCovariances>("rosabridge/odom_covar_srv");
00135   rosabridge_msgs::RequestOdometryCovariances odomCovarSrv;
00136   if (odom_client.call(odomCovarSrv))
00137   {
00138     odom_msg.pose.covariance[0] = odomCovarSrv.response.pose_covariance[0];
00139     odom_msg.pose.covariance[1] = odomCovarSrv.response.pose_covariance[1];
00140     odom_msg.pose.covariance[2] = odomCovarSrv.response.pose_covariance[2];
00141     odom_msg.pose.covariance[3] = odomCovarSrv.response.pose_covariance[3];
00142     odom_msg.pose.covariance[4] = odomCovarSrv.response.pose_covariance[4];
00143     odom_msg.pose.covariance[5] = odomCovarSrv.response.pose_covariance[5];
00144     odom_msg.pose.covariance[6] = odomCovarSrv.response.pose_covariance[6];
00145     odom_msg.pose.covariance[7] = odomCovarSrv.response.pose_covariance[7];
00146     odom_msg.pose.covariance[8] = odomCovarSrv.response.pose_covariance[8];
00147     odom_msg.pose.covariance[9] = odomCovarSrv.response.pose_covariance[9];
00148     odom_msg.pose.covariance[10] = odomCovarSrv.response.pose_covariance[10];
00149     odom_msg.pose.covariance[11] = odomCovarSrv.response.pose_covariance[11];
00150     odom_msg.pose.covariance[12] = odomCovarSrv.response.pose_covariance[12];
00151     odom_msg.pose.covariance[13] = odomCovarSrv.response.pose_covariance[13];
00152     odom_msg.pose.covariance[14] = odomCovarSrv.response.pose_covariance[14];
00153     odom_msg.pose.covariance[15] = odomCovarSrv.response.pose_covariance[15];
00154     odom_msg.pose.covariance[16] = odomCovarSrv.response.pose_covariance[16];
00155     odom_msg.pose.covariance[17] = odomCovarSrv.response.pose_covariance[17];
00156     odom_msg.pose.covariance[18] = odomCovarSrv.response.pose_covariance[18];
00157     odom_msg.pose.covariance[19] = odomCovarSrv.response.pose_covariance[19];
00158     odom_msg.pose.covariance[20] = odomCovarSrv.response.pose_covariance[20];
00159     odom_msg.pose.covariance[21] = odomCovarSrv.response.pose_covariance[21];
00160     odom_msg.pose.covariance[22] = odomCovarSrv.response.pose_covariance[22];
00161     odom_msg.pose.covariance[23] = odomCovarSrv.response.pose_covariance[23];
00162     odom_msg.pose.covariance[24] = odomCovarSrv.response.pose_covariance[24];
00163     odom_msg.pose.covariance[25] = odomCovarSrv.response.pose_covariance[25];
00164     odom_msg.pose.covariance[26] = odomCovarSrv.response.pose_covariance[26];
00165     odom_msg.pose.covariance[27] = odomCovarSrv.response.pose_covariance[27];
00166     odom_msg.pose.covariance[28] = odomCovarSrv.response.pose_covariance[28];
00167     odom_msg.pose.covariance[29] = odomCovarSrv.response.pose_covariance[29];
00168     odom_msg.pose.covariance[30] = odomCovarSrv.response.pose_covariance[30];
00169     odom_msg.pose.covariance[31] = odomCovarSrv.response.pose_covariance[31];
00170     odom_msg.pose.covariance[32] = odomCovarSrv.response.pose_covariance[32];
00171     odom_msg.pose.covariance[33] = odomCovarSrv.response.pose_covariance[33];
00172     odom_msg.pose.covariance[34] = odomCovarSrv.response.pose_covariance[34];
00173     odom_msg.pose.covariance[35] = odomCovarSrv.response.pose_covariance[35];
00174     odom_msg.twist.covariance[0] = odomCovarSrv.response.twist_covariance[0];
00175     odom_msg.twist.covariance[1] = odomCovarSrv.response.twist_covariance[1];
00176     odom_msg.twist.covariance[2] = odomCovarSrv.response.twist_covariance[2];
00177     odom_msg.twist.covariance[3] = odomCovarSrv.response.twist_covariance[3];
00178     odom_msg.twist.covariance[4] = odomCovarSrv.response.twist_covariance[4];
00179     odom_msg.twist.covariance[5] = odomCovarSrv.response.twist_covariance[5];
00180     odom_msg.twist.covariance[6] = odomCovarSrv.response.twist_covariance[6];
00181     odom_msg.twist.covariance[7] = odomCovarSrv.response.twist_covariance[7];
00182     odom_msg.twist.covariance[8] = odomCovarSrv.response.twist_covariance[8];
00183     odom_msg.twist.covariance[9] = odomCovarSrv.response.twist_covariance[9];
00184     odom_msg.twist.covariance[10] = odomCovarSrv.response.twist_covariance[10];
00185     odom_msg.twist.covariance[11] = odomCovarSrv.response.twist_covariance[11];
00186     odom_msg.twist.covariance[12] = odomCovarSrv.response.twist_covariance[12];
00187     odom_msg.twist.covariance[13] = odomCovarSrv.response.twist_covariance[13];
00188     odom_msg.twist.covariance[14] = odomCovarSrv.response.twist_covariance[14];
00189     odom_msg.twist.covariance[15] = odomCovarSrv.response.twist_covariance[15];
00190     odom_msg.twist.covariance[16] = odomCovarSrv.response.twist_covariance[16];
00191     odom_msg.twist.covariance[17] = odomCovarSrv.response.twist_covariance[17];
00192     odom_msg.twist.covariance[18] = odomCovarSrv.response.twist_covariance[18];
00193     odom_msg.twist.covariance[19] = odomCovarSrv.response.twist_covariance[19];
00194     odom_msg.twist.covariance[20] = odomCovarSrv.response.twist_covariance[20];
00195     odom_msg.twist.covariance[21] = odomCovarSrv.response.twist_covariance[21];
00196     odom_msg.twist.covariance[22] = odomCovarSrv.response.twist_covariance[22];
00197     odom_msg.twist.covariance[23] = odomCovarSrv.response.twist_covariance[23];
00198     odom_msg.twist.covariance[24] = odomCovarSrv.response.twist_covariance[24];
00199     odom_msg.twist.covariance[25] = odomCovarSrv.response.twist_covariance[25];
00200     odom_msg.twist.covariance[26] = odomCovarSrv.response.twist_covariance[26];
00201     odom_msg.twist.covariance[27] = odomCovarSrv.response.twist_covariance[27];
00202     odom_msg.twist.covariance[28] = odomCovarSrv.response.twist_covariance[28];
00203     odom_msg.twist.covariance[29] = odomCovarSrv.response.twist_covariance[29];
00204     odom_msg.twist.covariance[30] = odomCovarSrv.response.twist_covariance[30];
00205     odom_msg.twist.covariance[31] = odomCovarSrv.response.twist_covariance[31];
00206     odom_msg.twist.covariance[32] = odomCovarSrv.response.twist_covariance[32];
00207     odom_msg.twist.covariance[33] = odomCovarSrv.response.twist_covariance[33];
00208     odom_msg.twist.covariance[34] = odomCovarSrv.response.twist_covariance[34];
00209     odom_msg.twist.covariance[35] = odomCovarSrv.response.twist_covariance[35];
00210   }
00211   else
00212   {
00213     ROS_WARN("Failed to retrieve Odometry Covariances");
00214   }
00215 #endif
00216 
00217   ROS_INFO("Broadcasting odom tf");
00218   ROS_INFO_STREAM("Publishing to topic " << odom_topic);
00219   odom_pub = nh.advertise<nav_msgs::Odometry>(odom_topic, 1000);
00220   ROS_INFO("Subscribing to topic rosabridge/odom");
00221   odom_sub = nh.subscribe("rosabridge/odom", 1000, &OdomProxyNode::odom_callback, this);
00222 
00223   ROS_INFO("Relaying between topics...");
00224   ros::spin();
00225 
00226   ROS_INFO("Exiting");
00227 
00228   return 0;
00229 }
00230 
00231 int main(int argc, char **argv)
00232 {
00233 
00234   ros::init(argc, argv, "odom_proxy_node");
00235 
00236   OdomProxyNode node;
00237 
00238   // Override the default ros sigint handler.
00239   // This must be set after the first NodeHandle is created.
00240   signal(SIGINT, mySigintHandler);
00241 
00242   return node.run();
00243 }
00244 


rosabridge_server
Author(s): Chad Attermann
autogenerated on Thu Jun 6 2019 20:29:43