Driven variables are joints for which the trajectory is imposed by the user. Their position, velocity and acceleration must be given as a function of time.
Back to the pendulum-spring example¶
Impose a constant clockwise rotation speed of the crank with a frequency of 0.5Hz.
Step 2, 4 and 5 are not impacted by theses function. See the Bodies and joints part for more information
Step 1: Draw your multibody system¶
- Open the PendulumSpring model in MBsysPad
- Set the nature of the crank joint to Forced-Driven
- Click on the joint to edit its properties
- Click on Driven
- Remark: in the step 2 we assume that the name of the joint is
R2_crank. Adapt either the name in MBsysPad or in the code.
- Set the nature of the pendulum joint to dependent to maintain the
correct number of dependent variables
- If you had modified the joint nature in the code in the previous section you have to update the code, modifications done in MBsysPad are overwritten.
Setting the joint nature can also be done in the code. This feature is only recommanded for advanced users because any change of joint nature done in MBsysPad will be ovrewritten by the code!
Check the mbs_set_qdriven function to do it in the code.
Step 3: Write your user function¶
- Edit the user_DrivenJoints function (open the file from the userfctR subfolder of your project)
- Write the trajectory equations
- Note : The initial position of the cranck (set in MBsysPad) will
be overwritten by the command
q(id) = omega*tsim;. If your initial position is nonzero, you have to modify the line.
- Note : The initial position of the cranck (set in MBsysPad) will be overwritten by the command
function [q, qd, qdd] = user_DrivenJoints(mbs_data,tsim) %... % get the joint id id = mbs_get_joint_id(MBS_info,'R2_crank'); omega = -2*pi*0.5; % impose the position, velocity and acceleration q(id) = omega*tsim; qd(id) = omega; qdd(id) = 0; %... return
You have to set the full trajectory: position, velocity and acceleration. The component you don’t set will not be updated during the simulation.
For example in the spring pendulum: If you set the velocity only, the mass will oscillate (due to the velocity) but the crank will not rotate (the position will always be the initial position).
Check the results¶
Plot the graph of the joint position (results ares avilaible in resultsR/ folder) and check your results with the following graph.