Archive for April, 2009

WiiNxtBalance

Tuesday, April 21st, 2009

It’s cool if you can control the NXTway-GS robot using a gamepad as this guy is doing:

But since we are Wii addicted I’m going to teach you how to use the wiimote!
Follow the tutorial and you willl be driving the balancer (and eventually crash it :-) ) like a cowboy!

What you need:

  • lego NXT with OSEK firmware and the NXTway-gs program loaded
  • a wiimote of course
  • ubuntu and python with bluetooth modules
  • rfcomm,pybluez and pyserial
  • a python script to parse the wiimote data and send it to the lego nxt

First step is to install the nxtOsek firmware: instructions here. In the directory samples/nxtway_gs there’s the code for the balancing functions. I did a patch of the program to be controlled by the wiimote via bluetooth. You can download the code from here (already compiled).

The second step is to connect your NXT to your laptop via bluetooth and rfcomm -many thanx to Linus to helped me out with this problem!-, this script will help you to do it very easily btconnect).

#!/bin/bash

# script to ease connecting to an NXT brick
# (c) 2007 Johannes Ballé

# call either with a Bluetooth address or device name

if echo $* | grep -q ‘^..:..:..:..:..:..$’; then
MAC=$*
else
echo -n “Scanning for ‘$*’ … ” >&2
MAC=$( hcitool scan | grep ‘^    ..:..:..:..:..:..    ‘”$* *$” | cut -f 2 )
if [ -z $MAC ]; then
echo “not found.” >&2
exit 1
fi
if echo $MAC | grep -q ” “; then
echo “found multiple devices:” >&2
echo >&2
for i in $MAC; do
echo ‘    ‘$i >&2
done
echo >&2
echo “Use ${0##*/} with one of the addresses above.” >&2
exit 2
fi
echo “found $MAC.” >&2
fi

rfcomm -r connect rfcomm0 $MAC &

trap “kill $!” 1 3 9 15
wait

If the connection is going on well you should see this:

epokh@epokh-laptop:~/Documents/lego nxt$ sh btconnect.sh “NXT”
Scanning for ‘NXT’ … found 00:16:53:0A:8B:E4.
Connected /dev/rfcomm0 to 00:16:53:0A:8B:E4 on channel 1
Press CTRL-C for hangup

And the bluetooth-applet should ask for the passkey “1234″.

The last step is to run the wiimotenxt control script to interface your wiimote. Look for your wiimtoe address using:

hcitool scan

Then modifiy the script in the main function with the address you found:

w=Wiimote(”00:1E:35:DF:C5:75″,0)

Then run the script as:

epokh@epokh-laptop:~/wiimote$ python Wiimote.py
Attaching to Wiimote #1 at 00:1E:35:DF:C5:75
setled(0)
_send_command(0×52,0×11,[16])
opening serial port…
Enabling accelerometer.
_send_command(0×52,0×12,[0, 49])
_send_command(0×52,0×17,[0, 0, 0, 22, 0, 10])
Leaving _waitforpacket() after 2 packets
Got force calibration data: zero=[127, 128, 128], 1g=[152, 153, 153]
Receiving data from Wiimote #1

You can switch the control mode pressing B (’the rear button’). You can control either by the buttons either using the acceleration. The script corrects the gravity to give a better motion control.

Enjoy!

Control your spykee with fingers

Monday, April 13th, 2009

Today I want to show you how to control your Spykee using your finger movements.

What you need:

A webcam

Spykee Erector on Amazon right now is only £ 148 .

RoboRealm a software with visual and contro plugins.

A green tape to wrap around your fingers.

I wrote a simple cascade filter which:

  • filter from RGB only green channel with proper hue and saturation,
    you need to tune this according to your camera parameters
  • run a median filter
  • track the 2 biggest squared blobs on the left and right side
  • build a simple visual panel to identify your blobs
  • transform the coordinates of the blobs to motor commands
  • send the motor commands over wireless to spykee

You can download the code here:
RoboRealm module

I made some simple videos on how it works:

Because I have only 1 camera I tried to mix a video with the control tracking and the Spykee camera.
This is what I get, I’ll try to borrow another camera to make a better video soon.
Enjoy!

Cheap Head Tracking

Saturday, April 4th, 2009

I did a very simple lasr cut PVC frame where you can place your infrared LEDS.

It’s a simple 3 point model cap as the lego one:

You just need:

  1. wires
  2. 1 switch
  3. 2 AA batteries
  4. 3 IrLEDS (I used 100mA ones)
  5. any support (I used mine)

If you are lazy to make one you can buy one from my website:

http://shop.robomotic.com/

To find other distributors go here:

http://www.pixelpartner.de/openKMQen.htm

Lego Head Tracking

Thursday, April 2nd, 2009

Do you have a lego mindstorm NXT?
Do you want to play videogames using optical motion tracking?
This the idea I just had yesterday when playing with my robots.

What you need:

  • 3 lego nxt light sensors
  • 3 lego nxt cables
  • lego nxt core
  • a webcam which doesn’t have an IR optical filter OR a nintendo wiimote
  • a floppy disk
  • free-track software for windows

How it works:

the lego light sensors emits light in the visible and infra red spectrum
this 3 beams are captured by your camera
the coordinates of the 3 dots are used by the software free-track to estimate the player position
the head position is used in the game to look around

How to build it:

I used a 3 point cap model: build a triangle structure as in figure 1. I did it in such a way that you can attach it to a sport cap.

If your camera has ann IR filter you are in big trouble but you can still remove it as described here.
If you have a camera without an IR filter you are very lucky: open a floppy disk and remove the magnetic disk. Cut it and pose it in front of the camera lens as in figure 2.

Measure the distances as in figure 3 and insert them in the free-track configuration.

The Free-Track configuration can be downloaded from Free-Track configuration to use with Lego Head Tracker.

Write a simple program for the lego nxt that switches on and off the sensors when the user hold down the contact sensor. The simple program in NXT-G can be downloaded from Lego Nxt program

You can also use RoboRealm to track them:

The RoboRealm configuration file is Robo Realm script file.
And now enjoy your game!

If you are lazy to make one you can buy one from my website:

http://shop.robomotic.com/

To find other distributors go here:

http://www.pixelpartner.de/openKMQen.htm