MATLAB: How to control a virtual world using code generated by Real-Time Workshop

realitySimulink 3D Animationsimulink codervr

I created a model that drives a virtual world. When I generate and build code from this model, I am unable to control the virtual world with the generated executable.

Best Answer

The generated code alone cannot be used to control the virtual world. You must interface to the generated code using External mode. For example, open the demo vrmaglev and follow these steps.
1. Select Tools->Real-Time Workshop->Options
2. Click on the Interface node.
3. In the Data Exchange section, select External Mode from the pull down menu.
4. Push the OK button.
5. Build the model (CTRL-B).
6. From the model menu, select Simulation->External Mode
7. Type the following at the MATLAB command window
!vrmaglev -w
to start the generated executable. Note the -w option will put the executable into a wait state until the host (Simulink) connects to the code.
8. Open the VR window by double clicking on the VR Sink block.
9. Next, you will connect to the running code by selecting Simulation->Connect to Target
10. Once the target is connected, the Simulink "Play" button should be active. Pushing the "Play" button will cause the generated code to drive the VR animation.