Daz robot

game
Ambrose Chua 2014-05-26 00:27:36 +08:00
parent fa50e882bc
commit 9e9d8d7263
104 changed files with 11721 additions and 3 deletions

153
Bot_v2_two.ino Normal file
View File

@ -0,0 +1,153 @@
//motor A connected between A01 and A02
//motor B connected between B01 and B02
// http://opensource.org/licenses/mit-license.php
#include <WiFly.h>
#include <SPI.h>
int STBY = 10; //standby
//Motor A
int PWMA = 3; //Speed control
int AIN1 = 9; //Direction
int AIN2 = 8; //Direction
//Motor B
int PWMB = 5; //Speed control
int BIN1 = 11; //Direction
int BIN2 = 12; //Direction
int infoled = 13;
//char ssid[] = "Chua Family";
//char passphrase[] = "chua2680";
WiFlyServer server(44);
String readString = "";
String dir;
void setup(){
Serial.begin(9600);
pinMode(STBY, OUTPUT);
pinMode(PWMA, OUTPUT);
pinMode(AIN1, OUTPUT);
pinMode(AIN2, OUTPUT);
pinMode(PWMB, OUTPUT);
pinMode(BIN1, OUTPUT);
pinMode(BIN2, OUTPUT);
WiFly.setUart(&Serial);
WiFly.begin(true);
// if (!WiFly.join(ssid, passphrase)) {
if (!WiFly.createAdHocNetwork("wifly")) {
while (1) {
// Hang on failure.
digitalWrite(infoled, HIGH);
delay(300);
digitalWrite(infoled, LOW);
delay(500);
}
}
Serial.println(WiFly.ip());
server.begin();
}
void loop() {
WiFlyClient client = server.available();
if (client) {
digitalWrite(infoled, HIGH);
while (client.connected()) {
if (client.available()) {
char c = client.read();
// if (readString.length() < 100) {
// readString += c;
// }
String d = (String) c;
parseanddo(d);
// client.println("LEEEEEEL: " + d);
}
}
// give the web browser time to receive the data
// delay(200);
readString = "";
client.stop();
digitalWrite(infoled, LOW);
}
}
void parseanddo(String incar) {
if (incar == "g") {
move(1, 220, 0);
move(2, 140, 0);
}
else if (incar == "h") {
move(1, 180, 1);
move(2, 180, 1);
}
else {
stop();
}
}
//void blink() {
//
// digitalWrite(infoled, HIGH);
// delay(300);
// digitalWrite(infoled, LOW);
// delay(500);
// digitalWrite(infoled, HIGH);
// delay(300);
// digitalWrite(infoled, LOW);
// delay(500);
// digitalWrite(infoled, HIGH);
// delay(300);
// digitalWrite(infoled, LOW);
// delay(500);
// digitalWrite(infoled, HIGH);
// delay(300);
// digitalWrite(infoled, LOW);
// delay(500);
// digitalWrite(infoled, HIGH);
// delay(300);
// digitalWrite(infoled, LOW);
// delay(500);
//
//}
void move(int motor, int speed, int direction){
//Move specific motor at speed and direction
//motor: 0 for B 1 for A
//speed: 0 is off, and 255 is full speed
//direction: 0 clockwise, 1 counter-clockwise
digitalWrite(STBY, HIGH); //disable standby
boolean inPin1 = LOW;
boolean inPin2 = HIGH;
if(direction == 1){
inPin1 = HIGH;
inPin2 = LOW;
}
if(motor == 1){
digitalWrite(AIN1, inPin1);
digitalWrite(AIN2, inPin2);
analogWrite(PWMA, speed);
}
else{
digitalWrite(BIN1, inPin1);
digitalWrite(BIN2, inPin2);
analogWrite(PWMB, speed);
}
}
void stop(){
//enable standby
digitalWrite(STBY, LOW);
}

View File

@ -1,5 +1,5 @@
# LOL.
# Hi.
Here would be some code for an Arduino-powered, WiFly RN-XV module vehicle (or "bot") with a node-webkit and nodejs fontend.
Some code here is fo ze game version of ze bot, only canz move foard-lefz an backwards.
Nothing here yet, check out the `game` branch, contains code for some game project.
Yo cans mod it 2 make it move normally with wasd by adding more keys, I will do it when I am bored.

35
cli.js Normal file
View File

