We want to build upon last time's lab, but this time instead of finding out what is the final position as a function of motor values, this time we will be making (or trying at least) a function that takes as input the position and outputs the motor values. We will also play with this function to make the pupper's leg to move in a triangular shape
cd ~/lab_3_fall_2025 code .
lab_3.py to understand the structure of the InverseKinematics class and its methods.
tar -xvf pupper_viz.tar.gz cd pupper_viz/ docker build -t pupper_viz .
Once done, you may paste your lab 3 solution into the lab_3.py and then
./run.sh 3
inverse_kinematics method in the InverseKinematics class.TODO 1: Implement the cost_function(theta) for inverse kinematics. This function returns cost, a scalar, and l1, a vector of size 3. Use the forward_kinematics method to get the current end-effector position. Calculate the L1 distance between the current and target end-effector positions. Return the sum of squared L1 distances as the cost (AKA the squared L2 norm of the error vector). TODO 2: Implement the gradient(theta, epsilon) function to calculate the numerical gradient for inverse kinematics. TODO 3: Implement the gradient descent algorithm for inverse kinematics.
TODO 4: Implement the interpolation for the triangular trajectory. You need to create a function that performs linear interpolation between the triangle’s vertices. The trajectory should loop smoothly from vertex 1 to 2, vertex 2 to 3, and then from vertex 3 back to vertex 1 based on the time variable. The input to the function is a time variable t that dictates where along the triangle’s edges the point currently lies for a given 3-second period. Each vertex transition (e.g., from vertex 1 to vertex 2) should last approximately 1 second. For example, 0 ⇐ t < 1 should interpolate between vertex 1 and vertex 2.
ros2 launch lab_3.launch.py
python3 lab_3.py