Required Skills:
Light Soldering, Programming with virtual com ports and sockets, Critical Thinking
Required Hardware
IMU: http://www.sparkfun.com/products/10736" onclick="window.open(this.href);return false;
Programming and Data Cable: http://www.sparkfun.com/products/9717" onclick="window.open(this.href);return false;
6 pin header for the cable: http://www.sparkfun.com/products/10527" onclick="window.open(this.href);return false; (no soldering) otherwise: http://www.sparkfun.com/products/116" onclick="window.open(this.href);return false;
[EDIT by cybereality: get this instead http://www.sparkfun.com/products/9873" onclick="window.open(this.href);return false; as per this comment http://www.mtbs3d.com/phpBB/viewtopic.p ... 912#p68912" onclick="window.open(this.href);return false; ]
Required Software
Python 2.7.2: http://www.python.org/getit/releases/2.7.2/" onclick="window.open(this.href);return false;
PySerial: http://pyserial.sourceforge.net/" onclick="window.open(this.href);return false;
Code: http://www.varesano.net/projects/hardware/FreeIMU#v0.4" onclick="window.open(this.href);return false; (scroll down to FreeIMU library)
Block Diagram overview:
Sparkfun Razer --[UART]--> Python --[UDP Loopback]--> GMOD lua script
This will get you as far as sending UDP packets to yourself. I don't know how many ppl are interested in GMOD or
lua scripting so I'll leave that part out for now.
1. download and install the freeimu library
2. save and download the .pde code below to your arduino
3. check that you are receiveing UART data using the serial monitor button in the arduino IDE.
4. With pyserial and python installed, close the arduino IDE and run the python program below.
5. Use your own program to catch the packets.
Alternatively, I'm sure libraries exist for other languages that allow you to interface with sockets and COM ports.
I am using python because I like it and the code is really short.
Last thing: In the video, the head tracking is not done through mouse or joystick input. I am directly commanding
the neck joint inside of the game.
I hope that more competent coders than myself will look into GMOD's lua scripting. Joint manipulation down to the finger is possible
and there is example code. I am not skilled with lua scripts and there is little in documentation.
rename it to whatever.pde
Code: Select all
#include <ADXL345.h>
#include <HMC58X3.h>
#include <ITG3200.h>
//#define DEBUG
#include "DebugUtils.h"
#include "FreeIMU.h"
#include "CommunicationUtils.h"
#include <Wire.h>
#define ToRad(x) (x*0.01745329252) // *pi/180
#define ToDeg(x) (x*57.2957795131) // *180/pi
int raw_values[9];
//char str[512];
float ypr[3]; // yaw pitch roll
float val[9];
// Set the FreeIMU object
FreeIMU my3IMU = FreeIMU();
void setup() {
Serial.begin(9600);
Wire.begin();
delay(5);
my3IMU.init(); // the parameter enable or disable fast mode
delay(5);
}
void loop() {
my3IMU.getYawPitchRoll(ypr);
//roll pitch yaw format
Serial.print(ypr[2]);
Serial.print(",");
Serial.print(ypr[1]);
Serial.print(",");
Serial.print(ypr[0]);
Serial.println();
delay(5);
}
rename to whatever.py
Code: Select all
# UDP client example
import socket
import serial
import time
ser = serial.Serial(port='COM14',baudrate=9600, timeout=1)
client_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
port=5003
counter=0
print '---IMU Serial IPC Link---'
time.sleep(3)
try:
while 1:
counter = counter + 1
data = ser.readline()
client_socket.sendto(data, ("localhost",port))
time.sleep(0.020)
if (counter >= 30):
print data
counter = 0
except KeyboardInterrupt:
client_socket.close()
ser.close()
print 'Disconnected...'
client_socket.close()
ser.close()