Back in the day, I did a degree in kinesiology and learned about something called proprioception. Proprioception is how you know where your body is in space. Try this — close your eyes and touch your nose with your right pinky finger. Easy peasy. Why is that? How does your finger know where your nose is? The answer is proprioception.
Long story short, we have little stretch sensors in our muscles called muscle spindles and Golgi tendon organs. They're embedded in muscle fibres and tendons and send signals to the brain as they're stretched and compressed. Our brain interprets these signals to understand where the muscles are located compared to the rest of the body.
So when you go to touch your nose, your brain a) outputs signals telling certain muscles to contract, and b) receives feedback from stretch sensors about your body location. This tells your brain where your pinky is versus where you want it to go. Controlling a motor works basically the same way.
A little to the left.
In the RendAR system, a motor rotates the turntable using closed-loop feedback to capture product photos at specific angles. This is important because it ensures consistency across a retailer's online catalogue. It doesn't look good to a customer if you have a page of products facing different directions.
For RendAR, a microcontroller is the brain, a motor is the muscle, and a motor encoder is the muscle spindle. Closed-loop feedback is to machines what proprioception is to humans.
To start, let me tell you what we're working with. The motor I'm using to rotate the turntable is a 12V, 16.7 RPM DC motor with a rotary encoder. The main factors that went into choosing the motor were RPM and power.
The turntable needs to rotate pretty slowly in the range of 5-10RPM. For reference, a microwave rotates at about 6RPM. I control the speed of the motor using pulse-width modulation, but it's better if the motor is low-RPM to begin with.
I also need a 12V motor that draws less than 2.25A to fit within my power budget (power = voltage x current). Finally, I wanted the motor to have a built-in encoder, which is a sensor that measures how far the shaft rotates.
Controls Appreciation Paragraph
Automatic control systems has to be one of coolest things I've learned in engineering school. It's also the subject I knew nothing about beforehand. Now I think controls is kind of like peak-engineering. It combines physics, mathematical modelling, mechanical engineering, electrical engineering, simulation, and software.
In a nutshell, controls is how you make a dynamic (moving) system do what you want it to. Control systems engineering is how NASA can land Perseverance on Mars, SpaceX can launch and land rockets, and Boston Dynamics can make robots dance.
And now, controls is how I accomplish the infinitely less complex but deeply satisfying feat of making a motor rotate exactly 90 degrees.
There are two types of control systems — open-loop and closed-loop. In open-loop, you send a signal to an actuator, cross your fingers, and hope for the best. In closed-loop, you measure the output of the system and compare it to what you wanted to happen. If there's a difference between your input and your output, you try to correct it. This difference is called error.
RendAR uses a closed-loop negative feedback system with a PID controller. Negative feedback means the controller aims to reduce error, as opposed to positive feedback, which increases it. The PID controller is a mechanism that calculates how to reduce the error. It says, "Given this error...*does math*...send this voltage to the motor."
Here's a block diagram of my closed-loop negative feedback system:
Now for a side-by-side demo! Here's a comparison of the motor rotating with open-loop and closed-loop feedback. In the open-loop system, you can see that error accumulates with every rotation. In the closed-loop system, the motor rotates 90 degrees each time.
This is what happens for each rotation of the closed-loop system:
The PID controller determines how steps 4-6 pan out. The parameters Kp, Ki, and Kd shown in the diagram above can be varied to adjust how quickly the motor reaches its reference angle, how much the motor oscillates before settling, and how much error remains when the motor reaches steady state and stops moving.
I tuned the values of Kp, Ki, and Kd through trial-and-error to find ones that produced smooth rotation without any overshoot and oscillation. Simple but satisfying!
Up next: Connecting the capture rig and iPhone via Bluetooth