Links ===== .. container:: c-code .. highlight:: c A link is used to model a force in the system - It is a point-to-point force element: - A force is applied on the first body and an opposite force is applied on the other body. - The direction of the force is the direction of the line connecting the 2 points. - The intensity must be given by the user. - The hypothesis undelying the link force is that the link element is assumed to be massless. Thus, link forces are useful to model elements for which the mass dynamics can be neglected such the spring damper of a car suspension. .. figure:: figure/link_potatoes.png :alt: When adding a link between two points, a force aligned with the direction of those two point act on the first body and the reaction act on the second body Illustration of the link concept using a potato multibody diagram - The force intensity must be calculated in the *user_LinkForces* function: - The link length Z and the link velocity Zd are calculated by the symbolic engine and given as arguments of the *user_LinkForce* function. - The force intensity returned by the *user_LinkForce* function is automatically projected in the body. - A positive force value represents a link in traction (tends to bring the bodies closer). - A negative force value represents a link in compression (tends to separate the bodies). .. figure:: figure/link_diagSequentiel.png :alt: The user_LinkForces function is called by the mbs_link_xxx function (automatically generated) which compute the kinematics of the links and project the force on the generalized coordinate Flow chart of the function call for computing link forces Back to the pendulum-spring example ----------------------------------- .. figure:: figure/link_example.png :alt: A link is added to the pendulum spring system, between the pendulum and the ground Illustration of the modified example with a link Add a spring-damper between a point on the base and a point on the pendulum with the following parameters: - Spring stiffness: 100 N/m - Damping: 20 Ns/m - Free length: 0.05 m - Geometry given on the figure, the link is attached to the fixed frame in the X positive direction. .. REMARK: 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 Pendulum Spring model in MBsysPad - Add an anchor point on the base and fill the coordinates - Add an anchor point on the pendulum and fill the coordinates - Add the link to the diagram - Click on the Link button in the toolbar - Click on the first point - Click on the second point - Click on the link to edit its properties - Change the name of the link - Add a user model to store the parameter values of the spring damper: - **This** `page <./tipsAndTrick.html>`__ **explains you how to add a user model** for another application, only apply the step 1 and adapt it - Name of the user model : *mylink* - Parameter *K* to store the spring stiffness - Parameter *C* to store the damping - Parameter *Z0* to store the free length .. figure:: figure/link_snapshot_diagFull.png :alt: A link is added to the pendulum spring system, between the pendulum and the ground Illustration of the modified example in MBsysPad Step 2: Generate your multibody equations ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Regenerate the multibody equations with the same options as previously. Step 3: Write your user function ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. container:: c-code .. rubric:: Generate the user models :name: generate-the-user-models The user models are not loaded with the \*.mbs file. They need to be generated before compiling your model. The generation is done in the MBSysPad interface, open your project and click on *Tools->Generate C-specific user files->All*. REMARK You need first to create the executable that generates those files, see the installation tutorial `Windows `__ `Linux `__ `MacOS `__ .. figure:: figure/Generate_User_ID.png :alt: Generation of the user ID Generation of the user ID This action should create in your *userfctR/* folder of your project the following files: 1. user_model.h : define the user model structure 2. user_model.c 3. user_all_id.h : define all elements (joints, bodies, links, sensors…) ID as variables in the preprocessor with their name in MBsysPad followed by \*_id*. 4. user_hard_param.h : this file is not used by default, it contains all the parameters of the MBS (mass, inertia…) defined as preprocessing variables .. REMARK: If you want you can limit the generation of the C-specific files to your needs by using either *Tools->Generate C-specific user files->User model files* or *Tools->Generate C-specific user files->ID file for joints, links …* .. rubric:: Edit the user function :name: edit-the-user-function - Edit the *user_LinkForces* function (open the file from the userfctR subfolder of your project); - include the user model header in the preprocessing directive; - include the user ID header in the preprocessing directive; - Write the force equations. .. code:: c //... #include "user_model.h" #include "user_all_id.h" //... double user_LinkForces(double Z, double Zd, MbsData *mbs_data, double tsim, int ilnk) { //... double Flink; switch(ilnk) { // get the link id case MyLink_id : { // retrieve the user model UserModel *um = mbs_data->user_model; double K = um->mylink.K; double C = um->mylink.C; double Z0 = um->mylink.Z0; Flink = K*(Z-Z0)+C*Zd; break; } } //... return Flink; } .. REMARK: Sign convention: for a spring system - Flink < 0 ==> compression (Z-Z0 < 0) - Flink > 0 ==> traction (Z-Z0 > 0) .. REMARK If there are several links in the model, all the constitutive laws are introduced in the *user_LinkForces* function and the switch-case is used to distinguish the various links. Check the results ~~~~~~~~~~~~~~~~~ Plot the graph of the joint position (results are available in resultsR/ folder) and check your results with the following graph. .. figure:: figure/Link_curves_q1q2.png :alt: Plot the time history of the joint position of the pendulum spring example Time history of the joint position