Skip to Main Content Skip to Search
Product Documentation

Designing and Improving Controllers

Creating Improved Controllers for the Stewart Platform

This second control design case study begins by showing you how to create and optimize a new PID controller. It starts with the creation of a new PID controller ab initio, locates a steady state and linearizes the platform's motion about this equilibrium, and adjusts the linearized platform dynamics to optimize the new PID controller. The study ends by introducing multivariable synthesis as a step beyond PID control, implementing a more complex and realistic multivariable controller and comparing its performance with the new PID controller.

Designing a New PID Controller

The PID controller gains set by the initialization script are preoptimized. The preceding case study, Analyzing Controllers, uses these gain values as examples.

In the rest of this study, you follow a more realistic scenario where the gains are not initially known and you use control design tools in the MATLAB environment to create and optimize a filtered PID controller.

Making a First Guess for the Controller Gain

Make an initial guess for the integrator (I) gain Ki with dimensional analysis. Ki has dimensions force/length/time.

Thus an initial guess for the integrator gain is

Ki = 0.5*9.8*(top_mass/6+(upper_leg_mass+lower_leg_mass))/0.3

Ki = 7.1680e+003

Making a First Guess for the Controller Force

The initialization script sets the workspace variable initCondI to the value needed to put the platform in a symmetric equilibrium in the initial state. With a new Ki value, you need to recalibrate this initial condition.

initCondI = ...
   (upper_leg_mass+lower_leg_mass+(top_mass*1.3/6))*9.81/Ki
 
initCondI = 0.6839

Modifying the Null Controller with a Constant Force

Start by turning off the PID controller and applying a constant force to the platform.

  1. Right-click the controller subsystem. Select Block Choice > Null Controller.

  2. Right-click Null Controller again. Select Link Options > Go To Library Block.

    The configurable subsystem library mech_stewart_controller opens.

  3. Under Edit, select Unlock Library. Open the Null Controller template subsystem.

  4. In the subsystem, between the Gain and Force (Output) blocks, insert an Integrator block.

  5. Open the Integrator dialog. For Initial condition, enter Ki*initCondI. Click OK.

  6. Close Null Controller. Save and close the mech_stewart_controller library.

  7. Back in mech_stewart_control, update the diagram (Ctrl+D).

  8. At the command line, enter Ki*initCondI.

    This is your first guess for the controller force in one leg: the product of your PID integrator (I) gain guess and your controller initial state guess.

Simulating the Platform with the Constant Force

Now observe the effect of this constant force on the platform.

  1. In the Leg Reference Trajectory subsystem, set the Trajectory Switch position to down.

  2. Open the Scope and start the simulation. The control force is less than the platform weight. The platform accelerates downward.

Trimming and Linearizing the Platform Motion

A critical step in control design is to understand the response of a plant being controlled to small disturbances in its motion [5]. This step requires

For More About Trimming

As described in Trimming and Linearizing Through Inverse Dynamics, you can trim SimMechanics models in many ways. Control System Toolbox and Simulink Control Design provide linear analysis tools richer and more powerful than what Simulink and SimMechanics software alone offer.

Setting Up the Model for Trimming

Now set up the model for trimming. In Trimming mode, the model's mechanical states are the 40 constraints that reduce the 52 free (forward dynamics) states to the 12 independent states.

  1. Make sure the model observes these settings.

    1. Keep the controller subsystem Block Choice set to Null Controller and the derivative type to Filtered Derivative.

    2. Keep the Trajectory Switch down (static trajectory) in the Leg Reference Trajectory subsystem.

  2. Reset the SimMechanics analysis mode to trimming.

    1. Open the Plant subsystem. Double-click the orange Machine Environment block. Locate the Parameters tab.

    2. For Analysis mode, change the pull-down menu to Trimming. Click OK and close the subsystem.

  3. Observe the trimming output blocks that have appeared in the upper left of the main model.

Locating an Operating Point by Trimming

