The L3GD20 3-Axis Gyro

Similar documents
DS1307 Real Time Clock Breakout Board Kit

Arduino Lesson 16. Stepper Motors

Adafruit MCP9808 Precision I2C Temperature Sensor Guide

Ampere's Law. Introduction. times the current enclosed in that loop: Ampere's Law states that the line integral of B and dl over a closed path is 0

Eric Mitchell April 2, 2012 Application Note: Control of a 180 Servo Motor with Arduino UNO Development Board

Using Arduino Microcontrollers to Sense DC Motor Speed and Position

Flight Controller. Mini Fun Fly

The purposes of this experiment are to test Faraday's Law qualitatively and to test Lenz's Law.

The accelerometer designed and realized so far is intended for an. aerospace application. Detailed testing and analysis needs to be

Arduino Lesson 14. Servo Motors

Hand Gestures Remote Controlled Robotic Arm

Experiment 3: Magnetic Fields of a Bar Magnet and Helmholtz Coil

PHYS 2P32 Project: MIDI for Arduino/ 8 Note Keyboard

Your Multimeter. The Arduino Uno 10/1/2012. Using Your Arduino, Breadboard and Multimeter. EAS 199A Fall Work in teams of two!

cs281: Introduction to Computer Systems Lab08 Interrupt Handling and Stepper Motor Controller

PID Control. Proportional Integral Derivative (PID) Control. Matrix Multimedia 2011 MX009 - PID Control. by Ben Rowland, April 2011

Lecture 7: Programming for the Arduino

Experiment 3: Magnetic Fields of a Bar Magnet and Helmholtz Coil

TwinCAT NC Configuration

An Arduino Controlled GPS Corrected VFO

Adafruit SHT31-D Temperature & Humidity Sensor Breakout

The Quadcopter Controller

Arduino Lesson 1. Blink

How To Control Gimbal

EARTH PEOPLE TECHNOLOGY SERIAL GRAPH TOOL FOR THE ARDUINO UNO USER MANUAL

TSL2561 Luminosity Sensor

Hardware Connections between Arduino and IMU Nori Wilkins Apr. 5, 2013

INTRODUCTION TO SERIAL ARM

Reading assignment: All students should read the Appendix about using oscilloscopes.

Cornerstone Electronics Technology and Robotics I Week 15 Voltage Comparators Tutorial

Bluetooth + USB 16 Servo Controller [RKI-1005 & RKI-1205]

H-Bridge Motor Control

Lab E1: Introduction to Circuits

Controlling a Dot Matrix LED Display with a Microcontroller

Scripting Language Reference. SimpleBGC 32bit

Multi-Touch Control Wheel Software Development Kit User s Guide

MicroMag3 3-Axis Magnetic Sensor Module

An Introduction to MPLAB Integrated Development Environment

2013 G Miller. 3 Axis Brushless Gimbal Controller Manual

Adafruit BME280 Humidity + Barometric Pressure + Temperature Sensor Breakout

AN2680 Application note

Arduino Lab 1 - The Voltage Divider

Surveillance System Using Wireless Sensor Networks

Transmitter Interface Program

Lab Experiment 1: The LPC 2148 Education Board

FORCE ON A CURRENT IN A MAGNETIC FIELD

PLL frequency synthesizer

Arduino Lesson 13. DC Motors. Created by Simon Monk

Arduino Motor Shield (L298) Manual

LCD I 2 C/Serial RX Backpack. Data Sheet. LCD to I2C/Serial RX Backpack I2C or Serial RX communication with Standard 16 Pin LCD modules

Physics 121 Sample Common Exam 3 NOTE: ANSWERS ARE ON PAGE 6. Instructions: 1. In the formula F = qvxb:

Programming the Arduino

DEPARTMENT OF ELECTRONICS ENGINEERING

Application Note IMU Visualization Software

The Answer to the 14 Most Frequently Asked Modbus Questions

GT Sensors Precision Gear Tooth and Encoder Sensors

ADXL345-EP. 3-Axis, ±2 g/±4 g/±8 g/±16 g Digital Accelerometer. Enhanced Product FEATURES GENERAL DESCRIPTION ENHANCED PRODUCT FEATURES APPLICATIONS

FREE FALL. Introduction. Reference Young and Freedman, University Physics, 12 th Edition: Chapter 2, section 2.5

Character LCDs. Created by Ladyada. Last updated on :45:29 PM EDT

Lab 6 Introduction to Serial and Wireless Communication

ECE 495 Project 3: Shocker Actuator Subsystem and Website Design. Group 1: One Awesome Engineering

Electronic Brick of Current Sensor

An internal gyroscope minimizes the influence of dynamic linear acceleration on slope sensor readings.

HDMM01 V1.0. Dual-axis Magnetic Sensor Module With I 2 C Interface FEATURES. Signal Path X

Chapter 19 Operational Amplifiers

Pololu DRV8835 Dual Motor Driver Shield for Arduino

MCP4725 Digital to Analog Converter Hookup Guide

The Operational Amplfier Lab Guide

AirCasting Particle Monitor Bill of Materials

ARDUINO SEVERINO SERIAL SINGLE SIDED VERSION 3 S3v3 (REVISION 2) USER MANUAL

T-SERIES INDUSTRIAL INCLINOMETER ANALOG INTERFACE

#include <Gamer.h> Gamer gamer; void setup() { gamer.begin(); } void loop() {

EXPERIMENT 7 OHM S LAW, RESISTORS IN SERIES AND PARALLEL

Embedded Systems Design Course Applying the mbed microcontroller

Hands On ECG. Sean Hubber and Crystal Lu

Digital and Analog I/O

MAS.836 HOW TO BIAS AN OP-AMP

Lab 7: Operational Amplifiers Part I

Scaling and Biasing Analog Signals

Experiment 5: Magnetic Fields of a Bar Magnet and of the Earth

Measuring Electric Phenomena: the Ammeter and Voltmeter

PRODUCTIVITY THROUGH INNOVATION 600 CONTROL DIRECT DRIVE TECHNICAL/OPERATION MANUAL

Arduino Lesson 17. Sending Movement Detector

Display Board Pulse Width Modulation (PWM) Power/Speed Controller Module

The components. E3: Digital electronics. Goals:

Selecting and Implementing H-Bridges in DC Motor Control. Daniel Phan A

Table of Contents Getting Started... 3 The Motors... 4 The Control Board... 5 Setting up the Computer with Mach Starting up the Equipment...

MODULE BOUSSOLE ÉLECTRONIQUE CMPS03 Référence :

Servo Motors (SensorDAQ only) Evaluation copy. Vernier Digital Control Unit (DCU) LabQuest or LabPro power supply

1 Coffee cooling : Part B : automated data acquisition

Data Sheet. Adaptive Design ltd. Arduino Dual L6470 Stepper Motor Shield V th November L6470 Stepper Motor Shield

LAB 6: GRAVITATIONAL AND PASSIVE FORCES

LAB 6 - GRAVITATIONAL AND PASSIVE FORCES

MSc in Autonomous Robotics Engineering University of York

Force on Moving Charges in a Magnetic Field

HP TouchPad Sensor Setup for Android

AEO Head Movement Tracker X-GYRO 1000 USER MANUAL(V1.1bata )

Tiny Arduino Music Visualizer

Thermistor. Created by Ladyada. Last updated on :30:46 PM EDT

Lab 4 - Data Acquisition

Transcription:

The L3GD20 3-Axis Gyro Table of Contents 1 Overview... 1 1.1 Terminology... 2 2 Reading and Downloads... 3 3 Lab Checklist... 3 4 How it Works... 3 5 Wire the Gyro... 4 6 Install the L3G Arduino Library... 4 7 Create the GyroTest Program... 5 8 Calibrate the Gyro... 6 8.1 Measure Gyro Offset at Rest (Zero-rate Level)... 6 8.2 Measure Gyro Noise Level at Rest... 7 9 Measure Rotational Velocity... 8 10 Measure Angle... 9 11 Design Considerations... 10 1 Overview This is the first of two labs that make use of the gyroscope. In this lab you will use the Arduino microcontroller board to read the gyro and process its data into a usable form. In the PID lab you will use your gyro to detect when your rover drifts from a straight trajectory. The L3GD20 or older L3G4200D is a carrier/breakout board from Pololu which includes a voltage regulator and a high-precision ST L3GD20 (or ST L3G4200D) 3-axis gyroscope. The ST gyro measures the angular rates of rotation (velocity) about the pitch (x), roll (y), and yaw (z) 1

