Insane amount of info on IMU+Arduino

Razor 6DOF and Arduino

http://voidbot.net/razor-6dof.html

Razor 6 DOF board from SparkFun is “thin” IMU (Inertial Measurement Unit) and has 3 gyroscopes and 3 accelerometers. I wanted to evaluate it for robotic purposes, a UAV in this case, so I connected it to Arduino board. Reading sensor data from Razor board is straight forward as outputs are all analog values. I first wrote simple software code to just acquire raw ADC data – to see how board behaves, and then ported code for state estimation based on DCM algorithm.

When the Razor board arrived, I was amazed how small it is. Although I saw specs before, size of the board really registered only when I saw it – it’s about 35mm long, or just short of 1.5 inches. There are two gyroscope chips, ST LPR530AL [PDF specs] for roll and pitch and ST LY530ALH [PDF - specs] for yaw, and ADXL335 [PDF-specs] 3-axis accelerometer. Basic specs for gyros are +/- 300 degrees per second (or 1200 deg/sec not amplified) and accelerometers are +/- 3g. Only thing that needs to be done before the board can be used is to solder 0.1″ pitch header pins.

For testing purposes I decided to use gyros output of +- 300 deg/sec ( 4x amplified) and accelerometers, leaving reference pins (v1 and v2), ST (Self-test), PD (power down), HP ( high pass filter reset), as well as gyro non-amplified outputs disconnected. As a side note, pins HP, PD, and ST for both gyros are tied together.

Next step is to connect IMU board to Arduino. Gyro and accel pins are connected to Arduino’s analog pins 0 to 5. Power is obtained from 3.3 VDC pin, and is connected to AREF as well. This should be done in order to properly scale ADC, since Arduino default for analog reference is 5V. Better set up would be to have at least 3.3V regulator for power and reference, but for now this will do. See pin connection diagram below. For quick assembly and testing I used DIY general purpose Arduino shield – ok, it’s just a used PCB with some header pins and breadboard. Then I uploaded basic data acquisition code / sketch to Arduino. It’s a “Hello World” type of code and just reads and displays raw ADC data.

// Released under Creative Commons License
// SparkFun Razor 6DOF and Arduino – basic read of gyroscope and accelerometer data
// This is “Hello World” of acquiring sensor data from 6 DOF Razor board
//
// Gyro, from the amplified outputs, and accelerometer data are read and displayed
// Power is obtained from 3V3, not 5V
// 3.3V is also connected to AREF pin, as we want to scale ADC data
// Pinout connection is at
// http://voidbot.net/razor-6dof.html
//
// – by automatik
//——————————————————————

int val = 0; //value of individual accelerometer or gyroscope sensor
unsigned long timer=0; //timer
unsigned long delta_t; //delta time or how long it takes to execute data acquisition

void setup()

{
analogReference(EXTERNAL); //using external analog ref of 3.3V for ADC scaling
Serial.begin(115200); //setup serial
DDRC = B00000000; //make all analog ports as inputs – just in case….

delay (100); //dealy just in case – to get things stabilized if need be….

Serial.println(“t[ms] \t gy \t gx \t gz \t az \t ay \t ax “); //print data header

timer=millis();
}

void loop()
{
delta_t = millis() – timer; // calculate time through loop i.e. acq. rate
timer=millis(); // reset timer
Serial.print(delta_t);
Serial.print (“\t”);

for (long i=0; i<6; i++) //read gyroscope and accelerometer sensor data
{
val = analogRead(i); // read the input pin
Serial.print(val); //print data
Serial.print (“\t”);
}

Serial.println(“”);
delay(16); //loop delay; loop executed at ~ 50Hz or 20ms
}

Above code “Razor_raw_ADC_gyroscope_and_accelerometer.pde” can be downloaded here.

Hardware – software interface worked as expected. I just let the board sit motionless and observed data output.It quickly became apparent that gyros and accelerometers will need some “warming” up in order to produce consistant results. I powerd down everything and let it sit for few hours. Then I powerd it up and recorded raw ADC data. As evidend from plots below, gyros and accelerometers need at least 20 seconds to “warm-up”, although leting them work for 8 minites will not do any damage either. Plots show data recorded for over an hour, as well as ‘close up’ ofthe same data (first minute or so).
ColdStart-AccelX ColdStart-AccelX-CloseUp ColdStart-AccelY ColdStart-AccelY-CloseUp ColdStart-AccelZ ColdStart-AccelZ-CloseUp ColdStart-GyroX ColdStart-GyroX-CloseUp ColdStart-GyroY ColdStart-GyroY-CloseUp ColdStart-GyroZ ColdStart-GyroZ-CloseUp

To get a estimation of IMU board’s orientation in space I ported and slightly modifies DCM algorithm and code, basically just adopted it for Razor 6DOF board. There are many ways to figure out orientation, and most popular is to use Kalman filter, or Extended Kalman Filter (EKF), however I really like Direction Cosine Matrix (DCM) approach so I decide to try it out. You can find draft of DCM explanation here[PDF], as well as additional information and discussion on UAV Dev-board site at DIYdrones

In the DCM code, in order to properly adjust for yaw, GPS needs to be connected and you need to be moving (it can also be done with magnetometers but it needs code change, although it wouldn’t be too difficult). I commented out GPS code, so if you have uBlox GPS just un-comment the code. Also code conversion for EM 406 caneasily be done, and I plan to do so in near future.

In addition, I adopted Jordi’s (from DIYdrones) LabVIEW code to display DCM data. I modified it to display additional values (ArduIMU v13), to display “cube” orientation in the main window, and some small clean-up code changes.

You can download files:

Oh, and you can get Razor IMU board from SparkFun and find additional information here.

About these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s