How to set up your workspace¶
In this tutorial, you will set up a directory on your ROS 2 enabled PC as your workspace for development and install the competition ROS 2 packages. Please follow the instructions below carefully.
Note
This can ONLY be completed after you have set up your PC (by following the tutorial here: Setting up your PC).
Step 1: Setup ROS 2 workspace¶
Open a new terminal on your PC, then copy and paste the following one line at a time:
Step 2: Clone the repository¶
In the same terminal (or in a new one), copy and paste the following:
Step 3: Install dependencies¶
The cloned project repository contains ROS packages that require certain dependencies before they can be used. These dependencies are specified in the respective package.xml
file
of each package and are installed using rosdep a command-line utility for identifying and installing
dependencies to build or install a package.
To install the project dependencies, un the same terminal (or in a new one), copy and paste the following:
cd ~/ros2_ws
sudo rosdep init
rosdep update
rosdep install --from-paths src --ignore-src --rosdistro humble -r -y
Step 4: Set up ROS 2 environment¶
The following command needs to be run in every new terminal you open to get access to ROS 2 commands:
To avoid sourcing the ROS setup file every time you launch a new terminal, you can add the command to your shell startup script by executing these lines:
The ros2_ws
workspace is an overlay on top of the ROS installation, which is known as the underlay, and similarly to use the package executables or libraries
in ros2_ws
, the workspace will need to be sourced in every new terminal opened with this command:
Likewise to avoid manually sourcing the workspace in each newly launched terminal, the command can also be added to shell startup script:
Note
As you develop, it is good to set the environment variables whenever you run a colcon build
command to compile changes to your packages. You can do that by:
Step 5: Compile packages¶
The next step is to compile the installed packages using colcon build
:
Step 6: Gazebo Classic installation and setup¶
Gazebo Classic, version 11, is the robot simulator used in the competition and can be installed here.
The tomato field is made up of custom models, the tomato plants for instance, that are not available in Gazebo. These models are present in the models
folder in the parc_robot_bringup
package.
To completely view the tomato field in Gazebo, the path to the models
folder is made to Gazebo by executing the following commands one after the other:
echo "export GAZEBO_MODEL_PATH=:$HOME/ros2_ws/src/parc_robot_bringup/models" >> ~/.bashrc
source ~/.bashrc
Ensure that the workspace directory is correctly typed out assuming that a different workspace from ros2_ws
is used.
Note
The 3D visualizer for ROS, RViz
, is automatically installed when ROS 2 Humble was installed on your PC in the setting up your PC tutorial.
Step 7: Test installation¶
If you completed the preceding tasks successfully, you should be able to run this ROS 2 launch command and see the Gazebo Classic simulator and RViz simulator open with the following display:
Gazebo Classic Simulator windowRViz window
If you run the following command in a new terminal,
You will see a screen like this:You need to publish/write to the topic
robot_base_controller/cmd_vel_unstamped
to move the robot.
The following guide will help you control the robot using keyboard. Once you have tested that, you can follow the getting-started-with-ros guide to write a python program to control the robot.
Step 8: Controlling the robot using keyboard¶
First of all, the teleop_twist_keyboard
ROS 2 package is installed which will enable us to use the keyboard to control the robot in a terminal as follows,
Then run the following command in a new terminal,
ros2 run teleop_twist_keyboard teleop_twist_keyboard --ros-args --remap \
/cmd_vel:=/robot_base_controller/cmd_vel_unstamped
Now keeping this second terminal active (or on top) press i
to move the robot forward, you can see the robot moving in the “RViz” and “Gazebo” windows.
You can use the keys shown below to move the robot and k
key to stop the movement.