590 likes | 616 Views
Compasses, Accelerometers, and Gyros,. TYWu. Compass. Principles The earth is a huge magnet. Any freely suspended magnet will align itself with the earth’s magnetic poles. The compass is a self-contained unit requiring no external power source. Compass. Principles
E N D
Compass • Principles • The earth is a huge magnet. • Any freely suspended magnet will align itself with the earth’s magnetic poles. • The compass is a self-contained unit requiring no external power source.
Compass • Principles • The strength of the earth's magnetic field is about 0.5 to 0.6 gauss and has a component parallel to the earth's surface that always points toward the magnetic north pole. • In the northern hemisphere, this field points down. At the equator, it points horizontally and in the southern hemisphere, it points up. • This angle between the earth’s magnetic field and the horizontal plane is defined as an inclination angle. Another angle between the earth's magnetic north and geographic north is defined as a declination angle in the range of ± 20º depending on the geographic location.
Compass • Northerly Turning (Dip) Error • The earth’s magnetic field causes the compass to dip to the low side of the turn. • In the Northern Hemisphere: Lag North, Lead South. LAG NORTH
Compass • Acceleration/Deceleration Error • Most pronounced on headings of east and west. • Accelerate north, Decelerate south.
Compass • 3-Axis Digital (Electronic) Compass • 3-Axis Digital Magnetometer • LSM303DLH (MEMS) • LSM303DLH has a magnetic field full-scaleof ±1.3 / ±1.9 / ±2.5 / ±4.0 / ±4.7 / ±5,6 / ±8.1gauss • Fully selectable by the user. • High current in wiring and printed circuit traces can be the cause of errors in magnetic field measurements for compassing.
Compass • Compensated Compassing
Compass • A Working Electronic Compass System • Hardware design to make sure the MCU can get clean raw data from the accelerometer and the magnetic sensor • Accelerometer calibration to obtain parameters to convert accelerometer raw data to normalized values for pitch and roll calculation • Magnetic sensor calibration to obtain parameters to convert magnetic sensor raw data to normalized values for the heading calculation
Accelerometers • Gyroscopes & Accelerometers Used in the Airplane & Vehicle
Accelerometers • 3-Axis Digital Accelerometer • LSM303DLH (MEMS) • A linear acceleration full-scale of ±2 g / ±4 g / ±8 g • Fully selectable by the user.
Accelerometers • 3-Axis Digital Accelerometer • ADXL335 • Single-supply operation: 1.8 V to 3.6 V • Measure acceleration with a minimum full-scale range of ±3 g. • Measure the static acceleration of gravity in tilt-sensing applications, as well as dynamic acceleration resulting from motion, shock, or vibration.
Accelerometers • ADXL335 • Application • Mobile devices • Gaming systems • Disk drive protection • Image stabilization • Sports and health devices
Accelerometers • ADXL335
Accelerometers • ADXL335 • Output Response vs. Orientation to Gravity • However, the spec. and my experiment are inconsistent!
Accelerometers • Specification
Accelerometers • MMA7361
Accelerometers • MMA7361
Accelerometers • MMA7361
Accelerometers • MMA7361
Gyro • 3 Axes of Angular Freedom • Spin Axis • Horizontal Axis • Vertical Axis
Gyro • Applications • Motion control with MMI (man-machine interface) • Appliances and robotics • Gaming and virtual reality input devices • Navigation • Etc.
Gyro • Roll, Pitch, and Yaw
Gyro • 3-Axis Digital Gyroscope (MEMS Motion Sensor) • L3G4200D
Gyro • Dual axis pitch and roll ±100°/s analog gyroscope • LSM303DLH
Experiment I • Arduino • LSM303DLH 3D Compass and Accelerometer Carrier with Voltage Regulators
Experiment I • LSM303DLH Arduino Library • https://github.com/ryantm/LSM303DLH/tree/master/LSM303DLH • Wire Library • This library allows you to communicate with I2C / TWI devices. On most Arduino boards, SDA (data line) is on analog input pin 4, and SCL (clock line) is on analog input pin 5. On the Arduino Mega, SDA is digital pin 20 and SCL is 21
Experiment I • SDA is defined in ./libraries/SD/utility/Sd2PinMap.h
Experiment I • The board for the LSM303DLH can be purchased on Pololu • Make the following connections with wires between Arduino Uno/Duemilanove and LSM303DLH board • 5V -> VIN • GND -> GND • Analog Pin 5 -> SCL • Analog Pin 4 -> SDA
Experiment I • Sketch #include <Wire.h> #include <LSM303DLH.h> LSM303DLH compass; void setup() { Serial.begin(9600); Wire.begin(); compass.enable(); }
Experiment I void loop() { compass.read(); Serial.print("Accel.: "); Serial.print("X="); Serial.print(compass.a.x); Serial.print(", Y="); Serial.print(compass.a.y); Serial.print(", Z="); Serial.println(compass.a.z); Serial.print("Compass: "); Serial.print("X="); Serial.print(compass.m.x); Serial.print(", Y="); Serial.print(compass.m.y); Serial.print(", Z="); Serial.println(compass.m.z); delay(1000); }
Experiment I • Results
Experiment I • Results
Experiment II • L3G4200D 3-Axis Gyro Carrier with Voltage Regulator
Experiment II • LPR510AL Dual-Axis (Pitch and Roll or XY) Gyro with ±100°/s and ±400°/s Ranges
Experiment II • LPR510AL IC • Output Response vs. Rotation
Experiment II • Mechanical characteristics
Experiment II • LPR510AL • The axes of rotation are pitch (x) and roll (y) for LPR510AL
Experiment II • These two-axis gyros are essentially carrier boards or breakout boards for ST’s LPR510AL, LPY510AL, LPR550AL, and LPY550AL MEMS (micro-electro-mechanical systems) gyroscopes.
Experiment II • LPR510AL • For 5V microcontroller applications, the power down (PD) and self test (ST) lines should not be driven high. It is always safe for you to drive these lines low.
Experiment II • LPR510AL • The self-test input is pulled low by default. To activate the self-test feature, drive the line to Vdd (the same pull-up trick as above can be used for 5V applications).
Experiment II • LPR510AL • The devices can be powered directly through the Vdd/3.3V pin using a supply that is within the gyro chips’ acceptable power supply range of 2.7 V to 3.6 V.
Experiment II • LPR510AL • Alternatively, the boards can be powered by higher voltages, up to 16 V, using the VIN pin, which connects to a low-dropout 3.3V regulator. In this configuration, the 3.3V pin can serve as an output to be used as a reference voltage or power source for other low-power devices (up to around 50 mA, depending on the input voltage).
Experiment II • LPR510AL • Please note that unlike some other gyros and accelerometers, the outputs are not ratiometric with the Vdd/3.3V power line (i.e. at zero rate of rotation, the output should equal Vref, not half of the Vdd/3.3V supply).
Experiment II • Connection
Experiment II • Result • Steady State Position 258/1023*5V = 1.26V (But, the value described in data sheet is 1.23V)
AREF A0 A1 A2 Experiment III • ADXL335 & Arduino • (ZY?)
Experiment III • Sketch #define parameter 0.009765625 // AXDL335 用,代表 10 位元的 ADC 轉換 1 個刻度所代表的 G 值。(3.3/1024/0.33) #define rad 57.295779513082 // 徑度。(360/2*PI) double X,Y,Z,Xangle,Yangle,Zangle; int Xread,Yread,Zread; int Xref = 505; int Yref = 496; int Zref = 496; // XYZ 軸的偏差矯正參數,可透過此參數調整 XYZ 軸 0G 時的標準值 int Xinput = 0; // X 軸的類比電壓輸入腳位 int Yinput = 1; // Y 軸的類比電壓輸入腳位 int Zinput = 2; // Z 軸的類比電壓輸入腳位
Experiment III void setup() { Serial.begin(9600); // 串列傳輸的鮑率設定 analogReference(EXTERNAL); // 設定外部參考電壓 } void loop() { Xread = analogRead(Xinput); // 將 X 軸的輸入電壓存到所設定的變數 Yread = analogRead(Yinput); // 將 Y 軸的輸入電壓存到所設定的變數 Zread = analogRead(Zinput); // 將 Z 軸的輸入電壓存到所設定的變數 X = (Xread-Xref)*parameter; // 計算 X 軸的 G 值 Y = (Yread-Yref)*parameter; // 計算 Y 軸的 G 值 Z = (Zread-Zref)*parameter; // 計算 Z 軸的 G 值 Xangle = asin(constrain(X, -1, 1) )*rad; // 計算出 X 軸的傾斜角度 Yangle = asin(constrain(Y, -1, 1) )*rad; // 計算出 Y 軸的傾斜角度 Zangle = asin(constrain(Z, -1, 1) )*rad; // 計算出 Y 軸的傾斜角度
Experiment III Serial.print(" X = "); printDouble(X,2); Serial.print(" G"); Serial.print(9,BYTE); Serial.print(" Y = "); printDouble(Y,2); Serial.print(" G"); Serial.print(9,BYTE); Serial.print(" Z = "); printDouble(Z,2); Serial.print(" G"); Serial.print(9,BYTE); Serial.print(9,BYTE); Serial.print("thidaX = "); printDouble(Xangle,1); Serial.print(9,BYTE); Serial.print(" thidaY = "); printDouble(Yangle,1); Serial.print(9,BYTE); Serial.print(" thidaZ = "); printDouble(Zangle,1); Serial.println(" "); delay(500); }
Experiment III void printDouble( double val, byte precision){ if(val < 0.0){ Serial.print('-'); val = -val; } Serial.print (int(val)); //prints the int part if( precision > 0) { Serial.print("."); // print the decimal point unsigned long frac; unsigned long mult = 1; byte padding = precision -1; while(precision--) mult *=10;