Go Down

Topic: sketching to read 3 dof IMU combo board (Read 1 time) previous topic - next topic

dafid

Your sensor module seems a bit strange to me.
It adjusts readings relative to the first position of the board.
And then it adjusts the X readings by 205?

So the values displayed can not be interpreted without knowing the initial position.
And the X values require mental arithmetic after that.

Do have a reason for this?

Code: [Select]

// Sensors Module  ---------------------------------------------------------------------

/* dafid - this is called in the setup() and calculates a 'zero' value that is used to adjust
subsequent readings.
*/
void calibrateSensors() {                                       // Set zero sensor values
  long v;
  for(int n=0; n<3; n++) {
    v = 0;
    for(int i=0; i<50; i++)       v += readSensor(n);
    sensorZero[n] = v/50;
  }
/* dafid - except the X axis is specially offset by 205.
      I do not understand why you do this at all.
*/                                                         
  sensorZero[ACC_X] -= 205;                       
}

void updateSensors() {                                         // data acquisition
  long v;
  for(int n=0; n<3; n++) {
    v = 0;
    for(int i=0; i<5; i++)       v += readSensor(n);
    sensorValue[n] = v/5 - sensorZero[n];
  }
}

tejasinamdar

The link I gave in the first post actually set this value to 102 and the reasoning given for that on the link is as follows:
For ADXL330/335: 1g = 330 mV (+- 10%)
ACC_Z correction for 10 bit ADC and 3.3V AREF: 330/3300*1024 = 102 (to be fine tuned later on)

Based on a logic I quite don't understand myself, I decided to give a try based on my own sensors. So,
For ADXL203: 1g = 1000 mV (+- 10%)
ACC_Z correction for 10 bit ADC and 5V AREF: 1000/5000*1024 = approximately 205 (to be fine tuned later on)

I really have no idea, about the inside workings of the code. I was hoping you could help me out over there. I am following the link and its code and modifying the code where I deem necessary.

Hope that made a little bit of sense.
Come to think of it I might have possibly realized the answer to my last question. as to Why the x axis sign does not change? Based on my reasoning the trignometrically one of the orthogonal axes do not change sign if rotated about the origin in the 1st and 2nd quadrants. And this axes should be the one facing vertically upwards .ie x axis in my case. So the X axis should not change sign... but it is... and Y axis should change sign but it isn't...

thanks..

dafid

Given your explanation above.. the sensorZero stuff is just confusing you and every one else.

I recommend you remove it until you find a reason for it.

And then you could display the value sensed as a simple integer...

I understand that the sensor reads 0g of acceleration as 2.5 V and varies that by 1V for each g.

So you might expect to see 2.5 v on two and either 1.5 or 3.5v on the other.

ie 512, 512, and 307 or 723.

As you say, the orientation of the sensor would determine which reading is which value.


hitmitsu

@tejasinamda : I get the values alr .. the same codes as u
Code: [Select]
// Main module   K_bot               angles in Quids, 10 bit ADC  -------------
// 4 - Checking sensor data format    display raw sensors data           

#include <math.h>

#define   GYR_Z                 2                              // Gyro Z (IMU pin #7)
#define   ACC_X                 0                              // Acc  X (IMU pin #1)
#define   ACC_Y                 1                              // Acc  Y (IMU pin #2)

int   STD_LOOP_TIME  =          9;           

int sensorValue[3]  = { 0, 0, 0};
int sensorZero[3]   = { 0, 0, 0};
int lastLoopTime = STD_LOOP_TIME;
int lastLoopUsefulTime = STD_LOOP_TIME;
unsigned long loopStartTime = 0;


void setup() {
  analogReference(DEFAULT);                                   // Aref 5V
  Serial.begin(115200);
  delay(100);                                               
  calibrateSensors();
}

void loop() {
// ********************* Sensor aquisition & filtering *******************
  updateSensors();
 
// ********************* print Debug info *************************************
  serialOut_raw();

// *********************** loop timing control **************************
  lastLoopUsefulTime = millis()-loopStartTime;
  if(lastLoopUsefulTime<STD_LOOP_TIME)         delay(STD_LOOP_TIME-lastLoopUsefulTime);
  lastLoopTime = millis() - loopStartTime;
  loopStartTime = millis();
}

void serialOut_raw() {
static int skip=0;
  if(skip++==40) {                                                       
    skip = 0;
    Serial.print("ACC_X:");           Serial.print(sensorValue[ACC_X]);         
    Serial.print("  ACC_Y:");         Serial.print(sensorValue[ACC_Y]);
    Serial.print("  GYR_Z:");         Serial.println(sensorValue[GYR_Z]);
  }
}

// Sensors Module  ---------------------------------------------------------------------

