ICE4: Driving the Robot#
Purpose#
This In-Class Exercise will introduce you to utilizing pre-built ROS packages to accomplish a task. It will also provide you experience interacting with someone else’s source code (.py files) to learn how that component works. You will use ROS to run two nodes, turtlebot3_core and teleop_twist_keyboard, to drive the Turtlebot3 with a keyboard. You will continue to practice using ROS tools to observe how these components communicate.
Code used to drive the robot#
On the Master, open a terminal and run roscore.
Open a new terminal on the Master and create a secure shell into the Turtlebot3 using the SSH command you learned during Module 2. This will allow you to run commands as if you were on the Turtlebot3.
Using the secure shell, open the source code for the turtlebot3_core launch using the nano command line editor tool through the rosed command:
$ rosed turtlebot3_bringup turtlebot3_core.launch
⌨️ Syntax:
rosed <package> <filename>
Note
You may remember when we set up our .bashrc file we set the system variable EDITOR to
nano -w
. This enables therosed
command to utilize the nano editor.We will learn more about launch files in a few modules, but just understand that a launch file is used to launch one or more ROS nodes. This particular launch file only launches one node, serial_node.py. This node will connect to the OpenCR controller on the Turtlebot3 using the port and baud rate parameters. This connection will enable us to send Twist messages over the /cmd_vel topic to drive the Turtlebot3 using the keyboard.
Close the editor by hitting
ctrl+x
.It is always a good idea to check that the Turtlebot3 is communicating with the Master. To do this, we can list the active topics the Turtlebot3 sees. Run the following within your secure shell:
$ rostopic list`
If all is well, then there should be two topics provided by roscore running on the Master: /rosout and /rosout_agg. We will typically ignore these topics.
Run the turtlebot3_core.launch file using the
roslaunch
command:$ roslaunch turtlebot3_bringup turtlebot3_core.launch`
⌨️ Syntax:
roslaunch <package> <launchfile>
Your Turtlebot3 is now ready to drive and should be listening for Twist messages to be sent over the /cmd_vel topic.
Driving the robot#
Open a new terminal on the Master and observe the nodes currently running:
rosrun rqt_graph rqt_graph
You should only see one node running right now, turtlebot3_core, with no connections.
Open a new terminal tab and list the active topics. There should be one active topic other than the ones created by roscore: /cmd_vel.
We used the /cmd_vel topic when driving the simulated Turtlebot3, but let’s refresh our memory about the topic:
rostopic info cmd_vel
As you can see the /cmd_vel topic is currently subscribed to by the turtlebot3_core with no publishers (just as we would expect after seeing the rqt_graph). We also note that topic utilizes the Twist message type. The following will show information about the fields within the Twist message sent over the /cmd_vel topic:
rostopic type cmd_vel | rosmsg show
You can find information about pre-built packages by googling the package name along with the ROS distribution. Open up your favorite browser and google “teleop twist keyboard noetic”. The first result should be from the ROS wiki page.
Ensure the ROS package teleop_twist_keyboard is installed on your Master:
rospack find teleop_twist_keyboard
If installed, the command should return the absolute path to the package, similar to
/opt/ros/noetic/share/teleop_twist_keyboard
If the command instead returns an error, then you need to install the package using apt:
sudo apt install ros-noetic-teleop-twist-keyboard
Tip
All packages built for Noetic can be downloaded in the above manner (ros-noetic-desired-pkg with underscores in the package name replaced by dashes). Some packages were only built for previous ROS distribution and will have to be built from source (we will demonstrate this at a future time).
Run the teleop_twist_keyboard node on the Master:
Tip
Don’t forget your tab completion! You can start typing a package name or node and then hit tab for it to complete the command for you!
rosrun teleop_twist_keyboard teleop_twist_keyboard.py
Before we get too excited and drive the Turtlebot3 off a cliff, observe how the nodes communicate using the rqt_graph tool in a new terminal (if you still have the previous rqt_graph running, you can hit the refresh button in the top left corner).
Select the terminal that has the teleop_twist_keyboard node running and observe the instructions for sending Twist messages. These are the same as when driving the simulated Turtlebot3.
The Turtlebot3 operates best with a linear velocity between 0.2 m/s and 0.5 m/s. It turns best with an angular velocity between 0.5 rad/s and 1.5 rad/s. Drive the Turtlebot3 using these parameters.
ROS#
In labs throughout this course we will request information about the topics, nodes, and messages within your system. Accomplish the following in a new terminal on your Master (you can ignore all nodes/topics that result from roscore).
List all running nodes.
Determine what topics the nodes subscribe and publish to (repeat for each node).
Display running nodes and communication between them.
List the active topics.
Determine the type of messages sent over the topics (repeat for each topic).
Determine the fields of the messages.
Observe the information sent over a topic (repeat for each topic).
Checkpoint#
Once complete, push screenshots showing the output of each of the above to your student repo on github in a /master/module04 folder.
Summary#
In this exercise you examined and used pre-built packages and source code to drive the Turtlebot3 and understand how the system worked. You then were able to analyze the topics, nodes, and messages within the ROS system to better understand the flow of information and control. The pro-tips presented throughout this exercise will make you a better user of Linux and ROS.
Cleanup#
In each terminal window, close the node by typing ctrl+c
. Exit any SSH connections.