This wiki has been archived and made read-only.
For up-to-date information about TkkrLab and it's projects please visit our main website at tkkrlab.nl.

Real robotic rally

From

Revision as of 00:18, 16 January 2013 by Jjstwerff (Talk | contribs) (Arduino protocol)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Short term goals

lego

create a robot from lego for testing the driving

3x  LV 8548 + serie weerstand

robot:
- met tank besturing 3x
- battery pack... 3x ... 
- voor 6 packs aan batterijen en laad stations
- arduino bordje.. tkkrlab
- voeding arduino vanuit 9v -> 3.5 - 5
- 3x serial bluetooth
- 2x serial rgb sensor

breadbord

small breadbord with arduino to test sensors

  • 3 rgb sensors

We need rbs sensors to measure the light that falls on the robot. They can shoot each other, get damage from the environment, get moved by the environment or could win the game by entering the winning spot. Two sensors on top .. facing front/backwards .. one sensor at the bottom to read environment leds

http://www.kingbright.com/product_main_1.php?product01=20070911045707&product02=20070911050100&level=20070911050136&lang=Korea

  • simple laser pointer with relative wide arc of light.. preferred green 532 .. is the best for our rgb sensor

For a range weapon for the robot, no too precise to allow to hit something without exact hitting the sensor. Laser is preferred to allow the game to run under daylight.

  • bluetooth to serial module for programming, with their own id and not needed to point directly at to send it signals

http://dx.com/p/wireless-bluetooth-rs232-ttl-transceiver-module-80711?item=1

  • motor driver electronics.. for better electric performance

We want to run a servo motor for turning and a normal motor to drive.. we could use multiple servos for a walking robot or two motors for tracks.

  • battery pack that can be easily changed
  • optional but cool to have a small smoke generator on every robot for cool effects when hit.

print

create a small form factor print that incorporates the above electronics

admega..     4
bleutooth..  7
rgb-sensor.. 3
motors..     6
driver..     3
battery..    5
         ______
            28

arbiter program

On a laptop that polls the active robots if they have recieved all their programming and sends 'go' to all known robots.

  • credential QR code op de robot = pair with server.. ip / fingerprint / cookie
  • kaarten met QR.. action=23 .. geen uniek per robot wel per kaart.. er zijn al credential

is niet mooi vanwege accept vragen

  • alternatief is robot app die geen vragen stelt en alleen naar zelfde site gaat .. simple http request

programma:

  • stap 1
  • stap 2 .. etc.

checklist

  • 200 gram paper
  • bluetooth modules
  • rgb sensors
  • doorzichtig plastic sheets

already there

  • rgb leds


Arduino meten van rgb

RGB poten: 0 half, 1 lang, 2 half, 3 kort (en platte kant)

RGB led.. langste poot 1 = 5v 0 = R 2 = G 3 = B met alle 3 een 270 OHM weerstand naar poorten.. laag = uit, hoog = aan

RGB sensor: - base 5v - rood A1, groen A0, blauw A2 eerst meten daarna via 1 mega Ohm naar 0v

int vr = 0;
int vg = 0;
int vb = 0;
int c = 0;
int i = 0;
int thr = 25;

void setup() {
  pinMode(9, OUTPUT);  
  pinMode(10, OUTPUT);  
  pinMode(11, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  vr = analogRead(1);
  vg = analogRead(0);
  vb = analogRead(2);
  thr = (vr + vg + vb) / 5 + 12;
  Serial.println(thr);
  vr -= thr * 0.8 + (vb / 4);
  vg -= thr;
  vb -= thr;
  if (vr < 0) vr=0;
  if (vg < 0) vg=0;
  if (vb < 0) vb=0;  
  Serial.print("Read ");
  Serial.print(vr);
  Serial.print(", ");
  Serial.print(vg);
  Serial.print(", ");
  Serial.println(vb);

  int gain = 31; // max 63
  Serial.print("Write ");
  Serial.print((c & 1) * gain * 4);
  Serial.print(", ");
  Serial.print((c & 2) * gain * 2);
  Serial.print(", ");
  Serial.println((c & 4) * gain);
  
 // turn the ledPin on
 
  analogWrite(9, 255 - (c & 1) * gain * 4); // r
  analogWrite(10, 255 - (c & 2) * gain * 2); // g
  analogWrite(11, 255 - (c & 4) * gain); // b
  delay(400);
  if (i > 5) {
    c++;
    i = 0;
  }
  i++;
}


Arduino protocol

Send a 2 token command to the arduino. The arduino will respond with the same command if recognized. It will respond with a lower case version of the same commmand on completion. It is possible to send any command to break the current running command.

#define M1F 9
#define M1R 6
#define M2F 10
#define M2R 11
#define cmds 11

const char* cmd[]= {
    "F1", "F2", "F3", "B1", "L3", "L6", "L9", "R3", "R6", "R9", "S1"
};

int program[cmds][5] = {
    { 3000, 250, 0, 250, 0 }, // Forward F1 
    { 6000, 250, 0, 250, 0 }, // Forward F2
    { 9000, 250, 0, 250, 0 }, // Forward F3
    { 3000, 0, 250, 0, 250 }, // Back B1
    { 600, 255, 0, 0, 255 }, // Left 30 L3
    { 1200, 255, 0, 0, 255 }, // Left 60 L6
    { 1800, 255, 0, 0, 255 }, // Left 90 L9
    { 500, 0, 250, 250, 0 }, // Right 30 R3
    { 1000, 0, 250, 250, 0 }, // Right 60 R6
    { 1500, 0, 250, 250, 0 }, // Right 90 R9
    { 3000, 0, 0, 0, 0 } // Stop
};

void setup() {  
    pinMode(6, OUTPUT);
    pinMode(9, OUTPUT);
    pinMode(10, OUTPUT);
    pinMode(11, OUTPUT);
    Serial.begin(9600);
}

boolean first(char ch) {
    for(int i=0; i < cmds; i++) {
        if (cmd[i][0] == ch)
            return true;
    }
    return false;
}

void doit(int action) {
    int *step = program[action];
    analogWrite(M1F, step[1]);
    analogWrite(M1R, step[2]);
    analogWrite(M2F, step[3]);
    analogWrite(M2R, step[4]);
    boolean stop = false;
    for (int b=0 ; b< step[0] && !stop; b+=100) {
        delay(100);
        while (Serial.available() > 0 && !stop) {
            if (!first(Serial.peek()))
                Serial.read();
            else
                stop = true;
        }
    }
    analogWrite(M1F, 0);
    analogWrite(M1R, 0);
    analogWrite(M2F, 0);
    analogWrite(M2R, 0);
}

void listen() {
    if (Serial.available() > 0) {
        char c1 = Serial.read();
        if (!first(c1))
            return;
        while (Serial.available() == 0)
            delay(50);
        char c2 = Serial.read();
        for(int i=0; i < cmds; i++) {
            if (cmd[i][0] == c1 && cmd[i][1] == c2) {
                Serial.write(c1);
                Serial.write(c2);
                doit(i);
                Serial.write(c1 + 32);
                Serial.write(c2);
            }
        }
    }
}

void loop() {
    listen();
    delay(50);
}

Pair met ubuntu

hcitool dev
hcitool scan
sudo rfcomm bind 2 00:19:5D:EE:A4:0C
cd /usr/share/doc/bluez/examples
./list-devices

commando's geven:
echo "F1" > /dev/rfcomm2