CS 354 Autonomous Robotics
Fall 2020
ROS2 Python Lab
Introduction
The goals of this activity are to:
- gain experience using ROS2 tools to investigate a ROS2 system
- practice writing simple ROS2 Python publishers and subscribers
- gain experience with the Turtlebot3 platform
Resources
Controlling a Turtlebot using Python
Create a Python file named forward.py
. Your script should create a
node that moves the Turtlebot directly forward at a fixed, constant
rate of .2 meters per second. (This node will need a publisher, but
it won't need to create any subscriptions.)
Start the simulator and test your completed node. As a reminder, the command to start the simulator is:
ros2 launch turtlebot3_gazebo turtlebot3_world.launch.py
You should be able to test your script by starting it in the terminal using Python:
python3 forward.py
Using the /scan Topic
Create a new file named wander.py
that subscribes to the /scan
topic. This node should halt forward progress as soon as an object is
observed less than one meter in front of the Turtlebot.
You'll need to make use of the ROS2 command line tools to determine
the appropriate message type and message format associated with the
/scan
topic. Even then, it will probably require some
experimentation to figure out how to access the range values that
correspond to the front of the robot.
Note that the data on the /scan
topic is provided by a "Best effort"
publisher. This is not compatible with the default QoS subscriber
settings. (You can read more about QoS compatibility
here) You will need to include this import at the top of your file:
from rclpy.qos import qos_profile_sensor_data
You can then pass qos_profile_sensor_data
as the fourth argument
when you call create_subscription
to set up your subscription.
Improved Wandering
Modify your wander node so that, instead of stopping, the robot to rotates to avoid looming obstacles. Your finished node should be able to wander around while avoiding obstacles in the robot's path.
Submitting
Submit forward.py
and wander.py
through Canvas. Make sure that
your submission contains the names of all group members.