CanHaptics Lab 4: Controlled actuation using PID


The task for this lab was to understand the PID controller, experiment with stable P, I, D parameters for Haply, and experience and resolve instability issues in Haply control.

The Start

Well, the start was not really good for me as when I first ran the sample code. I had no idea what to expect and what consists of a “right” experience. I was also getting this error and caution message (which I ended up ignoring).

After receiving no force feedback on Haply even after changing all P, I, D values by a high margin, I consulted other classmates. I checked if I installed the correct library and got my PC up to speed; didn’t work. Later, I played around with gain values in file and things started to work. After talking with Antoine, I realized I was using an outdated version of the firmware.

Playing with Control Parameters

I referenced Kevin Lynch’s video to enhance my understanding of empirical PID control. My idea was to start with increasing proportional gain, then increasing derivative gain, and finally integral gain. Here in this video, while trying several proportion gain values, I am manually pushing the end effector to an unstable position and seeing how easily it stabilizes. As you can see, it didn’t stabilize and mostly ended up oscillating.

In the next round, I increased derivative gain values. As you can see in the next video, the overshooting vibrations have been reduced.

I slightly updated the GUI to check real-time parameter values tweaked through keyboard controls. Here are the demo videos, as I play around with different values of P and D.

A low P value doesn’t help the end effector to reach the target position whereas a very high value leads to overshoots and oscillations. Derivative Gain adds some sort of dampening in the system and hence helps reduce overshoots and oscillations. A low value of D didn’t provide much dampening, whereas a high value makes rugged movements. I needed to get a value in between. After playing around with different values, P = 0.04 and D between 1.60 to 1.80 worked well and led to stable position control. Here is a video of the tuned PID controller:

I tweaked Integral Gain values as well, but that didn’t affect the stability. It always led to an unstable overshoot, so I considered keeping I = 0. I understood from Kevin’s video Integral Gain is used for reducing the steady-state error. As I didn’t see a prevalent steady-state error (visually) while doing trial runs, I preferred to keep I = 0.

Changing Looptime and Smoothing Factor

Sampling signals at the right rate is very important. The looptime was set as 500 micro sec by default. It seemed pretty optimal to me. Reducing this value means we are doing oversampling and increasing it means we are doing undersampling; either side is dangerous. I tried several values of looptime. As I moved to either extreme, there were instabilities.

A similar trend applied while changing smoothing parameter, on either side of the default value (0.8), I observed instabilities. The lower value means frequent updates and a high value means delayed updates and slow movement of the end effector.

Path Tracking

For path tracking, I chose a simple geometric shape — Circle! It is easy to implement and I can play around with parameters of radius and sampling angle (theta diff). In polar coordinates:

x = r *cos(theta);
y = r*sin(theta);

where r is radius and theta is the angle from x-axis.

While trying out different radii for circles, I realized P value can be increased as there are fewer chances of overshooting. I observed that overshooting occurs frequently when the distance between two points is large. As I am keeping the distance between two points short (to allow for a smoother motion), I can increase the P value a bit. Additionally, I realized D value can be decreased to allow for a smoother motion. I played with different values of P, D, and radius here in this video. Note that theta diff value can also be changed. Smaller theta diff leads to smoother motion.

When I hold the end effector gently when it is tracing the line, it provides a dragging force. On the system side, holding the end effector allows for external dampening. As discussed, we can further tweak the P and D values as per the use. When there is external dampening due to the hand, we might not need high D values.

What didn’t go quite right?

As discussed in the beginning, getting started on this lab was hard. Here is the video of me increasing the PID values to the maximum and not getting any response:

Another struggle was dealing with locked motors after an unstable drift. Calibration was often off and it was hard to reset. I ended up turning off the motor using coding a button in GUI.

It took me a while to understand that I have to nudge the end effector a bit to get started. Initially, I was just increasing the parameter values and wondering why nothing is happening?

Overall, this lab was fun. It was hard in the sense that I didn’t know what’s the correct thing to do, and how should it feel like? Talking to other peers and instructors helped.

Here is the code if you would like to play around with some parameters and learn to draw some Circles. Enjoy!!!



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store