Skip to content

ROS2 Workspaces

Before setting up the ROS2 workspaces needed to control the robot, please make sure you have cloned this repository:

gh repo clone StanfordASL/trunk-stack
The ROS2 code lives in the stack/ directory.

Main Workspace

Note: This workspace runs on the main machine.

Enter the main/ folder. We primarily use ROS2 Humble, which should be sourced before doing the first build:

source /opt/ros/humble/setup.bash
For actually building the workspace, we use Colcon, i.e. run:
colcon build
in the main/ directory and check that the build process runs without any errors.

General note

It is highly recommended to build individual packages (within a workspace) upon changes, using the syntax:

colcon build --packages-select interfaces

Motion Capture Workspace

Note: This workspace runs on the main machine.

Make sure you have set up the motion capture system as described in the OptiTrack System Setup page.

Enter the mocap/ folder. Most code is already present, except for the mocap4ros2_optitrack plugin, which can be installed by following the instructions on the respective website. For completeness, we also list the steps here.

Enter the src/ directory. Download the plugin's repository:

cd src/
git clone https://github.com/MOCAP4ROS2-Project/mocap4ros2_optitrack.git
Install dependencies:
rosdep install --from-paths src --ignore-src -r -y
vcs import < mocap4ros2_optitrack/dependency_repos.repos
Now, make sure that configuration file, located in mocap4ros2_optitrack/mocap4ros2_optitrack_driver/config/, has the correct information. Specifically, the server_address should be equal to the address that Motive is streaming to (see the Local Interface entry in the Streaming pane in Motive), and local_address should be the address of the main machine, that will be running this workspace.

Once that information is entered correctly, compile the workspace:

cd ..
colcon build --symlink-install
Do make sure that ROS2 Humble is sourced again before building. Certain warnings can come up but may be ignored.

Then, check that the Optitrack configuration works fine and is connected by running it once:

source install/setup.bash
ros2 launch mocap4r2_optitrack_driver optitrack2.launch.py
This should say "Configured!" as a last message. As the driver node is a lifecycle node, you should transition to activate by running in a separate terminal:
source install/setup.bash
ros2 lifecycle set /mocap4r2_optitrack_driver_node activate
which should return "Transitioning successful".

Motor Control Workspace

Note: This workspace runs on the Raspberry Pi.

For the control of the motors, we use the ros_phoenix package. Due to compatibility constraints of this package, we use ROS2 Foxy for this workspace.

Clone the trunk-stack repository on the Pi and enter the motors/ folder.

Enter the source directory and clone the package:

cd src/
git clone https://github.com/vanderbiltrobotics/ros_phoenix

Note that the launch script trunk.launch.py is also being version controlled, therefore ensure that is placed in its respective location.

Again, build the workspace:

cd ..
colcon build --symlink-install

Camera Workspace

Note: This workspace runs on the Raspberry Pi.

First, change directory into the camera/ folder.

We closely follow this tutorial to install the camera driver, with the difference being that the Pi has Ubuntu 20.04 installed, not Raspberry Pi OS (previously Raspbian). Specifically, once ROS2 is installed, the following commands can be used to install the camera packages:

cd src/
git clone --branch foxy https://gitlab.com/boldhearts/ros2_v4l2_camera.git
git clone --branch foxy https://github.com/ros-perception/vision_opencv.git
git clone --branch foxy https://github.com/ros-perception/image_common.git
git clone --branch foxy-devel https://github.com/ros-perception/image_transport_plugins.git
cd ..
rosdep install --from-paths src -r -y
colcon build
You may need allow the camera to be accessed by the user, which can be done by adding the user to the video group, or by adding the following udev rule:
sudo nano /etc/udev/rules.d/99-webcam.rules
KERNEL=="video[0-9]*", MODE="0666"  # add this to the file
sudo udevadm control --reload-rules
sudo udevadm trigger

Gripper Workspace

Note: This workspace runs on the Raspberry Pi.

Setup Testing

To test the correct workings of the ROS2 workspaces, it is recommended to