美文网首页
ros topic 测试实例

ros topic 测试实例

作者: 谢小帅 | 来源:发表于2019-01-12 14:51 被阅读21次

    1、打开 launch 文件,启动仿真环境

    • 执行这个 launch 文件前就别执行 turtlebot_bringup minimal.launch 那个了,不然会冲突
    roscore
    roslaunch robot_sim_demo robot_spawn.launch # 执行
    
    itx@turtlebot:~$ roslaunch robot_sim_demo robot_spawn.launch 
    ... logging to /home/itx/.ros/log/649056f4-0fe8-11e9-a894-74de2b44b71c/roslaunch-turtlebot-24669.log
    Checking log directory for disk usage. This may take awhile.
    Press Ctrl-C to interrupt
    Done checking log file disk usage. Usage is <1GB.
    
    started roslaunch server http://10.180.179.209:45301/
    
    SUMMARY
    ========
    
    PARAMETERS
     * /cmd_vel_mux/yaml_cfg_file: /home/itx/tutoria...
     * /robot_description: <?xml version="1....">
     * /rosdistro: kinetic
     * /rosversion: 1.12.14
     * /use_sim_time: True
     * /xbot/joint_state_controller/publish_rate: 50
     * /xbot/joint_state_controller/type: joint_state_contr...
     * /xbot/pitch_platform_position_controller/joint: yaw_to_pitch_plat...
     * /xbot/pitch_platform_position_controller/pid/d: 10.0
     * /xbot/pitch_platform_position_controller/pid/i: 0.01
     * /xbot/pitch_platform_position_controller/pid/p: 100.0
     * /xbot/pitch_platform_position_controller/type: effort_controller...
     * /xbot/robot_state_publisher/publish_frequency: 20.0
     * /xbot/yaw_platform_position_controller/joint: base_to_yaw_platform
     * /xbot/yaw_platform_position_controller/pid/d: 10.0
     * /xbot/yaw_platform_position_controller/pid/i: 0.01
     * /xbot/yaw_platform_position_controller/pid/p: 100.0
     * /xbot/yaw_platform_position_controller/type: effort_controller...
    
    NODES # 划分了 nodes 属于不同的 node 归属
      /xbot/
        robot_state_publisher (robot_state_publisher/robot_state_publisher)
        spawner (controller_manager/spawner)
      /
        cmd_vel_mux (nodelet/nodelet)
        gazebo (gazebo_ros/gzserver)
        gazebo_gui (gazebo_ros/gzclient)
        mobile_base_nodelet_manager (nodelet/nodelet)
        urdf_spawner (gazebo_ros/spawn_model)
    
    ROS_MASTER_URI=http://localhost:11311
    
    # nodes 启动的 process 7个
    process[gazebo-1]: started with pid [24689]
    process[gazebo_gui-2]: started with pid [24694]
    process[urdf_spawner-3]: started with pid [24699]
    process[xbot/spawner-4]: started with pid [24700]
    process[xbot/robot_state_publisher-5]: started with pid [24701]
    process[mobile_base_nodelet_manager-6]: started with pid [24703]
    process[cmd_vel_mux-7]: started with pid [24718]
    

    2、查看所有的 Topic

    • 注意这里的 camera 是仿真的
    • turtlebot_bringup minimal.launch 里指定了 3D sensor,提供了相机传递 image 的 topic
    itx@turtlebot:~$ rostopic list
    /camera/depth/camera_info
    /camera/depth/image_raw  # 深度图
    /camera/depth/points
    /camera/parameter_descriptions
    /camera/parameter_updates
    /camera/rgb/camera_info
    /camera/rgb/image_raw  # rgb图
    /camera/rgb/image_raw/compressed
    /camera/rgb/image_raw/compressed/parameter_descriptions
    /camera/rgb/image_raw/compressed/parameter_updates
    /camera/rgb/image_raw/compressedDepth
    /camera/rgb/image_raw/compressedDepth/parameter_descriptions
    /camera/rgb/image_raw/compressedDepth/parameter_updates
    /camera/rgb/image_raw/theora
    /camera/rgb/image_raw/theora/parameter_descriptions
    /camera/rgb/image_raw/theora/parameter_updates
    /clock
    /cmd_vel
    /cmd_vel_mux/active # 多路速度控制器,选择多个信号中的一个作为输入转发到单行设备
    /cmd_vel_mux/input/avoid
    /cmd_vel_mux/input/navi
    /cmd_vel_mux/input/safety_controller
    /cmd_vel_mux/input/switch
    /cmd_vel_mux/input/teleop
    /cmd_vel_mux/parameter_descriptions
    /cmd_vel_mux/parameter_updates
    /gazebo/link_states
    /gazebo/model_states
    /gazebo/parameter_descriptions
    /gazebo/parameter_updates
    /gazebo/set_link_state
    /gazebo/set_model_state
    /gazebo_gui/parameter_descriptions
    /gazebo_gui/parameter_updates
    /imu
    /joint_states
    /mobile_base_nodelet_manager/bond
    /odom
    /rosout
    /rosout_agg
    /scan
    /tf  # transform 坐标系转换
    /tf_static
    /xbot/joint_states
    /xbot/pitch_platform_position_controller/command
    /xbot/pitch_platform_position_controller/pid/parameter_descriptions
    /xbot/pitch_platform_position_controller/pid/parameter_updates
    /xbot/pitch_platform_position_controller/state
    /xbot/yaw_platform_position_controller/command
    /xbot/yaw_platform_position_controller/pid/parameter_descriptions
    /xbot/yaw_platform_position_controller/pid/parameter_updates
    /xbot/yaw_platform_position_controller/state
    

    3、显示 /camera/rgb/image_raw 这个 topic 的属性信息

    topic 里包含了以下 3 种信息

    • 信息类型
    • 发布者
    • 订阅者
    itx@turtlebot:~$ rostopic info /camera/rgb/image_raw
    Type: sensor_msgs/Image  # 类型
    
    Publishers: # 发布者
     * /gazebo (http://10.180.179.209:41085/) # 这是 1个node
    
    Subscribers: None  # 接收者
    

    由此可知,此时并没有订阅者。

    4、用 image_view 作为订阅者接收消息

    rosrun image_view image_view image:=/camera/rgb/image_raw # image:= 这里 image 在下面 nodelet_plugins.xml 定义了
    [ INFO] [1546616959.571473531, 7864.310000000]: Using transport "raw"
    
    $ rosrun [--prefix cmd] [--debug] pkg_name node_name [ARGS]  # rosrun 语法结构
    

    查看一下 image_view 这个 package

    itx@turtlebot:~$ roscd image_view/
    itx@turtlebot:/opt/ros/kinetic/share/image_view$ ls
    cmake  nodelet_plugins.xml  package.xml
    
    itx@turtlebot:/opt/ros/kinetic/share/image_view$ cat nodelet_plugins.xml 
    <library path="lib/libimage_view">
      <!--显示 sensor 传回的 image-->
      <class name="image_view/image" type="image_view::ImageNodelet" base_class_type="nodelet::Nodelet">
        <description>Nodelet to view a sensor_msgs/Image topic</description>
      </class>
      <!--显示 stereo_msgs 传回的 DisparityImage 视差图-->
      <class name="image_view/disparity" type="image_view::DisparityNodelet" base_class_type="nodelet::Nodelet">
        <description>Nodelet to view a stereo_msgs/DisparityImage topic</description>
      </class>
    </library>
    

    可以看到新增了两个 node

    itx@turtlebot:~$ rosnode list
    /cmd_vel_mux
    /gazebo
    /gazebo_gui
    /image_view_1546616674359947887  # image_view
    /image_view_1546616958807306805  # image_view
    /mobile_base_nodelet_manager
    /rosout
    /turtlebot_teleop_keyboard
    /xbot/robot_state_publisher
    /xbot/spawner
    

    再次查看 topic info

    itx@turtlebot:~$ rostopic info /camera/rgb/image_raw
    Type: sensor_msgs/Image
    
    Publishers: 
     * /gazebo (http://10.180.179.209:41085/)
    
    Subscribers: 
     * /image_view_1546616958807306805 (http://10.180.179.209:43049/)
    

    此时已经有 Subscribers 了。

    相关文章

      网友评论

          本文标题:ros topic 测试实例

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