Playing with a robot to learn AJAX, CoffeeScript, and a touch of Node.js.
- Install NodeJS
$ brew install nodejs
- Use the Node Packaged Modules (npm) command to install CoffeeScript
$ npm install -g coffee-script
- Clone the repository
$ git clone https://github.com/bitmakerlabs/mc_hammer_bot.git
- Move to the cloned repo's directory
$ cd mc_hammer_bot
- Install Node Package Modules
$ npm install
- Update your path
$ echo "PATH=/usr/local/share/npm/bin:$PATH" >> ~/.bash_profile;. ~/.bash_profile
For those of you that are having trouble running coffee, while in your project directory enter this:
$ ln -s `pwd`/node_modules/coffee-script/bin/coffee coffee
(This creates a symlink.)
- Click the bluetooth icon on your utilities navbar
- Click "Set Up Bluetooth Device..."
- Click to highlight the "Firefly-CB32" device
- Click "Continue"
- In System Preferences, click "Bluetooth"
- Select the "FireFly-CB32" device
- Click the gear icon in the lower left corner of the window
- In the dropdown, click "Edit Serial Ports..."
- Make sure the device is selected and the checkbox is checked
- Click "Apply"
$ coffee cli.coffee
Note: You may need to type ./coffee
instead of coffee
Keyboard Controls:
- w/s = Forward/Reverse
- a/d = Left/Right
- q/e = Strafe Left/Strafe Right
- x = Stop Motion
$ coffee server.coffee
Note: You may need to type ./coffee
instead of coffee
$ coffee server.coffee --dry-run
Note: You may need to type ./coffee
instead of coffee
The above commands will start the server on "http://localhost:8071" and the two routes available are "http://localhost:8071/motors" and "http://localhost:8071/motion-control".
Motor Explanation --> "http://localhost:8071/motors"
There are 4 motors labeled "a", "s", "d", "f" that have a range of values from -1 to +1.
- "a" represents the back left motor.
- "s" represents the back right motor.
- "d" represents the front left motor.
- "f" represents the front right motor.
Motion Control Explanation --> "http://localhost:8071/motion-control/update"
There are 3 actions: "forward", "turn" and "strafe". They have a range of values from -1 to +1. These actions are interpreted by the server and set the motor values.
A forward value of +1 represents the motor combination: {a: +1, s: +1, d: +1, f: +1}
** Example: ** $.ajax({url: "127.0.0.1:8071/motion-control/update", data: {forward: 1}, dataType: "jsonp"});
A forward value of -1 represents the motor combination: {a: -1, s: -1, d: -1, f: -1}
- A turn value of +1 represents the motor combination: {a: +1, s: -1, d: +1, f: -1}
- A turn value of -1 represents the motor combination: {a: -1, s: +1, d: -1, f: +1}
- A strafe value of +1 represents the motor combination: {a: +1, s: -1, d: -1, f: +1}
- A strafe value of -1 represents the motor combination: {a: -1, s: +1, d: +1, f: -1}
Your assignemnt is to use JavaScript, CSS, HTML to build a user interface that connects to the Mc Hammer Bot using jquery's ajax functions to control the robot via the API outlined above.
-
You will get a chance to control the robot with your code but we will have to take turns. Sign up in the back of the class if you would like to use the robot. Robot control is first come, first serve.
-
You do not need the robot to test out your user interface. The server has a --dry-run option (see above: "To Connect to a mockup / testing bot") which allows you to run it without connecting a robot. This mode is specifically made for testing. Keep an eye on the server's command line output and you will be able to see if it is responding to your requests.
Your interface will be evaluated in two ways:
- We will take up the project on Monday during which time you will have a chance to show off your UI. We want to put those CSS and JS skills to use. More awesome UI's are better.
- You will have the opportunity to control the robot throughout friday and monday (up to the deadline). If you choose to you can use this time to attempt to beat the other Student's best time through a obstical course (the nature of which will be reveiled on friday).
The game pad API can be used to control the robot via one or both of the xbox 360 or PS3 controllers we have available in class. If you are able to control the robot from the keyboard and are looking for a challenge this is one definitely awesome option.
- Install the xbox 360 driver from http://tattiebogle.net/index.php/ProjectRoot/Xbox360Controller/OsxDriver
- Restart your computer when prompted
- Hope for the best
http://people.mozilla.com/~tmielczarek/mouselock+gamepad/
The HTML5 canvas API allows us to draw 2D lines, circles, squares, etc. using javascript easily and with hardware accelleration. You can use it to show where the robot has been and which direction it is (probably) facing.