presentation introduction to virtual reality in simulink
TRANSCRIPT
-
8/17/2019 Presentation Introduction to Virtual Reality in Simulink
1/19
Intro to Matlab-Simulink Virtual Reality
How to…
Objective:
Show you how to simulate a mathematical system in Simulink and
visually check your equation on a real-virtual system.
on: 2016/04/29
Problem Description:Let’s assume we let a ball freely falls from an initial height . We want to find the equation of
the motion, and then simulate it in Simulink Virtual Reality to check if our equation really drive
the physical ball as expected.
By: Shck Rodrigue Tchamna
Step 1: Equation of motion: Free Fall motion without initial velocity
0 20h m
0h
Note: y is measured from the
ground to the center of the ball.
2
2dy gdt
Free fall motion
1.5r mr
Watch the Video here: Youtbe link
https://www.youtube.com/watch?v=XaCRp2Dbzzs&feature=youtu.behttps://www.youtube.com/watch?v=XaCRp2Dbzzs&feature=youtu.be
-
8/17/2019 Presentation Introduction to Virtual Reality in Simulink
2/19
Collision equation
2 2
02 2
2
0
2
, y
dy dyif y r F m K r y mg m
dt dt
K dyr y g
m dt
Volume conservation equation
4
3 x y z
r r r
Ellipse Volume
34
3r
Sphere Volume
Before bouncing After bouncing
Let’s assume x z
r r
ywith r y
3
2 34 4
3 3 x x z
r
r y r r r y
3
; x z y
r r r r y
y
Scale equations
0K
K m
2
2,
dy
if y r K r y gdt Collision equation
Before collision
x y zr r r r
yr y
Note: There is a ballcompression!
After collision
is the amount
of compression
y
x r
yr
x r
yr
; x z y
r r r y
Assumption: after collision, the deformation in the x and z direction are equal.
-
8/17/2019 Presentation Introduction to Virtual Reality in Simulink
3/19
Step 2: Build this model in Simulink
2
2
dyg
dt
Free fall motion
2
2,
dyif y r f g
dt
3
; x z y
r r r r y
y
Scale equations
Collision equation f K r y
function [f, rx, ry,rz] = fcn(y)
%#codegen
% % f is the ground reaction. The
compression of the ball bring about
a repell force from the ground,
equal to the ball compression
K = 500;
r = 1.5;
% % To avoid division by zero
if y= r
f = 0;
rx = r; ry = r; rz = r;
else %% y
-
8/17/2019 Presentation Introduction to Virtual Reality in Simulink
4/19
Step 3: drag and drop the Simulink Virtual Reality Sink block from the Simulink 3D
Animation Library
-
8/17/2019 Presentation Introduction to Virtual Reality in Simulink
5/19
Step 5: Double-click on the VR Sink block, then Click on New
Step 4: Install the Virtual reality editor by typing the following command in the Matlab prompt
vrinstall -install editor
Starting editor installation ...
Done.
And you will have
the following
Step 6: Right click on Add Node, then open Group Transform
-
8/17/2019 Presentation Introduction to Virtual Reality in Simulink
6/19
This Transform node is for the Sphere-Ball. To rename the Transform node: 1) Right-click
the Transform node. 2) Select the Edit Name menu item. 3) In the edit box to the left of
the Transform node, type Ball.
Step 7: Add a Shape node
Expand the Ball Transform node. Then Select the children node. Then add a Shape node, usingthe following sequence of menu selections:
Step 8: Expand the Children Node, then the Shape and right-click on the Appearance node in
order to add an appearance under the appearance node.
-
8/17/2019 Presentation Introduction to Virtual Reality in Simulink
7/19
Step 9: Add a Sphere Node under the Geometry Node
-
8/17/2019 Presentation Introduction to Virtual Reality in Simulink
8/19
Step 10: Add Material under material node
Change the Ball colour if you wish
-
8/17/2019 Presentation Introduction to Virtual Reality in Simulink
9/19
Step 11 : Change the Size of the Ball; r=1.5m
Step 12: Click on Translation and Set the ball to its initial position, at 20 m
Note: After clicking on Apply, the Ball will Vanish from the Screen. Do not Panic. Do the following
to bring the ball back.
It is also advisable to save your file Now before continuing!!!
Step 13: Right click on Root and Add a Viewpoint
-
8/17/2019 Presentation Introduction to Virtual Reality in Simulink
10/19
-
8/17/2019 Presentation Introduction to Virtual Reality in Simulink
11/19
Note: Change the Viewpoint so as to have a good vision of the Ball. You can set different
viewpoint from the above viewpoint.
Step 14: Let’s add our floor where the Ball is going to bounce. The Floor is nothing but a Box
Node.
Lets copy the Ball Transform Node and make change from this Node. Right Click the
Ball(Transform), Then Copy it. Then go to the Edit menu, then Paste
Step 15: Refer to previous steps and rename it as “Floor”. Then expand all, Go to the Shape
node and delete the Sphere, then add a Box instead.
You should have something like this
-
8/17/2019 Presentation Introduction to Virtual Reality in Simulink
12/19
You should have something like this
-
8/17/2019 Presentation Introduction to Virtual Reality in Simulink
13/19
Step 16: Change the Floor size
Step 17: Then Go to Translation and bring the Floor position down
-
8/17/2019 Presentation Introduction to Virtual Reality in Simulink
14/19
Note. You can Click on the wheel of your mouse and drag the mouse in order to slightly roatate and see
The system in 3D.
Note. We can also add Background Node if we want to do so
-
8/17/2019 Presentation Introduction to Virtual Reality in Simulink
15/19
-
8/17/2019 Presentation Introduction to Virtual Reality in Simulink
16/19
Step 18: Close it and save it when it prompts to do so, then go back in your Simulink Model,
Double-click on the VR Sink, then Browse and find the location of the file you just saved.
Step 19: Click on the View button
-
8/17/2019 Presentation Introduction to Virtual Reality in Simulink
17/19
Step 20: Now Real things Start!!! We want to link our Simulink output signals to the Virtual Reality
Block. Since we are interested in the translation of the Ball, let’s thick the Translation checkbox of
the Ball.
You should be able to see this Figure
-
8/17/2019 Presentation Introduction to Virtual Reality in Simulink
18/19
Note that the translation node is a 3 by 1 vector, representing the translation on the x, y and z
axis. Since we only have one translation here on the y axis, we sill use a VR Signal Expander. The
output width is 3 and the non-zero index is 2, meaning the value of y.
The VR Signal Expander can be found in the Simulink 3D Animation Tab
-
8/17/2019 Presentation Introduction to Virtual Reality in Simulink
19/19
Watch the Video
Step 21: We want to see the actual deformation of the ball. It can be done using the Scale along
the x, y and z axis
Step 22: we need a bus in order to make a 3 by 1 deformation vector
Watch the Video here: Youtbe link
https://www.youtube.com/watch?v=XaCRp2Dbzzs&feature=youtu.behttps://www.youtube.com/watch?v=XaCRp2Dbzzs&feature=youtu.be