_SKU_SEN0258_10DOF_Attitude_Sensor - jimaobian/DFRobotWikiCn GitHub Wiki
简介
产品参数
- 工作电压:3.3V-5.5V DC
- 工作电流:265uA~35mA
- 接口:USB接口,SPI接口
- 3轴12-bit加速度传感器
- 3轴地磁传感器
- 3轴16-bit陀螺仪
- BMP280气压传感器
- 工作温度:-30~+80 ℃
- 产品尺寸:32*37 mm
- 接口:USB接口,SPI接口
引脚说明
| | | | -------------------------------------------------------------------------- | | | | |
标号 | 名称 | 功能描述 |
1 | USB | USB |
2 | VCC | 5V电源电压输入 |
3 | GND | GND |
4 | SPI接口 | SPI |
5 | INT接口 | 中断 |
电流转电压传感器引脚对应表
专业术语描述
该10DOF Attitude Sensor采用加速度计、陀螺仪以及电子罗盘传感器,并输出处理后的姿态飞行数据---欧拉角。因此,在使用该模块之前,需要对相关术语及原理进行了解。
- 什么是欧拉角?
欧拉角是用来唯一地确定定点转动明体位置的三个一组独立角参量,由章动角θ、进动角ψ和自转角φ组成,为L.欧拉首先提出,故得名。简单点说,就是刚体的姿态改变,可以具体到刚体沿着坐标系轴旋转的角度。我们把10DOF Attitude Sensor模块想象成一架飞机,而机头方向是10DOF Attitude Sensor的y轴方向,机身的翅膀方向是10DOF Attitude Sensor的x轴方向,与机身垂直的方向是z轴方向,如下图所示:
- 姿态的表示方法
围绕着X轴旋转的,称为俯仰角(pitch):机体抬头时,pitch为正,反之为负。如下图所示: 围绕着Z轴旋转的,称为偏航角(yaw):机头向右时,yaw为正,反之为负。如下图所示: 围绕着Y轴旋转的,称为翻滚角(roll):机体向右翻滚时,roll正,反之为负。如下图所示:
姿态模拟
- 通过串口查看姿态数据
为了方便姿态模拟,10DOF Attitude Sensor提供了姿态数据USB串口输出端口,打开arduino串口调试助手,选择10DOF Attitude Sensor对应的串口,波特率为115200,输出数据如下:
- 通过软件仿真姿态
- 点击链接,IMU_show.exe软件,下IMU_show.exe软件,进行姿态仿真。打开IMU_show.exe软件,选择10DOF Attitude Sensor模块对应的串口,波特率为115200,如下图所示:
使用教程
本教程演示如何使用这款10DOF Attitude Sensor模块。
准备
- 硬件
- Arduino UNO x1
- 10DOF Attitude Sensor x1
- 杜邦线、导线 若干
- 软件
- DFRobot_10DOF库文件
- imu_show.exe
- Arduino IDE 版本1.6.8 点击下载Arduino IDE
接线图
样例代码
| 6.3.1程序功能说明: 通过SPI接口读取MPU6050传感器的仰角、翻滚角、偏航角,并将读取到的数据通过串口打印出来。此demo结合DFRobot新推出的imu_show.exe软件,来显示姿态变化的实时过程,具体软件介绍请查看软件说明。
/*
* file 10DOF.ino
*
* @ https://github.com/DFRobot/DFRobot_10DOF
*
* connect with your board (please reference board compatibility)
*
* 10-DOF inertial guidance sensor, providing accurate Euler angle information: When the USB access,
* can cooperate with our software Imu_show(https://github.com/DFRobot/DFRobot_IMU_Show)
* real-time transmission display current posture (in the default standard mode),
* and other MCU through the SPI interface Communication transmission attitude information and temperature, altitude information.
*
* Copyright [DFRobot](http://www.dfrobot.com), 2016
* Copyright GNU Lesser General Public License
*
* version V1.0
* date 2018-04-23
*/
#include "DFRobot_10DOF.h"
#include "SPI.h"
/*
* pin_dataRdy ----> int1
* pin_accelInt ----> int2
*/
#ifdef __AVR__
uint8_t pin_cs = 4, pin_dataRdy = 2, pin_accelInt = 3;
#else
uint8_t pin_cs = D4, pin_dataRdy = D2, pin_accelInt = D3;
#endif
DFRobot_10DOF_SPI dof(pin_cs);
uint8_t dataRdyFlag = 0, accelIntFlag = 0;
//test data ready interrupt
void dataRdyInterrupt()
{
dataRdyFlag = 1;
}
//test accelerometer overflow interrupt
void accelInterrupt()
{
accelIntFlag = 1;
}
void setup()
{
Serial.begin(115200);
delay(500);
pinMode(pin_dataRdy, INPUT_PULLUP);
pinMode(pin_accelInt, INPUT_PULLUP);
attachInterrupt(pin_dataRdy, dataRdyInterrupt, FALLING);
attachInterrupt(pin_accelInt, accelInterrupt, FALLING);
while(!Serial);
SPI.begin();
Serial.println();
Serial.println("10dof test");
while(dof.begin() != 0) { //spend time 500ms
Serial.println("dof begin faild !");
delay(2000);
}
Serial.println("dof begin successful !");
delay(2000);
}
void loop()
{
float pitch = 0, roll = 0, yaw = 0;
dof.readAttitude(&pitch, &roll, &yaw); /* read euler angle */
/* In order to match the API of the upper computer, X ----> pitch */
Serial.print("pitch:");
Serial.print(((float)pitch), 3);
Serial.print(" ");
/* In order to match the API of the upper computer, Y ----> roll */
Serial.print("roll:");
Serial.print(((float)roll), 3);
Serial.print(" ");
/* In order to match the API of the upper computer, Z ----> yaw */
Serial.print("yaw:");
Serial.print(((float)yaw), 3);
Serial.println(" ");
delay(80);
}
6.3.2程序功能说明: 通过SPI接口读取10DOF的仰角、翻滚角、偏航角、陀螺仪三轴原始数据、加速计三轴原始数据、温度与大致海拔高度,并将读取到的数据通过串口打印出来。
/*
* file 10DOF.ino
*
* @ https://github.com/DFRobot/DFRobot_10DOF
*
* connect with your board (please reference board compatibility)
*
* 10-DOF inertial guidance sensor, providing accurate Euler angle information: When the USB access,
* can cooperate with our software Imu_show(https://github.com/DFRobot/DFRobot_IMU_Show)
* real-time transmission display current posture (in the default standard mode),
* and other MCU through the SPI interface Communication transmission attitude information and temperature, altitude information.
*
* Copyright [DFRobot](http://www.dfrobot.com), 2016
* Copyright GNU Lesser General Public License
*
* version V1.0
* date 2018-04-23
*/
#include "DFRobot_10DOF.h"
#include "SPI.h"
/*
* pin_dataRdy ----> int1
* pin_accelInt ----> int2
*/
#ifdef __AVR__
uint8_t pin_cs = 4, pin_dataRdy = 2, pin_accelInt = 3;
#else
uint8_t pin_cs = D4, pin_dataRdy = D2, pin_accelInt = D3;
#endif
DFRobot_10DOF_SPI dof(pin_cs);
uint8_t dataRdyFlag = 0, accelIntFlag = 0;
static inline void readAttitude(void)
{
Serial.println();
float pitch = 0, roll = 0, yaw = 0;
dof.readAttitude(&pitch, &roll, &yaw);
Serial.println("attitude: ");
Serial.print("pitch :");
Serial.print(((float)pitch));
Serial.print(" ");
Serial.print("roll :");
Serial.print(((float)roll));
Serial.print(" ");
Serial.print("yaw :");
Serial.print(((float)yaw));
Serial.print(" ");
Serial.println();
int16_t GX = 0, GY = 0, GZ = 0;
dof.readGyro(&GX, &GY, &GZ);
Serial.println("gyroscope: ");
Serial.print("GX :");
Serial.print(GX);
Serial.print(" ");
Serial.print("GY :");
Serial.print(GY);
Serial.print(" ");
Serial.print("GZ :");
Serial.print(GZ);
Serial.print(" ");
Serial.println();
int16_t AX = 0, AY = 0, AZ = 0;
dof.readAccelerometer(&AX, &AY, &AZ);
Serial.println("accelerometer: ");
Serial.print("AX :");
Serial.print(AX);
Serial.print(" ");
Serial.print("AY :");
Serial.print(AY);
Serial.print(" ");
Serial.print("AZ :");
Serial.print(AZ);
Serial.print(" ");
}
static inline void readEnvironment(void)
{
Serial.println();
int16_t temp = 0, humi = 0;
int32_t pre;
float alt;
dof.readEnvironment(&temp, &alt);
Serial.print("temp: ");
Serial.print(((float)temp) / 100);
Serial.print(" ");
Serial.print("altitude: ");
Serial.print(alt);
Serial.print(" ");
}
//test data ready interrupt
void dataRdyInterrupt()
{
dataRdyFlag = 1;
}
//test accelerometer overflow interrupt
void accelInterrupt()
{
accelIntFlag = 1;
}
void setup()
{
Serial.begin(115200);
delay(500);
pinMode(pin_dataRdy, INPUT_PULLUP);
pinMode(pin_accelInt, INPUT_PULLUP);
attachInterrupt(pin_dataRdy, dataRdyInterrupt, FALLING);
attachInterrupt(pin_accelInt, accelInterrupt, FALLING);
while(!Serial);
SPI.begin();
Serial.println();
Serial.println("10dof test");
while(dof.begin() != 0) { //spend time 500ms
Serial.println("dof begin faild !");
delay(2000);
}
Serial.println("dof begin successful !");
delay(2000);
}
void loop()
{
unsigned long lastMillis = 0;
Serial.println();
Serial.println();
Serial.println("test mode standerd"); //output rate 75hz in standerd mode
delay(1000);
dof.setMode(e10DOF_MODE_STANDERD);
lastMillis = millis();
while((millis() - lastMillis) < 1000) {
readAttitude();
readEnvironment();
delay(1000 / 10);
}
delay(1000);
Serial.println();
Serial.println();
Serial.println("test mode fast"); //output rate 500hz in fast mode and do not reference yaw data
delay(1000);
dof.setMode(e10DOF_MODE_FAST);
lastMillis = millis();
while((millis() - lastMillis) < 1000) {
readAttitude();
readEnvironment();
delay(1000 / 10);
}
delay(1000);
Serial.println();
Serial.println();
Serial.println("test data ready interrupt"); //when attitude data is ready, low level on pin 'int1'
delay(1000);
dof.enableDataInt();
lastMillis = millis();
while((millis() - lastMillis) < 1000) {
if(dataRdyFlag) {
dataRdyFlag = 0;
Serial.println();
float pitch = 0, roll = 0, yaw = 0;
dof.readAttitude(&pitch, &roll, &yaw);
Serial.println("attitude: ");
Serial.print("pitch :");
Serial.print(((float)pitch));
Serial.print(" ");
Serial.print("roll :");
Serial.print(((float)roll));
Serial.print(" ");
Serial.print("yaw :");
Serial.print(((float)yaw));
Serial.print(" ");
}
}
dof.disableDataInt();
delay(1000);
Serial.println();
Serial.println();
Serial.println("test accelerometer interrupt"); //when accelerometer is overflow, low level on pin 'int2'
delay(1000);
dof.setAccelInt(0, 0);
dof.enableAccelInt();
lastMillis = millis();
while((millis() - lastMillis) < 1000) {
if(accelIntFlag) {
accelIntFlag = 0;
Serial.println();
int16_t AX = 0, AY = 0, AZ = 0;
dof.readAccelerometer(&AX, &AY, &AZ);
Serial.println("accelerometer: ");
Serial.print("AX :");
Serial.print(AX);
Serial.print(" ");
Serial.print("AY :");
Serial.print(AY);
Serial.print(" ");
Serial.print("AZ :");
Serial.print(AZ);
Serial.print(" ");
}
}
dof.disableAccelInt();
delay(1000);
Serial.println();
Serial.println();
Serial.println("test LED control"); //test LED conrol on board
dof.disableLED();
delay(4000);
dof.enableLED();
delay(2000);
Serial.println();
Serial.println();
Serial.println("test stop mode"); //test stop mode
delay(1000);
dof.setMode(e10DOF_MODE_STOP);
delay(4000);
dof.weakUp(); //spend time 500ms
delay(500);
Serial.println();
Serial.println("-------- test end --------");
delay(1000);
}
常见问题
还没有客户对此产品有任何问题,欢迎通过qq或者论坛联系我们!
| 更多问题及有趣的应用,可以 访问论坛 进行查阅或发帖! |