(a todo esto, esta en ingles, pero como casi nadie lo va a leer, pues solo me preocupare de poner bien los links para descargarse el software y los videos que es lo que llama la atencion) (el primero es del robotito de lego controlado por un pad, y el segundo es del mismo robot, pero eso si, controlado por un wiimote, que es a lo qeu vamos aqui)
It’s cool if you can control the NXTway-GSrobot using a gamepad as this guy is doing:
[youtube]http://www.youtube.com/v/dIdVl3c7HL8&color1=0xb1b1b1&color2=0xcfcfcf&hl=en&feature=player_embedded&fs=1"></param><param name="allowFullScreen" value="true"></param><embed src="http://www.youtube.com/v/dIdVl3c7HL8&color1=0xb1b1b1&color2=0xcfcfcf&hl=en&feature=player_embedded&fs=1" type="application/x-shockwave-flash" allowfullscreen="true" width="425" height="344">youtube]
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!
<object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/gUzgYcokIF4&color1=0x6699&color2=0x54abd6&hl=en&feature=player_embedded&fs=1"></param><param name="allowFullScreen" value="true"></param><embed src="http://www.youtube.com/v/gUzgYcokIF4&color1=0x6699&color2=0x54abd6&hl=en&feature=player_embedded&fs=1" type="application/x-shockwave-flash" allowfullscreen="true" width="425" height="344"></embed></object>
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!
Fuente: neuro spaghetti
Via: hackawii















