|On this page…|
Trimming a mechanical system refers to the finding of solutions for inputs, outputs, states, and state derivatives satisfying conditions that you specify beforehand. For example, you can seek steady-state solutions where some or all of the derivatives of a system's states are zero. To use the Simulink® trim command on a system represented by a SimMechanics™ model, you must select the SimMechanics Trimming mode (see Choosing an Analysis Mode). You must also specify the conditions that the solution must satisfy. The examples following then show you how to trim mechanical models.
Consult the Simulink documentation for more on trimming models. You can also enter help trim at the MATLAB® command line.
You should avoid using certain SimMechanics or Simulink features when trimming a model.
A trimmed SimMechanics mechanism must be assembled. Do not use disassembled joints while trimming.
For more information, see Modeling Disassembled Joints.
You cannot use Driver blocks while trimming a model.
Joint Initial Condition Actuator blocks in a trimmed SimMechanics model are ignored.
Do not incorporate events or motion discontinuities in your trimmed model. In particular, do not use SimMechanics Joint Stiction Actuator blocks. Trimming mechanical models with stiction causes an error.
If you want to trim a SimMechanics model containing motion actuators, you must
Make the velocity and position/angle parts of the motion actuation signal dependent only on the acceleration signal
Make the velocity and position/angle consistent with the acceleration part by use of Integrator blocks. A motion actuation signal is a vector with components ordered as position/angle, velocity, and acceleration, respectively.
This technique is recommended in Stabilizing Numerical Derivatives in Actuation Signals. It is required here.
SimMechanics Trimming mode uses only the acceleration as an independent motion actuation input because it is equivalent to a force or torque. As a consequence, only the acceleration signal can be used as an independent motion actuation input.
A similar restriction holds for model linearization; see Linearizing in the Presence of Motion Actuation following.
Motion Actuation as a Model Input for Trimming
Motion Actuation as an Indirect Input. You can put your model input port in another part of your model, then feed that input as an acceleration into a motion actuator with a Simulink signal line. You must still derive the velocity and position/angle motion actuation signals in the same way: by integrating whatever signal you use for acceleration once and twice, respectively.
Consider the following spring-loaded double pendulum.
The joint connecting the upper and lower arms of this pendulum contains a torsional spring and damper system that exerts a counterclockwise torque linearly dependent on the angular displacement and velocity of the joint. Suppose that the lower arm is folded upward almost vertically and then allowed to fall under the force of gravity. At what point does the spring-damper system reach equilibrium. That is, at what point does it cease to unfold?
To find an equilibrium point for the spring-loaded double pendulum,
This model uses Body blocks to model the upper and lower arms of the pendulum and a Revolute Joint block (J1) to model the connection between the pendulum and ground.
The model uses a Subsystem block (J2) to model the spring-loaded revolute joint between the arms. This subsystem uses a negative feedback loop to model a joint subject to a damped torsional spring by multiplying the angular displacement and velocity of the joint, respectively, by spring and damper constants. The loop sums the resulting torques and feeds them back into the joint with a Joint Actuator block.
The result is that the joint experiences a torque opposing its motion and proportional to its angular displacement and velocity. You could also model this damped torsional spring with a Joint Spring & Damper block.
The spring and damper constants used here were chosen by running the model with various candidate values and choosing the ones that resulted in a moderate deflection of the pendulum.
The simulation reveals that the spring stops unfolding after about 9 seconds; that is, it reaches a steady-state point. At this point the angles of the upper and lower joints are about -18 and -51 degrees, respectively, and the velocities are zero. The trim command can find the values of these states precisely.
Examine the model's state vector and prepare it for use in trimming.
Determine the layout of the model's state vector, in order to tell the trim command where in the model's state space to start its search for the pendulum's equilibrium point (the point where it stops unfolding). Use the SimMechanics mech_stateVectorMgr command to perform this task. Refer to the Ground block, G.
StateManager = mech_stateVectorMgr('mech_dpend_trim/G'); StateManager.StateNames ans = 'mech_dpend_trim/J2/RevoluteJoint:R1:Position' 'mech_dpend_trim/J1:R1:Position' 'mech_dpend_trim/J2/RevoluteJoint:R1:Velocity' 'mech_dpend_trim/J1:R1:Velocity'
The StateNames field of the state vector object returned by mech_stateVectorMgr lists the names of the model's states in the order in which they appear in the model's state vector. Thus the field reveals that the model's state vector has the following structure:
x(1) = position of lower joint (J2) x(2) = position of upper joint (J1) x(3) = velocity of lower joint (J2) x(4) = velocity of upper joint (J1)
The initial state vector specifies the point in a system's state space where the trim command starts its search for an equilibrium point. The trim command searches the state space outward from the starting point, returning the first equilibrium point that it encounters. Thus, the starting point should not be at or near any of a system's trivial equilibrium points. For the double pendulum, the point [0; 0; 0; 0] (i.e., the pendulum initially folded up and stationary) is a trivial equilibrium point and therefore should be avoided. The initial state vector must be a column vector and must specify angular states in radians.
Often, the choice of a good starting point can be found only by experiment, that is, by running the trim command repeatedly from different starting points to find a nontrivial equilibrium point. This is true of the double pendulum of this example. Experiment reveals that this starting point,
ix(1) = J2 (lower joint) angle = -35 degrees = -0.6109 radians ix(2) = J1 (upper joint) angle = -10 degrees = -0.1745 radians ix(3) = J2 angular velocity = 0 radians/second ix(4) = J1 angular velocity = 0 radians/second
yields a nontrivial equilibrium point.
Reset the analysis type to Trimming on the Parameters tab of the Machine Environment dialog.
This option inserts a constraint subsystem and associated output at the top level of the model. Trimming inserts the constraint output to make the constraints available to the trim command. The spring-loaded double pendulum has no constraints. Hence the constraint outport does not output nontrivial constraint data and is not needed to trim the pendulum.
ix = [-35*pi/180; -10*pi/180; 0; 0]; iu = ; [x,u,y,dx] = trim('mech_dpend_trim',ix,iu);
The array ix specifies the starting point determined in Analyzing and Initializing the State Vector preceding. The array iu specifies the initial inputs of the system. Its value is null because the system has no inputs. (Thus the u and y outputs are null.) In this form, the trim command finds a system's steady-state (equilibrium) points, i.e., the points where the system's state derivatives are zero. The array x contains the state vector corresponding to the first equilibrium point located by trim:
x = -0.8882 -0.3165 -0.0000 0.0000
The resulting states are angular positions and velocities expressed in radians. Based on the layout of the model's state vector (determined previously in Analyzing and Using the State Vector) the pendulum reaches equilibrium when its upper joint has deflected to an angle of -18.1341 degrees and its lower joint to an angle of -50.8901 degrees. The system state derivatives dx are zero, within tolerances.
Consider a planar four bar system consisting of a crank, a coupler, and a rocker. The following figure shows a block diagram and a convex hull display of the four bar system. The model is mech_four_bar_trimmech_four_bar_trim.
This system is constrained by virtue of being a closed loop. Not all the degrees of freedom are independent. (In fact, only one is.) Suppose you want to find the torque required to turn the crank at an angular velocity of 1 radian/second over a range of crank angles. This section outlines the procedure with the trim command and the SimMechanics Trimming mode to determine the torque.
Reconfigure the model before performing the trim.
Cut the closed loop that represents the four bar system at the joint (Revolute1) connecting the rocker to ground (see Modeling Grounds and Bodies).
Manually cutting the rocker joint ensures that the simulation does not cut the four bar loop at the crank joint and thereby eliminate the crank's position and velocity from the system's state vector.
Simulink then displays the width of signals on the model diagram and hence enables you to read the number of constraints on the four bar system from the diagram in the next step.
Set the analysis mode to Trimming in the Machine Environment block.
Trimming mode then inserts a subsystem and an output block that outputs a signal representing the mechanical constraints on the four bar system. These constraints arise from the closure of the loop.
The width of the constraint signal (4) reflects the fact that the four bar system is constrained to move in a plane and thus has only four constraints: two position constraints and two velocity constraints.
Examine the state vector and prepare it for use in trimming.
Reveal the layout of the system's state vector with mech_stateVectorMgr:
Handle = get_param('mech_four_bar_trim/Revolute2','handle'); StateManager = mech_stateVectorMgr(Handle); StateManager.StateNames ans = 'mech_four_bar_trim/Revolute2:R1:Position' 'mech_four_bar_trim/Revolute3:R1:Position' 'mech_four_bar_trim/Revolute4:R1:Position' 'mech_four_bar_trim/Revolute2:R1:Velocity' 'mech_four_bar_trim/Revolute3:R1:Velocity' 'mech_four_bar_trim/Revolute4:R1:Velocity'
x0 = [0;0;0;0;0;1]; ix = [3;6];
The array x0 specifies that the trim command should start its search for a solution with the four bar system in its initial position and with the crank moving at an angular velocity (state 6) of 1 radian/second. The array ix specifies that the angular position (state 3) and velocity (state 6) of the crank must equal their initial values, 0 radians and 1 radian/second, respectively, at the equilibrium point. It is not necessary to constrain the other states because the four bar system has only one independent position DoF and only one independent velocity DoF.
u0 = 0;
y0 = [0;0;0;0]; iy = [1;2;3;4];
The y0 array specifies the initial values of the constraint outputs as zero. The iy array specifies that the constraint outputs at the solution point must equal their initial values (0). This ensures that the solution satisfies the mechanical constraints on the system.
dx0 = [0;0;1;0;0;0]; idx = ;
The dx0 array specifies the initial derivatives of the four bar system's states. In particular, it specifies that the initial derivative of the crank angle (i.e., the crank angle velocity) is 1 radian/second and all the other derivatives (i.e., velocities and accelerations) are 0. The idx array specifies that the acceleration of the crank at the solution point must be 0; i.e., the crank must be moving at a constant velocity. It is not necessary to constrain the accelerations of the other states because the system has only one velocity DoF.
Note: The four bar system has only constraint outputs. If you were trimming a system with nonconstraint outputs, you would have to include the nonconstraint outputs in the initial output vector.
The four bar system also has only mechanical states. If you were trimming a system with nonmechanical Simulink states, you would have to also include those nonmechanical states in the initial state vector.
Carry out the trimming and study the output.
[x,u,y,dx] = ... trim('mech_four_bar_trim',x0,u0,y0,ix,,iy,dx0,idx);
Trim the system over a range of angles.
Angle = ; Input = ; State = ; dAngle = 2*pi/10; Constraint = ; for i=1:11; x0(3) = (i-1)*dAngle; x0(6) = 1; [x,u,y,dx] = ... trim('mech_four_bar_trim',x0,u0,y0,ix,,iy,dx0,idx); disp(['Iteration: ', num2str(i), ' completed.']); Angle(i) = x0(3); Input(:,i) = u; State(:,i) = x; Constraint(:,i) = y; if (i>3), u0 = spline(Angle,Input,Angle(end) + dAngle); x0 = spline(Angle,State,Angle(end) + dAngle); else x0 = x; u0 = u; end; end;
figure(1); plot(Angle,Input); grid; xlabel('Angle (rad)'); ylabel('Torque (N-m)'); title('Input Torque Vs. Crank Angle');
The following figure displays the resulting plot.
Note: You can use Property Editor to refine the appearance of your plot. To open Property Editor, in the figure toolbar select View > Property Editor.
The following section, Linearizing Mechanical Models contains an example, Closed-Loop Linearization: Four Bar Machine, of trimming the system in a different way, searching for the stable natural equilibrium of the four bar mechanism.