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.
Imposing the trajectory of an independent or dependent joint will lead to inconsistent results.
Edit the user_dirdyn.py and do your computation in the function
#... from MBsysPy import MbsSensor #... def user_dirdyn_loop(mbs_data, mbs_dirdyn): #... # Creating the sensor my_sensor = MbsSensor(mbs_data) # Computing the sensor with number 1 id_sensor = 1 my_sensor.comp_s_sensor(id_sensor) # Add the sensor vertical acceleration as output. mbs_data.set_output(my_sensor.A, "sensor") #...
The saved value will be accessible in the results
MbsDirdyn.results) instance in the dictionary
Computing multiple sensor
If you need to use the results of multiple sensors you just have to
repeat the previous code. For example in
#... from MBsysPy import MbsSensor #... def user_dirdyn_loop(mbs_data, mbs_dirdyn): #... # Creating the sensors my_sensor_1 = MbsSensor(mbs_data) my_sensor_2 = MbsSensor(mbs_data) # Defining the sensor ids as 1 and 4 (assuming your project has 4 sensors). id_sensor_1 = 1 id_sensor_2 = 4 # Computing the sensors my_sensor_1.comp_s_sensor(id_sensor_1) my_sensor_2.comp_s_sensor(id_sensor_2) # Add different outputs: mbs_data.set_output(my_sensor_1.A, "sensor_1_vert_acc") # The vertical acceleration of the first defined sensor mbs_data.set_output(my_sensor_2.A, "sensor_4_vert_acc") # The vertical acceleration of the second defined sensor mbs_data.set_output(my_sensor_2.P - my_sensor_1.P, "sensors_vert_distance") # The vertical distance between the sensors #...
REMARK, for advanced user:
If you want, you can compute your sensor via the list
MbsData.sensors. This list contains (by default) one allocated sensor (
MbsData.sensors) that is kept during the whole simulation. Doing so avoids creation and destruction of the MbsSensor at each time step (faster).
If you need to compute more than one sensor at the same time you can add them in the list
mbs_data.sensors.append(MBsysPy.MbsSensor(mbs_data))in the function
user_dirdyn_init(mbs_data, mbs_dirdyn)will allocate a second sensor in the list. Pay attention that the sensors will be available for all the simulation, except if you delete them in the function
When creating a sensor instance you can specify the sensor id with
my_sensor = MBsysPy.MbsSensor(mbs_data, id_=sensor_id). Then calling my_sensor.comp_s_sensor() without specifying any number will compute the sensor with the id specified at creation.
Check the results¶
Plot the graph of the sensor acceleration (results ares available 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