ros topicテスト例

6318 ワード

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: 
     * /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では3 D 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このパッケージ
    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 
    
      
      
        Nodelet to view a sensor_msgs/Image topic
      
      
      
        Nodelet to view a stereo_msgs/DisparityImage topic
      
    
    

    新しいnodeが2つ追加されていることがわかります
    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があります.