Next, locate an operating point for the Stewart platform plant.

  1. Select linearization points in your model as follows. Right-click, in turn, on each of the Simulink signal lines defining the input and output of the Plant subsystem:

    • Leg Forces (input)

    • Pos (output)

    On each signal line's right-click menu, under Linearization Points, select

    • Both Input Point and Open Loop for the input line

    • Both Output Point and Open Loop for the output line

    Choosing the open-loop property for these signals breaks the feedback loop from controller to plant back to controller. The plant instead takes a given set of externally imposed controller forces.

  2. Then, from the model menu bar, select Tools > Control Design > Linear Analysis. The Control and Estimation Tools Manager window opens.

  3. To the left of the Manager window, select the Operating Points node. Then, to the right, select the Compute Operating Points tab. Click the Sync with Model button at the bottom of the tab.

    The default subtab is States. The Steady State check boxes are selected by default. This choice searches for a plant operating point where the platform is at rest relative to its initial configuration.

  4. Examine the states by scrolling down in the States window.

    • There are six states associated with the null controller Integrator block.

      Clear the Steady State check boxes for these states. The trimming will not hold the controller signal as fixed.

    • Below these six are twelve states associated with the Transfer Fcn blocks in the Filtered Derivative subsystem.

      Free them from being fixed by clearing their Steady State check boxes. Make their values (0) known by selecting their Known check boxes.

    The rest of the states are associated with the positions and velocities of the Stewart platform leg joints. Only six of these states are independent. The others are constrained. Leave their settings as the defaults.

  5. Move to the Outputs subtab. Under Output Specifications, select the Known check box (the topmost check box in that column). This action specifies all outputs, the state deviations from the desired operating point. There are 40 states (constraints) in Trimming mode.

    The output values are specified in the Value column. The values are all zero, indicating that all constraints on states (the specifications of the operating point) must be satisfied within tolerance.

  6. From the Manager window menu bar, select Tools > Options. The Options window opens. Select the Operating Point Search tab.

    In the Optimization Method area, select Nonlinear least squares in the Optimization Method menu.

    Leave the other defaults. Click OK. The Options window closes.

  7. Back in the Control and Estimation Tools Manager, click the Compute Operating Points button at the bottom of the Compute Operating Points tab.

    The Computation Results subtab indicates the progress of the trimming. When finished, it should indicate that the operating point specifications were successfully met.

    In the Operating Points node to the left, a new Operating Point subnode appears, Operating Point, containing the results of this trimming.

Interpreting and Saving the Operating Point

Examine and save the operating point results.

  1. Click Operating Point. Look at the States and Outputs tabs.

    Under Outputs, the Desired dx values (if not marked N/A) are zero. For the mechanical states (constraints), the Actual dx values (deviations from the requested operating point) are zero within tolerance.

    This is not true for the Controller states, which you did not require to vanish. The Filtered Derivative states are all zero.

  2. Save this operating point by right-clicking Operating Point and selecting Export. Except for the name, leave the defaults.

    For Variable Name, enter oppoint_PLANT. Click OK.

    You now have a workspace object (opcond.OperatingPoint class) called oppoint_PLANT representing the plant holding still at the start of simulation (t=0). Retain this object for later use.

  3. Examine its states by entering

    oppoint_PLANT % List plant states at t=0
  4. Reset the controller initial condition to the new operating point.

    initCondI = oppoint_PLANT.States(1).x(1);

Linearizing the Platform Motion at the Operating Point

Now switch the model back to Forward Dynamics mode. The mechanical states are now the 52 tree states corresponding to the uncut joint primitives.

  1. Open the Plant subsystem, then its orange Machine Environment block. Locate the Parameters tab.

  2. In the Analysis mode pull-down menu, select Forward Dynamics. Click OK and close the subsystem.

