Jedi-Con 2010

Photos from the R2 builders meet:

Posted in Uncategorized | Leave a comment

Reading serial data from MaxBotix range finders with an Arduino

I have bought a couple of MaxBotix EZ3 ultrasound range finders for my droid, to use for collision avoidance and mapping. Those things have very nice range (15cm to 6,5m), and they’re very small. They also offer several ways to get at their range data: via voltage (0-5V), via a PWM signal, and via a serial connection at 9600bps. I’ve chosen serial because it’s less susceptible to noise than voltage.

However, the serial connection that the MaxBotix sensors use is a weird beast: It’s TTL-like in that voltage levels are 0 and VCC, but it’s RS232-like in that a low voltage level corresponds to a logical one and a high voltage level to a logical 0. Therefore, the Arduino’s hardware serial connection or SoftwareSerial aren’t usable. So I’ve written my own implementation of RS232-at-TTL-level based on Arduino’s SoftwareSerial code, and it works great.

Here’s the code in the hope that someone might find it useful:

/*
* USTest - test program for Ultrasound rangers of the Maxbotix EZ range
*
* This uses serial communication for noise-free transfer. Since the Maxbotix
* sensors use RS232 logic but TTL levels, I had to write my own implementation
* of serial communications, which borrows from Arduino's SoftwareSerial code.
*/

#define PIN_USTX 25
#define PIN_USBW 24
#define PIN_SERIAL 15

void setup() {
Serial.begin(115200);
pinMode(PIN_USTX, OUTPUT);
pinMode(PIN_USBW, OUTPUT);
pinMode(PIN_SERIAL, INPUT);
digitalWrite(PIN_USBW, 1);
digitalWrite(PIN_USTX, 0);
}

int bitPeriod = 1000000/9600;

int read() {
char buf[6];
buf[5] = 0;
for(int i=0; i<5; i++) {
int val = 0;
int bitDelay = bitPeriod - clockCyclesToMicroseconds(50);
while(digitalRead(PIN_SERIAL) == LOW);

if(digitalRead(PIN_SERIAL) == HIGH) {
delayMicroseconds(bitDelay/2 - clockCyclesToMicroseconds(50));
for(int offset = 0; offset < 8; offset++) {
delayMicroseconds(bitDelay);
int pinval = digitalRead(PIN_SERIAL);
if(pinval == LOW) val |= 1 << offset;
}
}

buf[i] = val;
delayMicroseconds(bitPeriod);
}

if(buf[0] != 'R' || buf[4] != 13) return -1;
buf[4] = 0;
return atoi(&(buf[1]));
}

void loop() {
int val;

// command ranging (pull TX pin up)
digitalWrite(PIN_USTX, 1);
delayMicroseconds(30);
digitalWrite(PIN_USTX, 0);

// wait >40ms for measurement and processing
delay(50);

// command output over serial and read
digitalWrite(PIN_USBW, 0);
int val = read();
digitalWrite(PIN_USBW, 1);

Serial.print("Range: "); Serial.println(val);

delay(100);
}

Posted in Astromech, Development | 7 Comments

Auto-transcoding videos for PS3

First of all, I’m back from vacation. Happy new year everyone, and sorry for the piled-up unapproved comments. I had no Internet in Switzerland. Can you believe that? In 3 weeks of Vietnam, there was no place that didn’t have free Wifi, but in Switzerland, there was no place that did. Eat that, western world!

What’s new? Ilka gave me a PlayStation 3 for Christmas! Yay! Which gave me an excuse to look at my home theater system again. I have a G4 Mac mini which serves these websites and also acts as a NAS server.

What I’d like is to stream video from the Mac to the PS3. There are plenty of UPnP media servers that run on the Mac, first of all PS3 Media Server. The problem is the dearth of good codecs on the PS3, meaning that you can stream for example MKVs very well, only the PS3 can’t play them. Ironically, PS3 Media Server can even re-encode the files on the fly into something the PS3 can play, but that requires a Windows PC or an Intel Mac or a very very very fast PPC Mac. All of which I don’t have.

So what I did is hack up a small Python script that will solve the problem for me. Basically, what it does is synchronize two directory hierarchies so that hierarchy 2 (DSTDIR) as the slave is maintained as a mirror image of hierarchy 1 (SRCDIR) as the master. But where a true master-slave sync would create copies of the files in the master, this script runs shell commands which:

  • if the master file is not something the PS3 can play, re-encode it into something playable
  • if the master file is something the PS3 can play, just link it.

The result, from a usability point of view:

  • I dump my files into SRCDIR or remove them from there if I no longer want them
  • I publish DSTDIR to the PS3
  • The script makes sure DSTDIR contains everything from SRCDIR in a playable format, but not more.

Right now, I’ve only tried the script with a number of MKVs (which can’t be played) and DivX AVIs (which can), and it seems to work great. I’m putting it up here for download in case anyone wants a look.

Note that I’m not supporting this script and it deletes files. That is part of its purpose, and it’s very well possible that it contains bugs which cause it to delete more than it should. It seems reasonably well-behaved here, but you’re warned. If anyone can make use of this thing, I’d be happy to hear about your experiences, though!

Posted in Uncategorized | 1 Comment

Compiling OpenSceneGraph 2.8.2 on Snow Leopard

…on the other hand, OpenSceneGraph 2.8.2 wants to be compiled by Makefile, not by Xcode, or else its plugins won’t load… oh well. Strangeness.