@ -0,0 +1,35 @@
var net = require("net");
var socket = new net.Socket();
socket.setEncoding("utf8");
process.stdin.setEncoding('utf8');
process.stdin.setRawMode(true);
var soc = socket.connect(44, "169.254.1.1", function () {
soc.on("data", function (data) {
console.log(data);
});
soc.write("g");
soc.write("h");
setTimeout(function () {
soc.write("n");
}, 500);
// soc.write("GET /?dir=w HTTP/1.1");
// soc.write("\n\n");
});
process.stdin.on('data', function(key) {
if (key === "\u0003") {
process.exit();
}
else if (key == "g") {
soc.write("g");
}
else if (key == "h") {
soc.write("h");
}
else {
soc.write("s");
}
});

Binary file not shown.

View File

@ -0,0 +1,46 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>BuildMachineOSBuild</key>
<string>12C3006</string>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleDisplayName</key>
<string>node-webkit Helper EH</string>
<key>CFBundleExecutable</key>
<string>node-webkit Helper EH</string>
<key>CFBundleIdentifier</key>
<string>com.intel.nw.helper.EH</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>node-webkit Helper EH</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>32.0.1700.107</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1700.107</string>
<key>DTSDKBuild</key>
<string>11E52</string>
<key>DTSDKName</key>
<string>macosx10.7</string>
<key>DTXcode</key>
<string>0452</string>
<key>DTXcodeBuild</key>
<string>4G2008a</string>
<key>LSFileQuarantineEnabled</key>
<true/>
<key>LSMinimumSystemVersion</key>
<string>10.6.0</string>
<key>LSUIElement</key>
<string>1</string>
<key>NSSupportsAutomaticGraphicsSwitching</key>
<true/>
<key>SCMRevision</key>
<string>239963</string>
</dict>
</plist>

View File

@ -0,0 +1 @@
APPL????

View File

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleDisplayName</key>
<string>crash_report_sender</string>
<key>CFBundleExecutable</key>
<string>crash_report_sender</string>
<key>CFBundleIconFile</key>
<string>crash_report_sender</string>
<key>CFBundleIdentifier</key>
<string>com.Breakpad.${PRODUCT_NAME:identifier}</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>crash_report_sender</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>LSHasLocalizedDisplayName</key>
<true/>
<key>NSMainNibFile</key>
<string>MainMenu</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
</dict>
</plist>

View File

@ -0,0 +1,46 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>BuildMachineOSBuild</key>
<string>12C3006</string>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleDisplayName</key>
<string>node-webkit Helper NP</string>
<key>CFBundleExecutable</key>
<string>node-webkit Helper NP</string>
<key>CFBundleIdentifier</key>
<string>com.intel.nw.helper.NP</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>node-webkit Helper NP</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>32.0.1700.107</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1700.107</string>
<key>DTSDKBuild</key>
<string>11E52</string>
<key>DTSDKName</key>
<string>macosx10.7</string>
<key>DTXcode</key>
<string>0452</string>
<key>DTXcodeBuild</key>
<string>4G2008a</string>
<key>LSFileQuarantineEnabled</key>
<true/>
<key>LSMinimumSystemVersion</key>
<string>10.6.0</string>
<key>LSUIElement</key>
<string>1</string>
<key>NSSupportsAutomaticGraphicsSwitching</key>
<true/>
<key>SCMRevision</key>
<string>239963</string>
</dict>
</plist>

View File

@ -0,0 +1 @@
APPL????

View File

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleDisplayName</key>
<string>crash_report_sender</string>
<key>CFBundleExecutable</key>
<string>crash_report_sender</string>
<key>CFBundleIconFile</key>
<string>crash_report_sender</string>
<key>CFBundleIdentifier</key>
<string>com.Breakpad.${PRODUCT_NAME:identifier}</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>crash_report_sender</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>LSHasLocalizedDisplayName</key>
<true/>
<key>NSMainNibFile</key>
<string>MainMenu</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
</dict>
</plist>

View File

@ -0,0 +1,46 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>BuildMachineOSBuild</key>
<string>12C3006</string>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleDisplayName</key>
<string>node-webkit Helper</string>
<key>CFBundleExecutable</key>
<string>node-webkit Helper</string>
<key>CFBundleIdentifier</key>
<string>com.intel.nw.helper</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>node-webkit Helper</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>32.0.1700.107</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1700.107</string>
<key>DTSDKBuild</key>
<string>11E52</string>
<key>DTSDKName</key>
<string>macosx10.7</string>
<key>DTXcode</key>
<string>0452</string>
<key>DTXcodeBuild</key>
<string>4G2008a</string>
<key>LSFileQuarantineEnabled</key>
<true/>
<key>LSMinimumSystemVersion</key>
<string>10.6.0</string>
<key>LSUIElement</key>
<string>1</string>
<key>NSSupportsAutomaticGraphicsSwitching</key>
<true/>
<key>SCMRevision</key>
<string>239963</string>
</dict>
</plist>

