From the optimization point of view, a fixed-step solver is the best choice if that is sufficient to solve the ODE. A choice must be made about the type of solver to use. The call to sim results in a call to one of the Simulink ordinary differential equation (ODE) solvers. The resulting closed-loop step response is shown in Figure 2-4.įigure 2-4: Closed-Loop Response Using lsqnonlin Iteration Func-count Residual Step-size derivative Lambda The optimization gives the solution for the proportional, integral, and derivative ( Kp, Ki, Kd) gains of the controller after 64 function evaluations: In this case you ask for output, use the medium-scale algorithm, and give termination tolerances for the step and objective function on the order of 0.001. The variable options passed to lsqnonlin defines the criteria and display characteristics. % Put variables back in the base workspace Options = optimset('LargeScale','off','Display','iter'. Pid0 = % Set initial valuesĪ1 = 3 a2 = 43 % Initialize plant variables in model Opt = simset('solver','ode5','SrcWorkspace','Current') % Choose solver and set model workspace to this function Kp = pid(1) % Move variables into model parameter names The Outport block is used in the block diagram model to put yout into the current workspace at the end of the simulation. When the simulation completes, the variables tout, xout, and yout are now in the current workspace (that is, the workspace of tracklsq). The simulation is performed using a fixed-step fifth-order method to 100 seconds. lsqnonlin then passes a1 and a2 to tracklsq each time it is called, so you do not have to use global variables.Īfter choosing a solver using the simset function, the simulation is run using sim. You can initialize a1 and a2 before calling lsqnonlin and then pass these two variables as additional arguments. Kp, Ki, and Kd are the variables to be optimized. To run the simulation in optsim, the variables Kp, Ki, Kd, a1, and a2 ( a1 and a2 are variables in the Plant block) must all be defined. In this example, the simset command is used to tell sim to run the simulation in the current workspace by setting 'SrcWorkspace' to 'Current'. The simulation can be run either in the base workspace or the current workspace, i.e., the workspace of the function calling sim, which in this case is tracklsq's workspace. The function tracklsq must run the simulation. The error signal is yout, the output computed by calling sim, minus the input signal 1. This is defined via a MATLAB function in the file tracklsq.m, shown below, that defines the error signal. The routine lsqnonlin is used to perform a least-squares fit on the tracking of the output. But the goal is to minimize the error for all time steps from 0 to 100, thus producing a multiobjective function (one function for each time step). If you only need to minimize the error at one time unit, it would be a single objective function. The variables are the parameters of the PID controller. One way to solve this problem is to minimize the error between the output and the input signal. A Scope block displays output trajectories during the design process. The closed-loop plant is entered in terms of the blocks where the plant and actuator have been placed in a hierarchical Subsystem block. The problem is to design a feedback control loop that tracks a unit step input to the system. You can see this response by opening the model (type optsim at the command line or click the model name), and selecting Start from the Simulation menu. The open-loop response of the system to a step input is shown in Figure 2-2, Closed-Loop Response. The slew rate limit of the actuator is 0.8 units/sec. The actuator saturation limit cuts off input values greater than 2 units or less than -2 units. The actuator limits are a saturation limit and a slew rate limit. The plant is an under-damped third-order model with actuator limits. Note that Simulink must be installed on your system to load this model.) The model includes a nonlinear process plant modeled as a Simulink block diagram shown in Figure 2-1, Plant with Actuator Saturation.įigure 2-1: Plant with Actuator Saturation (This model can be found in the Optimization Toolbox optim directory. Let's say that you want to optimize the control parameters in the Simulink model optsim.mdl. Included is an example of how to optimize parameters in a Simulink model. This section demonstrates solving problems with multiobjective functions using lsqnonlin, fminimax, and fgoalattain. The previous examples involved problems with a single objective function. Tutorial (Optimization Toolbox) Optimization Toolbox
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |