Now that we know how to read the sensors, we need to make sense of it. Lets have a good look at the sensor datasheet.
ADXL335 3-axis Accelerometer
Accelerometer, measures resultant acceleration acting on the sensor.
This ADXL335 outputs an analogue voltage based on acceleration. Its sensitivity of the ADXL335 is 300mV/g, which means that the output will change by .30v per 9.8m/s2 .
The ADXL335 has a ratiometric output, meaning 0g is always around half of the supply voltage Vcc, The datasheet stated that the zero Voltage is typically at 1.5V.
Hence,
Accel = Vaccel - 1.5V
BUT I prefer to get the actual count reading when the accelerometer is resting on horizontal position
and Sensitivity is typically 0.3V/g, the Arduino ADC gives a 10-bit value based on a 3.3v reference, the gain on the raw ADC value can be calculated by:
Hence,
(1g/0.3V) X (3.3V/1024) =0.01627 g/LSB
Hence,
Position of the accelerometer = Accel *0.011
IDG500 2-axis Gyro
This gyroscope measures angular rate and return a analogue voltage signal proportional to the rate of rotation. The at the 4.5x, IDG500 has a sensitivity of 9.1mV/°/s, i.e. the output changes 9.1.0mV for every °/s of rotation. Since the Arduino ADC gives a 10-bit value based on a 5v reference, the gain on the raw ADC value can be calculated by:
(1°/s/0.0091V) X (3.3/1024) = 0.354 °/s/LSD
deduct the factory set 1.35V from raw analogue input & multiplying result with 0.354°/s/LSD will return the angular velocity in degrees-per-second.
Gyro rate =(Gyro_reading - 1.35V)*0.354 deg/sec
Since we are doing discrete maths with our controller, we multiply the known interval between gyro reading which is the loop time; we get the change in angular position in degree
Gyro Angular change = Gyro rate * Loop time
Now we have enough data to measure angular position with the gyro with the following line.
Gyro angle= Gyro angle + Gyro Angular change.
What we had just done is to rationalised both the accelerometer & gyro output to angular position with the same unit of measurement.
It is now convenient to write code to compare the sensors on the same page.
Showing posts with label Gyroscope. Show all posts
Showing posts with label Gyroscope. Show all posts
Saturday, July 14, 2012
Tuesday, May 1, 2012
Tinkering Accelerometer + Gyroscope AKA IMU (Part 2)
The IMU is a combo board consisting of 2 sensors.
What good is a sensor if we can not read it.
Here I jury jig a bench top test for reading the sensors.
Hardware involved:-
Arduino Duemilanove
5DOF IMU
some hook-up leads
- 3V3 to IMU Vss & ARef pin
-Gnd to Gnd
- accel X axis to Analog input 0
- accel Y axis to Analog input 2
- gyro X axis(4x output) to Analog input 1
- gyro Y axis(4x output) to Analog input 3
- USB cable
We still need to write some codes to get the job done.
Following is a simple code which I came up with
// Reading 5DOF IMU
//Analog Pins
int Xaccel_pin = 0; //connect accel X axis to Analog input 0
int Yaccel_pin = 2; //connect accel X axis to Analog input 2
int Xgyro_pin = 1; //connect gyro X axis(4x output) to Analog input 1
int Ygyro_pin = 3; //connect gyro Y axis(4x output) to Analog input 3
//Digital Pins
int Xaccel_reading; //X axis Accelerometer reading
int Yaccel_reading; //y axis Accelerometer reading
int Xgyro_reading; //X axis Gyro reading
int Ygyro_reading; //Y axis Gyro reading
float loop_time = 0.05;
int last_loop = 0;
void setup(){
Serial.begin(9600); // start Serial monitor to print values
pinMode(Xaccel_pin,INPUT);
pinMode(Xgyro_pin,INPUT);
pinMode(Yaccel_pin,INPUT);
pinMode(Ygyro_pin,INPUT);
pinMode(13,OUTPUT);
}
void loop() {
Xaccel_reading=analogRead(Xaccel_pin);
Xgyro_reading=analogRead(Xgyro_pin);
Yaccel_reading=analogRead(Yaccel_pin);
Ygyro_reading=analogRead(Ygyro_pin);
while((millis()-last_loop)
{
delay(1);
}
last_loop=millis();
Serial.print("X-Accel: ");
Serial.print(Xaccel_reading);
Serial.print(" ");
Serial.print("X-Gyro: ");
Serial.print(Xgyro_reading);
Serial.print(" ");
Serial.print("YAccel: ");
Serial.print(Yaccel_reading);
Serial.print(" ");
Serial.print("Y-Gyro: ");
Serial.print(Ygyro_reading);
Serial.print(" ");
}
What good is a sensor if we can not read it.
Here I jury jig a bench top test for reading the sensors.
Hardware involved:-
Arduino Duemilanove
5DOF IMU
some hook-up leads
- 3V3 to IMU Vss & ARef pin
-Gnd to Gnd
- accel X axis to Analog input 0
- accel Y axis to Analog input 2
- gyro X axis(4x output) to Analog input 1
- gyro Y axis(4x output) to Analog input 3
- USB cable
We still need to write some codes to get the job done.
Following is a simple code which I came up with
// Reading 5DOF IMU
//Analog Pins
int Xaccel_pin = 0; //connect accel X axis to Analog input 0
int Yaccel_pin = 2; //connect accel X axis to Analog input 2
int Xgyro_pin = 1; //connect gyro X axis(4x output) to Analog input 1
int Ygyro_pin = 3; //connect gyro Y axis(4x output) to Analog input 3
//Digital Pins
int Xaccel_reading; //X axis Accelerometer reading
int Yaccel_reading; //y axis Accelerometer reading
int Xgyro_reading; //X axis Gyro reading
int Ygyro_reading; //Y axis Gyro reading
float loop_time = 0.05;
int last_loop = 0;
void setup(){
Serial.begin(9600); // start Serial monitor to print values
pinMode(Xaccel_pin,INPUT);
pinMode(Xgyro_pin,INPUT);
pinMode(Yaccel_pin,INPUT);
pinMode(Ygyro_pin,INPUT);
pinMode(13,OUTPUT);
}
void loop() {
Xaccel_reading=analogRead(Xaccel_pin);
Xgyro_reading=analogRead(Xgyro_pin);
Yaccel_reading=analogRead(Yaccel_pin);
Ygyro_reading=analogRead(Ygyro_pin);
while((millis()-last_loop)
{
delay(1);
}
last_loop=millis();
Serial.print("X-Accel: ");
Serial.print(Xaccel_reading);
Serial.print(" ");
Serial.print("X-Gyro: ");
Serial.print(Xgyro_reading);
Serial.print(" ");
Serial.print("YAccel: ");
Serial.print(Yaccel_reading);
Serial.print(" ");
Serial.print("Y-Gyro: ");
Serial.print(Ygyro_reading);
Serial.print(" ");
}
Once loaded, you can see the IMU reading via the "Serial Monitor" or <>
Now that I have IMU readings, the next gargantuan task is to figure out what can I do with them...
Maybe in Part 3 I'll have an answer....
Labels:
Accelerometer,
Arduino,
DIY Robotic,
Gyroscope,
IMU,
mcu,
Sensor
Subscribe to:
Posts (Atom)