# Inverse dynamics¶

Computation of the system inverse dynamics. It computes the required forces and torques in the actuated joints to follow a given motion. For more information, see Robotran theoretical framework.

## Code sample¶

For running the inverse dynamics, in the current configuration, insert the following code in your main script and adapt it to your need:

```
mbs_data.process = 6
mbs_invdyn = MBsysPy.MbsInvdyn(mbs_data)
mbs_invdyn.set_options(motion = "oneshot")
mbs_invdyn.run()
```

You can compute the inverse dynamics for a time-define trajectory by providing the trajectory files as follow:

```
# Set all driven joint as independent
mbs_data.set_qu(mbs_data.qc[1:].tolist())
mbs_data.process = 6
mbs_invdyn = MBsysPy.MbsInvdyn(mbs_data)
# Set the motion to be solved as a trajectory
mbs_invdyn.set_options(motion = "trajectory")
# Provide the trajectory files to use
mbs_invdyn.set_options(trajectoryqname = "../resultsR/inverse_kinematics_q.res",
trajectoryqdname = "../resultsR/inverse_kinematics_qd.res",
trajectoryqddname = "../resultsR/inverse_kinematics_qdd.res")
# Provide the time interval and time step to solve the inverse dynamics.
mbs_invdyn.set_options(t0 = 0.0, tf = 6.0, dt = 1e-3)
# The final time "tf' must be less than the last time of the trajectory files.
mbs_invdyn.run()
```

In all cases the analysis requires actuated joint, see next section to set them.

## Use¶

The inverse dynamics computation is requires an instance of `MbsInvdyn`

.
Then the analysis is performed by calling the function `MbsInvdyn.run()`

.

The options of the module are set with the function `MbsInvdyn.set_options()`

.

The force and torques are computed on the actuated joints (see Robotran
theoretical framework).
A joint is (de)selected as actuated with the function `MbsData.set_qa()`

(resp. `MbsData.unset_qa()`

).

## Requirements on the system¶

The system either:

contains independent joints:

The driven joints cannot be actuated;

The independent and dependent joint can be actuated;

The number of actuated joint must be equal or greather (over-actuated) than the number of independent joints.

does not contain any independent joints:

The driven joints must be actuated;

The dependent joints cannot be actuated