Bodies and joints¶
Bodies and joints define the tree structure of the multibody systems
Bodies¶
They are fully defined by:
The mass
The position of center of mass
The inertia matrix
Particular points of a body can be identified using anchor points
Each body must be connected to one and only one parent joint
Joints¶
A joint defines the relative motion between two bodies
A joint can be attached to
The base
An anchor point
Another joint
Example: the pendulum-spring-mass system¶
REMARK:
In Robotran right handed coordinates convention is used. In this case, on the figure, positive rotations are anticlockwise
Model data¶
The example model is composed of the following elements:
Two bodies
the pendulum
Mass: 5 kg
Inertia along axis \(\hat{I}_{2}\): 0.1 kg.m2
the slider
Mass: 2 kg
Two joints
A revolute joint between the pendulum and the base
A prismatic joint between the pendulum and the slider
A linear spring-damper element
Will be implemented as a joint force
Stiffness: 100 N/m
Damping: 2 Ns/m
Free length: 0.1 m
Geometrical data is given in the figure above.
The following initial conditions are considered:
Rotation of the pendulum: 1 rad
Translation of the slider with respect to point A: 0.2 m
Step 1: Draw your multibody system¶
Draw a base body:
Click the body button
Select a shape
Click in the drawing area (for a rectangle: click twice: once for 1st corner and once for 2nd corner)
In the right panel, set the z component of the gravity to 9.81m/s2
REMARK:
The shape of bodies in the 2D diagram does not influence the dynamics
Draw a R2 joint:
Click the joint button
Select R2
Click in the drawing area to draw the joint
Activate the joint properties panel by clicking on the joint
Give a name to the joint, for instance “R2_pendulum”
REMARK:
In the R2 naming:
“R” stands for revolute
“2” stands for axis 2 (y-axis)
WARNING:
be careful when giving name to the elements: use only alphanumeric characters, always start with a letter (as for any variable in a program code).
Draw the pendulum body:
Same procedure as for the base body
Attach this body to the R2 joint
Activate the body properties panel by clicking on the body
In the right panel, give a name to the body and fill the dynamic properties
Center of Mass coordinates in the body-fixed frame, it is aligned with the local Z axis
Inertia matrix in the body-fixed frame, with respect to the center of mass
REMARK:
When drawing a body, you can select the joint it will be attached to by coming close to this joint (which will be highlighted).
REMARK:
For each body, there is a body-fixed frame: this frame move with the body and is fixed at the position of the parent joint. Its axis are aligned with the axis of the parent body when joint positions between the 2 bodies are set to 0.
Draw an anchor point on the pendulum body:
Click the Anchor Point button
Click in the drawing area on the pendulum body
Fill the point coordinates in the right panel (coordinates in the body fixed frame, it is aligned with the local Z axis)
This anchor will be reference point for the prismatic joint.
Complete the diagram:
Draw a T3 joint attached to the anchor point using the same procedure as for the R2 joint
Draw a body for the slider (Don’t forget to fill in its dynamical properties)
REMARK:
In the T3 naming:
“T” stands for translation
“3” stands for axis 3 (z-axis) of the pendulum fixed-frame
Set initial conditions for the joints:
Click on the joint you want to edit
Enter the initial value at the bottom of the right panel
Save your project
REMARK:
All the data entered in MBsysPad are saved in a *.mbs file which is located in the dataR subfolder of your project. The *.mbs file uses an XML format.
Step 2: Generate your multibody equations¶
Click on the menu Tools > Generate Symbolic Files
Enter your username and password
Select your programming language: C
The language is case-sensitive;
Several language can be generated, split them with a coma;
The language of the template has te be included;
Keep other options to default
Click on the Generate button
Check that symbolic files have been downloaded to the symbolicR subfolder of your project
REMARKS:
If you don’t have an account you can either use demo account (usr = demo, pw = demo) or ask one via the online form Need an account ? on the Robotran website
You can save you configuration (username, password, language …) by clicking on the “Save To File” button
You can reset your parameters by clicking on “Settings->Reset password for symbolics”
Step 3: Write your user function¶
Implement the spring-damper law
Edit the user_JointForces function (located in the user_JointForces.c file from the userfctR subfolder of your project
Write the force equations with a stifness K of 100 [N/m] and a damping C of 2 [Ns/m]
double* user_JointForces(MbsData *mbs_data, double tsim)
{
//...
// set the joint force in joint 2
int id = 2;
double K = 100;
double C = 2;
double L0 = 0.1;
mbs_data->Qq[id] = - ( K*(mbs_data->q[id]-L0) + C*mbs_data->qd[id] );
//...
}
NB :
mbs_data->q is the joint position
mbs_data->qd is the joint speed
id
is a python build-in function, avoid to replace it by a variable.
REMARK:
A joint force/torque is a force/torque acting along the axis of a joint. It is thus:
a force for a prismatic joint,
a torque for revolute joint.
Joint forces correspond to the Qq vector in the equations of motion:
\(\begin{matrix} M(q)\ddot{q} + c(q, \dot{q}, frc, trq, g) = Q(q, \dot{q}) + J^T\lambda \\ h(q) = 0 \end{matrix}\)
Qq is the force/torque acting from the parent body to the child body. The reaction is automatically taken into account by the multibody formalism.
Step 4: Run your simulation¶
Adapt the files
Open the main.c file located in your workR/src folder:
Set the end of simulation at 5 seconds :
mbs_dirdyn->options->tf = 5.0;
Check that the name of the project at the line
mbs_data = mbs_load("ProjectName");
is the same as your .mbs fileMBsyspad should have create the file with your project name already included.
You have to update the name if you retrieve the file from an older project (or change the directories).
Open the CmakeLists.txt file located in your workR folder:
Check that the name of the project at the line
project (ProjectName)
is the same as your .mbs fileMBsyspad should have created the file with your project name already included.
Set the path to your Robotran common files
MBsyspad should have create the file with the default version of MBsysC you’ve set (see Tools > Edit preference)
You have to update the path to MBsysC if you want to use a specific version of MBsysC. This could be done
Build and run the project
You first need to install CMake. More information is provided on the official CMake website. Once this is done, you can generate a project with the CMakeLists.txt file located in the workR folder.
The basic steps consists in :
Create a build directory in the /workR/ folder
Compile the project
Run the file
This can be done using a Unix Terminal (Linux, Mac OS), a specific Terminal (Windows) or trough a Gui interface (Windows, Linux, Mac OS).
Compiling in terminal (Unix, MacOS)
After having installed mbsysc, you can compile your project. These below are the command lines on a Unix Terminal (on Mac OS, the Terminal is located in the Applications/Utilities folder):
cd workR # go in workR folder
mkdir build # create a folder named build
cd build # go in build folder
cmake .. -DCMAKE_PREFIX_PATH="XXX/mbsysc/MBsysC/install" # generate a Makefile with the path to the installed mbsysc
make install -j # build and install the project
./exe_PRJNAME # run the project (you can run the project directly from here, or from the folder install/)
Compiling in terminal Developer Command Prompt for Visual Studio (Windows)
These are the command lines on a Developer Command Prompt for Visual Studio Terminal: These commands should also work for Unix/Mac OS.
cd workR # go in workR folder
mkdir build # create a folder named build
cd build
cmake .. -DCMAKE_PREFIX_PATH="XXX/mbsysc/MBsysC/install" # generate a Makefile with the path to the installed mbsysc
cmake --build . --config Release # Choose Debug or Release
cd Debug/ # then go to Debug or Release
./exe_PRJNAME # run the project
Or use the install tool to get a lighter version (you can delete the build folder afterwards)
cmake .. -DCMAKE_INSTALL_PREFIX="../install" -DCMAKE_PREFIX_PATH="XXX/mbsysc/MBsysC/install" # gives the mbsysc path and the install path for your project
cmake --build . --target install --config Release # compile and install
cd ../install # then go to the install folder
./exe_PRJNAME # run the project
REMARK
You may need admin rights to install, depending on the path where you want to install
Compiling with the CMake Gui interface (Windows, Unix, MacOS)
To use the CMake Gui interface, you first need to run the corresponding application (look for CMake in your applications). Then, click on Browse Source… and select the location of the main CMakeLists.txt file, i.e. your workR folder. Click on Browse Build… and select an empty folder where the binaries will be automatically created. This can be inside your project (inside the workR/build folder in the Unix Terminal example above) or anywhere on your computer, like on Desktop/build, as you can see in the next illustration.
WARNING:
Since v1.25.X and higher, you need to add the path for installing the project. Click on + Add Entry ->
Name
=CMAKE_PREFIX_PATH
,Type
=PATH
,value
=XXX/mbsysc/MBsysC/install
. This will ensure your project used the right mbsysc modules . If this path is already present, just check that the path is correct. If not, change it to “XXX/mbsysc/MBsysC/install”. XXX is the path to your mbsysc directory.
Click on the Configure button and select the type of generator (IDE…) you want to use. Pay attention to use a 64 bit configuration if your OS is 64 bit (same thing for 32 bit).
The configuration panel will appear. Red does not mean that something went wrong. Check the lines below the Configure button to check if all libraries were found. Otherwise, look at the Installation tutorial. Symbolic … not found, linking to void function is not an error, it means that this function was not generated because you do not use it in your project.
You can change some options like selecting the Real-time features in the next figure. You then need to press again the Configure button.
Finally, click on the Generate button. Your project will be created inside the build folder you specified. In this folder, you can click on the project to launch it (projectRobotran as a Visual Studio project in the following example).
If you use Visual Studio on
Windows (recommended), exe_projectRobotran should already be set as
StartUp project. You can then choose between Debug
and
Release
before compiling.
To launch the project, go in DEBUG
and launch Start Debugging
(for Debug
mode) or Start Without Debugging
(for Release
mode). You can also go inside your build folder (folder you
configured in CMake for the binaries) and launch the executable
exe_projectRobotran
in the Debug
folder (for Debug version)
or the one in the Release
folder (for Release version).
Finally, to launch the Debug version, you can also click on
Local Windows Debugger
.
WARNING:
Since v1.25.X and higher, if you want to execute the project from Visual Studio, you need to change the
mbs_load("YOURPROJECTNAME.mbs");
call inmain.c
by the following line:
mbs_data = mbs_full_loader("dataR/YOURPROJECTNAME.mbs", NULL, NULL, NULL, NULL, NULL, "./Debug/", NULL, "./Debug/", -1, -1, NULL);
or, more compact :
mbs_data = mbs_load_with_exec("dataR/YOURPROJECTNAME.mbs", argv[0]);
Finally, install everything by right clicking on the solution
“INSTALL” under the Solution Explorer
then (re)regenerate this
solution. This should put everything in the
mbsysc/MBsysC/install/
folder, as required.
Importantly, to run the Debug
version, you might have to remove
the Java visualization features (part of the real-time features).
This can be done in userfctR/realtime/user_realtime_options.c
with the line options->flag_visu = 0;
.
Step 5: Animate your 3D MBS¶
Draw your MBS system in 3D¶
You can customize the 3D view of your system as follows:
Open your *.mbs file in MBsysPad
Click on the Design 3D model button
Activate the body you want to edit
Click on the body in the 2D view
Or go to the 3D view and, in the right panel, use the drop down menu of the Comp tab
Add a shape and edit its properties
The shape inline allow to add a 3D part exported from CAD software. The part must be saved in the VRML format (extension *.wrl). Only VRML 2.0 or VRML 97 are supported (not VRML 1.0).
Use the ViewPt to add registered viewpoint
Use the Light tab to add lights to the scene
REMARK:
Attaching a viewpoint or a light to a joint will make them follow the motion when animating the model.
Animate your results¶
You can view a 3D animation of the system using MBSysPad as follows:
Open your *.mbs file in MBsysPad
Click on the Animate 3D model button
Load the result file
Click on the Open button
Select the *.anim file located in the animationR subfolder of your project
Use the control buttons to run the animation
REMARK:
Navigating in the 3D view:
Rotation : Mouse motion + left button
Zoom : Mouse motion + middle button (OR ALT + mouse motion + single button)
Translation : Mouse motion + right button
Check the results¶
Plot the graph of the joint position (results ares avilaible in resultsR/ folder) and check your results with the following graph.