Foreword
Previous chapter has completed the simulation operation and navigation turtlebot3 slam, and this section will be script-controlled turtlebot3 navigate back and forth between multiple points. Project link: Download
Implementation process
Startup environment map
roslaunch turtlebot3_gazebo turtlebot3_world.launch
Using the previous chapter talked about navigation maps built and open rviz visualization
roslaunch turtlebot3_navigation turtlebot3_navigation.launch map_file:=$HOME/map.yaml
Using a modified 2D pose Estimate position
Location on a mouse click on the map is your initial position, that is, the arrow points toward your initial robot.
Can be modified as shown below:
Ready to work
Create a multi-point navigation script
cd ~/wanderbot_ws/src/wanderbot/src
vi patrol.py
patrol.py: multi-point navigation script
#!/usr/bin/env python
import rospy
import actionlib
from move_base_msgs.msg import MoveBaseAction, MoveBaseGoal
waypoints = [ # <1>
[(1.522, 0.444, 0.0), (0.0, 0.0, -0.519, 0.85)],
[(-2.0432, -0.439, 0.0), (0.0, 0.0, -0.559, 0.82902)]
]
def goal_pose(pose): # <2>
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[0][1]
goal_pose.target_pose.pose.position.z = pose[0][2]
goal_pose.target_pose.pose.orientation.x = pose[1][0]
goal_pose.target_pose.pose.orientation.y = pose[1][1]
goal_pose.target_pose.pose.orientation.z = pose[1][2]
goal_pose.target_pose.pose.orientation.w = pose[1][3]
return goal_pose
if __name__ == '__main__':
rospy.init_node('patrol')
client = actionlib.SimpleActionClient('move_base', MoveBaseAction) # <3>
client.wait_for_server()
while True:
for pose in waypoints: # <4>
print("goal:x=%f y=%f"%(pose[0][0],pose[0][1]))
goal = goal_pose(pose)
client.send_goal(goal)
client.wait_for_result()
Determining the waypoint location
rostopic list
View All Topics name
apparently topic navigation coordinates are amcl_pose.
AMCL: In ros, we use amcl package robot localization on the map. amcl nodes to achieve a series of probabilistic location algorithm, collectively referred to as adaptive Monte Carlo localization algorithms (Adaptive Monte Carlo Locatization).
Specifically, he uses sample_motion_model_odometry, beam_range_finder_model, likelihood_filed_range_finder_model, Augmented_MCL and KLD_Sampling_MCL algorithm.
So we monitor this topic, it was still used ros debugging tools: rostopic
rostopic echo amcl_pose -n 1
Print out the current coordinates:
pose:
position:
x: -2.03239229723
y: -0.408803583203
z: 0.0
orientation:
x: 0.0
y: 0.0
z: -0.529167851235
w: 0.848517168488
Obviously this is what we want the coordinates.
Then rviz by just a few points navigation point
print position to reach the target again:
rostopic echo amcl_pose -n 1
ok we know the initial coordinates and target coordinates:
Initial:
position:
X: -2.03239229723
Y: -0.408803583203
Z: 0.0
Orientation:
X: 0.0
Y: 0.0
Z: -0.529167851235
W: 0.848517168488
objectives:
position:
X: 1.76888229632
Y: .588761452838
z: 0.0
Orientation:
the X-: 0.0
the y-: 0.0
z: -0.459069601992
w: 0.888400304214
them write to our multi-point navigation script written inside.
This section can be modified.
After modification exit, set permissions
chmod 777 patrol.py
Start multi-point navigation
rosrun wanderbot patrol.py
You can see the robot coordinate between the initial and target the back and forth.
to sum up
emmm really fun bar under review the way in front of the school. . . enjoy it ~
reference
"Ros robot programming practice."