UR5e Kinematics Simulation

Introduction

In my previous project, I built a 5-DOF robot arm and implemented the kinematics using the D-H method and an analytical solver.
Have you ever felt the pain of crashing a servo? I have, but now I can crash much more expensive parts in a risk-free environment.
During my wild Googling, I came across a different method that involves screw theory, but it looked incredibly complex and I knew I would make many mistakes. I also came to realize that debugging math on a physical robot is incredibly inefficient (and potentially expensive).
 
In order to isolate the high level controls from the numerous sources of error on a physical robot, I set up a simulation in Webots with an industrial robot arm. With a "perfect" physics setup where errors such as gear backlash is not an issue, I can narrow down the scope of troubleshooting to the math and the code. Once I eventually port this method back to my physical robot arm, I'll be certain that any jitter is a hardware flaw, not a miscalculation.

Kinematics - Screw Theory

While there are definitely kinematics libraries out there, I wanted to build the kinematics solver from the ground up to understand exactly how the Jacobian and the concept of "twist" work.
 
To solve the forward and inverse kinematics, I followed the theory detailed in Lynch and Park's Modern Robotics book, which revolves around screw theory. Screw theory is based on the Mozzi-Chasles Theorem, which states that any rigid body motion in 3D can be represented by a screw motion (a rotation and translation along a screw axis).
Advantages
  • More robust to singularities with the Jacobian-based approach.
  • Easier to set up since screw axes are much more intuitive to assign than D-H frames. No more axis alignment headaches.
 
If you're interested in the math, check out my high-level overview of how it's done.
 
Newton-Raphson Solver
While this method lacks an analytical solution for the inverse kinematics, the Newton-Raphson iterative method allows the solver to be robot-agnostic. If I were to add or remove a degree of freedom, I wouldn't have to manually re-solve the forward and inverse kinematics.
 
The idea behind the Newton-Raphson algorithm is simple. You feed it an initial guess to what all the joint angles should be, then it computes the forward kinematics to get the end-effector pose at that initial guess. If the error between the new end-effector pose and the target is not within some threshold, it moves on to the next guess and this process repeats until the end-effector is "close enough" to the target.
 
Below is a diagram of the Newton-Raphson algorithm where the initial guess is (x0, f(x0)).

Position Control

I initially tried controlling the arm using position control where I solve the inverse kinematics for the target joint positions.

PID Control

Adding PID control allows the arm to move a little more smoothly to the final positions.
To better tune and debug the PID control, I implemented a visualizer for the twist error. Notice how the errors spike up when the robot starts moving, then reduce down to 0 as the robot approaches its target.

Velocity Control

The problem with the previous position control method is this method is that each joint moves a different amount, so they will all arrive at their targets at different times and the arm will end up swinging in an unpredictable arc rather than moving along a smooth path. One solution would be to set intermediate waypoints that lie along a straight path. Another way to do it would be to control joint velocities instead of position. Velocity control solves this problem with a special matrix called the Jacobian. The Jacobian is a matrix that relates the end-effector's velocity to all the joint velocities. In particular, it helps us answer the question of "what joint velocities will result in the desired end-effector velocity?".
 
I explored this next by computing the Jacobian matrix at every simulation step and implementing a trapezoidal velocity profile. The motions look so smooth!

Closing Thoughts

The trapezoidal velocity profile resulted in a much smoother motion than the position control + PID control. Maybe it's just a matter of tuning the PID parameters, or maybe I need to combine PID + velocity control. But would the PID control fight with the trapezoidal velocity profile? These are things I'd like to explore in the future.

You can see the code for this project on Github: https://github.com/ianhong95/ur5e_webots

A deep dive into the math behind the kinematics can also be found in that repository.