This is an old revision of the document!


Lab 4: ROS introduction and PD control

Part 1: ROS2 Introduction

We’ll be using ROS2 (Robot Operating System) throughout this course. ROS2 provides tools, libraries, and conventions that facilitate building robotic applications and allow different parts of the robot to interact with each other.

Familiarize yourself with the basics of ROS by reviewing the ROS introduction guide (https://wiki.ros.org/ROS/Introduction). Keep this guide handy as a ROS2 cheat sheet (https://github.com/ubuntu-robotics/ros2_cheats_sheet/tree/master) that you can refer to throughout the course. We also have a list of important ROS2 commands for this course here: What is ROS 2?

ROS services in Pupper: robot.service manages control code (face controller, rl or heuristic controller, etc). See if controller is running: systemctl status robot.service You should see the status as “active (running)”. Checkout all topics and services: ros2 topic list and ros2 service list.

Since we are running custom code, we must disable the robot service before working on your code. This will prevent the robot from running any pre-existing code that may interfere with your work. Make sure to place Pupper on the stand during this process. To disable the robot service, run the following commands:

Note: Robot Service should already be disabled. So you can skip this step and proceed to Part 2.

sudo systemctl disable robot.service
sudo reboot

Troubleshooting. If you encounter any issues, try the following:

If you see “ros_2 not found”, run source ~/.bashrc again

Part 2: Hello PD

Step 1: Setup Lab 1 Code Base

  • Open the lab 1 folder in VSCode
cd ~/lab_1_fall_2025
code .
  • Examine lab_1_fall_2025/lab_1.py to understand where the motor angle and velocity are read and where the motor is commanded.

Note: In ROS2 code, pay attention to publishers and subscribers defined in the init section of the node definition. Publishers send messages to topics, while subscribers listen to messages on topics. Callback functions run when new information is published to a topic.

DELIVERABLE: Before running your code, explain in your lab document what you understand about the publishers and subscribers. What gets sent and received on each message publish? How does this correspond to what is physically commanded in the motor?

Step 2: Run ROS Launch Code

  • Check the launch description in lab_1.launch.py and lab_1.yaml. Familiarize yourself with the structure and parameters defined in these files.
  • Run the launch file using the following command:
ros2 launch lab_1.launch.py

This command will start all the necessary nodes for your PD control experiment.

When you run the launch file, Pupper is trying to calibrate its legs, and so the motor dial will spin for a bit before the software determines that the mechanical calibration stops have been hit. Since we do not have the full legs attached just yet, the motor dial will spin for some time before stopping. Let this process complete (dials stop spinning) before running the code you implement.

  • After running the launch file, you should see output in your terminal indicating that the nodes have been started successfully. If you encounter any errors, double-check your file paths and make sure all dependencies are installed.
  • Open a new terminal window (if using SSH, you can open multiple connections to your Raspberry Pi, or add a terminal from VSCode) and run the following command to see the list of active topics:
    ros2 topic list

You should see topics related to joint states and commands. These are the topics your node will be publishing to and subscribing from.

  • To inspect the data being published on a specific topic, you can use the ros2 topic echo command. For example:
    ros2 topic echo /joint_states

This will show you real-time data about the joint states of your robot leg.

DELIVERABLE: In your lab document, provide screenshots of:

  1. The terminal output after running the launch file, showing successful node startup.
  2. The list of active topics you observed.
  3. A sample of the joint states data you saw when using the ros2 topic echo command.

Also, answer the following questions:

  1. What nodes are being launched by your lab_1.launch.py file?
  2. What parameters are being set in the lab_1.yaml file, and what do you think they control?
  3. Based on the topics you observed, how do you think the different parts of your robot control system are communicating with each other?

Remember, understanding how the launch system works and how to inspect your ROS2 system is crucial for debugging and developing more complex robotic systems in the future.

rasb/lab/04.1782624961.txt.gz · Last modified: 2026/06/28 08:36 by jan.vaduva
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0