I began this project in May of 2020. Having spent a good deal of time reading about PID control, I was excited to try it for myself while I was in Covid lockdown. Since I had no prior controls experience, I wanted to write a simulation in Matlab before running my control algorithms on real hardware. I decided the best way to begin was to consider a system that could only move along one axis, so I set out modeling an arm that was hinged on one end and had a drone motor on the other end. The goal was to get the arm to self-level into a horizontal state.
I weighed all of the hardware that I intended to use in the real system and used these values in my simulation, modeling their respective contributions to the moment of inertia and total torque applied to the system. The next step was adding friction to the model, and finally controlling the thrust output of the simulated drone motor. I wrote a PID controller, tuned the gains on my simulated system, and eventually ended up with a result I was happy with. My modeled system behaved the way I expected it to, and I had successfully controlled the angle of the arm.
Plots showing simulated data from the PID model. The arm begins at -90 degrees and stabilizes at 0 degrees (horizontal).
At this point, I had to take a break on the project because my controls internship at Lockheed Martin Space was beginning. But I considered my efforts a success: one month prior I had no experience with Matlab or PID control, and through my work I had gained skills that proved incredibly valuable during my internship.
I picked this project back up in December of 2020 after I had completed my summer internship and fall semester at Tufts. I had just taken my first robotics course, and I was ready to dive into the hardware phase of the project.
I began by preparing and assembling the physical system. I soldered pins to my orientation sensor, drilled holes in the board, mounted the motor, hinge, and orientation sensor, and connected all the wiring.
Next, I began writing the control software. After successfully reading orientation data from the sensor and demonstrating control of the motor, I translated the control algorithm from my Matlab simulation into Arduino.
In my initial tests, the system was unstable and continually oscillated. After troubleshooting, I discovered two problems: I had underestimated the maximum thrust output of the motor, and there was a slight lag in the system that caused the motor to take too much time to react to the orientation data. I found that decreasing the PID gains solved the thrust problem, and swapping out the motor for one with less internal friction while further decreasing the derivative gain solved the lag problem. After a lot of work, I had built my first control system! See the code on GitHub here.
Plot showing data from an early test where the arm oscillated out of control
The final product: a hinged arm using PID control to self-level.