Then linearize the plant motion about the operating point you specified in earlier. Return to the Control and Estimation Tools Manager.

  1. Select Tools > Options. In the Options dialog, select the Linearization State Ordering tab.

    Click the Sync with Model button at the bottom, then click OK.

  2. Now select the Linearization Task node to left, then the Operating Points tab. Select the Operating Point called Operating Point.

  3. At the bottom of the tab, make sure the Plot linear analysis result in a check box is selected. Then choose a plot type in the pull-down menu. For example, pick Bode response plot.

  4. Then click the Linearize Model button. The LTI Viewer opens with a large family of Bode response plots.

    For later reference, you can choose other response plot types by right-clicking on one of the plots and, under Plot Type, selecting a different plot, such as Bode, Step, or Impulse. (You do not need to go back to Linearization and relinearize the model.)

Interpreting and Saving the Linearization Results

This plant linearization started with six inputs (the leg forces) and 12 outputs (six leg positions and six leg velocities). The LTI Viewer displays 6 x 12 = 72 response plots. To view one plot individually,

  1. Right-click any one of the 72 plots and select I/O Selector. The I/O Selector dialog opens.

  2. This dialog lets you to choose any response of one output relative to one input. To see that plot in the LTI Viewer, click the corresponding black dot.

Each plot shows how one of the outputs (a position or velocity) responds to the application of a small force in one of the input channels. Different plot types (impulse, step, Bode, etc.) yield different aspects of the response.

Export the results of your linearization.

  1. Select File > Export in the LTI Viewer.

  2. Choose your model and give it a unique name (call it sys) under Export As.

  3. Click Export to Workspace. The model is saved as an LTI object. The variable class is ss, the canonical state space form used by Simulink.

Retain this LTI object for the next section, where you use it to improve the PID controller.

Further Suggestions

You can apply these results to other controllers (see Synthesizing a Robust, Multichannel Controller following), as well as choose other operating points.

Improving the New PID Controller

In this section, you use the linearization results to create a controller to better match the plant. This information allows you to convert open-loop information about the controller and plant into closed-loop behavior of the coupled system.

A PID controller acts as the same controller on each of the platform legs. You can improve the controller's response to each leg's motion by working with the diagonal components of the plant response. These components represent a leg's motion response to the force acting on that leg. This control design paradigm is single-in, single-out (SISO). By symmetry, designing the PID settings with one of the leg's control behavior optimizes them for the other five.

The SISO approach ignores coupling between the legs. The last section of this study, Synthesizing a Robust, Multichannel Controller following, tackles multichannel coupling to achieve a more accurate controller design.

What You Need from Previous Sections

From the preceding section, Trimming and Linearizing the Platform Motion, you should have these saved in your workspace:

Throughout this section, keep the derivative block as Filtered Derivative and the PID controller as biproper.

Reducing the State Space with Minimal Realization

Many of the mechanical states in sys are constrained. Remove them with the sminreal command. This reduction works with the structure of the sys, rather than (like minreal) with the numerical properties of sys.

G = sminreal(sys); % Structural reduction of linearized sys

G now represents the reduced linearized plant.

Exploring PID Gains, Filtered Derivative, and Force Saturation

One way to get a feel for the effect of PID feedback control on the Stewart platform's motion is to vary the gains, frequency cutoff, and force saturation systematically, while holding fixed the reference trajectory and the platform initial conditions.

The larger Kd is relative to Kp and Ki, the more sensitive the controller is to immediate changes in the reference signal. (The same is true of Kp relative to Ki.) The derivative term emphasizes rapid change. On the other hand, if Kd is small, the controller is more sluggish in response. The Ki term emphasizes memory of motion errors past. A fundamental tradeoff of control design is

For large filtering constant A, the biproper transfer function c(s) behaves at small s almost exactly like the improper C(s). But as you reduce A, c(s) behaves less like C(s). In the time domain, for smaller A, the controller c(s) shows more transient deviation from the pure derivative behavior of C(s).

The PID controller also depends on the force saturation limit, set in the workspace by force_act_max. Making the force saturation limit too small means that the controller cannot actuate the legs sufficiently to make them keep up with the reference trajectory signal. The platform motion moves toward instability with a lower force saturation limit. Too low a limit eventually yields motion that is unacceptably extreme or completely unstable. Up to a point, you can compensate for a lower force saturation limit by making the controller more responsive.

