This section is heavily based on previous one (navigation_bot_07), the only difference is, that instead of waypoint_follower.py script that calls navigator.followWaypoints(goal_poses), we have nav_through_poses.py that calls navigator.goThroughPoses(goal_poses). This way we can use points on map to "draw" the path for a robot.
In other words, we are going to give the robot an array of points and tell it to move through them. The difference between this section and a previous one (with waypoints) is that the entire path is calculated at once, while before we were calculating the path to the next waypoint only after we reached the previous one.
Note that whenever robot arrives at an intermediate waypoint, it should face the next waypoint, as otherwise the robot will have to adjust its direction at each intermediate point, which is not nice. So we need to provide orientation the robot should have when it arrives at the intermediate points. To do it, we use goal_pose2.pose.orientation.w.
path follower:
goal_pose = PoseStamped() goal_pose.header.frame_id = 'map' goal_pose.header.stamp = navigator.get_clock().now().to_msg() goal_pose.pose.position.x = -7.0 goal_pose.pose.position.y = 3.2 goal_pose.pose.position.z = 0.0 goal_pose.pose.orientation.x = 0.0 goal_pose.pose.orientation.y = 0.0 goal_pose.pose.orientation.z = 0.707 goal_pose.pose.orientation.w = 0.707 goal_poses.append(goal_pose)
In ROS2, goal_pose2.pose.orientation.w is the scalar component of the quaternion that
represents the orientation of the pose in the 3D space.
Quaternions are a mathematical representation of orientation that are commonly used in robotics
and computer graphics. They consist of a scalar component and a vector component, and can be used
to represent rotations in three-dimensional space.
The scalar component w represents the rotation angle in radians divided by 2. The vector
component x, y, and z represent the axis of rotation in three-dimensional space.
In the code snippet above, goal_pose2.pose.orientation.w is set to 0.707, which
represents a rotation of approximately 45 degrees around the z-axis. The
goal_pose2.pose.orientation.z
component is also set to 0.707, which indicates that the rotation axis is in the direction of
the positive z-axis.