PIBOT移植ROS2记录(4)

作者: PIBOT导航机器人 | 来源:发表于2022-05-06 23:10 被阅读0次

    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

    相关文章

      网友评论

        本文标题:PIBOT移植ROS2记录(4)

        本文链接:https://www.haomeiwen.com/subject/tpbgyrtx.html