Analyzing the Plant Response with the SISO Design Tool

A better way to optimize the PID controller is to analyze the open- and closed-loop machine response with the SISO design tool.

Open the SISO Design Tool by entering

sisotool(G(1,1)); % SISO design tool for first leg-leg pair

The design tool opens with a unity controller (compensator), C(s) = 1. Use the Help menu for more information about the design tool, including how to interpret the plot symbols.

The Root Locus Editor to the left shows the closed-loop CG/(1+CG) response, the s-plane poles, zeros, and root-loci. The Open-Loop Bode Editor to the right shows the open-loop CG plant response, including poles and zeros.

The closed-loop response has eight poles, four on the left-half and four on the right-half of the s-plane, the latter indicating instability. The open-loop Bode plot displays the gain and phase margins.

SISO Design Tool with Stewart Platform Plant at Rest and Unity Controller

Designing a New Biproper PID Controller with the Plant Response

To design a biproper PID controller, add two zeros and two poles and adjust the overall gain. Observe these general rules for the poles and zeros:

To implement,

  1. Select Compensators > Edit > C. The Edit Compensator C dialog opens. Add poles and zeros. Click OK. The dialog closes.

  2. In the root-locus plot, you can move controller and closed-loop poles and zeros around by dragging them with your mouse. As you move closed-loop poles, you also change the overall controller gain. Be sure to leave the initially stable closed-loop poles in the left half-plane.

    In the Bode editor, you can move open-loop (controller) poles and zeroes by dragging them. You can also change the gain and phase margins.

  3. The SISO design tool controller form is κ(1+αs)(1+βs)/s(1+γ]s). The overall control gain κ is Ki in this form.

    For Ki, use the value of your first guess found previously in Designing a New PID Controller.

Optimizing the New Biproper PID Controller with the Plant Response

To optimize your controller, change its response to suppress undesirable and enhance desirable feedback. The objectives, typical in control problems, are a high-gain response at low frequencies to achieve tracking performance and a diminishing response at high frequencies to limit the controller's sensitivity to plant variations and noise.

The platform motions have low bandwidth, typically only a few Hertz (Hz). The system should have strong response up to a few Hz (ω = about 10 rad/s), then falling response for higher frequencies.

One controller pole must always remain at zero. Five system poles have positive (unstable) real parts, a result of the first leg coupling to the other five. You cannot eliminate these in a SISO analysis.

Improve the controller by

Saving the Optimized New Biproper Control Law

Once you have a satisfactory controller, you can export the new optimized biproper control law to the workspace and analyze it there to redefine the filtered PID controller parameters Ki, Kp, Kd, and A.

Export the modified compensator from the SISO design tool.

  1. Go to File > Export. Select Compensator. Rename it cBiproperOpt under Export as.

  2. Then click Export to Workspace.

cBiproperOpt is a zero-pole-gain form (LTI object of class zpk). For example,

cBiproperOpt

Zero/pole/gain:
6171074.4994 (s+15.51) (s+0.08378) 
----------------------------------
            s (s+400)

Resetting the PID Gains and Derivative Cutoff

Extract the biproper PID controller parameters by inverting the zeros s±, poles, and gain K. The standard zero-pole-gain form is

c(s) = K(s - s+)(s - s-)/s(s+A) = [(Kp + AKd)*s2 + (Ki + AKp)*s + AKi]/s(s + A)

Reset your workspace variables accordingly.

[z,p,k] = zpkdata(cBiproperOpt) % Extract ZPK data from cBiproper
A = -p{1,1}(2) % Extract nonzero pole
Ki = k*z{1,1}(1)*z{1,1}(2)/A % Extract Ki gain
Kp = -(k*(z{1,1}(1) + z{1,1}(2)) + Ki)/A % Extract Kp gain
Kd = (k - Kp)/A % Extract Kd gain

Checking the Symmetric Equilibrium

