View unanswered posts | View active topics It is currently Sun Oct 26, 2014 2:30 am






Reply to topic  [ 6 posts ] 
Problem with HiTechnic Acceleration sensor 
Author Message
Rookie

Joined: Sat Mar 31, 2007 6:11 pm
Posts: 3
Post Problem with HiTechnic Acceleration sensor
I've got HiTechnic acceleration sensor. Couldn't find any data on it aside from little paper that came with it saying that different addresses contain lower and upper bits. But still doesn't explain how positive or negative acceleration is denoted. Is the upper most bit a sign value?


Sat Mar 31, 2007 6:15 pm
Profile
Creator
Creator

Joined: Fri Feb 09, 2007 9:21 am
Posts: 615
Post 
To get started with minimal effort, setup the sensor as a standard ultrasonic sensor. That will give you "X" axis values in the range 0 to 255. The following code snipped will give you the signed value.
Code:
//
// Convert unsigned 0..255 to range -512 to +5111 (i.e. signed 10-bits)
//
short nSignedValue ;

nSignedValue = SensorValue[xx]; // 'xx' is the sensor number
nSignedValue <<= 8;
nSignedValue >>= 6;

You'll have to do a bit more "work" to get all three axis. First, you need to write a task that will background poll the sensor for all six-bytes of data and then convert to ten bit values. A sample program that you can simply "#include" in your program should be available soon.


Tue Apr 03, 2007 9:06 am
Profile
Rookie

Joined: Sat Mar 31, 2007 6:11 pm
Posts: 3
Post 
Thanks Dick!

But I actually want to understand the logic behind it all.

Here's what I did (pseudoCode)
[code]

int upperPart = readSensorRegister(42H); //upper 8 bits
int lowerPart = readSensorRegister(45H); //lower 2 bits
if (upperPart>128)
{
//sign is negative
return (-1)*((upperPart-128)<<4 + lowerPart);
} else
{
return (upperPart<<4)+lowerPart;
}
[/code]

The thing is - if I hold a sensor so that it is positive 1g then I get 200
But if I hold it upside dows - I get 300 value.

Is my path above wrong in making 10-digit signed value?


Tue Apr 03, 2007 8:51 pm
Profile
Rookie

Joined: Wed Apr 04, 2007 3:38 pm
Posts: 1
Post 
I found the following to work: Do the addition (with shifting) first. Then decide, if the value is above 511. If this is the case, then subtract 1024. This gives the correct results.


Wed Apr 04, 2007 3:42 pm
Profile
Rookie

Joined: Sat Mar 31, 2007 6:11 pm
Posts: 3
Post 
[quote="eivets"]I found the following to work: Do the addition (with shifting) first. Then decide, if the value is above 511. If this is the case, then subtract 1024. This gives the correct results.[/quote]
Thanks man! This actually works (and makes sense too)!


Fri Apr 06, 2007 8:47 pm
Profile
Creator
Creator

Joined: Fri Feb 09, 2007 9:21 am
Posts: 615
Post 
I posted a more comprehensive reply on the forums at nxtasy.org. DO a search on those forums for "RobotC acceleration". There's also a sample program for the HiTechnic accelerometer on that site.

The sample program -- Nxt Hitechnic Accelerometer.c -- is included in release 1.05 (firmware 7.15) of RobotC for NXT.

Hope this helps.


Sun May 06, 2007 11:43 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 6 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.