axes with a configurable sensitivity of ±250 /s, ±500 /s, or ±2000 /s. You will be using the z-axis sensor if your gyro board lies parallel to the ground. This lab assumes use of the z-axis sensor with the board inverted, so you can read the pin labels from above. Otherwise you can determine your axis of rotation, as well as the "positive" direction of rotation, by referring to the axis diagram printed on the gyroscope breakout board. The ST gyro communicates with our microcontroller over an I2C serial interface. The board includes a 3.3 V linear regulator and integrated level-shifters that allows it to work over an input voltage range of 2.5 5.5 V. The carrier/breakout board uses a standard.1" header allowing it to plug into our solderless breadboard. As the L3GD20 is an upgrade to the L3G4200D, you may have this older version of the ST gyroscope. If this is the case, you must make three adjustments to this lab: 1. In place of the L3G Arduino library, the L3G4200D library must be added. This library can be found on the Pololu product page for the L3G4200D. 2. In the GyroTest program, the L3G4200D library must be imported in place of the L3G library. 3. The line "while(!gyro.init());" in GyroTest may be deleted or commented out. At this time including this line with a L3G4200D has not been tested. 1.1 Terminology Sensitivity An angular rate gyroscope is a device that produces a positive-going digital output for counterclockwise rotation around the sensitive axis considered. Sensitivity describes the gain of the sensor and can be determined by applying a defined angular velocity to it. This value changes very little over temperature and time. Note: Our gyros are mounted upside down on the breadboard so a clockwise rotation generates a positive output. Zero-rate level Zero-rate level describes the actual output signal if there is no angular rate present. The zerorate level of our precise MEMS (Microelectromechanical system) gyro sensor is, to some extent, a result of stress to the sensor and, therefore, the zero-rate level can slightly change after mounting the sensor onto a printed circuit board or after exposing it to extensive mechanical stress. This value changes very little over temperature and time. Stability over temperature and time The single driving mass design of the ST gyroscopes matches the MEMS mechanical mass and the ASIC interface, delivers a high level of stability over temperature and time. 2

2 Reading and Downloads 1 L3GD20 MEMS motion sensor: ultra-stable three-axis digital output gyroscope http://www.pololu.com/catalog/product/2125 2 Arduino library for the L3GD20 https://github.com/pololu/l3g 3 STMicroelectronics L3GD20 data sheet 4 http://www.st.com/web/catalog/sense_power/fm89/sc1288/pf252443 5 Read about Gyroscopes: http://tom.pycke.be/mav/70/gyroscope-to-roll-pitch-and-yaw and Kalman Filters (optional): http://tom.pycke.be/mav/71/kalman-filtering-of-imu-data 3 Lab Checklist Here is your checklist for this lab. Learn how to connect and sample Gyro data Measure Gyro noise and drift at rest Compute angle as the Gyro is rotated Explore data filtering techniques 4 How it Works The purpose of a gyro is to maintain a sense of direction. A gyro does this by sensing changes in its angular motion (angular velocity), and outputting a digital number that is proportional to its rotating speed. This angular velocity can then be integrated over time to give you the offset, in degrees, of the gyro from its zeroed position. In other words, it will tell you the net rotation the gyro is experiencing over time. Our gyro can measure three axes referred to as roll (x axis), pitch (y axis), and yaw (z axis). For our rover application, we are only concerned with the yaw (z axis). In terms of the L3GD20, angular velocity is measured in degrees per second. Our gyro returns a positive number for clockwise rotation and a negative number for counterclockwise (note: L3GD20 MIMS chip is inverted) A parameter of interest for a gyro is the sensitivity, which is found in the sensor s data sheet. It is the parameter linking your DN to your angular velocity (degrees/s). EQ 1-1 Our gyro has three sensitivity range settings ±250 /s, ±500 /s, or ±2000 /s. Our rover does not change direction very quickly, so we choose the lowest scale due to its higher level of precision. 3

