2008-09-28

Robotics - Telemetry

As a hobby project, I build an autonomous LEGO robot controlled by an Arduino Nano with assorted sensors and actuators.

Using a simple radio link between the robot and a PC, I can monitor the current state of the software running on the Arduino.

The radio link is based on the circuits TX433 and RX433 from Velleman. The receiver is connected to the PC with a TTL-232R cable from FTDI. See the image below for the complete circuit layout.



To transmit data from the Arduino, I open the serial link and write tagged data to it.
Serial.begin(4800);

Serial.print("acc:");
Serial.println((long)fwdAcc);
Serial.print("speed:");
Serial.println((long)fwdSpeed);

The various tags and values are collected and displayed by a Processing application on the PC.
import processing.serial.*;

String tty = "/dev/ttyUSB0";
Hashtable data;
Serial port;
PFont font;

void setup() {
size(300, 600);

data = new Hashtable();
port = new Serial(this, tty, 4800);
font = loadFont("Dialog.plain-14.vlw");
textFont(font);
fill(0, 0, 0);
}

void draw() {
background(255);

while (port.available() > 0) {
String line = port.readStringUntil(10);
int pos = 0;
if (line != null &&
(pos = line.indexOf(":")) > 0 &&
pos < 30) {
data.put(line.substring(0, pos+1), line.substring(pos+1));
data.put("time:", "" + hour() + "." + minute() + "." + second());
}
}

int y = 20;
for (Enumeration e = data.keys() ; e.hasMoreElements() ;) {
String key = e.nextElement().toString();
String value = data.get(key).toString();
text(key, 4, y);
text(value, 104, y);
y += 20;
}
}

You need to create the font Dialog.plain-14 in Processing GUI for the program to work. The end result looks something like this.



The time parameter is there to show when the last message was received.

No comments:

Felfri produktutveckling

Skojade bara. När vi konstruerar och tillverkar produkter är det alltid möjligt att göra misstag. Konstruktionen fungerar inte som det var t...