# How can I control two outputs with a single PID-controller?

• azeriAggie
In summary, the conversation discusses the setup and goal of levitating a constrained permanent magnet with 2 electromagnets, along with the problem of conceptualizing the control system for this operation. The goal is to change the voltage of each electromagnet to achieve a desired angle, and the use of a PID controller is suggested. However, there is uncertainty about using a single PID loop for two outputs and the conversation seeks advice on how to solve similar problems. The system uses an absolute rotary encoder and LabVIEW-controlled power supply for data acquisition and setting electromagnet voltages.
azeriAggie
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 pendulum 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.

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 +25 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.

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) = y1 and f(x) = y2 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!

Could you sketch the system, for example labelling the magnets M1, M2, M3 or whatever? It will then be much easier to comment the system, referring to these labels/names.

Are you using digital control ( encoder ) or analog control?

azeriAggie said:
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 pendulum 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.

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 +25 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.

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) = y1 and f(x) = y2 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!
You should still follow Hesch's advice, but I am going to try and point some things out

Your feedback mechanism is the measured angle. You want to match that to the desired angle.

The difference of those two signals will give you your error. It is this error that you then use the controller on. This is to determine how much actuation is needed to bring the error to zero. After that you address the actuation of your system, in this case increasing and decreasing the voltage to electromagnets, assuming they are the same and linear. If not, after your first pid controller, you will need to map out what voltage vs force will be for the various angles you can have.
does that make sense?

azeriAggie said:
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.

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.

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) = y1 and f(x) = y2 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!

@Hesch : I'm not sure what you mean by digital/analog. I'm using an absolute rotary encoder that outputs an analog voltage if that's what you're asking. I acquire it's data using a DAQ and set the electromagnet voltages via a LabVIEW-controlled power supply.

@donpacino : What do you mean by "assuming they are the same and linear"--are you referring to the voltage of the electromagnets? If so, they will not be the same because em2 will have to be stronger than em1 to also overcome gravity. So I'm going to have to figure out the gains completely by trial and error?

I don't understand why you not just connect em1 and em2 in series in such a way that the polarity as of m1 is switched, so that the em's are helping each other instead of working against each other. The direction of the force can be controlled by changing the direction of the current, and you will need only one PID since there is only one output.
azeriAggie said:
I'm not sure what you mean by digital/analog.
Digital control is when using a (digital) computer to compute the control loop. The computer samles signal values at a sample frequency of say 200Hz,
( sample period = 5ms ), and calculates the output within say 0.5ms. In the remaining 4.5ms the computer will do other jobs ( e.g. controlling another plant ).

Contrary an analog controller will do "analog calculations" by means of amplifiers, resistors and capacitors.

Be aware of the number of poles in the control loop: By mental arithmetic I can count 4 poles:

* pid
* self-induction in the em's
* force/acceleration → velocity
* velocity → position

