Chapter 13. On Patrol
In Chapter 10, you saw how to use the ROS nav stack to get your robot to a specific place in the world. In this chapter, we’ll build on these basic navigation capabilities and look at how to get your robot to patrol around the world, collecting interesting information as it goes. We’ll also use this application as an excuse to learn about task-level control of robots, where we sequence entire behaviors rather than single actions.
Simple Patrolling
As with most things in ROS, there are several ways to implement a patrol system. In fact, the code we saw in Example 10-1 is all we need. This code, shown again in Example 13-1, moves the robot from one pose in the world to another. All we need to do is to put the places in the world that we want the patrol to cover in the list of waypoints, and we’re all set.
Example 13-1. patrol.py
#!/usr/bin/env python
import
rospy
import
actionlib
from
move_base_msgs.msg
import
MoveBaseAction
,
MoveBaseGoal
waypoints
=
[
[
(
2.1
,
2.2
,
0.0
)
,
(
0.0
,
0.0
,
0.0
,
1.0
)
]
,
[
(
6.5
,
4.43
,
0.0
)
,
(
0.0
,
0.0
,
-
0.984047240305
,
0.177907360295
)
]
]
def
goal_pose
(
pose
)
:
goal_pose
=
MoveBaseGoal
(
)
goal_pose
.
target_pose
.
header
.
frame_id
=
'
map
'
goal_pose
.
target_pose
.
pose
.
position
.
x
=
pose
[
0
]
[
0
]
goal_pose
.
target_pose
.
pose
.
position
.
y
=
pose
Get Programming Robots with ROS now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.