Arduino/Genuino 101 的姿态数据获取代码,你们能跑多长时间?-Arduino中文社区 - Powered by Discuz! Archiver

老铁 发表于 2017-6-30 10:50

Arduino/Genuino 101 的姿态数据获取代码,你们能跑多长时间?

本帖最后由 老铁 于 2017-6-30 10:51 编辑

    最近在玩Arduino/Genuino 101,通过用官方网站的代码得到了我想要的欧拉角数据!哈哈,然后开始玩耍吧!我用他们控制舵机,后来问题出现了!    程序跑着跑着就死了,通过询问各方大神,舵机需要外部供电(我用了双舵机),那就该吧!我外部添加了一个5v的电池组。跑起来…………还是不行,而且是不定性的跑死。今天我把舵机程序给去除了,用官方欧拉角获取数据代码单测……问题找到了,跑死的居然是源码!!!    难道是我的板子问题?不知道这段代码在你们板子上能跑多长时间!我的板子上运行时间,最短40秒,最长40分,一般情况下就是4分。(不含重启时间)!    哪位大神能给看看代码,帮忙改一改。--------不会真的是板子问题吧!
#include <CurieIMU.h>
#include <MadgwickAHRS.h>

Madgwick filter;
unsigned long microsPerReading, microsPrevious;
float accelScale, gyroScale;

void setup() {
Serial.begin(9600);

// start the IMU and filter
CurieIMU.begin();
CurieIMU.setGyroRate(25);
CurieIMU.setAccelerometerRate(25);
filter.begin(25);

// Set the accelerometer range to 2G
CurieIMU.setAccelerometerRange(2);
// Set the gyroscope range to 250 degrees/second
CurieIMU.setGyroRange(250);

// initialize variables to pace updates to correct rate
microsPerReading = 1000000 / 25;
microsPrevious = micros();
}

void loop() {
int aix, aiy, aiz;
int gix, giy, giz;
float ax, ay, az;
float gx, gy, gz;
float roll, pitch, heading;
unsigned long microsNow;

// check if it's time to read data and update the filter
microsNow = micros();
if (microsNow - microsPrevious >= microsPerReading) {

    // read raw data from CurieIMU
    CurieIMU.readMotionSensor(aix, aiy, aiz, gix, giy, giz);

    // convert from raw data to gravity and degrees/second units
    ax = convertRawAcceleration(aix);
    ay = convertRawAcceleration(aiy);
    az = convertRawAcceleration(aiz);
    gx = convertRawGyro(gix);
    gy = convertRawGyro(giy);
    gz = convertRawGyro(giz);

    // update the filter, which computes orientation
    filter.updateIMU(gx, gy, gz, ax, ay, az);

    // print the heading, pitch and roll
    roll = filter.getRoll();
    pitch = filter.getPitch();
    heading = filter.getYaw();
    Serial.print("Orientation: ");
    Serial.print(heading);
    Serial.print(" ");
    Serial.print(pitch);
    Serial.print(" ");
    Serial.println(roll);

    // increment previous time, so we keep proper pace
    microsPrevious = microsPrevious + microsPerReading;
}
}

float convertRawAcceleration(int aRaw) {
// since we are using 2G range
// -2g maps to a raw value of -32768
// +2g maps to a raw value of 32767

float a = (aRaw * 2.0) / 32768.0;
return a;
}

float convertRawGyro(int gRaw) {
// since we are using 250 degrees/seconds range
// -250 maps to a raw value of -32768
// +250 maps to a raw value of 32767

float g = (gRaw * 250.0) / 32768.0;
return g;
}

奈何col 发表于 2017-6-30 13:29

试试最新的101 package
https://github.com/01org/corelibs-arduino101/releases/download/2.1.0/package_public-2.1.0-rc1_index.json

老铁 发表于 2017-6-30 13:40

奈何col 发表于 2017-6-30 13:29
试试最新的101 package
https://github.com/01org/corelibs-arduino101/releases/download/2.1.0/package_p ...

怎么使用这个文件?看不懂啊:funk:

老铁 发表于 2017-6-30 13:52

老铁 发表于 2017-6-30 13:40
怎么使用这个文件?看不懂啊

正在下载中,文本打开文件,点击最上面的2.1.0的链接就开始下载了

老铁 发表于 2017-6-30 14:09

本帖最后由 老铁 于 2017-6-30 15:02 编辑

奈何col 发表于 2017-6-30 13:29
试试最新的101 package
https://github.com/01org/corelibs-arduino101/releases/download/2.1.0/package_p ...
怎么安装?

奈何col 发表于 2017-6-30 16:59

翻墙再试试
页: [1]
查看完整版本: Arduino/Genuino 101 的姿态数据获取代码,你们能跑多长时间?