View unanswered posts | View active topics It is currently Thu Oct 23, 2014 4:38 am






Reply to topic  [ 11 posts ] 
accelerometer register layout 
Author Message
Expert

Joined: Sun Aug 19, 2007 2:43 pm
Posts: 138
Location: New Jersey
Post accelerometer register layout
would anyone clarify the reason the "upper"..., vs "lower"... x-y-axis. upper + the lower 2 bits from another address!?

--Elizabeth


Tue Aug 12, 2008 8:54 pm
Profile WWW
Creator
Creator

Joined: Fri Feb 09, 2007 9:21 am
Posts: 615
Post Re: accelerometer register layout
I'm not exactly sure what your question is. You retrieve the acceleration from the sensor via a 6-byte read of the sensor. The first three bytes contain the 8 most significant bits of the three axes and the next three bytes the 2 least significant bits.

That way, if you only need 8-bit accuracy, you only have to look at three bytes.

I encourage you to use ROBOTC version 1.40 or higher which has "native" drivers for many of the HiTechnic and Mindsensors sensors. It makes the supported sensors extremely easy to use in ROBOTC.

The "drivers" are actually a blend of firmware with some ROBOTC helper functions:
  • The firmware looks after continuously polling the sensors with I2C messages to read their data. Which bytes to poll and how many bytes to poll is determined by the type of sensor you configure.
  • The ROBOTC helper functions retrieve the last polled data and "format them intelligently". You need to add the statement #include "AdvancedSensors.c" to your program to make the helper functions available.
As an example, the following function is included in the "AdvancedSensors.c" file and is used to get the acceleration values for the three axis of a acceleration sensor. It shows how to build the 10-bit acceleration values from the 6-byte I2C message reply data.

Code:
void getAccel(const tSensors nSensorIndex, int &nXAxis, int &nYAxis, int &nZAxis)
{
  ubyte nAccelSensorData[6];

  getI2CSensorData(nSensorIndex, sizeof(nAccelSensorData), nAccelSensorData[0]);
  nXAxis   = (nAccelSensorData[0] << 2) | nAccelSensorData[3];
  nYAxis   = (nAccelSensorData[1] << 2) | nAccelSensorData[4];
  nZAxis   = (nAccelSensorData[2] << 2) | nAccelSensorData[5];
  return;
}


For sample code showing how to use the acceleration sensor and the above function, look at the source file for the "Accel.c" Try Me program.


Wed Aug 13, 2008 1:45 am
Profile
Expert

Joined: Sun Aug 19, 2007 2:43 pm
Posts: 138
Location: New Jersey
Post Re: accelerometer register layout
thank you, that's what I understood...creating the 10 bits. My question was indeed silly and vague... Sorry about that. My questions were two-folded:

1) I was confused at first because I was looking at the sample code "HiTechnic Accelerometer.c"
Code:
      xUpper = replyMessage[0];
      yUpper = replyMessage[1];
      zUpper = replyMessage[2];
      xLower = 0xFF & replyMessage[3];// Was "xLower = (int) replyMessage(4);"
      yLower = 0xFF & replyMessage[4];// Was "yLower = (int) replyMessage(5);"
      zLower = 0xFF & replyMessage[5];// Was "zLower = (int) replyMessage(6);"

      xVal = (xUpper << 2) + xLower;  // Was  "xVal = (xUpper << 4) + xLower;"
      yVal = (yUpper << 2) + yLower;  // Was  "yVal = (yUpper << 4) + yLower;"
      zVal = (zUpper << 2) + zLower;  // Was  "zVal = (zUpper << 4) + zLower;"


I didn't understand the point of doing this... "yLower = 0xFF & replyMessage[4];" replyMessage[4] is one byte. I thought I ware missing some significant details I must have missed. Then, I removed and changed it last night to :
Code:
      xUpper = replyMessage[0];
      yUpper = replyMessage[1];
      zUpper = replyMessage[2];

      xVal = (xUpper << 2) | xLower;       
      yVal = (yUpper << 2) | yLower;
      zVal = (zUpper << 2) | zLower; 


So, I guess that sample code probably was some leftover from previously different layout. I should have tested this before I posted such vague question. Sorry about that.

2) I am just curious. I understand that is not something that RobotC can change, or any software. It is the hardware. upper8-bit-x;upper-8bit-y;upper-8bit-z;lower-... instead of upper8-bit-x;lower-8bit(taking the last two bits);upper8-bit-y;lower-8bit(taking the last two bits);...


Wed Aug 13, 2008 7:16 am
Profile WWW
Expert

Joined: Sun Aug 19, 2007 2:43 pm
Posts: 138
Location: New Jersey
Post Re: accelerometer register layout
thank you, that's what I understood...creating the 10 bits. My question was indeed silly and vague... Sorry about that. My questions were two-folded:

