Table of Contents

Lab 5: Forward Kinematics

Part 1: Intro

In order to be able to control the pupper, the first thing we would need is to get the position of the legs. What we are given through the power of ROS magic as an input is the angles of each joint, and by knowing the topology of the robot we can figure out the end position of each leg through the power of linear algebra.

Recall from computer graphics that points in space are represented with vectors, and that any transformations can be represented with a matrix

Part 2: Setup

cd ~/lab_2_fall_2025
code .

For docker users, you may try to simulate with this setup, download this and then do these following commands:

tar -xvf pupper_viz.tar.gz
cd pupper_viz/
docker build -t pupper_viz .

Once done, you may paste your forward_kinematics solution into the lab_2.py and then

./run.sh

Step 3. Understanding the Code Structure

Before we start implementing the TODOs, let's understand the structure of the lab_2.py file:

  1. The code defines a ForwardKinematics class that inherits from rclpy.node.Node
  2. It subscribes to the joint_states topic and publishes to the leg_front_1_end_effector_position and marker topics.
  3. The forward_kinematics method is where we'll implement the forward kinematics calculations
  4. The code uses NumPy for matrix operations.
  5. Note that it is the convention to orient the coordinate frame so that the rotation about each motor is the z axis.

Step 4: Implementing Forward Kinematics

Step 1: Implement Rotation Matrices
  1. Open lab_2.py and locate the forward_kinematics method.
  2. Implement the rotation matrices about the x, y, and z axes.

Which axis is typically used as the default axis for rotations in robotic systems? What angles are we rotating along the default axis? Why?

== Step 2: Implement Transformation Matrices

In the following steps, (theta) represents the motor angle. Figuring out the sign of will be trickier than you might expect!

Transformation from base link to leg_front_l_1

Part 5: Debugging Your Implementation With RVIZ2

ros2 launch lab_2.launch.py
python lab_2.py

To test your code in simulation to make sure that the code works as expected, you can use RVIZ2. RVIZ2 will show the Pupper model as well as a marker that shows the output from the forward kinematics.

rviz2 -d lab_2.rviz

The above command will load the RVIZ config file. If you just run rviz2, you can manually add the configuration. After running rviz, click the “Add” button, and then select a Robot Model type. Select the /robot_description topic. Next, add the marker by selecting “Add” again, and select a Marker type. Select the topic /marker.

While we’ve tested this pipeline on a Pupper and it works as expected, rviz2 may fail on your robot due to heating in the Raspberry Pi. If this happens, reach out to a TA to check the implementation first, then turn off Pupper, wait a while to let it cool down, and try again.

Part 6: Analyzing the Results

  1. Record the end-effector positions for the left front leg configurations.
  2. Compare these positions with the expected positions based on the physical dimensions of your robot. (Why are the numbers printed in the terminal so small?)
  3. If there are discrepancies, try to identify the source of the errors. It could be due to: incorrect transformation matrices, innacurate joint angle readings, errors in the physical measurements of the robot

Additional challenges (optional

If you finish early and want to explore further:

  1. Extend your implementation to calculate forward kinematics for all four legs of the Pupper robot. Save your calculations for these other legs for lab 4, where we will need forward kinematics for all four legs.

We provide the base link to leg_back_r1 transformation in the diagram below. The rest of the transformations are identical to the front leg:

  1. During the testing with rviz2, write a script that saves the sequence of your well-crafted motion, recorded as end effector positions into a file. You will have a chance to let Pupper replay this recorded motion in the next lab! You will need to use the joint_states topic to record the motor angles, and the leg_front_l_end_effector_position topic to record the end effector positions.