Location : ubic/projects/monkey3d
Monkey3D | Screenshots | Editor | Engine | Engine commands | Local stimulation | Remote stimulation | Contact

Remote stimulation


General informations

If you run the engine by choosing "Remote" Stimulation, the display can then be stimulated via a TCP/IP connection.
All commands have to be sent in the Java modified UTF format (see javadoc for details).

Available commands : here

Some remote stimulation notes :

  • Works synchronously, the server will not listen to any further commands unless the current command is finished.
  • Each command sent by the client is guaranteed to be executed.
  • When a command is received, it is not guaranteed to be processed immediately, however commands are challenged to be executed (and the result being seen) at each frame.
  • Delay calculation :
    • min delay = network delay + command processing delay
    • max delay = 1/fps + network delay + command processing delay
    • Note that the delay may vary all the time since network delay, fps and command processing delay may not be constant.
    Example : 75 average FPS, network average delay = 2 ms, command processing average delay = 1 ms
    • min delay = 2 + 1 = 3 ms
    • max delay = 1/75 + 2 + 1 = 16 ms
Note : you may want to use the limit FPS feature for debugging purpose : with this option activated, you can voluntary slow the fps rate and also slow the whole engine.

Note : if you pause the engine (pressing 'p' on the keyboard), the engine will not process further commands nor do anything until you unpause it.
While the engine is paused, the client may be blocked also until pause is released.

Matlab specific

Place remote commands into a quoted string parameter of the send() function defined in send.m.
Example :

send('move x 0 y 5 during 1000');
When sending commands via Matlab, it is a good idea to put a semicolon ';' at the end of the send() function in order to avoid a standard output printing that would massively slow everything.

Building commands

Important : Don't use Matlab strcat function when building command parameters (this command trims bounding whitespaces.
Use the Matlab square bracket string concatenation instead.
Example (assuming i=5) :

NOT WORKING, produces 'move x5' because strcat trims bounding whitespaces :
send(strcat('move x ', num2str(i)));

WORKING, produces 'move x 5' because square bracket concatenation doesn't trim bounding whitespace :
send(['move x ' num2str(i)]);

Files

See the Mathab M scripts in the "matlab" dir located in the Monkey3D folder.

Each M file contains one function having the same name as the M file :

  • init.m : contains the server adress and port, please edit it before doing anything else
  • connect.m : contains the connect() function that connects to the server
  • disconnect.m : contains the disconnect() function that disconnects from the server
  • send.m : contains the send() function that sends a command to the server

The matlab/demo directory contains some demo scripts :

  • reward_N_start_S.m : this is a full example, simply open the M file in the workspace, then type reward_N_start_S and use the keyboard
  • image_demo.m : illustrates how to use the image command and what is the difference between a synchronous and an asynchronous command
  • alteration.m : illustrates the powerfull set command
  • creation.m : illustrates the powerfull set, create, remove and save commands
  • starwars.m : a super tie fighter demo, better experienced in stereo !
  • Script example

    function example()
    
      %initializes global parameters (ie : server, port, etc...)
      init();
    
      %connect to Monkey3D server (be sure to have it running in remote mode)
      connect();
      
      %ensure the engine is reseted (also automatically done when loading a scene)
      send('reset');
      
      %create a sphere
      send('add sphere mysphere');
      
      %move backward
      send('move z 10');
      
      %alter the sphere color
      send('set mysphere.material red');  
      
      %save the scene
      send('save supercalifragilisticexpialidocious.xml');
      
      %disconnect from the Monkey3D server
      disconnect();