pose2d_to_odom_converter.cpp
Go to the documentation of this file.
1 
59 
60 #if defined __ROS_VERSION && __ROS_VERSION == 1
61 ros::Publisher nav_odom_publisher;
62 void process_pose_msg(const ros_geometry_msgs::Pose2D::ConstPtr& pose2d_msg)
63 {
64  ROS_INFO_STREAM("pose2d_to_odom_converter: Pose2D message received, x = " << pose2d_msg->x << "m, y = " << pose2d_msg->y << " m, theta=" << (180.0 * pose2d_msg->theta /M_PI) << " deg");
65  ros_nav_msgs::Odometry odom_msg;
66  // The pose in odom_msg should be specified in the coordinate frame given by header.frame_id.
67  // The twist in odom_msgshould be specified in the coordinate frame given by the child_frame_id.
68  tf2::Quaternion theta_quaternion;
69  theta_quaternion.setRPY(0, 0, pose2d_msg->theta);
70  odom_msg.header.stamp = rosTimeNow();
71  odom_msg.header.frame_id = "map";
72  odom_msg.child_frame_id = "laser";
73  odom_msg.pose.pose.position.x = pose2d_msg->x;
74  odom_msg.pose.pose.position.y = pose2d_msg->y;
75  odom_msg.pose.pose.position.z = 0;
76  odom_msg.pose.pose.orientation.x = theta_quaternion.getX();
77  odom_msg.pose.pose.orientation.y = theta_quaternion.getY();
78  odom_msg.pose.pose.orientation.z = theta_quaternion.getZ();
79  odom_msg.pose.pose.orientation.w = theta_quaternion.getW();
80  odom_msg.pose.covariance = {0};
81  odom_msg.twist.twist.linear.x = 0;
82  odom_msg.twist.twist.linear.y = 0;
83  odom_msg.twist.twist.linear.z = 0;
84  odom_msg.twist.twist.angular.x = 0;
85  odom_msg.twist.twist.angular.y = 0;
86  odom_msg.twist.twist.angular.z = 0;
87  odom_msg.twist.covariance = {0};
88  nav_odom_publisher.publish(odom_msg);
89  ROS_INFO_STREAM("pose2d_to_odom_converter: Odometry message published, x = " << odom_msg.pose.pose.position.x << "m, y = " << odom_msg.pose.pose.position.y << " m, yaw = " << (180.0 * pose2d_msg->theta /M_PI) << " deg, frame_id = " << odom_msg.header.frame_id << ", child_frame_id = " << odom_msg.child_frame_id);
90 }
91 #endif // __ROS_VERSION == 1
92 
93 
94 int main(int argc, char** argv)
95 {
96 #if defined __ROS_VERSION && __ROS_VERSION == 1
97  ros::init(argc, argv, "pose2d_to_odom_converter");
98  ros::NodeHandle nh("~");
99  rosNodePtr node = &nh;
100 
101  ROS_INFO_STREAM("pose2d_to_odom_converter started");
102  nav_odom_publisher = nh.advertise<ros_nav_msgs::Odometry>("/rtabmap/odom", 10);
103  ros::Subscriber pose2d_subscriber = nh.subscribe<ros_geometry_msgs::Pose2D>("/pose2D", 10, process_pose_msg);
104 
105  rosSpin(node);
106 
107  ROS_INFO_STREAM("pose2d_to_odom_converter finished");
108 #endif // __ROS_VERSION == 1
109  return 0;
110 }
ros::Publisher
ros::init
ROSCPP_DECL void init(const M_string &remappings, const std::string &name, uint32_t options=0)
alternate ROS initialization function.
tf2::Quaternion::getW
const TF2SIMD_FORCE_INLINE tf2Scalar & getW() const
geometry_msgs::Pose2D
::geometry_msgs::Pose2D_< std::allocator< void > > Pose2D
Definition: Pose2D.h:58
tf2::Quaternion::setRPY
void setRPY(const tf2Scalar &roll, const tf2Scalar &pitch, const tf2Scalar &yaw)
ros::Publisher::publish
void publish(const boost::shared_ptr< M > &message) const
ros::NodeHandle::advertise
Publisher advertise(AdvertiseOptions &ops)
Definition: rossimu.cpp:350
sick_ros_wrapper.h
nav_msgs::Odometry
::nav_msgs::Odometry_< std::allocator< void > > Odometry
Definition: Odometry.h:67
ROS_INFO_STREAM
#define ROS_INFO_STREAM(...)
Definition: sick_scan_ros2_example.cpp:71
polar_to_cartesian_pointcloud_ros1.node
node
Definition: polar_to_cartesian_pointcloud_ros1.py:81
main
int main(int argc, char **argv)
pose2d_to_odom_converter: utility to convert pose2D to odometry messages, used for testing rtabmap wi...
Definition: pose2d_to_odom_converter.cpp:94
ros::NodeHandle::subscribe
Subscriber subscribe(const std::string &topic, uint32_t queue_size, const boost::function< void(C)> &callback, const VoidConstPtr &tracked_object=VoidConstPtr(), const TransportHints &transport_hints=TransportHints())
ros::NodeHandle
rosSpin
void rosSpin(rosNodePtr nh)
Definition: sick_ros_wrapper.h:207
rosTimeNow
rosTime rosTimeNow(void)
Definition: sick_ros_wrapper.h:173
tf2::Quaternion
The Quaternion implements quaternion to perform linear algebra rotations in combination with Matrix3x...
Definition: melodic/include/tf2/LinearMath/Quaternion.h:29
ros::NodeHandle
ros::Subscriber


sick_scan_xd
Author(s): Michael Lehning , Jochen Sprickerhof , Martin Günther
autogenerated on Fri Oct 25 2024 02:47:09