For our Adaptive Control & Reinforcement Learning class, our assignment was to design controllers for a simulated helicopter. However, the visualization was only through MATLAB graphs, which prompted myself and my teammate Joydeep Biswas to create a simple OpenGL helicopter simulation to visualize our controllers. Recently, our professor requested it, so we spent some time making it into a nice little package. We swapped to using Plinth, a 3D game engine developed by two of my friends Pyry Matikainen and Prasanna Velagapudi. NOTE: Plinth requires OpenGL 2.0 and Shader Model 2.0, so most likely you’ll need a decent graphics card. My Thinkpad x201 integrated graphics can handle it, although it seems like a lot of the rendering is done in software and the shadows are a bit wonky.

Our helicopter simulation is very basic, with just a gunship model that spins the blades. It works on Windows, Linux, and Mac. You can set 6-DOF positions for the helicopter from MATLAB or any network interface and record frames to XVID avis.

Instructions

To run the helicopter simulation in download our helicopter simulation zip file (~25 MB).

  1. On Windows, install the Visual C++ 2010 Redistributable.
  2. Run run_XXX for your appropriate architecture (i.e. run_win.bat on Windows) and when prompted, allow access so the firewall doesn’t block communication.
  3. Control of the helicopter is done through MATLAB. Launch MATLAB and run sock = heliConnect(IP, port); where IP is usually ‘localhost’ (if running on the same computer) and port is 12345. You can change the port number the run scripts.
  4. To set the 6-DOF position of the helicopter, call heliSetPosition(sock, [Northing Easting Down], rotation); Rotation can be in Euler angles (i.e. [0, 45, 90]) or quaternions (i.e. [0, 0, 0, 1]).
  5. To set the speed of the rotor blades (to visualize thrust), call heliSetRotorSpeed(sock, speed);
  6. To record the simulation, call heliStartRecord(sock, filename); to begin recording and heliStopRecord(sock); You must stop recording to successfully finish the video (otherwise it’s broken). Since compressing to AVI takes extra time, you might want to insert some MATLAB pause statements to slow down the simulation. For some reason, it seems my laptop doesn’t want to render the shadows or to AVIs, but my desktop does.

Controls

To move the camera angle around in the helicopter visualization, click and drag the left or right mouse buttons. Left mouse controls rotation; right mouse controls pan + zoom. You can also use WASD to move the camera around. To move the camera vertically, use ctrl (down) and space (up). Alternatively, you can set the 6-DOF position of the camera with the MATLAB script heliSetCameraPosition.

A few experimental abilities are available with the F1-F4 keys. F2 turns on motion blurring. F3 turns on a fancier version that renders 10 frames for each frame (so you have to have a good graphics card). F1 and F4 turn off the normal and fancy versions of the motion blurring, respectively.

Internals

Plinth uses Horde3D combined with Lua scripts for most of the heavy lifting. Edit game\testmaster.lua if you want to modify the helicopter visualization. Most things can be done through that one Lua script. One of the great things about Plinth is you can use Putty to telnet and execute custom Lua commands. This is how MATLAB is able to communicate and control the simulation. See plinth.bat and the assorted MATLAB scripts to find out more about how the socket communication works. It’s pretty simple, except make sure to whitelist the connecting IP in Plinth.bat before trying to connect.

If an error occurs, check the log files log.txt and Horde3D_Log.html.

Shadow Woes

On integrated graphics, shadows seem to act up. Thus, if you experience problems with weird shadows, you can disable them by changing ShadowMapCountI from 3 to 0 in game\testmaster.lua. So line 42 should read:

h3d:SetNodeParamI(self.light, h3d.H3DLight.ShadowMapCountI, 0)

Swapping Out Graphics

The current visualization is themed on an ice plain with a sunset, however this might not be for everybody. Plinth can swap out models and textures. Another possible configuration already in the simulation is the thunderstorms + rocks visualization. You just need to rename two folders and a file in the zip file. Rename textures\ambientMap_thunderstorm.dds to textures\ambientMap.dds, and models\skybox_thunderstorms to models\skybox, and textures\models_rocks to textures\models. That should turn the visualization to the one on the right. Further customizations can be made in game\testmaster.lua..

Linux/Mac Support

We provide Mac and Linux (x86 and x64) binaries and run shell scripts. It isn’t well tested, but seems to work.

Youtube Video

This was part of our assignment report where the helicopter simulation was the old version.

http://code.google.com/p/plinth-engine/