Navigation send target point

In this chapter, a python program is written, and the goal is sent to the move_base navigation system through the navigation interface of ros, so that the robot can navigate to the target point. When we let the robot navigate to the target point, we need to determine the target point first, and then tell the target point to the robot.

Determine the target coordinate point

First of all, we need to learn a technique to obtain the map through rviz. Let's demonstrate how to obtain the coordinates of the target point through simulation.

Open the terminal and enter the following command to start a simulation node

roslaunch handsfree_2dnav navigation.launch

Under normal circumstances, the rviz visualization interface will be opened and a map will be displayed. The place surrounded by red in the figure below is the location of the robot. rviz-room-stage

  • 2D Pose Estimate can manually calibrate the initial pose of the robot and adjust the position of the robot in rviz.
  • 2D Nav Goal can set a point for the robot to navigate to.
  • Publish Point allows us to view the coordinate points on the map in the lower left corner. Usage, just click Publish Point with the mouse, and then move the mouse on the map to see the corresponding point. This square bracket has three values [11.7, 27.9, 0.00768], the first two values correspond to the x and y of the coordinate point.

code description

There are three codes here, namely set_goal.py, set_tow_goal.py and set_four_goals.py

  • set_goal.py Set a point and let the robot navigate to this point
  • set_tow_goal.py Set two points and let the robot navigate to these two points
  • set_four_goals.py Set four points and let the robot navigate to four points

Here we mainly talk about the function of sending goal

self.move_base.send_goal(goal, self.donecb, self.activecb, self.feedbackcb)

The first parameter is the target point to be sent, and the following three are callback functions, which are:

  1. The callback function when the robot arrives.
  2. The callback function when the robot starts.
  3. The callback function when the robot returns information with a certain frequency

Because move_base uses action to deliver messages, so many callback functions are used. Our code is stored in the handsfree_tutorials/script/3_navigation directory.

Test autonomous patrol script

This time we take set_goal.py as an example, we can use the simulation to simulate it first, and then use the robot and the map built by the radar to actually operate it.

Test the script by emulation

  1. Close all previous terminals, open a new terminal, and open the simulation node

       roslaunch handsfree_2dnav navigation.launch
    

    Under normal circumstances, the visualization interface will be opened, showing the map and the robot. rviz-0

  2. Open the second terminal and open the set_goal.py file through gedit. We need to change a few parameters.

      gedit ~/handsfree/handsfree_ros_ws/src/handsfree/handsfree_tutorials/script/3_navigation/set_goal.py
    

    We only need to change two values, the picture below is not modified goal-before

    The following figure is modified, using the coordinates of the lower left corner of the rviz visualization figure to determine the coordinate point. goal-after

  3. Open the third terminal and run the python file

      rosrun handsfree_tutorials set_goal.py
    

    Normally, it will display: set_goals

    At the same time, on the visual interface, you will see that the robot is moving along a red line. rviz-move

  4. You can also run the launch file, but before that, you need to modify the launch file, enter in the previous second terminal

      gedit ~/handsfree/handsfree_ros_ws/src/handsfree/handsfree_tutorials/script/3_navigation/launch/set_goal.launch
    

    Modify the value of the value inside: launch-after

    The value of value should not be the same as the current robot position coordinates, otherwise the robot will not move.

  5. Run the modified set_goal.launch file in the previous third terminal

      roslaunch handsfree_tutorials set_goal.launch
    

    Similar to the result of running python. launch-set-goals

Robot physical test script

According to the Autonomous Navigation experiment of the primary tutorial, run the relevant nodes.

  1. Open the terminal and open the robot navigation node

      roslaunch handsfree_2dnav navigation.launch sim:=false map_name:=my_map
    
  2. Run the python file and navigate to the target point

    Before running the script, please refer to the technique of selecting the target point in this section, and modify the coordinates of the target point in the script:

      rosrun handsfree_tutorials set_goal.py
    

    If all goes well, the robot will plan a path and move autonomously to the specified target point.

Test multi-point patrol script

The other two python files and the corresponding launch files are test programs for two-point patrol and four-point patrol respectively, and are used in the same way as the above single-point navigation. Just modify the corresponding target point coordinates in the python file or launch file.

Tips: Make good use of Tab to complete the command!

results matching ""

    No results matching ""