角速度+加速度_第1頁(yè)
角速度+加速度_第2頁(yè)
角速度+加速度_第3頁(yè)
全文預(yù)覽已結(jié)束

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、#include #define Acc 0x1D#define Gyr 0x69#define Mag 0x1E#define Gry_offset -13 / 陀螺儀偏移量#define Gyr_Gain 0.07 / 滿量程2000dps時(shí)靈敏度(dps/digital)#define pi 3.14159float angleG;unsigned long timer = 0; / 采樣時(shí)間void setup() sensor_init(); / 配置傳感器 Serial.begin(19200); / 開(kāi)啟串口以便監(jiān)視數(shù)據(jù) delay(1000); void loop() long

2、 o_timer = timer; / 上一次采樣時(shí)間(ms) float Y_Accelerometer = gDat(Acc, 1); / 獲取向前的加速度 float Z_Accelerometer = gDat(Acc, 2); / 獲取向下的加速度 float angleA = atan(Y_Accelerometer / Z_Accelerometer) * 180 / pi; / 根據(jù)加速度分量得到的角度(degree) timer = millis(); / 當(dāng)前時(shí)間(ms) int dt = timer - o_timer; / 微分時(shí)間 angleG = angleG +

3、Gyr_Gain * (gDat(Gyr, 0) + Gry_offset) * dt / 1000; / 對(duì)角速度積分得到的角度(degree) Serial.print(timer); Serial.print(,); Serial.print(angleA, 6); Serial.print(,); Serial.print(angleG, 6); Serial.print(;); / 輸出數(shù)據(jù) delay(10); int gDat(int device, int axis) / 讀九軸姿態(tài)傳感器寄存器函數(shù)/ For Arduino, by 黑馬/ 調(diào)用參數(shù)表/ type device

4、 axis/ 0 1 2/ ADXL345 Acc x y z/ L3G4200D Gyr x y z/ HMC5883L Mag x z y/ Example/ 00 #include / 01 #define Acc 0x1D;/ 02 #define Gyr 0x69;/ 03 #define Mag 0x1E;/ 04/ 05 void setup() / 06 sensor_init();/ 07 delay(1000);/ 08 / 09/ 10 void loop() / 11 int Z-Gyroscope;/ 12 Z-Gyroscope = gDat(Gyr, 2);/ 1

5、3 delay(50);/ 14 int v; byte vL, vH, address; / 存放byte數(shù)值 if (device = Acc) address = 0x32; / ADXL345的讀數(shù)地址 if (device = Gyr) address = 0xA8; / L3G4200D的讀數(shù)地址 if (device = Mag) address = 0x03; / HMC5883L的讀數(shù)地址 address = address + axis * 2; / 數(shù)據(jù)偏移-坐標(biāo)軸 Wire.beginTransmission(device); / 開(kāi)始傳輸數(shù)據(jù) Wire.send(ad

6、dress); / 發(fā)送指針 Wire.requestFrom(device, 2); / 請(qǐng)求2 byte數(shù)據(jù) while(Wire.available() 2); / 成功獲取前等待 vL = Wire.receive(); vH = Wire.receive(); / 讀取數(shù)據(jù) Wire.endTransmission(); / 結(jié)束傳輸 if (device = Mag) v = (vL 8) | vH; else v = (vH 8) | vL; / 將byte數(shù)據(jù)合并為Int return v; / 返回讀書(shū)值void sensor_init() / 配置九軸姿態(tài)傳感器 write

7、Register(Acc, 0x2D, 0b00001000); / 測(cè)量模式 / 配置ADXL345 writeRegister(Gyr, 0x20, 0b00001111); / 設(shè)置睡眠模式、x, y, z軸使能 writeRegister(Gyr, 0x21, 0b00000000); / 選擇高通濾波模式和高通截止頻率 writeRegister(Gyr, 0x22, 0b00000000); / 設(shè)置中斷模式 writeRegister(Gyr, 0x23, 0b00110000); / 設(shè)置量程(2000dps)、自檢狀態(tài)、SPI模式 writeRegister(Gyr, 0x24, 0b00000000); / FIFO & 高通濾波 / 配置L3G4200D(2000 deg/sec) writeRegister(Mag, 0x02, 0x00); / 連續(xù)測(cè)量 / 配置HMC5883Lvoid writeRegister(int device, byte

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論