5 Wire the Gyro Install the breakout in the breadboard as shown in the figure above (chip inverted). When the sensor is installed upside down, it will give a positive value for clockwise rotation and a negative value for counterclockwise rotation about the z-axis. Make the following connections with wires between the Arduino and the L3G4200D: Arduino Uno/Duemilanove L3G4200D Carrier 5V VIN GND GND Analog Pin 5 SCL Analog Pin 4 SDA 6 Install the L3G Arduino Library Step 1: Download the library The L3G library can be found at https://github.com/pololu/l3g. Note: If you are using the L3G4200D gyro, you must use the L3G4200D library instead. Step 2: Place the whole L3G library folder in your Arduino libraries directory 4

7 Create the GyroTest Program Open the Arduino IDE and create a new sketch using the BareMinimum template. This sets up the two loops necessary to all Arduino programs. Save this new sketch under the new name "GyroTest" before adding code. Add the following code above the "void setup()" block. It imports the L3G gyro and Arduino I2C libraries, and creates an L3G gyro object. #include <Wire.h> #include <L3G.h> L3G gyro; Note: L3G4200D users must use #include <L3G4200D.h> instead of #include <L3G.h> Inside the setup() block, place the following code. This sets up serial communication for the Arduino, and initializes the gyro sensor. Serial.begin(115200); Wire.begin(); while (!gyro.init()); gyro.enabledefault(); Note: L3G4200D users should delete or comment out the "while (!gyro.init());" line. 5

8 Calibrate the Gyro Ideally the gyro should output an angular velocity of 0 when it is at rest. In reality the output tends to have a non-zero average value. As we must integrate the angular velocity (degrees/sec) output by the sensor to measure the angle (degrees) of our rover, any DC offset can accumulate and lead to the gyro angle drifting while the rover is sitting still. To fix this problem, we must calculate the zero-rate level of the gyro output on startup and subtract it from subsequent readings. Noise can also cause inaccurate readings, so it's useful to calculate the noise level of the gyro output at rest. This can help us determine whether or not to set a noise threshold for our sensor readings. 8.1 Measure Gyro Offset at Rest (Zero-rate Level) In your GyroTest program, add the following variable declarations above the setup() block. int samplenum=500; int dc_offset=0; Then, at the bottom of the setup() block, add the code to calculate the gyro sensor's DC offset. This code works by taking 500 sample readings and calculating the average value. You can change the number of samples to improve performance: a lower number will reduce calibration time while a larger number will increase precision. //Calculate initial DC offset and noise level of gyro for(int n=0;n<samplenum;n++){ gyro.read(); dc_offset+=(int)gyro.g.z; } dc_offset=dc_offset/samplenum; //print dc offset and noise level Serial.println(); Serial.print("DC Offset: "); Serial.print(dc_offset); Serial.println(); Now save the program and upload it to your Arduino, making sure to keep the gyro sensor completely still. Check the serial monitor. It should display an integer representing your gyro's current zero-rate level. 6

8.2 Measure Gyro Noise Level at Rest Add the following variable declaration above the setup() block. double noise=0; Add the highlighted code to your existing setup() block. This code calculates the noise level by finding the reading with the largest absolute value. Notice that these readings take the DC offset obtained in the previous section into account. //Calculate initial DC offset and noise level of gyro for(int n=0;n<samplenum;n++){ gyro.read(); dc_offset+=(int)gyro.g.z; } dc_offset=dc_offset/samplenum; for(int n=0;n<samplenum;n++){ gyro.read(); if((int)gyro.g.z-dc_offset>noise) noise=(int)gyro.g.z-dc_offset; else if((int)gyro.g.z-dc_offset<-noise) noise=-(int)gyro.g.z-dc_offset; } noise=noise/100; //gyro returns hundredths of degrees/sec //print dc offset and noise level Serial.println(); Serial.print("DC Offset: "); Serial.print(dc_offset); Serial.print("\tNoise Level: "); Serial.print(noise); Serial.println(); 7

