Create a Mechanism with Different Joints in MATLAB
This 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 and Gravity.
import simscape.Value simscape.multibody.*; mb = Multibody; addComponent(mb, 'World', WorldFrame()); sep = Value(20, 'cm'); % Separation between blocks % Translucent ground plane ground = Solid(Brick([[5 4] * sep, Value(1, 'cm')]), UniformDensity, ... SimpleVisualProperties(0.7 *[1 1 1], 0.6)); addComponent(mb, 'Ground', ground); addComponent(mb, 'Ground_Pose', RigidTransform(CartesianTranslation([2 1.5 0] * sep))); connectVia(mb, 'Ground_Pose', 'World/W', 'Ground/R'); % Zero gravity mb.Gravity = Value([0 0 0], 'm/s^2');
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]);
To create operating points that specify the position or velocity targets of a joint, get the path to each of the joint primitives. The Multibody object provides a method jointPrimitivePaths to list the paths to all the joint primitives in the mechanism. Use this list as one of the inputs to the custom function randomOpPoint that creates an operating point specifying random velocities for all the joints.
jointPrimPaths = jointPrimitivePaths(mb); op = randomOpPoint(jointPrimPaths, 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:
Status: Valid
Assembly diagnostics:
x
Revolute_Joint
'Revolute_Joint' successfully assembled
Rz
Free position value: +0 (deg)
High priority velocity target +23.5864 (deg/s) achieved
Prismatic_Joint
'Prismatic_Joint' successfully assembled
Pz
Free position value: +0 (m)
High priority velocity target +0.210897 (cm/s) achieved
Spherical_Joint
'Spherical_Joint' successfully assembled
S
Free position value: [+0 +0 +0], +0 (deg)
High priority velocity target [-80.4494 -62.6214 -85.1939] (deg/s) achieved
LeadScrew_Joint
'LeadScrew_Joint' successfully assembled
LSz
Free position value: +0 (deg)
High priority velocity target +0.0848914 (cm/s) achieved
ConstantVelocity_Joint
'ConstantVelocity_Joint' successfully assembled
CV
High priority position target +90 (deg) achieved
High priority velocity target [-5 +10] (deg/s) achieved
Universal_Joint
'Universal_Joint' successfully assembled
Rx
Free position value: +0 (deg)
High priority velocity target +73.9708 (deg/s) achieved
Ry
Free position value: +0 (deg)
High priority velocity target +10.0194 (deg/s) achieved
Rectangular_Joint
'Rectangular_Joint' successfully assembled
Px
Free position value: +0 (m)
High priority velocity target +0.162366 (cm/s) achieved
Py
Free position value: +0 (m)
High priority velocity target +0.00724535 (cm/s) achieved
Cylindrical_Joint
'Cylindrical_Joint' successfully assembled
Rz
Free position value: +0 (deg)
High priority velocity target -12.8893 (deg/s) achieved
Pz
Free position value: +0 (m)
High priority velocity target +0.984314 (cm/s) achieved
PinSlot_Joint
'PinSlot_Joint' successfully assembled
Px
Free position value: +0 (m)
High priority velocity target +0.454274 (cm/s) achieved
Rz
Free position value: +0 (deg)
High priority velocity target +21.4513 (deg/s) achieved
Gimbal_Joint
'Gimbal_Joint' successfully assembled
Rx
Free position value: +0 (deg)
High priority velocity target +89.4072 (deg/s) achieved
Ry
Free position value: +0 (deg)
High priority velocity target +28.0298 (deg/s) achieved
Rz
Free position value: +0 (deg)
High priority velocity target +25.9604 (deg/s) achieved
Cartesian_Joint
'Cartesian_Joint' successfully assembled
Px
Free position value: +0 (m)
High priority velocity target -0.25679 (cm/s) achieved
Py
Free position value: +0 (m)
High priority velocity target -0.640975 (cm/s) achieved
Pz
Free position value: +0 (m)
High priority velocity target +0.594411 (cm/s) achieved
Planar_Joint
'Planar_Joint' successfully assembled
Px
Free position value: +0 (m)
High priority velocity target +0.433686 (cm/s) achieved
Py
Free position value: +0 (m)
High priority velocity target +0.215342 (cm/s) achieved
Rz
Free position value: +0 (deg)
High priority velocity target -60.8224 (deg/s) achieved
Bearing_Joint
'Bearing_Joint' successfully assembled
Pz
Free position value: +0 (m)
High priority velocity target +0.908122 (cm/s) achieved
Rx
Free position value: +0 (deg)
High priority velocity target +2.55215 (deg/s) achieved
Ry
Free position value: +0 (deg)
High priority velocity target -63.2583 (deg/s) achieved
Rz
Free position value: +0 (deg)
High priority velocity target -63.7585 (deg/s) achieved
Telescoping_Joint
'Telescoping_Joint' successfully assembled
S
Free position value: [+0 +0 +0], +0 (deg)
High priority velocity target [-89.3162 -43.8057 -52.8736] (deg/s) achieved
Pz
Free position value: +0 (m)
High priority velocity target -0.844793 (cm/s) achieved
Weld_Joint
'Weld_Joint' successfully assembled
Bushing_Joint
'Bushing_Joint' successfully assembled
Px
Free position value: +0 (m)
High priority velocity target +0.66129 (cm/s) achieved
Py
Free position value: +0 (m)
High priority velocity target +0.148752 (cm/s) achieved
Pz
Free position value: +0 (m)
High priority velocity target -0.792454 (cm/s) achieved
Rx
Free position value: +0 (deg)
High priority velocity target -44.7294 (deg/s) achieved
Ry
Free position value: +0 (deg)
High priority velocity target -32.5625 (deg/s) achieved
Rz
Free position value: +0 (deg)
High priority velocity target -71.8616 (deg/s) achieved
SixDof_Joint
'SixDof_Joint' successfully assembled
Px
Free position value: +0 (m)
High priority velocity target +0.664527 (cm/s) achieved
Py
Free position value: +0 (m)
High priority velocity target -0.294531 (cm/s) achieved
Pz
Free position value: +0 (m)
High priority velocity target -0.806505 (cm/s) achieved
S
Free position value: [+0 +0 +0], +0 (deg)
High priority velocity target [-24.8307 -63.8315 -74.1798] (deg/s) achieved
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