View unanswered posts | View active topics It is currently Tue Sep 30, 2014 11:51 am






Reply to topic  [ 6 posts ] 
HiTechnic Accelerometer Sensor 
Author Message
Rookie

Joined: Sat Oct 20, 2007 10:19 am
Posts: 2
Post HiTechnic Accelerometer Sensor
Hi,

I've just been given the new Hitechnic Accelerometer Sensor, and looking at the sample program it all seems very cool, But i'm having problems acutaly using the data from the program. I see that the real values from the sensor are xVal, yVal, zVal, but i dont no how to take that and start feeding it into a function that would say control a motor, to keep a platform at level, or to change a platform to match the level of the sensor, I'm not asking for complete code, just help in the rite direction.

Cheers
Chris


Sat Oct 20, 2007 12:02 pm
Profile
Rookie

Joined: Sat Oct 20, 2007 10:19 am
Posts: 2
Post 
i've got stuff to work now, and using a touch sensor made a very cool joy stick to control a platform.


Sat Oct 20, 2007 4:37 pm
Profile
Creator
Creator

Joined: Fri Feb 09, 2007 9:21 am
Posts: 615
Post 
If you're willing to send me a sample program illustrating the use, I'll add it to the directory of sample files that is distributed with ROBOTC.


Sun Nov 04, 2007 2:00 am
Profile
Expert
User avatar

Joined: Fri Nov 09, 2007 4:51 am
Posts: 121
Location: Hungary, Europe
Post Re: HiTechnic Accelerometer Sensor
Hi Chris,

Try to write a program first that simply displays the accelerometer readings on the display of the NXT, just to see, what information you will have to work with.

Generally, working with accelerometer and gyroscope sensors requires some physics and mathematics knowledge. A self-balancing robot, something like Segway really needs higher mathematics to process the accelerometer and gyro sensor readings to combine them into a reading of the balance.


Fri Nov 09, 2007 4:57 am
Profile
Expert

Joined: Sun Aug 19, 2007 2:43 pm
Posts: 136
Location: New Jersey
Post balance bot
Is it possible to achieve this by just using the accelerometer alone? Idea is greatly appreciated.


Sun Jun 15, 2008 6:41 am
Profile WWW
Rookie

Joined: Fri Apr 20, 2007 3:22 am
Posts: 36
Post 
Well, simply the sensor should read 200 on an axis when it is pointing straight up. The other axis wshould read 0. That reading of 200 is the force of gravity.

It's possible to detrimine the angle that the sensor is relative to that force.

Without going into a lot of explanation the simple way to do it is:

float unitX = ((float)accellX)/200.0;
float angle = acos(unitX);
angle = radiansToDegrees(angle);

where accelX is the reading of the x axis of the sensor. 200 is the force of gravity.

accelX can be changed to an axis you want and you should verify the the reading at level to make sure that it reads 200;

If you just want it to level something here's a simple sample program
(x should read 0 when level)
Code:

#include "accelerometer.h"

task main()
{
accelData accelerometer;
   accelStart(S1);

   while(1)
   {
      readAccel(accelerometer);

      if(accelerometer.x>0)
         motor[motorA]=8;

      if(accelerometer.x<0)
         motor[motorA]=-8;
   }
}


accelerometer.h is

Code:
/*
Hitechnic accelerometer sensor driver

sample:

#include "accelerometer.h"

task main()
{
accelData accellerometer;
   accelStart(S1);

   while(1)
   {
      readAccel(accelerometer);

      nxtDisplayTextLine(1,"x %d",accelerometer.x);
      nxtDisplayTextLine(2,"y %d",accelerometer.y);
      nxtDisplayTextLine(3,"z %d",accelerometer.z);

   }
}

*/

#define accelAddress 0x02

typedef struct{
    byte MsgSize;
    byte DeviceAddress;
    byte LocationPtr;
   }accelBlock;

typedef struct{
   int x;
   int y;
   int z;
   }accelData;

accelBlock accelI2C;
tSensors Accelport;

void accelStart(tSensors port)
{
   Accelport =port;

   accelI2C.MsgSize =2;
   accelI2C.DeviceAddress = accelAddress;
   accelI2C.LocationPtr = 0x42;

   SensorType[Accelport]= sensorI2CCustomFast;
}

void readAccel(accelData &values)
{
   byte rawData[6];

   nI2CBytesReady[Accelport] = 0;

  sendI2CMsg(Accelport, accelI2C.MsgSize, 6);

  while (nI2CStatus[Accelport] == STAT_COMM_PENDING)
     wait1Msec(2);

   if (nI2CStatus[Accelport] == NO_ERR)
   {
      readI2CReply(Accelport, rawData[0], 6);

      values.x =  ( rawData[0] << 2) + (0xFF & rawData[3]);
      values.y =  ( rawData[1] << 2) + (0xFF & rawData[4]);
      values.z =  ( rawData[2] << 2) + (0xFF & rawData[5]);
   }
}



this program will producce a little "head bobbing" but it illustrates the point.

balancing is much more difficult. I've read that it's not possible with a accelerometer alone, you also need a gyroscope. But that may not be true. I think I've seena balancing robot that only used an accelerometer but there wasn't much in the way of details, so it might of had a gyro as well.


Sun Jun 15, 2008 3:46 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.