1. odom topic
- 修改头文件
#include <nav_msgs/Odometry.h>
--->#include <nav_msgs/msg/odometry.hpp>
- 修改定义
ros::Publisher
---->rclcpp::Publisher<nav_msgs::msg::Odometry>::SharedPtr
nav_msgs::Odometry
---->nav_msgs::msg::Odometry
- 创建pub对象
advertise
---->create_publisher
- timestamp
使用Node->get_clock()->now()
获取timestamp - yaw to Quaternion
tf2::Quaternion q;
q.setRPY(0.0, 0.0, th);
- CMakeList.txt中新增
nav_msgs
依赖项
2. odom tf
- 修改头文件
#include <tf/transform_broadcaster.h>
---->#include <tf2_ros/transform_broadcaster.h>
#include <geometry_msgs/Vector3Stamped.h>
---->#include <geometry_msgs/msg/transform_stamped.hpp>
- 修改类型
geometry_msgs::TransformStamped
---->geometry_msgs::msg::TransformStamped
tf::TransformBroadcaster
---->std::unique_ptr<tf2_ros::TransformBroadcaster>
- CMakeList.txt中新增
tf2_msgs
tf2_ros
依赖项
...
find_package(tf2_msgs REQUIRED)
find_package(tf2_ros REQUIRED)
...
ament_target_dependencies(pibot_driver
rclcpp
geometry_msgs
nav_msgs
tf2_msgs
tf2_ros)
3. 运行测试
ros2 launch pibot_bringup bringup_launch.py
➜ ros2 topic list
/cmd_vel
/odom
/parameter_events
/rosout
/tf
可以使用ros2 topic echo /odom
查看topic的输出
本文代码https://gitee.com/pibot/pibot_bringup/tree/3b8d945f3924aa0fd58d95fc8539145abc65dfd3
网友评论