|On this page…|
The Transform Sensor block provides the broadest motion-sensing capability in SimMechanics™ models. Using this block, you can sense motion variables between any two frames in a model. These variables can include translational and rotational position, velocity, and acceleration.
In this example, you use a Transform Sensor block to sense the lower link translational position with respect to the World frame. You output the position coordinates directly to the model workspace, and then plot these coordinates using MATLAB® commands. By varying the joint state targets you can analyze the lower-link motion under quasi-periodic and chaotic conditions.
Before continuing, you must have completed example Model Double Pendulum.
In this example, you rely on gravity to cause the double pendulum to move. You displace the links from equilibrium and then let gravity act on them. To displace the links at time zero, you use the State Targets section of the Revolute Joint block dialog box. You can specify position or velocity. When you are ready, you simulate the model to analyze its motion.
To sense motion, you use the Transform Sensor block. First, you connect the base and follower frame ports to the World Frame and lower link subsystem blocks. By connecting the ports to these blocks, you can sense motion in the lower link with respect to the World frame. Then, you select the translation parameters to sense. By selecting Y and Z, you can sense translation along the Y and Z axes, respectively. You can plot these coordinates with respect to each other and analyze the motion that they reveal.
To sense motion in the double-pendulum model:
Open the double_pendulum that you created in example Model Double Pendulum.
Drag these blocks to the model.
|Transform Sensor||SimMechanics Second Generation (SM 2G) > Frames and Transforms||1|
|World Frame||SimMechanics Second Generation (SM 2G) > Frames and Transforms||1|
|PS-Simulink Converter||Simscape > Utilities||2|
|To Workspace||Simulink > Sinks||2|
In the Transform Sensor block dialog box, select Translation > Y and Translation > Z.
In the PS-Simulink Converter blocks, specify cm physical units.
In the two To Workspace blocks, enter the variable names y_link and z_link.
Connect the blocks to the model as shown in the figure.
Specify the initial state of each joint. Later, you can modify this state to explore different motion types. For the first iteration, rotate only the top link by a small angle:
Double-click block Revolute Joint.
This is the block between Pivot Mount and Binary Link subsystem blocks.
In the State Targets section of the block dialog box, select Specify Position Target.
In Value, enter 10.
Check that the physical unit is deg (degrees).
To simulate the model, in the Simulink® tool bar click the Run button. Alternatively, with the model window active, press Ctrl+T. Mechanics Explorer displays the model simulation in the visualization pane.
You can now plot the position coordinates of the lower link. At the MATLAB command line, enter:
figure(1); hold; plot(y_link.data, z_link.data, 'color', [60 100 175]/255); axis([-10 10 -40 -39]) xlabel('Y Coordinate (cm)'); ylabel('Z Coordinate (cm)'); grid on;
The figure shows the plot that opens. This plots shows that lower link path is nearly, but not quite, the same with each oscillation. This behavior is characteristic of quasi-periodic systems.
By adjusting the revolute joint state targets, you can simulate the model under chaotic conditions. One way to obtain chaotic motion is to rotate the top revolute joint by a large angle. To do this, in the Revolute Joint dialog box, change State Targets > Position > Value to 90 and click OK.
Simulate the model with the new joint state target. To plot the position coordinates of the lower pendulum link with respect to the World frame, at the MATLAB command line enter this code:
figure(2); hold; plot(y_link.data, z_link.data, 'color', [60 100 175]/255); axis([-42 42 -42 15]) xlabel('Y Coordinate (cm)'); ylabel('Z Coordinate (cm)'); grid on;
The figure shows the plot that opens. This plots shows that lower link path is very different with each oscillation. This behavior is characteristic of chaotic systems.
So that you can reuse this model in subsequent examples, save it in a convenient folder as double_pendulum.