Lab 2: Forward Kinematics
Goal
Implement forward kinematics for the right front leg of the Pupper robot using ROS2 and Python.
Fill out the lab document as you go. Make a copy and add your responses.
Part 1: Hardware Build
Follow the build instructions for lab 2: lab 2 assembly instructions. You will build a front right leg for Pupper in this lab. Begin by checking to see that your kits contain all the pieces, if not, please ask a TA.
Part 2: Setup
Make sure you have completed Lab 1 and are familiar with the ROS2 environment on your Raspberry Pi 5.
Clone the lab 2 code repository on the Raspberry Pi:
cd ~/ git clone https://github.com/cs123-stanford/lab_2_2024.git lab_2
Open the workspace (lab_2 directory) in VSCode and examine the
lab_2.pyfile.Change all the 12 occurances of
homing_kpvalues to1.0andhoming_kdvalues to0.1in the~/ros2_ws/src/pupper_v3_description/description/components.xacrofile.
DELIVERABLE: Why do you think that there are 12 occurances of these values in the xacro file? What do you think that changing them from the previous value does?
Part 3: Understanding the Code Structure
Before we start implementing the TODOs, let’s understand the structure of the lab_2.py file:
The code defines a
ForwardKinematicsclass that inherits fromrclpy.node.Node.It subscribes to the
joint_statestopic and publishes to theleg_front_r_end_effector_positiontopic.The
forward_kinematicsmethod is where we’ll implement the forward kinematics calculations.The code uses NumPy for matrix operations.
Note that it is convention to orient the coordinate frame so that the rotation about each motor is the z axis.
Part 4: Implementing Forward Kinematics
Step 1: Implement Rotation Matrices
Open
lab_2.pyand locate theforward_kinematicsmethod.Implement the rotation matrices about the x, y, and z axes. Follow the homogeneous coordinates representation as presented in lecture.
DELIVERABLE: Which axis is typically used as the default axis for rotations in robotic systems? Why?
Step 2: Implement Transformation Matrices
Note that theta is the motor angle
The transformation matrix from the base link to leg_front_r_1 has been implemented for you in
T_0_1. This involves a translation and two rotations. Understanding this transformation will help you complete the remainder of the transformations.
DELIVERABLE Explain the reasoning behind this implementation. What does the translation and each of the rotations do in T_0_1?
Implement the transformation matrix from leg_front_r_1 to leg_front_r_2 in
T_1_2. Follow the same thought process as withT_0_1.Implement the transformation matrix from leg_front_r_2 to leg_front_r_3 in
T_2_3.Implement the transformation matrix from leg_front_r_3 to the end effectorin
T_3_ee.Compute the final transformation matrix following the described process from lecture in
T_0_ee. Remember that the end effector position is not in homogeneous coordinates. Calculateend_effector_positionfromT_0_ee.Note: The translation values may need to be adjusted based on the actual dimensions of your robot. Make sure to verify these values with your robot’s specifications.
DELIVERABLE:
1. Write out the full equation you used to calculate the forward kinematics (in math), please use Latex and take a screenshot, or use the equation functionality in google docs What is the benefit of using homogeneous transformations?
Why is there a 1 in the bottom-right corner of a homogeneous transformation matrix?
Part 5: Testing Your Implementation
Save your changes to
lab_2.py.Run the ROS2 nodes:
ros2 launch lab_2.launch.py
In another terminal, use the following command to run the main code:
python lab_2.pyMove the right front leg of your robot and observe the changes in the published positions.
To test your code in simulation to make sure that the code works as expected, you can use RVIZ. RVIZ 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 rviz, 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.
Part 6: Analyzing the Results
Record the end-effector positions for at the front right leg configurations.
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?)
If there are discrepancies, try to identify the source of the errors. It could be due to:
Incorrect transformation matrices
Inaccurate joint angle readings
Errors in the physical measurements of the robot
DELIVERABLE:
Measuring the correct physical parameters of the robot (leg lengths, motor angles, etc) is essential to compute accurate kinematics. This process is called system identification. How would your estimate of the end effector (EEF) position change if your estimate of leg link 2 is off my 0.2 cm? What about 0.4cm, or 0.8cm? Write out the number you computed, and how you calculated them, for both 0 degrees rotation in each of the joints, and 45 degrees rotation in each of the joints. Qualitatively, how does error in estimated EEF position change with respect to error in leg length?
How does computational complexity of FK scale with respect to degree of freedom (number of motor angles)? Please use big O notation.
Additional Challenges (Optional)
If you finish early or want to explore further:
Extend your implementation to calculate forward kinematics for all four legs of the Pupper robot.
Create a visualization of the leg’s end-effector position using RViz or another visualization tool.
Remember, understanding forward kinematics is crucial for robot control and motion planning. Take your time to ensure you understand each step of the process.