I'm only going to focus on simple software executions for now, as the complete software and the hardware is not trivial.
A state feedback example is fairly easy to describe. Let's assume you have a plant with two states, e.g., a permanent magnet dc motor (position and velocity are usually chosen), that you'll control by linearly manipulating the applied terminal voltage vt. Assume both states are measured, have voltage values that can be read in to a computer via an ADC, and are stored in variables Position and Velocity. Assume also that you've developed a plant model and a state feedback law u = -Kx, e.g., using pole placement or LQR methods. Using the typical control law for state feedback, you'll simply calculate the variable Voltage, e.g., Voltage = -[K(1)*Position+K(2)*Velocity] and write it to the output port that you are controlling to adjust the terminal voltage. Your sample rate should be around ten times faster than the fastest pole in the closed loop system you are concerned about.
An observer-based controller implementation isn't that much harder if you understand controls pretty well. Now, assume that only the velocity of your motor is available for measurement (e.g., via a tachometer connected to the motor shaft), but the velocity signal is very noisy due to unmodeled dynamics. An observer-based controller can help if the plant is observable. The observer will not only provide you an estimate of the position, but can clean up the noisy velocity signal and provide you with a smooth estimate of the velocity. A controller based on a full-state observer contains both the control law u=-Kx and the estimator, possibly designed via LQR and LQG/LTR methods taking advantage of the separation principle that says you can place the poles of the system and the observer using separate calculations. Note that the observer-based controller receives its input from the output of the plant (Velocity, in this case) and gives Voltage as its output. Once you've designed the controller, find the open-loop transfer function of the controller from Velocity to Voltage. Discretize this transfer function using your sample rate. Write both the numerator and denominator of the discretized controller transfer function in terms of z
-x, where x is an integer valued exponent of z.
As an example, I'll assume that your observer is second-order (since your plant is also), so if your controller transfer function denominator was z
2+0.5z+0.01 and your numerator was z
2+0.4z+0.03 (both completely made up), divide both by z
2 to obtain 1z
0+0.5z
-1+0.01z
-2 and 1z
0+0.4z
-1+0.03z
-2, respectively. Note that I've kept the 1z
0 terms even though I could have written them as 1; this lets me know these are the present term coefficients.
Recalling that the transfer function is the ratio of the output of the controller Voltage to the input of the controller Velocity in the discrete frequency domain, cross multiplying (using *, but meaning multiplication, not meaning conjugation) gives you: (1z
0+0.5z
-1+0.01z
-2)*Voltage = (1z
0+0.4z
-1+0.03z
-2)*Velocity.
Since a z
-x term means that signal is delayed by x samples, you'll need to have memory locations for the present value of Voltage and the two previous values of Voltage, as well as the present value of Velocity and the two previous values of Velocity as a function of sampling.
To implement the controller algorithm I've made up, create a loop in the code that executes at your desired sample rate with the following instructions. Here's some pseudocode:
Code:
While Stop <> 1
Read the present value of Velocity(n) on the appropriate input port
Solve for the present Voltage term:
Voltage(n) = Velocity(n)+0.4*Velocity(n-1)+0.03*Velocity(n-2)-0.5*Voltage(n-1)-0.01*Voltage(n-2)
where n is the current time step, n-1 is the previous time step, etc.
Write the Voltage(n) term out to the output port.
Shift the values stored in your memory locations:
Voltage(n-2) = Voltage(n-1)
Voltage(n-1) = Voltage(n)
Velocity(n-2) = Velocity(n-1)
Velocity(n-1) = Velocity(n)
Return
Does that help?
xnuke
"Live and act within the limit of your knowledge and keep expanding it to the limit of your life." Ayn Rand,
Atlas Shrugged.
Please see FAQ731-376 for tips on how to make the best use of Eng-Tips.