Architecture - loristissino/RoboThree GitHub Wiki
Basically, there is a world where robots can move. The world is represented and managed by a Three.js web application, with an underlying Physi.js physics simulation engine.
Outside, there are some robots' managers, and each of them manages one or more robots.
When updating a frame, the world makes an HTTP post request to each of the managers, which is implemented as a Node.js command line application.
In this request, the world sends a JSON-formatted array of data containing information needed by the managed robots, and the manager sends a JSON-formatted array of data containing information needed to implement the required behaviors (application controllers).
World
The world is simulated in a web page. From the controls section of the page, you can add one or more robots to it, choosing them from the list of managers.
You can tweak the position and field of view of the main camera and the position and the intensity of the light.
You can add some meshes (boxes and spheres) to the scene.
You can enable and disable the simulation at your will.
Robots
Robots have a representation (how they look like and behave in the simulated world) and an application controller (how they are programmed to behave, how they react to commands, etc.).
The representation code is in the world/representations
directory. Basically, in an object-oriented fashion, a robot contains methods to build its structure (addBody, addWheels, etc.) and a way to update its status (move/stop the wheels, switch the leds on and off, etc.).
The application controller code is in the servers/node/controllers
directory. The code says how the robot is set up, and how it must behave. For instance, when the robot receives a certain signal through the infrared remote control, it should start blinking a led, or activate the wheels.
The code of the application controller is meant to be compatible with the Espruino board. There is a compatibility layer in the files under the servers/node/virtualizers
directory. This layer assures that the input and output that would happen in real conditions (like the distance sensed by the sonars, or the status of the pins associated with the leds) can be managed by the simulation environment.
Managers
Robots managers have the responsibility to collect the information coming from the world (an HTTP post for each frame), pass the relevant piece of information to the single robot's application controller, get the processed output and pass it back to the world.
Simulated Infrared Remote Controls
To simulate the reaction to infrared readings, you can use the simulated remote controls, that are implemented as little web pages. Keep the button pressed, and the page will make a post to the robot's manager, thus updating its status. Simulated remote controls can be used on a different browser, or even on a different device (it's useful to use a smartphone or a tablet, for instance).
Virtual Devices
Robots can have virtual devices, to enable thing that would not be easily done in reality, but could have a didactic value. For instance, a robot can have a pen which is put down and pulled up when needed, a compass to know its orientation, a localizer to know its position in world's coordinates.