MATLAB: How to make the mass of a Body block become tunable when generating a S-Function for a subsystem in SimMechanics 4.1 (R2012b)

Simscape Multibody

I have a subsystem and generate a S-Function by right clicking, selecting C/C++ -> generate S-Function. I then choose the mass variable in the Body block to be tunable. Once the S-Function is generated, I click on the mask of the S-Function but the mass does not appear.

Best Answer

The mass and inertia parameters for the SimMechanic's Body block are not directly tunable. However, as a workaround, it is possible to get around that block's limitation by using a Variable Mass & Inertia Actuator block in conjuction with the Body block. This works by setting the mass property inside the body block to zero and then adding an additional inport to the Body block. You can then connect a Constant block with the mass variable as the value to the Variable Mass & Inertia Actuator which is then in turn connected to the new input port for the Body block. Since the Constant block allows its value to be tunable, you can then generate the S-Function and select the mass to be tunable which will in turn show the mass parameter as tunable on the mask. You can do a similar thing to the inertia parameter if you so desire.
Related Question