Create a Mechanism with Different Joints in MATLAB
R2026bThis example shows how to model a mechanism that contains different types of joints in MATLAB®. It also shows a way of setting operating point targets for the joint primitives of the joints.
Create a Multibody object and add the necessary components, such as WorldFrame.
import simscape.Value simscape.multibody.*; mb = Multibody; addComponent(mb, 'World', WorldFrame()); sep = Value(20, 'cm'); % Separation between blocks % Ground plane ground = UniformSolid(Brick([[5 4] * sep, Value(1, 'cm')]), Value(1000, 'kg/m^3')); addComponent(mb, 'Ground', ground); addComponent(mb, 'Ground_Pose', RigidTransform(CartesianTranslation([2 1.5 0] * sep))); connectVia(mb, 'Ground_Pose', 'World/W', 'Ground/R');
Add different types of joints to the Multibody object using the custom function addJoint.
% Row 1: Single-primitive joints addJoint(mb, 'Revolute', [0 0] * sep, [1 0 0]); addJoint(mb, 'Prismatic', [1 0] * sep, [1 1 0]); addJoint(mb, 'Spherical', [2 0] * sep, [0 .8 0]); addJoint(mb, 'LeadScrew', [3 0] * sep, [0 0 .9]); addJoint(mb, 'ConstantVelocity', [4 0] * sep, [.8 0 .8]); % Row 2: 2-DOF multi-primitive joints addJoint(mb, 'Universal', [0.5 1] * sep, [.95 .4 0]); addJoint(mb, 'Rectangular', [1.5 1] * sep, [.4 .9 0]); addJoint(mb, 'Cylindrical', [2.5 1] * sep, [0 .7 .7]); addJoint(mb, 'PinSlot', [3.5 1] * sep, [.6 0 1]); % Row 3: 3-DOF and 4-DOF multi-primitive joints addJoint(mb, 'Gimbal', [0 2] * sep, [.37 .86 .57]); addJoint(mb, 'Cartesian', [1 2] * sep, [.28 .55 .96]); addJoint(mb, 'Planar', [2 2] * sep, [.91 .63 .10]); addJoint(mb, 'Bearing', [3 2] * sep, [.96 .49 .80]); addJoint(mb, 'Telescoping', [4 2] * sep, [.8 .8 .5]); % Row 4: 0-DOF and 6-DOF joints addJoint(mb, 'Weld', [1 3] * sep, .1 * [1 1 1]); addJoint(mb, 'Bushing', [2 3] * sep, .8 * [1 1 1]); addJoint(mb, 'SixDof', [3 3] * sep, 1 * [1 1 1]);
Use the custom function randomOpPoint to create an operating point specifying random velocities for all the joints.
op = randomOpPoint(mb, Value(90, 'deg/s'), Value(1, 'cm/s'));
After you create the operating point, compile the Multibody object and use the computeState method to view if the above random velocity targets are achieved.
cmb = compile(mb); state = computeState(cmb,op)
state =
State with properties:
Status: Valid
To perform any simulation workflows, generate the Simulink® model of the mechanism by using the makeBlockDiagram method.
makeBlockDiagram(mb,op,'jointZooModel');See Also
simscape.multibody.Multibody | simscape.multibody.RigidBody | simscape.multibody.Joint | compile