SimMechanics | ![]() ![]() |
Constrained Example: Four-Bar System
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 diagram of the four-bar system. The model is the demo mech_four_bar_trim
.
Suppose you want to find out the torque required to turn the crank at a constant angular velocity of 1 radian/sec over a range of crank angles. The following procedure uses the trim
command and the SimMechanics Trimming mode to determine the torque:
Trimming
(see Trimming Mode).
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.
mech_stateVectorMgr
to perform this task:
Handle = get_param(find_system('mech_four_bar_trim/ Revolute2'),'handle'); StateManager = mech_stateVectorMgr(Handle{1}); 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
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/sec. 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/sec, respectively, at the equilibrium point. It is not necessary to constrain the other states because the four-bar system has only one global position DoF and only one global velocity DoF.
trim
command to drive the constraint outputs to 0:
y0
array specifies that the initial values of the constraint outputs are 0. The iy
array specifies that the constraint outputs at the solution point must equal their initial values (0). This assures that the solution satisfies the mechanical constraints on the system.
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. |
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/sec 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 mechanical states. If you were trimming a system that has nonmechanical states, you would have to include the nonmechanical states in the initial state vector. |
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 (Nm)'); title('Input torque vs crank angle');
![]() | Trimming Mechanical Systems | Linearizing SimMechanics Models | ![]() |