Now save and run the program again, making sure to keep the gyro sensor completely still, and you should get a reading that includes both the DC offset and noise level. The noise should be around 1 or 2. If it is significantly higher, a noise threshold may be needed for accurate measurement. 9 Measure Rotational Velocity The ST gyro returns an integer value proportional to the sensor s rate of rotation in degrees/second. To display this data, first add the following variable declarations above the setup() block of your GyroTest program. unsigned long time; int sampletime=10; int rate; Then, add the following code to the loop() block. The millis() function returns the number of milliseconds that have passed since the Arduino was reset, so it is used to record time differences between events. // Every 10 ms take a sample from the gyro if(millis() - time > sampletime) { time = millis(); // update the time to get the next sample gyro.read(); rate=((int)gyro.g.z-dc_offset)/100; Serial.print("rate: "); Serial.println(rate); } Since the velocity readings will quickly take over the whole window, add a time delay at the end of the setup() block to give you time to read the DC offset and noise level values. 8

delay(7000); Save and run GyroTest again, and this time you should see a rapid stream of integers corresponding to the rotational velocity of the sensor. Try turning the rover and watching the values change. 10 Measure Angle To obtain the angular position of the sensor, the rate of rotation returned by the sensor must be integrated with respect to time. A simple and fairly accurate method of numerical integration is the trapezoid method. This algorithm takes the mean average of the current and previous reading, and multiplies the amount of time between those two readings. To integrate the sensor output, first add the following variable declarations above the setup() block. int prev_rate=0; double angle=0; Then, add the highlighted code below to the loop() block. void loop() { // Every 10 ms take a sample from the gyro if(millis() - time > sampletime) { time = millis(); // update the time to get the next sample gyro.read(); rate=((int)gyro.g.z-dc_offset)/100; angle += ((double)(prev_rate + rate) * sampletime) / 2000; // remember the current speed for the next loop rate integration. prev_rate = rate; // Keep our angle between 0-359 degrees if (angle < 0) 9

} } angle += 360; else if (angle >= 360) angle -= 360; Serial.print("angle: "); Serial.print(angle); Serial.print("\trate: "); Serial.println(rate); To test this program, print out the compass drawing at the end of this document and place it on a solid floor or table, then place your rover on top of it facing zero degrees. Save and upload GyroTest to your rover and open the serial monitor. Once the gyro readings begin appearing in the window, turn the rover and make sure the program measures the same angle as the compass. The output must be divided by an integer value to obtain proper degrees per second. I have used 100, but this number may need to be adjusted to get correct angle readings. 11 Design Considerations Errors in measurement can be caused by a gradual drift in the DC offset value of the sensor output. This can be corrected by adjusting calibration whenever the rover is motionless using the following code. This has the obvious drawback that the rover must stop to recalibrate during its mission. //Code to correct for gyro drift when rover is motionless dc_offset = (samplenum-1)*dc_offset+(1/samplenum)*(int)gyro.g.z; High levels of noise can potentially interfere with gyro operation. If the gyro output tends to oscillate rather than giving steady readings, a noise threshold can be set by adding the following 10

highlighted code. Note that setting a threshold will cause low-speed rotation to be ignored, which can cause angle readings to become increasingly inaccurate over time. // Ignore the gyro if our angular velocity does not meet our threshold if(rate >= noise rate <= -noise) angle += ((double)(prev_rate + rate) * sampletime) / 2000; Also note that since GyroTest uses the polling method to determine when the appropriate sample time has passed, the readings may become inaccurate if this code is added to a program that incorporates large time delays. This can be fixed by setting an interrupt to take a gyro reading every time the appropriate sample time has passed regardless of what the rest of the program is doing. Appendix: Compass Drawing 11

12