Driven variables

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.

Imposing a constant speed along the x-axis

Illustration of a mbsyspad diagram with an imposed dof

Back to the pendulum-spring example

Impose a constant clockwise rotation speed of the crank with a frequency of 0.5Hz.

The crank rotation is imposed, i.e. the angular position, velocity and acceleration are given as function of time

Pendulum spring illustration with driven variable


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.

A joint can be set as driven using the joint properties panel in MBsysPad

Snapshot of the nature section of the joint properties gui


Setting the joint nature can also be done in the code. This feature is only recommended for advanced users because any change of joint nature done in MBsysPad will be overwritten by the code!

Check the ‘MbsData.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 crank (set in MBsysPad) will be overwritten by the command mbs.q[id] = omega*tsim. If your initial position is nonzero, you have to modify the line.

def user_DrivenJoints(mbs_data, tsim):

   # get the joint id
   id_j = mbs_data.joint_id["R2_crank"]
   omega = -2.0*np.pi*0.5

   # impose the position, velocity and acceleration
   mbs_data.q[id_j]   = omega*tsim
   mbs_data.qd[id_j]  = omega
   mbs_data.qdd[id_j] = 0


The MBysPy package implement functions that compute some basic trajectories (cosine, ramp, …) and the possibility to combine them (add, multiply…). The functions compute and return the position, velocity and acceleration resulting of the choosen trajectory. All the function are listed in the documentation.


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 available in resultsR/ folder) and check your results with the following graph.

Plot the time history of the joint position of the pendulum spring example

Time history of the joint position