“(SKU:RB-02S073)LSM9DS0- 9軸姿態(tài)傳感器”的版本間的差異
來自ALSROBOT WiKi
(→?產品相關推薦) |
|||
第99行: | 第99行: | ||
==應用例程== | ==應用例程== | ||
===示例代碼=== | ===示例代碼=== | ||
? | + | [https://github.com/sparkfun/SparkFun_LSM9DS0_Arduino_Library 庫文件官方下載地址]<br/> | |
? | + | <pre style='color:blue'> | |
? | + | #include <SPI.h> | |
? | + | ||
? | https://github.com/sparkfun/ | + | |
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | #include <SPI.h> | + | |
#include <Wire.h> | #include <Wire.h> | ||
#include <SFE_LSM9DS0.h> | #include <SFE_LSM9DS0.h> | ||
? | + | #define LSM9DS0_XM 0x1D | |
? | + | #define LSM9DS0_G 0x6B | |
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | #define LSM9DS0_XM 0x1D | + | |
? | #define LSM9DS0_G 0x6B | + | |
? | + | ||
? | + | ||
? | + | ||
LSM9DS0 dof(MODE_I2C, LSM9DS0_G, LSM9DS0_XM); | LSM9DS0 dof(MODE_I2C, LSM9DS0_G, LSM9DS0_XM); | ||
? | |||
? | |||
? | |||
? | |||
? | |||
? | |||
? | |||
? | |||
? | |||
? | |||
? | |||
? | |||
? | |||
#define PRINT_CALCULATED | #define PRINT_CALCULATED | ||
? | + | #define PRINT_SPEED 500 | |
? | + | ||
? | #define PRINT_SPEED 500 | + | |
? | + | ||
void setup() | void setup() | ||
{ | { | ||
? | Serial.begin(115200); | + | Serial.begin(115200); |
? | + | ||
? | + | ||
uint16_t status = dof.begin(); | uint16_t status = dof.begin(); | ||
? | |||
? | |||
? | |||
? | |||
? | |||
? | |||
? | |||
Serial.print("LSM9DS0 WHO_AM_I's returned: 0x"); | Serial.print("LSM9DS0 WHO_AM_I's returned: 0x"); | ||
Serial.println(status, HEX); | Serial.println(status, HEX); | ||
第221行: | 第124行: | ||
printAccel(); // Print "A: ax, ay, az" | printAccel(); // Print "A: ax, ay, az" | ||
printMag(); // Print "M: mx, my, mz" | printMag(); // Print "M: mx, my, mz" | ||
? | |||
? | |||
printHeading((float) dof.mx, (float) dof.my); | printHeading((float) dof.mx, (float) dof.my); | ||
printOrientation(dof.calcAccel(dof.ax), dof.calcAccel(dof.ay), | printOrientation(dof.calcAccel(dof.ax), dof.calcAccel(dof.ay), | ||
dof.calcAccel(dof.az)); | dof.calcAccel(dof.az)); | ||
Serial.println(); | Serial.println(); | ||
? | + | ||
delay(PRINT_SPEED); | delay(PRINT_SPEED); | ||
} | } | ||
第233行: | 第134行: | ||
void printGyro() | void printGyro() | ||
{ | { | ||
? | |||
? | |||
? | |||
dof.readGyro(); | dof.readGyro(); | ||
? | |||
? | |||
? | |||
Serial.print("G: "); | Serial.print("G: "); | ||
#ifdef PRINT_CALCULATED | #ifdef PRINT_CALCULATED | ||
? | |||
? | |||
? | |||
Serial.print(dof.calcGyro(dof.gx), 2); | Serial.print(dof.calcGyro(dof.gx), 2); | ||
Serial.print(", "); | Serial.print(", "); | ||
第261行: | 第153行: | ||
void printAccel() | void printAccel() | ||
{ | { | ||
? | |||
? | |||
? | |||
dof.readAccel(); | dof.readAccel(); | ||
? | |||
? | |||
? | |||
Serial.print("A: "); | Serial.print("A: "); | ||
#ifdef PRINT_CALCULATED | #ifdef PRINT_CALCULATED | ||
? | |||
? | |||
? | |||
Serial.print(dof.calcAccel(dof.ax), 2); | Serial.print(dof.calcAccel(dof.ax), 2); | ||
Serial.print(", "); | Serial.print(", "); | ||
第290行: | 第173行: | ||
void printMag() | void printMag() | ||
{ | { | ||
? | |||
? | |||
? | |||
dof.readMag(); | dof.readMag(); | ||
? | |||
? | |||
? | |||
Serial.print("M: "); | Serial.print("M: "); | ||
#ifdef PRINT_CALCULATED | #ifdef PRINT_CALCULATED | ||
? | |||
? | |||
? | |||
Serial.print(dof.calcMag(dof.mx), 2); | Serial.print(dof.calcMag(dof.mx), 2); | ||
Serial.print(", "); | Serial.print(", "); | ||
第315行: | 第189行: | ||
#endif | #endif | ||
} | } | ||
? | |||
? | |||
? | |||
? | |||
? | |||
? | |||
? | |||
void printHeading(float hx, float hy) | void printHeading(float hx, float hy) | ||
{ | { | ||
float heading; | float heading; | ||
? | + | ||
if (hy > 0) | if (hy > 0) | ||
{ | { | ||
第339行: | 第206行: | ||
else heading = 0; | else heading = 0; | ||
} | } | ||
? | + | ||
Serial.print("Heading: "); | Serial.print("Heading: "); | ||
Serial.println(heading, 2); | Serial.println(heading, 2); | ||
} | } | ||
? | |||
? | |||
? | |||
? | |||
void printOrientation(float x, float y, float z) | void printOrientation(float x, float y, float z) | ||
{ | { | ||
? | float pitch, roll; | + | float pitch, roll; |
? | + | ||
pitch = atan2(x, sqrt(y * y) + (z * z)); | pitch = atan2(x, sqrt(y * y) + (z * z)); | ||
roll = atan2(y, sqrt(x * x) + (z * z)); | roll = atan2(y, sqrt(x * x) + (z * z)); | ||
pitch *= 180.0 / PI; | pitch *= 180.0 / PI; | ||
roll *= 180.0 / PI; | roll *= 180.0 / PI; | ||
? | |||
Serial.print("Pitch, Roll: "); | Serial.print("Pitch, Roll: "); | ||
Serial.print(pitch, 2); | Serial.print(pitch, 2); | ||
Serial.print(", "); | Serial.print(", "); | ||
Serial.println(roll, 2); | Serial.println(roll, 2); | ||
? | }</pre> | + | } |
+ | </pre> | ||
===程序效果=== | ===程序效果=== | ||
下載完程序,然后打開串口監(jiān)視器,將波特率調到115200,然后按照顯示的內容輸入相應數字進行功能選擇,可以觀察到多種數據。 | 下載完程序,然后打開串口監(jiān)視器,將波特率調到115200,然后按照顯示的內容輸入相應數字進行功能選擇,可以觀察到多種數據。 |
2015年10月9日 (五) 11:22的版本
目錄 |
產品概述
LSM9DS0-9軸姿態(tài)傳感器選用的是LSM9DS0芯片,它是一種可實現(xiàn)動作感應的系統(tǒng)芯片,里面包括了一個3軸加速計,一個3軸陀螺儀和一個3軸磁力計。在LSM9DS0中,每種傳感器都有良好的檢測范圍:LSM9DS0線性加速滿量程為±2g/±4g/±6g/±8g/±16g;磁場滿量程為±2 /±4 /±8 /±12高斯;陀螺儀滿量程為±245 /±500 /±2000°/S。9軸姿態(tài)傳感器還包含了I2C串行總線接口,支持標準和快速模式(100 kHz和400 kHz)及SPI串行接口標準。
規(guī)格參數
- 模擬電源電壓范圍:2.4V~3.6V
- 3軸加速度計:±2/±4/±6/±8/±16 g
- 3軸陀螺儀:±245/±500/±2000°/S
- 3軸磁力計:±2/±4/±8/±12高斯
- 16位的數據輸出
- SPI/ I2C串行接口
- 嵌入式FIFO(先入先出的隊列);
- 可編程中斷發(fā)生
- 嵌入式自測試
- 嵌入式溫度傳感器
- 尺寸大?。?3.302cm x 1.524cm
- 重量大?。?0g
使用方法
引腳定義
9軸姿態(tài)傳感器 | 引腳定義 |
CSG | 陀螺儀芯片操作方式選擇引腳 |
CSXM | 加速度芯片操作方式選擇引腳 |
SDOG | 地址選擇引腳 |
SDOX | SPI模式輸出陀螺儀數據 |
SCL | 信號時鐘引腳 |
SDA | 數據引腳 |
VDD | 電源正極 |
GND | 電源地 |
DEN | 陀螺儀數據使能引腳 |
INTG | 陀螺儀可編程中斷 |
DRDYG | 陀螺儀數據準備引腳 |
INT1XM | 加速度中斷1 |
INT2XM | 加速度中斷2 |
連接圖示
首先需要安裝一下LSM9DS0的Arduino庫,然后圖中右側的小紅色芯片為電平轉換芯片。
9軸姿態(tài)傳感器 | Arduino |
CSG、CSXM、SDOG、SDOXM、DEN、INTG | 不接 |
SCL | SCL |
SDA | SDA |
VDD | 3.3V |
GND | GND |
DRDYG | D4 |
INT1XM | D2 |
INT2XM | D3 |
應用例程
示例代碼
#include <SPI.h> #include <Wire.h> #include <SFE_LSM9DS0.h> #define LSM9DS0_XM 0x1D #define LSM9DS0_G 0x6B LSM9DS0 dof(MODE_I2C, LSM9DS0_G, LSM9DS0_XM); #define PRINT_CALCULATED #define PRINT_SPEED 500 void setup() { Serial.begin(115200); uint16_t status = dof.begin(); Serial.print("LSM9DS0 WHO_AM_I's returned: 0x"); Serial.println(status, HEX); Serial.println("Should be 0x49D4"); Serial.println(); } void loop() { printGyro(); // Print "G: gx, gy, gz" printAccel(); // Print "A: ax, ay, az" printMag(); // Print "M: mx, my, mz" printHeading((float) dof.mx, (float) dof.my); printOrientation(dof.calcAccel(dof.ax), dof.calcAccel(dof.ay), dof.calcAccel(dof.az)); Serial.println(); delay(PRINT_SPEED); } void printGyro() { dof.readGyro(); Serial.print("G: "); #ifdef PRINT_CALCULATED Serial.print(dof.calcGyro(dof.gx), 2); Serial.print(", "); Serial.print(dof.calcGyro(dof.gy), 2); Serial.print(", "); Serial.println(dof.calcGyro(dof.gz), 2); #elif defined PRINT_RAW Serial.print(dof.gx); Serial.print(", "); Serial.print(dof.gy); Serial.print(", "); Serial.println(dof.gz); #endif } void printAccel() { dof.readAccel(); Serial.print("A: "); #ifdef PRINT_CALCULATED Serial.print(dof.calcAccel(dof.ax), 2); Serial.print(", "); Serial.print(dof.calcAccel(dof.ay), 2); Serial.print(", "); Serial.println(dof.calcAccel(dof.az), 2); #elif defined PRINT_RAW Serial.print(dof.ax); Serial.print(", "); Serial.print(dof.ay); Serial.print(", "); Serial.println(dof.az); #endif } void printMag() { dof.readMag(); Serial.print("M: "); #ifdef PRINT_CALCULATED Serial.print(dof.calcMag(dof.mx), 2); Serial.print(", "); Serial.print(dof.calcMag(dof.my), 2); Serial.print(", "); Serial.println(dof.calcMag(dof.mz), 2); #elif defined PRINT_RAW Serial.print(dof.mx); Serial.print(", "); Serial.print(dof.my); Serial.print(", "); Serial.println(dof.mz); #endif } void printHeading(float hx, float hy) { float heading; if (hy > 0) { heading = 90 - (atan(hx / hy) * (180 / PI)); } else if (hy < 0) { heading = - (atan(hx / hy) * (180 / PI)); } else // hy = 0 { if (hx < 0) heading = 180; else heading = 0; } Serial.print("Heading: "); Serial.println(heading, 2); } void printOrientation(float x, float y, float z) { float pitch, roll; pitch = atan2(x, sqrt(y * y) + (z * z)); roll = atan2(y, sqrt(x * x) + (z * z)); pitch *= 180.0 / PI; roll *= 180.0 / PI; Serial.print("Pitch, Roll: "); Serial.print(pitch, 2); Serial.print(", "); Serial.println(roll, 2); }
程序效果
下載完程序,然后打開串口監(jiān)視器,將波特率調到115200,然后按照顯示的內容輸入相應數字進行功能選擇,可以觀察到多種數據。
產品相關推薦
產品購買地址
周邊產品推薦
Arduino 9 Axes Motion Shield 9軸運動擴展板
相關問題解答
Arduino 9 Axes Motion Shield 9軸運動擴展板 三軸加速度計