Main Content

Specify Joint Motion in Planar Manipulator Model

This example shows how to specify the trajectory of the end effector of a planar manipulator and measure the required actuator torques of the manipulator joints in the multibody dynamics model. For more information about multibody dynamics simulations, see Multibody Dynamics.

Illustration of the manipulator

In this example, you specify the time-varying trajectory coordinates of the end-effector frame with respect to the world frame by using a 6-DOF Joint block. This block provides the requisite degrees of freedom between the two frames. In this model, the 6-DOF Joint block does not act as a physical connection.

During the simulation, the end effector traces the specified square pattern and the revolute joints compute the required actuator torques.

Add Virtual Joint

  1. At the MATLAB® command prompt, enter openExample("sm/DocDoublePendulumModelExample") to open the model. For instructions on how to create this multibody dynamics model, see Model an Open-Loop Kinematic Chain.

  2. Add a 6-DOF Joint block to the model and connect the blocks as shown in the figure.

    Double pendulum with 6-DOF joint

    In this model, the 6-DOF Joint block works as a virtual connection between the world frame and the end-effector frame. The block uses the position inputs to specify the trajectory of the end-effector frame with respect to world frame. Ensure that the base frame of the 6-DOF Joint block connects to the world frame and the follower frame connects to the end-effector frame.

Prescribe Motion Inputs

  1. Double-click the 6-DOF Joint block to open the block dialog and specify these parameters.

    ParameterSelect
    Y Prismatic Primitive (Py) > Actuation > MotionProvided by Input
    Z Prismatic Primitive (Pz) > Actuation > MotionProvided by Input

    The block exposes ports py and pz.

  2. Add two Simulink-PS Converter blocks and one Signal Editor block to the model.

  3. Use the Signal Editor block to specify the position inputs.

    • Double-click the Signal Editor block to open the dialog box.

    • Under Signal properties, click the Launch Signal Editor button to open the Signal Editor window.

    • In the left pane, expand Scenario, rename the signal 1 to py, select the Plot/Edit check box, and edit the data as shown in the image.

      Signal Editor UI showing position data py

    • In the left pane, right-click Scenario, select Insert > Signal, rename the new signal to pz, select the Plot/Edit check box, and edit data as shown in the image.

      Signal Editor UI showing position data pz

    • In the Signal Editor tab, click Save to save the data to a MAT-file. Close the Signal Editor window.

    • In the dialog box, under Signal properties, set Active signal to py and select Interpolate data. Then, set Active signal to pz and select Interpolate data. Click Apply and OK.

  4. Use the Simulink-PS Converter blocks to convert Simulink® signals into physical signals.

    In the two Simulink-PS Converter blocks, specify these parameters.

    ParameterValue
    Units > Input signal unitcm
    Input Handling > Filtering and derivativesFilter input, derivatives calculated
    Input Handling > Input filtering orderSecond-order filtering
    Input Handling > Input filtering time constant (in seconds)0.1

    Note that a small time filtering constant can slow a simulation significantly. For most Simscape™ Multibody™ models, a value of 0.1 seconds often provides a sufficient balance between simulation time and accuracy.

  5. Connect the blocks as shown in the figure.Block diagram with signal editor

Sense Joint Actuation Torques

  1. In the two Revolute Joint blocks, set these parameters:

    ParameterSetting
    Actuation > TorqueAutomatically Computed
    Sensing > Actuator TorqueSelected

    Note

    Simscape Multibody requires the number of joint primitive degrees of freedom with motion inputs to be equal to the number of joint primitive degrees of freedom with automatically computed joint actuator forces and torques. If the model does not meet this condition, the simulation fails with an error.

  2. Add two PS-Simulink Converter blocks and two To Workspace blocks to the model.

  3. In the PS-Simulink Converter blocks, set Vector format to 1-D array. The PS-Simulink Converter blocks convert the physical signal outputs into Simulink signals.

  4. In the two To Workspace blocks, specify the Variable name parameter as t1 and t2, respectively.

  5. Connect the blocks as shown in the figure.Block diagram with ps-simulink Converter blocks and To Workspace blocks

Simulate Model

If you run the simulation, Simulink fails with an error.

Note

Simscape Multibody requires any closed kinematic loop to contain at least one joint block without motion inputs or automatically computed actuator forces or torques.

To solve the error, add a Weld Joint block to the Binary Link A subsystem and connect the blocks as shown in the figure.

Binary link subsystem with Weld Joint block

Run the simulation again. Mechanics Explorer opens with a dynamic 3-D display of the planar manipulator model.

Planar manipulator model in the Mechanics Explorer

Plot the computed actuation torques that act at the two revolute joints in the linkage. At the MATLAB command line, enter:

figure; 
hold on;
plot(t1.time, t1.data, 'color', [60 100 175]/255); 
plot(t2.time, t2.data, 'color', [210 120 0]/255); 
xlabel('Time'); 
ylabel('Torque (N*m)'); 
grid on;
The plot shows the time-varying actuation torques. These torques enable the manipulator end frame to trace the prescribed square trajectory.

Plot of the time-varying actuation torques

Related Examples

More About