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 pythonimportrospyimportactionlibfrommove_base_msgs.msgimportMoveBaseAction,MoveBaseGoalwaypoints=[[(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)]]defgoal_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
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access