So I think you'll need something like a PI2D3 controller to make the loop stable, and without too much noise. That will be hard.
I'd recommend making an inner loop in the controller, that will control the current in the em's. You then build this current loop into a bigger loop.
In this way you solve one problem at a time ( here the time-constant in the em's ). You will get a much more rigid and robust system in this way.
donpacino said:
electromagnets, assuming they are the same and linear. If not, after your first pid controller, you will need to map out what voltage vs force will be for the various angles you can have.
Yes, you may have ( will have ) problems with linearity, and if you had used a digital controller, it would be very easy to create a map/look-up-table for linearization.

Should you one day have the opportunity to study digital controllers, I'd recommend that. You'll see what they can do.

Last edited:
Hesch said:
I don't understand why you not just connect em1 and em2 in series in such a way that the polarity as of m1 is switched, so that the em's are helping each other instead of working against each other. The direction of the force can be controlled by changing the direction of the current, and you will need only one PID since there is only one output.

My current repulsion/repulsion setup barely works because the permanent magnet snaps up to the electromagnet's magnetic housing (as in the outer housing of the electromagnet is magnetic). Thus, when I have an attraction/repulsion setup with my electromagnets, my permanent magnet would tend to snap even more! However, I guess a PID controller that is sufficiently-tuned can handle this.

Re: Analog vs. Digital: I'm using a PID vi in LabVIEW, so I'm using a digital controller. Correct?

Hesch said:
So I think you'll need something like a PI2D3

Given 4 poles, how did you get PI2D3?

Also, in another thread, you tried helping someone with calculating the strength of an electromagnet. Is there a model, like Newton's theory of universal gravity or Coulomb's law for electrostatic forces, that would enable me to calculate the strength of a particle's magnetic field at a distance?
If I knew the magnetic field or force strength at a distance, then I could work backwards to find the voltage necessary to create that field and program my control loop that way.

azeriAggie said:
Given 4 poles, how did you get PI2D3
Well, I'm an old ( and experienced ) man, so I guessed.

I just mentally "see" this root-locus as for the system, all these curves spreading out in all directions: If a PID is requested, you have these 4 poles. You can control the 4 curves coming from the poles by 2 - 3 zeroes, but these zeroes will create a lot of noise, so it's better to reserve en extra pole to dampen this noise and then keep to 3 zeroes.

Thus PI2D3.

Making a printet circuit board ( PCB ), it's better to have too many knobs to adjust than too few ( you can always short-circuit a PI-function if it's not needed ).

Root locus ( 11 poles ):

Last edited:
azeriAggie said:
calculate the strength of a particle's magnetic field at a distance?
I don't know anything about particles voltage creating a magnetic field strength?

I've heard people speaking of such particles, but have anybody found one? I regard a magnetic field to be a circulation field, and thus is not emitted by some particle, having some "starting point". But "show" me one of these particles. ( I'm saying: The Earth is flat as a pancake ).

As for the control loop: Stick to root locus. That's a very heavy tool, and it works.

azeriAggie said:
attraction/repulsion setup with my electromagnets, my permanent magnet would tend to snap even more! However, I guess a PID controller that is sufficiently-tuned can handle this.
Exactly: Show them what you can do. That's the spirit. ( Maybe you can make some mechanical stop that prevents the magnets to snap ( some non-magnetic material glued to the poles of the em's ). A hit will give you a fine = -1 point ).

## 1. How does a PID-controller work?

A PID-controller works by taking in an error signal, which is the difference between the desired output and the actual output. It then calculates and adjusts three components - the proportional, integral, and derivative - to minimize this error and reach the desired output.

## 2. Can a single PID-controller control two outputs?

Yes, a single PID-controller can control two outputs by using a multi-input, multi-output (MIMO) control strategy. This involves incorporating the error signals from both outputs into the controller's calculations and adjusting the control inputs accordingly.

## 3. What are the advantages of using a single PID-controller for two outputs?

Using a single PID-controller for multiple outputs can reduce the complexity and cost of a control system. It also allows for better coordination and synchronization between the two outputs, as the controller can take into account the relationship between them.

## 4. What are the limitations of using a single PID-controller for two outputs?

One limitation is that the controller may not be able to optimize each output individually, as it is taking into account both outputs simultaneously. Additionally, if the two outputs have very different dynamics or require vastly different control inputs, a single PID-controller may not be the most effective solution.

## 5. How can I tune a PID-controller for two outputs?

The tuning process for a multi-output PID-controller is similar to that of a single-output controller, but with the added complexity of considering the relationship between the two outputs. It may require more advanced tuning methods and experimentation to find the optimal settings for both outputs.

Replies
6
Views
4K
Replies
2
Views
5K
Replies
4
Views
4K
Replies
12
Views
2K
Replies
4
Views
3K
Replies
3
Views
2K
Replies
10
Views
3K
Replies
3
Views
2K
Replies
17
Views
2K
Replies
12
Views
1K