1) I was confused at first because I was looking at the sample code "HiTechnic Accelerometer.c"
Code:
      xUpper = replyMessage[0];
      yUpper = replyMessage[1];
      zUpper = replyMessage[2];
      xLower = 0xFF & replyMessage[3];// Was "xLower = (int) replyMessage(4);"
      yLower = 0xFF & replyMessage[4];// Was "yLower = (int) replyMessage(5);"
      zLower = 0xFF & replyMessage[5];// Was "zLower = (int) replyMessage(6);"

      xVal = (xUpper << 2) + xLower;  // Was  "xVal = (xUpper << 4) + xLower;"
      yVal = (yUpper << 2) + yLower;  // Was  "yVal = (yUpper << 4) + yLower;"
      zVal = (zUpper << 2) + zLower;  // Was  "zVal = (zUpper << 4) + zLower;"


I didn't understand the point of doing this... "yLower = 0xFF & replyMessage[4];" replyMessage[4] is one byte. I thought I ware missing some significant details I must have missed. Then, I removed and changed it last night to :
Code:
      xUpper = replyMessage[0];
      yUpper = replyMessage[1];
      zUpper = replyMessage[2];

      xVal = (xUpper << 2) | xLower;       
      yVal = (yUpper << 2) | yLower;
      zVal = (zUpper << 2) | zLower; 


So, I guess that sample code probably was some leftover from previously different layout. I should have tested this before I posted such vague question. Sorry about that.

2) I am just curious. I understand that is not something that RobotC can change, or any software. It is the hardware. upper8-bit-x;upper-8bit-y;upper-8bit-z;lower-... instead of upper8-bit-x;lower-8bit(taking the last two bits);upper8-bit-y;lower-8bit(taking the last two bits);...


Wed Aug 13, 2008 7:16 am
Profile WWW
Expert

Joined: Sun Aug 19, 2007 2:43 pm
Posts: 138
Location: New Jersey
Post Re: accelerometer register layout
Also, what is a good application of using the z-axis with the tilt sensor? My current project is to use it in a steering wheel simulation. Still cannot figure out how to put the z-axis in good use?


Wed Aug 13, 2008 7:20 am
Profile WWW
Creator
Creator

Joined: Fri Feb 09, 2007 9:21 am
Posts: 615
Post Re: accelerometer register layout
Good question -- "How to use the Z-axis"

I've thought that the 3-axis accelerometer would be good for a balancing robot. Perhaps it has a role in whether the robot is balanced and stationary or balanced but moving forward/backward at constant velocity.

It could also ack as a tilt sensor to indicate whether robot is travelling up/down an incline.


Wed Aug 13, 2008 8:56 am
Profile
Expert

Joined: Sun Aug 19, 2007 2:43 pm
Posts: 138
Location: New Jersey
Post Re: accelerometer register layout
i must be missing something... the x-axis will do this... I'm writing data out to a file to see if I can figure out a set of pattern which can help me to figure out a way to use the z-axis.... advice?


Wed Aug 13, 2008 12:10 pm
Profile WWW
Creator
Creator

Joined: Fri Feb 09, 2007 9:21 am
Posts: 615
Post Re: accelerometer register layout
For a balancing robot don't you need two axis to determine the "tilt" and whether it is "forward" or "reverse" tilt?

With a single axis, you can determine the "tilt is XX" but not be able to tell which direction it is??


Wed Aug 13, 2008 1:44 pm
Profile
Expert

Joined: Sun Aug 19, 2007 2:43 pm
Posts: 138
Location: New Jersey
Post Re: accelerometer register layout
x-axis : positive = forward
: negative = backward

No need to worry about the y-axis.

So, leave z-axis unused.


Wed Aug 13, 2008 2:18 pm
Profile WWW
Creator
Creator

Joined: Fri Feb 09, 2007 9:21 am
Posts: 615
Post Re: accelerometer register layout
I was thinking that the Z-axis, pointing straight up, would give the best deviation from balancing.

Using the X-axis blends tilt and actual forward/reverse acceleration.

I'm basing this on most videos I've seen where the balancing robot does not simply stand still. At least not the ones I've seen with LEGO components; I did see a terrific one with a 32-bit DSP running the algorithm. The LEGO balancing robots seem to have a lot of "front - to - back " oscillations as they keep the robot balanced which I thought might disturb the X-axis if used to measure tilt.


Wed Aug 13, 2008 5:36 pm
Profile
Expert

Joined: Sun Aug 19, 2007 2:43 pm
Posts: 138
Location: New Jersey
Post Re: accelerometer register layout
Yea... just using the x-axis is close to impossible. The ones shown in the video clip on youtube, if my recollection serves me right, they use Gyro, not tilt sensor. Since I have about 8 tilt sensors, I want to have my kids play with the tilt sensor to its fullness, not just go to play with the gyro. Since the tilt sensor provides the z-axis, I want to use it if possible.

I'll try it out with both the x and z togother to see it can achieve like those in the youtube videp clip... I think they use gyro sensors.

--E


Wed Aug 13, 2008 9:53 pm
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 11 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.