Lab 4: Controlled actuation using PID

Goal: Achieve controlled actuation using Haply

Kattie
5 min readFeb 26, 2021

Controlled actuation could be very useful in many different cases. For example, controlling a robotic arm to have a precise movement; Controlling HVAC systems for heating and cooling of a building; and industrial cases where a valve needs to precisely controlled. In this lab, I will tune the Haply to achieve controlled actuation and experiment with different PID parameters.

1.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 controller determines the amount of proportional response or “stiffness”. This term is proportional to the difference between the set point and the process variable. While experimenting with the P controller, I realized that increasing this variable increases the speed and also the force of the end effector. At a low P, there is a lot of distance between the set point and the end effector, but a higher P will decrease this distance. At a certain point, if P is too large it will cause vibrations, matching with the PID theory. I experimented with both using my hand and also not using my hand to hold the end effector. In general, when using my hand, the device behaved better because I guess it causes a damping of the vibration. Obviously, a higher P was needed to actually “move” my hand with the end effector to the tracker. For the majority of the lab, if I was not using my hand, the P-value was set to 0.01 and if I was using my hand it was set to 0.08.

Also throughout the whole experiment, I lowered the range of random positions for the set point to -0.3–0.3 because I realized -0.5–0.5 range results in too big of movements and sometimes pushes the end effector outside of the available plate size.

To implement this, I just added more points to the RandomPosition (Not the cleanest way) function with delays for each point as shown in the code below for the first few points:

xr = 0.3;
yr = 0.1;

delay (1000);
xr = xr — 0.1;
yr = yr — 0.1;

delay (1000);
xr = xr — 0.1;
yr = yr — 0.1;

delay (1000);
xr = xr — 0.1;
yr = yr — 0.1;

……..

2. 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 component is the derivative response or the “damping”. This is proportional to the rate of change of the derivative variable and can generally be used to lower the oscillations in P. I felt that increasing the D gets the end effector closer to the set point. However, increasing it too much will cause very low frequency vibrations. Adding the filter that is closer to 1 removes these vibrations and gives the best response (high value results in delayed response). I generally observed that between 0.9–1.36 the response is more accurate with very low oscillations.

3. 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?

This is the variable that I had the most trouble with but also the most interesting. The I component is the Integral response and the effect is that this variable will continuously increase unless the steady-state error reaches zero. In the case of the Haply and only using low PI values, I could feel a level of instability already. As the I vale increased, the oscillations got larger and larger. However at a certain point, around 0.01, it would cause the end effector to slowly move towards the set point. If I tried to move the end effector away from the set point, I would feel a proportional push on my hand as I applied more force and the length of the arrow would increase.

4. 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?

Since I had a hard time tuning the PID loop and getting a stable response, it was also hard to achieve a path. I realized that oddly enough, each time the program is run, the loop needs to be tuned again since the previously recorded values for a “stable” system would cause a different response. The most common difficulty was the arm moving too fast or oscillating and the Haply losing track of its position. To fix this issue, I experimented with changing fEE.x and fEE.y but it would either cause the arm to not move at all or make a fast movement. Eventually, I managed to get a stable enough response to create a triangle path.

In hindsight, decreasing the distances between the points even further may have resulted in better and more stable tracking. I also found that sometimes stopping the vibrations with my hand can achieve a stable system and proceed to the next set point. Sometimes the system would start very stable but start oscillating as more points were hit.

5. 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)?

The loop time variable controls the rate of sampling. I am not quite sure what is meant by “random sampling” for the looptime parameter. But I played around with changing this variable and anything above the 500–1000 range would cause more oscillations and overshooting the end effector. Increasing the loop time too high also caused the program to crash on my computer.

Overall, this lab was fun but almost scary at times as I felt that I am breaking the Haply with those very strong and fast movements. Motors being stuck in a certain position and causing a force towards the right direction (for some reason?) was a common difficulty. Also, I found it unintuitive that each time the program starts from the initial state, I need to move the Haply with my hand before the arm can move on its own.

Code on Github

--

--