void calibrateSensors() {                                       // Set zero sensor values
  long v;
  for(int n=0; n<3; n++) {
    v = 0;
    for(int i=0; i<50; i++)       v += readSensor(n);
    sensorZero[n] = v/50;
  }                                                         
  sensorZero[ACC_X] -= 103;                       
}

void updateSensors() {                                         // data acquisition
  long v;
  for(int n=0; n<3; n++) {
    v = 0;
    for(int i=0; i<5; i++)       v += readSensor(n);
    sensorValue[n] = v/5 - sensorZero[n];
  }
}

int readSensor(int channel){
  return (analogRead(channel));
}


I am using Arduino ProMini + IMU Combo Board and i get this values


ACC_X:102  ACC_Y:0  GYR_Z:1
ACC_X:103  ACC_Y:0  GYR_Z:-2
ACC_X:102  ACC_Y:0  GYR_Z:1
ACC_X:103  ACC_Y:0  GYR_Z:2
ACC_X:103  ACC_Y:0  GYR_Z:1
ACC_X:103  ACC_Y:0  GYR_Z:0
ACC_X:102  ACC_Y:0  GYR_Z:0
ACC_X:102  ACC_Y:0  GYR_Z:2
ACC_X:102  ACC_Y:0  GYR_Z:2
ACC_X:102  ACC_Y:0  GYR_Z:-1
ACC_X:102  ACC_Y:-1  GYR_Z:4
ACC_X:103  ACC_Y:0  GYR_Z:1
ACC_X:103  ACC_Y:0  GYR_Z:-1
ACC_X:103  ACC_Y:0  GYR_Z:0
ACC_X:103  ACC_Y:0  GYR_Z:-1
ACC_X:103  ACC_Y:0  GYR_Z:2
ACC_X:103  ACC_Y:0  GYR_Z:-1
ACC_X:103  ACC_Y:1  GYR_Z:2
ACC_X:102  ACC_Y:0  GYR_Z:-2
ACC_X:102  ACC_Y:0  GYR_Z:-1
ACC_X:103  ACC_Y:1  GYR_Z:1
ACC_X:102  ACC_Y:0  GYR_Z:-3
ACC_X:102  ACC_Y:0  GYR_Z:1
ACC_X:102  ACC_Y:1  GYR_Z:-3
ACC_X:102  ACC_Y:0  GYR_Z:-1
ACC_X:103  ACC_Y:0  GYR_Z:3
ACC_X:103  ACC_Y:0  GYR_Z:0
ACC_X:113  ACC_Y:4  GYR_Z:4
ACC_X:103  ACC_Y:0  GYR_Z:16
ACC_X:102  ACC_Y:0  GYR_Z:-1
ACC_X:102  ACC_Y:0  GYR_Z:2
ACC_X:102  ACC_Y:0  GYR_Z:-1
ACC_X:103  ACC_Y:1  GYR_Z:2
ACC_X:102  ACC_Y:0  GYR_Z:-1
ACC_X:103  ACC_Y:1  GYR_Z:2
ACC_X:103  ACC_Y:0  GYR_Z:2
ACC_X:102  ACC_Y:0  GYR_Z:-2
ACC_X:103  ACC_Y:0  GYR_Z:1
ACC_X:102  ACC_Y:0  GYR_Z:1
ACC_X:102  ACC_Y:0  GYR_Z:1
ACC_X:102  ACC_Y:-1  GYR_Z:-1
ACC_X:103  ACC_Y:0  GYR_Z:-1
ACC_X:110  ACC_Y:-8  GYR_Z:14
ACC_X:114  ACC_Y:11  GYR_Z:-3
ACC_X:106  ACC_Y:8  GYR_Z:-4
ACC_X:100  ACC_Y:0  GYR_Z:-4
ACC_X:102  ACC_Y:0  GYR_Z:4
ACC_X:103  ACC_Y:0  GYR_Z:2
ACC_X:104  ACC_Y:-1  GYR_Z:0
ACC_X:103  ACC_Y:0  GYR_Z:-4
ACC_X:103  ACC_Y:0  GYR_Z:-1
ACC_X:103  ACC_Y:0  GYR_Z:1
ACC_X:102  ACC_Y:1  GYR_Z:1
ACC_X:103  ACC_Y:0  GYR_Z:2
ACC_X:105  ACC_Y:1  GYR_Z:-1
ACC_X:102  ACC_Y:0  GYR_Z:1
ACC_X:102  ACC_Y:0  GYR_Z:2

i dunno if this values is correct or wrong. and i'm building something like a balancing robot but it's not a balancing robot. I need to connect my Arduino ProMini with IMU combo board and joystick and servo together. I do not understand how to use gyro to control my servo and the what readings does the servo read.. My Gyro is giving an unstable values which i think is not correct. but i got no idea how to correct. Please help ..

Go Up