Frankly, ten years ago I would have taken the time to see why the heck it will work with one toolchain and not with the other. Nowadays, I just try a couple of different ways to do it, am happy if I get it right and just abandon it if I don’t, because I just don’t have enough free time anymore to {waste on|invest in} stuff like that. Sad, in a way.

Posted in Development, Mac | Leave a comment

Compiling OpenCV 2.0 on Snow Leopard

Just a quick info-push to the net. I’ve tried for a while to compile OpenCV 2.0 on Snow Leopard, which always failed with problems in Carbon and Quicktime support of highgui, like so:

opencv/src/highgui/window_carbon.cpp: In function ‘void icvDrawImage(CvWindow*)’:
opencv/src/highgui/window_carbon.cpp:222: error: ‘GetWindowPortBounds’ was not declared in this scope
opencv/src/highgui/window_carbon.cpp:238: error: ‘SetPortWindowPort’ was not declared in this scope

This was using CMake to generate Unix Makefiles to build OpenCV. The solution is simple: Just build it via Xcode! Using

ccmake -G Xcode

on the command line, you can create Xcode project files that will work just fine with Xcode 3.2.

I’ve put an installer here. Requires Snow Leopard and installs to /usr.

[Edit] Of course, this builds for x386 architecture and not x86_64, i.e. the libraries you get are 32bit. This is necessary because Carbon is 32bit. If you need 64bit, you’re out of luck with Carbon.
[Edit] This means you have to add “-arch i386″ to your compile flags.

Posted in Development, Mac | 40 Comments

Moving! and first sensors

I’ve been posting my main updates over at Astromech.net for a while, so just a quick update here. I’m about 2/3rd finished with working on my droid’s feet, and even did a couple of simple driving tests — some successful, some not so much. :-)

(My droid is OK again; I’ve made him much more stable since.)

Today I’ve finally finished one of the main feet. Looking good so far! I’ve put in two Sharp IR distance sensors (GP2D120, range 4cm to 30cm) that will eventually be used as stairway / pothole detectors so my droid doesn’t accidentally go down stairs. A couple of pictures to finish up:

Posted in Astromech | 5 Comments

Main Ankles Progress

It’s Saturday evening, I have the whole Sunday off for building, the hobby store where I buy glue is closed, and I’ve run out of glue!!!! Damnit! ;-)

Oh well, I’ll post an update anyway. My short sabbatical is finished, and I’m almost done with the main ankles. One is finished, the other one is 75% done. My plan was to get both of them and the weight-bearing parts of the main foot done by Monday, until the glue disaster struck. Now I’m happy if I get them done by Tuesday night. Note to self: Always keep some spare glue.

Building the main ankles was surprisingly easy and fast. The photos below show the parts for one ankle and a build in progress. I’ve found some minor glitches in Dave Everett’s plans. The MAIS parts are in the plans, but they’re not mentioned in the instructions. The photo to the right shows where they go: They must be glued to the inside of the MAS parts (MAS = main ankle side, MAIS = main ankle inner side?). Also, the two parts named MAP overlap a couple mm in the plans. No big deal, I measured them and cut them appropriately.

  

The bushings Dave uses / recommends (steel bushings, outer diameter 12mm, inner diameter 10mm) weren’t available locally, so I took a 12mm Aluminium tube and cut it. This gives a nice Aluminium bushing, maybe not as durable as steel but I’m sure it will do. I was about to write “if it goes, I’ll just take it out and replace it”, but I had to push it in forcefully with a clamp, as you can see below. It fits great, but that thing isn’t coming out of that hole ever.


  

So, R2 is coming along nicely. Next up, as I wrote above, are the weight-bearing parts of the center foot and the main feet. I’m going to deviate from Dave’s plans a bit for the drive system, so I’m not going to finish the feet at first but rather prototype them and see how far I come. I’ve ordered an Arduino Mega with Lady Ada’s motor shield and a very nice color LCD shield from a German dealer, will order the motors next week, and I already have two old HP printers here that will get ripped apart for their very nice rotary encoders. More on that later.


   

Posted in Astromech | Leave a comment

Center Ankle done

I finished my center ankle today. This, again, took way longer than I thought, which is mostly due to the curved 1mm parts which I never seem to get quite right. I had to redo them twice and even then they needed a lot of filing. Also, two of the curved parts are not round but elliptical — you can’t route these but have to cut them by hand. That was actually easier than I thought, see the pic below.

Nonetheless, this is the first part that I’m really happy with. It looks good, I think; when it’s painted, it’s not going to look very different from a solid aluminium part. I filed and sanded a lot to get all the edges slightly rounded, which hides the glued edges. I like it. It’s also a very heavy part, almost weighs as much as solid aluminium, so it might as well look the part :-)

I’m going to take a two-week sabbatical from droid building, since I have two music gigs coming up and some things to prepare for a friend’s wedding. After that, it’s on to the main ankles and the feet. I can’t wait to have the thing driving!

Posted in Astromech | Leave a comment

Shoulder Hubs and Arms work in progress

Just a short update to show my arms and shoulder hubs. Arislan has detailed the process very nicely in his blog so I don’t have to :-)

The arms aren’t fully skinned yet, I think I’ll do that tomorrow. Then I’m going to take a short breather after working on the droid almost every day for two weeks now. But I’ll start with the ankles soon enough.

Posted in Astromech | 4 Comments

Club member :-)

Chris (http://www.artoo-detoo.net) has added my blog to the builders’ blog RSS feed. I guess that means I’m officially a club member now. I feel honored.

Posted in Astromech | 5 Comments