CanHaptics Lab 4: Controlled actuation using PID

Unma Desai
6 min readFeb 26, 2021

--

For this lab, we implemented a PID controller using our Haply device, and also had it trace a path.

I worked with Raquel R. and Sri G., and it was much better than working alone particularly for this lab — working collaboratively we realised that the PID configurations did not work the same for all of us; what worked for Raquel’s device did not work on mine as efficiently and vice versa. We spent quite some time figuring out the impact of P, I, and D on the Haply’s movements and finding stable configurations. We also brainstormed on different paths to trace and made a triangle path, an infinity sign path and a star path.

Preeti V. and Rubia G. provided some great resources for reference for PID control, all of which greatly helped my understanding; Preeti provided the link for this video about PID gain tuning, and Rubia shared this Reddit thread about PID controller theory as well as this StackExchange thread for PID tuning.

Run the code and try out the P controller. How does it feel? What happens when you change the target position? What does changing the P parameter do? Do you notice any problems?

The P (proportional) part controls how the controller reacts to the distance between the current point and the target setpoint. On testing it out with the Haply, extremely low P values performed well.

The Random Position button provides a target for the end-effector to reach, and based on the PID values, we can create a stable controller that reaches the target smoothly and accurately.

To start with the PID tuning, I initially only set a very low P value, of 0.01. The P value initiates the Haply to start moving towards the target. However, just the P value is not enough (we later add a D and I value), and increasing it beyond a point causes oscillations.

On trying high P values, beyond 0.1, the Haply end-effector would end up losing calibration, overshooting, and there would be oscillations at high frequency (seen in the video 0:14 onwards). A value of 0.04 seemed to get me the most balanced movement; almost at the target. It was not as smooth as required, but anything below that led to a higher steady-state error, and beyond it led to oscillations and overshooting. On changing the target position, the end-effector moves towards the target, at higher speeds and with more instability at higher P values, and slower and more accurately at lower P values.

P value of 0.04 and 0.1

Add the D component to your controller. Tip: You can use a high smoothing (close to 1) to better see the effect of the derivative filter when manually moving the handle, but this adds delay and should be reduced for improving the stability. How does this change the behaviour of the Haply? Are there any problems?

The D (differential) value helps in dampening the oscillations, so it was very useful in increasing the accuracy of the end-effector. I had already found the best P value for my setup at 0.04, so I started with D values of 0.1 and slowly increased them. At D values of >0.9, I observed the end-effector was most accurate and stable, often exactly landing over the target. D values beyond 1.2 for me caused oscillations and overshooting again, and 0.98 worked the best.

I did not take a video of just this stage, instead taking one at the next stage with all P, I, D values set.

Add the I component to your controller. How does this change the behaviour of the Haply? Can you create a stable system that reaches the target?

The I (integral) component was the most difficult to tune. The I component helps in reducing the steady-state error, when P and D have created an almost-stable system, i.e. there are no oscillations and steady-state error has been reduced to a major extent.

The I value should be minimal, so I started with 0.01, and anything beyond that caused massive vibrations and overshooting. I had to reset my Haply several times, using the Reset Device and Reset Integrator buttons. A couple of times I also had to turn the power off as the Haply would turn unresponsive.

However, a combination of P=0.04, I=0.01, and D=0.98 gave the best result of an almost stable system. The end effector moves quickly to the target’s surrounding area, after which it slowly arrives at the exact location, as the I and D components reduce the error and oscillations.

Haply with PID values set

Implement path tracking, specifically, replace the random position by a position following a track over time (e.g., a circle or square). What happens when you old the handle ? How is it affected by the PID parameters?

For path tracking, we decided to use the SimulationThread loop already in the program. Using the millis() function from Processing, we made a loop such that the target would switch between three points every second, forming a triangle. The triangle program worked best for me with P=0.06 and D=1.24, while for Raquel it worked best at P=0.03 and D=0.77.

Triangle path tracing

For my version, I also tried a star path, creating an array of 5 points and defining a direction such that it would make it look like the end-effector is tracing a star path. I also increased the interval to 2 seconds so the end-effector had sufficient time to reach the target.

Star path code

For this setup, I did not keep any I value, as the I component slows down the movement of the end-effector, and thus would require time to reach the target, which would not be possible within the span of 2 seconds it took for the target to move from one point to another.

Hence, I kept a P value of 0.04 and a D value of 0.98.

Star path with coordinates and order of traversal
Star path tracing

I also tried to create a more continuous set of points, which would result in smoother motion in each direction, but failed to get the direction of translation right, with a very bizarre set of target points :’) so I left it at that, but certainly something that can be done with a bit more brain-racking.

Attempt at continuous point tracing

On changing the P, I, D parameters, the behaviour is similar as before— there are oscillations, the steady-state error increases and the Haply ends up overshooting the target.

On trying to hold it while it is traversing the path, there is resistance, as the Haply tries to return to its original motion. The end-effector tries to break free, and on freeing it, shoots back to the path and continues the path traversal.

Holding the Haply while path tracing

Interfering with this fixed path also leads to a little error, and the Haply takes some time to reconfigure itself to its initial accuracy before the interruption. However, if I just lightly hold the end-effector and allow the Haply to continue its traversal along the path, the added support of my hand increases the stability and leads to smoother movement.

Play with the controller update rates, and with introducing delays. Hint: use the “looptime” parameter. How does this change the system? What happens if you sample faster or slower? What happens if it’s random (this would require some coding)?

Increasing the looptime parameter led to increased oscillations. The looptime of 500 worked best, anything more that that caused oscillations and overshooting.

Source code can be found here: https://github.com/unmadesai/CanHaptics

Through this lab I learnt how to tune a PID controller. It was interesting to learn about the impact of each of the PID components and configuring them to get the best combination for a stable system. It was also interesting to see how the same values gave different outputs on different systems, via collaborating with my peers. The path tracing part was particularly fun to program and test.

--

--

Unma Desai
Unma Desai

Written by Unma Desai

CS graduate student at the University of British Columbia, with a focus on Human-Computer Interaction

No responses yet