View File

@ -0,0 +1 @@
APPL????

View File

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleDisplayName</key>
<string>crash_report_sender</string>
<key>CFBundleExecutable</key>
<string>crash_report_sender</string>
<key>CFBundleIconFile</key>
<string>crash_report_sender</string>
<key>CFBundleIdentifier</key>
<string>com.Breakpad.${PRODUCT_NAME:identifier}</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>crash_report_sender</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>LSHasLocalizedDisplayName</key>
<true/>
<key>NSMainNibFile</key>
<string>MainMenu</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
</dict>
</plist>

View File

@ -0,0 +1,74 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>BuildMachineOSBuild</key>
<string>12C3006</string>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleDisplayName</key>
<string>node-webkit</string>
<key>CFBundleExecutable</key>
<string>node-webkit</string>
<key>CFBundleIconFile</key>
<string>nw.icns</string>
<key>CFBundleIdentifier</key>
<string>com.intel.nw</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>node-webkit</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>32.0.1700.107</string>
<key>CFBundleVersion</key>
<string>1700.107</string>
<key>DTSDKBuild</key>
<string>11E52</string>
<key>DTSDKName</key>
<string>macosx10.7</string>
<key>DTXcode</key>
<string>0452</string>
<key>DTXcodeBuild</key>
<string>4G2008a</string>
<key>LSFileQuarantineEnabled</key>
<true/>
<key>LSMinimumSystemVersion</key>
<string>10.6.0</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
<key>NSSupportsAutomaticGraphicsSwitching</key>
<true/>
<key>SCMRevision</key>
<string>239963</string>
<key>UTExportedTypeDeclarations</key>
<array>
<dict>
<key>UTTypeConformsTo</key>
<array>
<string>com.pkware.zip-archive</string>
</array>
<key>UTTypeDescription</key>
<string>node-webkit App</string>
<key>UTTypeIconFile</key>
<string>nw.icns</string>
<key>UTTypeIdentifier</key>
<string>com.intel.nw.app</string>
<key>UTTypeReferenceURL</key>
<string>https://github.com/rogerwang/node-webkit/wiki/How-to-package-and-distribute-your-apps</string>
<key>UTTypeTagSpecification</key>
<dict>
<key>com.apple.ostype</key>
<string>node-webkit</string>
<key>public.filename-extension</key>
<array>
<string>nw</string>
</array>
<key>public.mime-type</key>
<string>application/x-node-webkit-app</string>
</dict>
</dict>
</array>
</dict>
</plist>

Binary file not shown.

View File

@ -0,0 +1 @@
APPL????

View File

@ -0,0 +1,110 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Client</title>
<style>
* {
padding: 0;
margin: 0;
}
body {
background-color: rgb(237, 237, 237);
border-top: 1px solid rgb(105, 105, 105);
text-align: center;
}
.man {
text-align: left;
margin: 0 auto;
width: 520px;
}
</style>
</head>
<body>
<pre class="man">
____ _ _ _
Arduino / ___| (_) ___ _ __ | |_
Bot | | | | |/ _ \ '_ \| __|
| |___| | | __/ | | | |_
\____|_|_|\___|_| |_|\__|
Usage: press "G" to turn
press "H" to move backwards
Goal:
Knock down as many blocks using only two possible
directions: forward-left and backward.
Description:
The bot will start at the start point in a boundary.
Three blocks are in the area, with difficulty 1 to 3,
the third block being the hardest to be accessed by
the bot.
Rules:
* Time limit: 10 minutes
* Not allowed out of the box or you will have a
penalty of one less stamp!
* No physical contact with the bot :)
Tips:
* Do block 1 first.
</pre>
<script src="jquery-2.1.0.min.js"></script>
<script>
var gui = require('nw.gui');
gui.Window.get().showDevTools();
var net = require("net");
var socket = new net.Socket();
socket.setEncoding("utf8");
var keymap;
var soc = socket.connect(44, "169.254.1.1", function () {
soc.on("data", function (data) {
console.log(data);
});
console.log("yay");
$(document).ready(function () {
// $.ajax({
// url: 'keymap.json',
// async: true,
// dataType: 'json',
// success: function (response) {
// keymap = response;
// console.log(keymap);
$(window).on("keydown", function (e) {
if (e.which == 71) {
soc.write("g");
}
else if (e.which == 72) {
soc.write("h");
}
});
$(window).on("keyup", function (e) {
if (e.which == 71) {
soc.write("n");
}
else if (e.which == 72) {
soc.write("n");
}
});
// }
// });
});
});
</script>
</body>
</html>

Some files were not shown because too many files have changed in this diff Show More