# Sensors¶

Sensors are used to compute the kinematics of a point of the system. They can compute the following information for a given point:

• The absolute position vector
• The absolute rotation matrix of the body on which the point is attached
• The absolute velocity vector
• The absolute angular velocity vector of the body
• The absolute acceleration
• The absolute angular acceleration vector of the body
• The Jacobian matrix of the sensor, i.e. the relation between generalized velocities and the sensor velocity and angular velocity

There are two kinds of sensors:

• S sensor: sensor attached to a given point;
• F sensor: sensor used to compute external force (see the external force);

Note that there also exist Gen sensor: it is equivalent to S sensors attached on each joint of the system.

## Back to the pendulum-spring example¶

The goal is to capture the vertical acceleration of the point located at the middle of the blue rod.

### Step 1: Draw your multibody system¶

Open the existing *.mbs file project with MBsysPad:

• Set back the pendulum joint to independent and the crank joint to dependent;
• Add an anchor point on the rod and enter its coordinates;
• Add a sensor to the anchor point:
• Click on the Sensor button;
• Click on the anchor point at the end of the rod;
• A “S” is added next to the anchor point;
• Click on the “S” to edit its properties and give it a name;

### Step 2: Generate your multibody equations¶

Regenerate the multibody equations with the same options as previously.

### Step 3: Write your user function¶

Edit the user_DrivenJoints function to remove the imposed trajectory of the crank. You can delete or comment the part which imposes the trajectory of the crank.

WARNING:

Imposing the trajectory of an independent or dependant joint will lead to inconsistent results.

Python section:

Edit the main.py file and declare the quantity you want to save.

#...
dirdyn=Dirdyn(mbs)
#...

# Add the sensors vertical acceleration as output.
dirdyn.set_output_sensor('rodAccZ', 'RodSensor', 'A', 3)

#...


The acceleration is accessible via the MBS_user.resdirdyn structure:

• dirdyn.result.timeParam: the time
• dirdyn.result.paramToSave[‘rodAccZ’]: the value of the acceleration at the correspondig time

### Check the results¶

Plot the graph of the sensor acceleration (results ares avilaible in resultsR/ folder) and check your results with the following graph. The evolution of the system is the same as for the Cuts part of the tutorial