UGV Rover PI ROS2 10. Command interaction
| ||
10. Command interaction
This tutorial shows you how to use commands to control the robot for basic movement and to move the robot to a navigation point. Before starting this tutorial, by default you have completed the main program and remotely connected to the Docker container according to the content in Chapter 1 UGV Rover PI ROS2 1. Preparation.
First, start the robot behavior control interface in the container and keep this command running:
ros2 run ugv_tools behavior_ctrl
10.1 Basic control
Before performing basic control, you must first ensure that the robot is placed on the ground. The robot needs to judge whether the distance traveled by the robot has completed the goal based on the odometer.
Then open a new Docker container terminal, click the ⭐ symbol in the left sidebar, double-click to open Docker's remote terminal, enter username: root, password: ws.
In the container, go to the workspace of the ROS 2 project for that product:
cd /home/ws/ugv_ws
Start the car driver node and keep this command running:
ros2 launch ugv_bringup bringup_lidar.launch.py use_rviz:=true
At this moment, the robot pan-tilt will be turned to the center position, and the camera will face forward, and you can view the RVIZ2 model interface of the product. When you rotate the car manually, you can see that the model will also rotate along with it.
10.1.1 Move forward
Then in a new Docker container, send the action target of the robot's moving forward, and data is the distance the robot travels, in meters:
ros2 action send_goal /behavior ugv_interface/action/Behavior "{command: '[{\"T\": 1, \"type\": \"drive_on_heading\", \"data\": 0.5}]'}"
At this time, the robot will advance the distance set by data in the command, and you can see that the model in the Rviz2 model interface of the product will also move forward together.
10.1.2 Move backward
Send the action target of the robot's moving backward, and data is the distance the robot travels, in meters:
ros2 action send_goal /behavior ugv_interface/action/Behavior "{command: '[{\"T\": 1, \"type\": \"back_up\", \"data\": 0.5}]'}"
At this time, the robot will retreat the set distance, and you can see that the model in the Rviz2 model interface of the product will also move backward together.
10.1.3 Rotate
Send the action target of the robot rotation (the unit of data is degrees, positive number means to turn left, negative number means to turn right):
ros2 action send_goal /behavior ugv_interface/action/Behavior "{command: '[{\"T\": 1, \"type\": \"spin\", \"data\": -50}]'}"
At this time, the robot will rotate to the set angle, and you can see that the model in the Rviz2 model interface of the product will also rotate along with it.
10.1.4 Stop
Send the action target of the robot to stop:
ros2 action send_goal /behavior ugv_interface/action/Behavior "{command: '[{\"T\": 1, \"type\": \"stop\", \"data\": 0}]'}"
At this time, the robot will stop moving, and you can see that the model in the Rviz2 model interface of the product will also stop moving. Normally, the robot will stop moving after the value of the given data parameter is finished.
10.2 Get current point location
Before interacting with the following tutorial commands, you need to enable navigation first. Before enabling navigation, make sure you have built an environment map. If you have not followed the previous tutorial, you first need to follow UGV Rover PI ROS2 4. 2D Mapping Based on LiDAR or UGV Rover PI ROS2 5. 3D Mapping Based on Depth Camera to create a map.
After the map construction is completed, place the robot at the actual location of the map. The robot needs to judge whether it has completed the movement to the target location based on the odometer, and run the command to start navigation in a new container:
ros2 launch ugv_nav nav.launch.py use_rviz:=true
There is no use_localization specified in this command, and the navigation based on the AMCL algorithm is used by default, as detailed in UGV Rover PI ROS2 6. Auto Navigationsection.
You can save several target positions as navigation points before using commands to control the robot to move to navigation points. First get the current point location information:
ros2 topic echo /robot_pose --once
Save the location information obtained previously as a navigation point, in the following command, data is the name of the navigation point, which can be set to any letter between a~g:
ros2 action send_goal /behavior ugv_interface/action/Behavior "{command: '[{\"T\": 1, \"type\": \"save_map_point\", \"data\": \"a\"}]'}"
You can use Nav2 Goal in the RViz navigation interface to move the robot to the next target position and save it as the next navigation point.
After saving the navigation point, send a control command to let the robot move to the corresponding navigation point, and the data is the name of the previously saved navigation point:
ros2 action send_goal /behavior ugv_interface/action/Behavior "{command: '[{\"T\": 1, \"type\": \"pub_nav_point\", \"data\": \"a\"}]'}"
The saved navigation point information will also be stored in the map_points.txt file, which is located in the /home/ws/ugv_ws/ directory.