embedding vr_sink asked . 2021-08-16

How can I display the value of a Simulink signal in the virtual scene during simulation using the Virtual Reality Toolbox?

I would like to be able to view the value of a Simulink signal in a virtual scene during simulation. Also, I would like to realize a HUD-type display in the Virtual Reality Toolbox Viewer window.

vr , sink , hud , simulink , signal , virtual , reality

Expert Answer

John Williams answered . 2024-12-22 04:26:31

This can be accomplished using the Virtual Reality Toolbox in Simulink by following the instructions below:
 
 Q1: How can I view the value of a Simulink signal in a virtual scene during simulation?
Virtual Reality Toolbox allows you to set a VR scene Text node string
using its MATLAB interface (see the "vrheat" example). Setting the text from Simulink using the standard "VR Sink" block is not possible, as this block accepts Simulink signals which must be numeric or boolean. However, setting the text in a virtual scene from Simulink is possible, using one of the following three options:
 
 a) Use a VR Sink and convert the value of the signal to text using a VRML script.
See the HUD_UsingRouteandScript.mdl and its associated VRML scene. This method is simple to do from Simulink point of view, but requires some knowledge about VRML scripts. With this model as a template, however, it is fairly straightforward.
 
In the VR scene, you have to create a dummy. This is usually an invisible object
 
that can be used for passing the value from Simulink into the VR scene. In the scene "HUD_TXT_Routed_Script.wrl" there are objects "Charon" and "Charon3Floats" that can be used to pass the scalar float value and vectors of 2 and 3 floats, MFVec2F and MFVec3F.
 
Depending on what type of signal you want to output, select a field of the appropriate type in the VR Sink block. In this example there is one scalar (a textureTransform rotation field) and one MFVec3F (a Transform center field). The rest of the functionality is done in the VRML file.
 
There are ROUTEs defined that route the values received in the above fields into a Script node. The script node processes these values as eventIns and converts them into text. Value captions/descriptions can be added in the script functions to form the resulting output string. Numbers can be rounded and manipulated using JavaScript object
 
methods. (In this example the toFixed() method is used to restrict the string converted from a number to 2 digits after decimal point.)
 b) Using Virtual Reality Toolbox MATLAB interface, implemented as 

 Embedded MATLAB function.
This method requires a little MATLAB programming experience, but does not
require any additional VRML programming.
 
See HUD_DirectEmbedded.mdl and HUD_TXT_Direct.wrl. In this model there is a "Embedded MATLAB function" block, in which uses MATLAB code exactly the way how it would be used in MATLAB. The VR Sink block in the model handles correct opening and closing the VR world on our behalf. The virtual world handle is taken from the property of a "VR Sink" block in order to maintain consistency between the world
 
associated with VR Sink and the world in which you want to update the text.
 
% Get vrworld associated with the VR Sink found there

wh=vrworld(get_param('HUD_DirectEmbedded/VR Sink', 'WorldFileName'));

% Handle to the Text node we want to control

nh=vrnode(wh,'HUDText');

% Set the new value of the 'string' field of the Text node)

% the string can be a vector of strings

setfield(nh, 'string', strcat('Value:  ', num2str(u)) );
Note:
 
In the "Embedded MATLAB function" you can use only a subset of the MATLAB
language. Due to this restriction, it is not possible use the dot notation to
set the text value (access to structures is not possible; use setfield() instead). Also, use strcat() to concatenate strings.
 
 c) Use the Virtual Reality Toolbox MATLAB interface, implemented as (MATLAB) S-function.
This method requires knowledge of writing S-functions, but does not require any additional VRML programming.
 
See the HUD_UsingSFunc.mdl, vr_txtout.m and HUD_TXT_Direct.wrl. In this example an S-function is used and one parameter is defined: the name of the text node whose string we want to output. The S-function vr_txtout.m takes one input: the value to output. The S-function converts the value to a text value.
 
All the functionality of this S-function is done in the mdlInitialize and mdlUpdate phases.
 
 Q2: How do I realize a HUD-type display in the Virtual Reality Toolbox Viewer window?
HUD can be realized in VRML with the help of a "ProximitySensor"
 
node. This sensor senses the current position of a user, as he/she
 
navigates in the virtual scene. If the output of this sensor is ROUTEd to a position and rotation of a Transform containing graphical elements of the HUD display, the relative position between user and the HUD is constant.
 
See the attached .wrl files that use this technique for HUDs containing some text nodes. Use a text editor to see all the comments in the WRL files.
 
HUD is used in all 3 Simulink examples.


Not satisfied with the answer ?? ASK NOW

Frequently Asked Questions

MATLAB offers tools for real-time AI applications, including Simulink for modeling and simulation. It can be used for developing algorithms and control systems for autonomous vehicles, robots, and other real-time AI systems.

MATLAB Online™ provides access to MATLAB® from your web browser. With MATLAB Online, your files are stored on MATLAB Drive™ and are available wherever you go. MATLAB Drive Connector synchronizes your files between your computers and MATLAB Online, providing offline access and eliminating the need to manually upload or download files. You can also run your files from the convenience of your smartphone or tablet by connecting to MathWorks® Cloud through the MATLAB Mobile™ app.

Yes, MATLAB provides tools and frameworks for deep learning, including the Deep Learning Toolbox. You can use MATLAB for tasks like building and training neural networks, image classification, and natural language processing.

MATLAB and Python are both popular choices for AI development. MATLAB is known for its ease of use in mathematical computations and its extensive toolbox for AI and machine learning. Python, on the other hand, has a vast ecosystem of libraries like TensorFlow and PyTorch. The choice depends on your preferences and project requirements.

You can find support, discussion forums, and a community of MATLAB users on the MATLAB website, Matlansolutions forums, and other AI-related online communities. Remember that MATLAB's capabilities in AI and machine learning continue to evolve, so staying updated with the latest features and resources is essential for effective AI development using MATLAB.

Without any hesitation the answer to this question is NO. The service we offer is 100% legal, legitimate and won't make you a cheater. Read and discover exactly what an essay writing service is and how when used correctly, is a valuable teaching aid and no more akin to cheating than a tutor's 'model essay' or the many published essay guides available from your local book shop. You should use the work as a reference and should not hand over the exact copy of it.

Matlabsolutions.com provides guaranteed satisfaction with a commitment to complete the work within time. Combined with our meticulous work ethics and extensive domain experience, We are the ideal partner for all your homework/assignment needs. We pledge to provide 24*7 support to dissolve all your academic doubts. We are composed of 300+ esteemed Matlab and other experts who have been empanelled after extensive research and quality check.

Matlabsolutions.com provides undivided attention to each Matlab assignment order with a methodical approach to solution. Our network span is not restricted to US, UK and Australia rather extends to countries like Singapore, Canada and UAE. Our Matlab assignment help services include Image Processing Assignments, Electrical Engineering Assignments, Matlab homework help, Matlab Research Paper help, Matlab Simulink help. Get your work done at the best price in industry.