一、安装:

对于 Genuino 101(在美国叫做 Arduino 101),目前最新的 Arduino IDE 还默认不会支持,需要手动安装驱动。

将 Genuino 101 插入电脑 USB ,等待基本驱动安装完毕后,打开 Arduino IDE。

然后打开“开发板管理器”,在“开发板管理器”中找到“Intel Curie Bords by Intel”,在右边点安装。

等4个步骤全部下载安装完毕后,将 Arduino IDE 关闭,拔出 Genuino 101。

重新打开 Arduino IDE ,插入 Genuino 101。在开发板选择中选中 Genuino 101。端口应该会自动识别,如果没有正确识别,再勾选正确的端口。

二、测试:

本段参考Arduino.cc官网指南:https://www.arduino.cc/en/Tutorial/Genuino101CurieIMUOrientationVisualiser

  1. Genuino 101入门中所述,设置Arduino软件(IDE)。
  2. 连接101和用户电脑。
  3. 启动Arduino软件(IDE),并从“工具 > 开发板” 菜单项中选择Arduino/Genuino 101。
  4. 由开发库管理器中安装Madgwick 库。可打开Arduino软件(IDE),选择”Sketch -> Include Library -> Manage Libraries”。然后搜索’Madgwick’ 并直接安装开发库。请参阅开发库安装指导 了解安装和导入开发库的更详细解释。
  5. 下载启动Processing软件 ,并使用如下所示处理代码创建一个文件。
  6. 修改串行端口,使用用户101开发板正在使用的端口号(参阅”处理代码”章节)。
  7. 上传CurieIMU 示例至用户101开发板,请确保开发板保持水平和静止以便进行精确校准。
  8. 几秒钟后,运行Processing代码,调整开发板方向,查看程序对开发板的可视化显示。

Genuino 101 的代码

#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;
}

Processing 的代码

import processing.serial.*;
Serial myPort;

float yaw = 0.0;
float pitch = 0.0;
float roll = 0.0;

void setup()
{
  size(600, 500, P3D);

  // if you have only ONE serial port active
  myPort = new Serial(this, Serial.list()[0], 9600); // if you have only ONE serial port active
  //必须注意,如果你运行无效,但是知道自己用的哪个COM口,就修改一下这里的代码。
  // if you know the serial port name
  //myPort = new Serial(this, "COM5", 9600);                    // Windows,注意官网上有错误,COM5后应该没有冒号:才对
  //myPort = new Serial(this, "/dev/ttyACM0", 9600);             // Linux
  //myPort = new Serial(this, "/dev/cu.usbmodem1217321", 9600);  // Mac

  textSize(16); // set text size
  textMode(SHAPE); // set text mode to shape
}

void draw()
{
  serialEvent();  // read and parse incoming serial message
  background(255); // set background to white
  lights();

  translate(width/2, height/2); // set position to centre

  pushMatrix(); // begin object

  float c1 = cos(radians(roll));
  float s1 = sin(radians(roll));
  float c2 = cos(radians(pitch));
  float s2 = sin(radians(pitch));
  float c3 = cos(radians(yaw));
  float s3 = sin(radians(yaw));
  applyMatrix( c2*c3, s1*s3+c1*c3*s2, c3*s1*s2-c1*s3, 0,
               -s2, c1*c2, c2*s1, 0,
               c2*s3, c1*s2*s3-c3*s1, c1*c3+s1*s2*s3, 0,
               0, 0, 0, 1);

  drawArduino();

  popMatrix(); // end of object

  // Print values to console
  print(roll);
  print("\t");
  print(pitch);
  print("\t");
  print(yaw);
  println();
}

void serialEvent()
{
  int newLine = 13; // new line character in ASCII
  String message;
  do {
    message = myPort.readStringUntil(newLine); // read from port until new line
    if (message != null) {
      String[] list = split(trim(message), " ");
      if (list.length >= 4 && list[0].equals("Orientation:")) {
        yaw = float(list[1]); // convert to float yaw
        pitch = float(list[2]); // convert to float pitch
        roll = float(list[3]); // convert to float roll
      }
    }
  } while (message != null);
}

void drawArduino()
{
  /* function contains shape(s) that are rotated with the IMU */
  stroke(0, 90, 90); // set outline colour to darker teal
  fill(0, 130, 130); // set fill colour to lighter teal
  box(300, 10, 200); // draw Arduino board base shape

  stroke(0); // set outline colour to black
  fill(80); // set fill colour to dark grey

  translate(60, -10, 90); // set position to edge of Arduino box
  box(170, 20, 10); // draw pin header as box

  translate(-20, 0, -180); // set position to other edge of Arduino box
  box(210, 20, 10); // draw other pin header as box
}

运行视频:

https://www.taholab.com/wp-content/uploads/genuino101test.wmv

2 条评论

回复 taho 取消回复

您的邮箱地址不会被公开。 必填项已用 * 标注