Control 2 outputs with a single input and pid

control systempid controller

Overview

I'm trying to levitate a constrained permanent magnet with 2 electromagnets. I'm having trouble conceptualizing the control system for such an operation.

Setup

The permanent magnet is fixed onto a horizontal arm and is repelled by an electromagnet above and repelled by an electromagnet below. The pendulum is attached to a rotary encoder that provides the absolute angle of the pendulum with respect to the horizontal.

simplified graphic of my setup

Goal

Given a desired angle (relative to the horizontal), I need to change change the voltage going to each electromagnet. For example, if I want the pendulum to be at +X degrees, the control system would increase voltage to the electromagnet below the pendulum and decrease voltage to the electromagnet above the pendulum, resulting in a net upwards force.

setup with desired performance

Problem

I was advised to use a PID controller. I'd heard of, but never used, a PID controller, so I researched them a bit online, and I understand the general idea–it's just like somebody adjusting water temperature before showering. However, my intuition tells me that I cannot use a single PID loop to control the two electromagnets because I'd be using a single input to solve two outputs. It'd be like saying $$f(x) = y_{1}$$ and $$f(x) = y_{2}$$ where f is a linear function. Since that's not possible for a linear function–and PIDs are linear control systems–then I cannot control 2 motors with a single PID controller.

Am I right? If so, could you point me towards how people have solved similar problems? I feel like this is a common problem with control systems.

If I'm wrong, could you provide an example?

Many thanks!

Best Answer

Your magnet approach is the only one that is likely to work, but there are a number of gotchas. Be aware that stabilizing an attractive magnetic setup (rather than a repulsive one) is not for the faint of heart, and especially not for beginners. The problem is that the attractive force can get very high very quickly if the two magnets get close together, so the magnets tend to "snap" together faster than your system can respond.

First, there is no need to make the magnet currents independent. I'd advise making the two linearly dependent. If the lower coil current varies from 0 to 1 amp, make the top coil vary from 1 to 0 amp, with the sum constant. This is hardly optimal in terms of performance, since the two repulsive forces will not be linearly related with respect to displacement from the center position, but it will be far easier to control and stabilize. Think ahead - upgrading to independent loops will be a no-brainer for further credit.

Second, your encoder scheme, while OK in principle, is unlikely to work well. The problem is that, unless you have access to a really high-resolution encoder your angle measurements will be too coarse to give the sort of accurate position information you need. Not only that, but measuring angular velocity (the D in PID) will be very coarse in granularity, and for low rates will have a very slow update rate. Get hold of your encoder specs and pendulum arm length, and calculate just what your vertical quantization is. You cannot do better than this.

Third, you'll be able to do a simple open-loop calibration of your system simply by putting differing currents into your coils and seeing where the moveable magnet gets to, although you'll have to be careful about damping out residual motion. This is probably a better bet than trying to calculate position from first principles. See https://en.wikipedia.org/wiki/Force_between_magnets for a discussion of inter-magnet forces. Be aware that these results are very sensitive to small changes in geometry, including the size of your magnet cores.