Setup - loristissino/RoboThree GitHub Wiki

Files

There are three main directories:

  • programs (for simple CLI programs with a high-level interface);
  • servers (containing the code of the robots' managers and the code for the behaviors of robots, aka application controllers);
  • user-agents (containing the code that should be read by a browser, like the simulation environment, the simulated infrared remote controls, etc.).

The application is meant to be a playground. This is why there is a separate directory, examples, containing configuration files, robots' sample behaviors (application controllers) and representations, etc. The examples directory contains three subdirectories, programs, servers and user-agents, having the same structure of the main ones.

In order to let you play with the code and run your own experiments without risking of having your code overwritten with git updates, copy the examples to the main directories, following the directory structure. The simulated infrared remote controls need their own jQuery script and you should copy it from the directory user-agents/world/libs/vendor/.

On Linux (with bash), you can get the whole job easily done with:

cd examples
for file in $(find . -type f); do cp -v  "$file" "../$file"; done
cd ..
cp -v user-agents/world/libs/vendor/jquery-2.1.4.min.js user-agents/remote-controls/

On Windows, use a bash like the one provided by Git for Windows or copy the files manually.

You should get something like this:

.
β”œβ”€β”€ contributors.txt
...
β”œβ”€β”€ programs
β”‚   β”œβ”€β”€ dashed_line.js
β”‚   └── node_modules
β”‚       └── RobotCommander.js
β”œβ”€β”€ README.md
β”œβ”€β”€ servers
β”‚   └── node
β”‚       β”œβ”€β”€ controllers
β”‚       β”‚   β”œβ”€β”€ node_modules
β”‚       β”‚   β”‚   └── HC-SR04.js
β”‚       β”‚   β”‚   └── IRReceiver.js
β”‚       β”‚   └── ThreeWheelDistanceSensingRobotController.js
β”‚       β”œβ”€β”€ managers
β”‚       β”‚   β”œβ”€β”€ node_modules
β”‚       β”‚   β”‚   └── EspruinoSimulator.js
β”‚       β”‚   └── simplemanager.js
β”‚       └── virtualizers
β”‚           β”œβ”€β”€ node_modules
β”‚           └── ThreeWheelDistanceSensingRobotVirtualizer.js
└── user-agents
    β”œβ”€β”€ remote-controls
    β”‚   β”œβ”€β”€ codes
    β”‚   β”‚   └── nexPRO.json
    β”‚   β”œβ”€β”€ infrared.html
    β”‚   β”œβ”€β”€ jquery-2.1.4.min.js
    β”‚   └── parseUri.js
    └── world
        β”œβ”€β”€ assets
        β”‚   └── textures
        β”‚       β”œβ”€β”€ general
        β”‚       β”‚   β”œβ”€β”€ floor-wood-256.png
        β”‚       β”‚   └── floor-wood.jpg
        β”‚       └── robot
        β”‚           └── wheel.png
        β”œβ”€β”€ config
        β”‚   β”œβ”€β”€ defaults.js
        β”‚   └── gui.js
        β”œβ”€β”€ libs
        β”‚   β”œβ”€β”€ robothree
        β”‚   β”‚   └── robothree.js
        β”‚   └── vendor
        β”‚       β”œβ”€β”€ ammo.js
        β”‚       β”œβ”€β”€ chroma.js
        β”‚       β”œβ”€β”€ dat.gui.js
        β”‚       β”œβ”€β”€ jquery-2.1.4.min.js
        β”‚       β”œβ”€β”€ physi.js
        β”‚       β”œβ”€β”€ physijs_worker.js
        β”‚       β”œβ”€β”€ stats.min.js
        β”‚       β”œβ”€β”€ ThreeBSP.js
        β”‚       └── three.min.js
        β”œβ”€β”€ representations
        β”‚   └── ThreeWheelDistanceSensingRobotRepresentation.js
        └── world.html

The file world/config/defaults.js is the place where you can tweak the main configuration of the simulation environment. Edit it at will, but pay attention to IP addresses and port numbers in order to let them match your servers.

Running the robots' managers

You will need a working version of node and npm. Follow the instructions for your OS at nodejs.org. If you use a GNU/Linux distribution, chances are that you already have a packaged version of node (the packages involved could be nodejs and nodejs-legacy, but check the documentation for your distribution and OS version).

To run the servers, you will need the extend module, that you can obtain by typing

npm install extend -g

(you might need to prepend this command with sudo).

Go to the servers/node/managers and run the following command:

node simplemanager.js

You should get an output like:

Activated robot: Β«greenΒ»
Activated robot: Β«redΒ»
Listening on port 9080

If you get an error that reads "Cannot find module 'extend'", you'll need to setup the NODE_PATH environment variable (something like export NODE_PATH=/usr/local/lib/node_modules or export NODE_PATH=/usr/lib/node_modules, depending on how you installed node), or to use the npm link command to link the global-installed modules to the node_modules directories under managers and virtualizers.

You can use a different port, just adding the number as first parameter:

node simplemanager.js 10080

Opening the simulation

The files of the directory user-agents must be served by a webserver. If you have one, configure it so that it offers the files. Otherwise, you can use a light webserver like node http-server. For instance, run

npm install http-server -g   # only the first time
cd user-agents
http-server

On my computer, I get

Starting up http-server, serving ./
Available on:
  http:127.0.0.1:8081
  http:192.168.1.12:8081
Hit CTRL-C to stop the server

Open your browser and point it to the /world/world.html resource.

You should be able to add meshes and robots, to open the simulated infrared remote controls, etc. Just remember that you should activate the simulation to see it action.