🔮Adafruit sale all weekend long – use the code ADATHX for 15% off! 🔮
0

Help please--->USB+SNES pad project
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Help please--->USB+SNES pad project

by eduardo on Sun May 23, 2010 5:55 pm

Hi mates!
I´m facing a doubt in this project due to my lack of knowledgment with accelerometers, despite my commitment during the weekend :(
First of all, I must say that I won´t use the SNES pad. Instead, I only want to connect the teensy and the accelerometer adxl335, and put them in a pair of glasses.
The goal is to move the field of view (of a first person shooter game, f.example), moving my head :lol:

So the problem is that in the code available here : http://github.com/adafruit/USBgamepad/b ... _test2.pde
we have this constants for the accelerometer:

Code: Select all | TOGGLE FULL SIZE
//The average zero acceleration values read
//from the accelerometer for each axis:
const int cintZeroXValue = 328;
const int cintZeroYValue = 328;
const int cintZeroZValue = 328;

//The maximum (positive) acceleration values read
//from the accelerometer for each axis:
const int cintMaxXValue = 396;
const int cintMaxYValue = 396;
const int cintMaxZValue = 396;

//The minimum (negative) acceleration values read
//from the accelerometer for each axis:
const int cintMinXValue = 256;
const int cintMinYValue = 256;
const int cintMinZValue = 256;


I think that this values were measured placing the accelerometer in certain positions. For example, I think that the first block (328,328,328) was measured placing the accelerometer horizontally on a table... Am I right?

However using the same accelerometer (adxl335), and placing it on a table I get 302;396 and 327 for x y and z ...I was expecting to get 1024/3=341 for each axis...In addiction the value for the x axis is very unstable, despite having the accelerometer unmovable on the table.

So , what I´m doing wrong ? anyone could help me regarding the calibration positions?

Thanks for all!

Best regards
eduardo
eduardo
 
Posts: 17
Joined: Thu Mar 04, 2010 11:36 am

Re: Help please--->USB+SNES pad project

by charliex on Sun May 23, 2010 7:40 pm

a generic reply, but there's going to be local deviations, noise and slight calibration differences to take into account, and your table probably isn't flat.

but they're average and range values, so it should be the average home position, then the max/min ranges.

so add up a sampled range of home xyz. then divide by the number of samples, and thats a simple average.
http://032.la - Null Space Labs.
charliex
 
Posts: 179
Joined: Sat Nov 28, 2009 5:54 pm
Location: Las Vegas

Re: Help please--->USB+SNES pad project

by eduardo on Mon May 24, 2010 5:53 am

Charliex!
Thanks a lot for your reply. However what I want to know is: in what positions should I place the accelerometer in order to collect the samples?
best regards

eduardo
eduardo
 
Posts: 17
Joined: Thu Mar 04, 2010 11:36 am

Re: Help please--->USB+SNES pad project

by adafruit_support_bill on Mon May 24, 2010 6:06 am

You probably want to put it in what will be the 'neutral' orientation in actual use.

adafruit_support_bill
 
Posts: 79404
Joined: Sat Feb 07, 2009 10:11 am

Re: Help please--->USB+SNES pad project

by eduardo on Mon May 24, 2010 7:19 am

Thanks, btw i will give you an example to clarify my doubt.
First , I want to get the average zero acceleration values read from the accelerometer for each axis.
For this I´m placing the accelerometer horizontally on my table. I did the average of a sample and I got 302, 396 and 327 for x y and z.
Considering that I´m correct in my above assumption, now I want to get the the maximum (positive) acceleration values read
from the accelerometer for each axis, and finally the minimum (negative) acceleration values read from the accelerometer for each axis. The problem is that I don´t know how the accelerometer should be placed to get these values :oops:

Can you help me to go further?

best regards

eduardo
eduardo
 
Posts: 17
Joined: Thu Mar 04, 2010 11:36 am

Re: Help please--->USB+SNES pad project

by adafruit_support_bill on Mon May 24, 2010 7:45 am

The zero values should be from the neutral orientation in actual use. If you are calibrating from a flat tabletop, then you should make sure it is horizontal when mounted in your glasses.

The min and max values should be measured at the expected limits of movement. Using your neutral position(probably head up, eyes straight ahead) as a reference, tilt your head to the positions you want to be full forward, full back, full left & right. Take measurements at these angles and those will be your minimum & maximum.

adafruit_support_bill
 
Posts: 79404
Joined: Sat Feb 07, 2009 10:11 am

Re: Help please--->USB+SNES pad project

by eduardo on Thu Jun 10, 2010 12:57 pm

Hi mates!
Ardwino thanks for your clear reply :D
Today I had a free time and I decided to pick up again this project!
My doubt lies in the equations used in the tutorial to calculate the mouse movement for each axis.
For example for x axis we have:

intMouseXMovement = cintXSign * ( ( ( (float)( 2 * cintMaxMouseMovement ) / ( cintMaxXValue - cintMinXValue ) ) * ( intAnalogXReading - cintMinXValue ) ) - cintMaxMouseMovement );

Where is this equation coming from? I compared this with the motion equation x=x0+v(t-t0), but they´re not similar!
this is the link for the tutorial code :

http://github.com/adafruit/USBgamepad/b ... _test2.pde

Anyone could help me?
In the meanwhile I will continue searching about this :)

Best regards

Eduardo
eduardo
 
Posts: 17
Joined: Thu Mar 04, 2010 11:36 am

Re: Help please--->USB+SNES pad project

by adafruit_support_bill on Thu Jun 10, 2010 1:24 pm

This equation is converting between sensor units and mouse-move units. It helps to break it down:

( intAnalogXReading - cintMinXValue ) subtracts the minimum scale value from the actual reading to get a value relative to the minimum scale (which is not zero for this sensor)

( cintMaxXValue - cintMinXValue ) results an a value representing the range of valid sensor readings

(float)( 2 * cintMaxMouseMovement ) / ( cintMaxXValue - cintMinXValue ) gives you a scaling factor to convert from sensor readings to +/- mouse movements

adafruit_support_bill
 
Posts: 79404
Joined: Sat Feb 07, 2009 10:11 am

Re: Help please--->USB+SNES pad project

by eduardo on Thu Jun 10, 2010 1:36 pm

Hi!
Allright! You´re god!!!! Thanks a lot, and sorry for my lack on maths and electronics :P

Thanks again!
Eduardo
eduardo
 
Posts: 17
Joined: Thu Mar 04, 2010 11:36 am

Please be positive and constructive with your questions and comments.