Check that the symmetric equilibrium is stable with your new controller.

  1. Make sure the Trajectory Switch is set to down.

  2. Update the diagram (Ctrl+D) and rerun the model.

    A trim point is rarely exact. There is typically a small but nonzero motion error as the platform relaxes toward equilibrium.

Simulating the Moving Platform and Capturing the Motion Errors

Now test the platform motion with the moving trajectory and your new retuned biproper control law.

  1. Set the Trajectory Switch back to up.

  2. Restart the model. You should see reasonable motion errors and leg forces, except perhaps for an initial transient.

  3. Capture the Motion Errors from the logged signals structure sigsOut.

    pid_opt_TS = sigsOut.('Motion Errors'); % Record motion errors

Synthesizing a Robust, Multichannel Controller

The controllers you have designed so far in this and the preceding control design studies are based on classical PID techniques, where each channel is subject to the same control law and the control law is tuned one channel at a time. This approach misses the cross-coupling, the effect that the force on one platform leg has on the motion of the other legs.

In this section, you redesign the Stewart platform controller by using modern techniques that take multichannel coupling into account and implementing a robust H-infinity controller [6][7].

What You Need from Previous Sections

From preceding sections, you should have these saved in your workspace:

Viewing the H-Infinity Controller

Before starting,

  1. From its right-click menu, under Block choice, switch the controller subsystem to H_inf Controller.

  2. Make sure that the derivative subsystem remains set to Filtered Derivative and the Trajectory Switch in the Leg Reference Trajectory subsystem is set to up.

Examine the controller subsystem, which is implemented via state space.

Stewart Platform H-Infinity Controller Subsystem

Defining a Desired Loop Shape Response

Start by specifying a desired open-loop response |C*G(1,1)| and plot its singular values. For example,

Lsd = zpk([],[-1000 0],612770) % Define desired loop shape

Zero/pole/gain:  
  612770
----------
 s (s+1000)

 sigma(Lsd) % Plot singular values

View the closed-loop response generated by this loop shape by entering:

step(feedback(Lsd,1)) % Feedback step response

Desired Loop Shape: Singular Values

Synthesize and Reduce a Controller with the Desired Loop Shape

Now create a controller using the desired loop shape and plant response:

[K_ls,CL,GAM,INFO] = loopsyn(G,Lsd); % Synthesize controller

Check the size of the controller by entering

size(K_ls) % Check size of loopsyn controller

The example controller has 48 states. It is usually impractical to implement a controller of such high order and computational intensity. So try reducing the controller to 24th order:

Kr_ls = reduce(K_ls,24); % Reduce controller order

To estimate how many states you can ignore (truncate), plot both the full and reduced singular values

sigma(K_ls,Kr_ls) % Plot singular values 

Full and Reduced Loop-Synthesized Controllers: Singular Values

Simulating the Robust Controller and Capturing Its Motion Errors

From the synthesized loop shape, extract the matrices needed to define the state space model used in the H_inf Controller subsystem.

[Ak,Bk,Ck,Dk] = ssdata(Kr_ls); % Extract state space model

Run the loop-synthesized controller model. Then capture the motion errors.

loopsyn_TS = sigsOut.('Motion Errors'); % Record motion errors

Plotting and Comparing the Results

Finally, compare the motion error data from the two controllers:

At the command line, enter:

figure
plot(pid_opt_TS.Time,pid_opt_TS.Data(1,:),'r', ...
   loopsyn_TS.Time,loopsyn_TS.Data(1,:),'b')
ylabel('Motion Errors','FontSize',16) 
xlabel('t (seconds)','FontSize',16)  
legend('Redesigned PID Controller','Loopsyn Controller')

Apart from the initial transient, the loop-synthesized controller performs better than the redesigned PID controller. In this example, the late-time robust controller motion errors are more than an order of magnitude smaller and exhibit no oscillatory "ringing."

Redesigned PID and Loop-Synthesized Control System Motion Errors

  


Related Products & Applications

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.

 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS