ROS2 S1 module code explained - HU-ICT-LAB/RobotWars GitHub Wiki

This page contains info on the code developed to control the robomaster-S1 using a controller. The code should be run on the NVIDIA Jetson Nano and within the Docker ROS2 image environment. More on this on the wiki page "Docker and ROS2 on NVIDIA Jetson Nano".

Sections

The ROS2 environment

The developed code runs within a ROS2 docker-image environment, which is specialized to incorporate the required dependencies. More on how to create the image on the wiki page "Docker and ROS2 on NVIDIA Jetson Nano".

Multiple terminals are going to be required in order to run the application. The first should be used to build the environment using:

colcon build

at the root of the workspace. This builds the workspace and allows you to "source" it as an overlay when wanting to run nodes.

It's important that you use a new terminal for the subsequent actions, as using the same terminal as the one the environment was build in will lead to unexpected behaviour.

To run a node or launch a launchfile, first open up a new terminal, start the docker-environment, and move to the root of the workspace. From there, run the following command to "source the overlay", meaning it will be able to access the ROS2 overlay:

. install/setup.bash

Now all ROS2 applications are available to you.

More info on running packages within the ROS2 environment can be fount at "Running ROS2 and packages within the image"

Packages

Note: Both packages can be run using their own launch files, or using the workspace launchfile "S1__full_launch.launch.py", which will launch both packages at once.

S1_Master

The S1_Master package contains the code to communicate with the S1 using the robomaster-SDK for chassis and gimbal movement control. The package listens to the "/cmd_vel" topic for twist-messages and uses a callback function to react whenever a message is received. The callback function reads the message and translates it to movement instructions for the S1.

The package contains a launchfile named "launch_S1_drivers__1.launch.py". Calling this launchfile will start this nodes functionality. Simply call:

ros2 launch S1_Master launch_S1_drivers__1.launch.py

teleop_joy

The teleop_joy package contains the code to post twist-messages on the "/cmd_vel" topic (which the S1_Master package listens to and translates to movement). It contained 2 nodes:

  • joystick_ros2 Reads joystick input and posts it on the "/joy" topic as joy-messages. If your controller is not recognized, you should check if the configuration exists.
  • teleop_joy listens to the /joy topic and transforms posted joy-messages into twist-messages to post on the "/cmd_vel" topic.

The package contains a launchfile named "launch_teleop_joy_twist.launch.py". Calling this launchfile will start both nodes's functionality. Simply call:

ros2 launch teleop_joy launch_teleop_joy_twist.launch.py