Curie Nano与processing互动-Arduino中文社区 - Powered by Discuz!

Arduino中文社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 5176|回复: 6

Curie Nano与processing互动

[复制链接]
发表于 2017-6-10 19:24 | 显示全部楼层 |阅读模式
本帖最后由 芥末秋刀鱼 于 2017-6-11 20:14 编辑

Curie Nano上板载 加速度计,罗盘,还有陀螺仪是最吸引人的,现在赶快来上电玩一下吧
材料:Curie Nano和数据线足以
软件:arduino IDE和processing


先再IDE里配置一下开发环境吧
要arduino1.6.7以上的IDE才可以
1) 打开IDE,选择菜单栏工具"Tools",下拉栏点击板子"Board"选项,打开Boards Manager选项来扩展安装Intel Curie主板的编程库和驱动。

2) 在Board Manager弹出窗口中,找到"Intel Curie Boards by Intel version..."选项,在左下方,选择最新版本"select version",点击"Install"按钮,成功安装后效果如图。 3) 在成功安装Intel Curie Boards的插件和驱动包之后,在Board选项中就能选择并对所有基于Curie的开发板进行编程了。你有可能安装2.0.0的版本失败是因为你没翻墙,不能下载的话翻一下墙,不会翻墙的话下载那个低版本的即可。
废话不多说,先来跑一下101的那个互动示例吧
姿态解算Arduino官方提供了现成的解决方案,这让测试顺利的不行不行的
示例程序来自Madgwick库示例,可通过Arduino IDE菜单>文件>示例>Madgwick>Visualize101打开。即可


这个姿态算法把陀螺仪和加速度数据加以融合,然后返回四元数形式的姿态参数。接着通过四元数计算欧拉角,得到俯仰角(英文名pitch),横滚角(英文名roll)和偏航角(英文名yaw)。


IDE的代码:(烧录程序时板型选择101)
[kenrobot_code]#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;
}[/kenrobot_code]
下面是processing中的代码,这个是101的示例,本人对processing不怎么懂,准备自学,这里就不仔细介绍了。
[mw_shl_code=cpp,true]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

  // if you know the serial port name
  //myPort = new Serial(this, "COM5:", 9600);                    // Windows
  //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
}[/mw_shl_code]
发表于 2017-6-10 21:28 | 显示全部楼层
例程只采集了6轴
发表于 2017-6-11 09:01 | 显示全部楼层

processing在图像处理方面怎么样?比如灰度处理、特征值获取等

点评

具体我也没做过,反正都能实现  详情 回复 发表于 2017-6-11 10:19
发表于 2017-6-11 10:19 | 显示全部楼层
suoma 发表于 2017-6-11 09:01
processing在图像处理方面怎么样?比如灰度处理、特征值获取等

具体我也没做过,反正都能实现
 楼主| 发表于 2017-6-11 20:16 | 显示全部楼层

标题打错了,这个是6轴融合和processing互动,本来准备和采集9轴写一起的,但决定重新开一篇采集9轴数据到processing的贴

点评

其实只要把updateIMU换成update就可以带入九轴数据了  详情 回复 发表于 2017-6-11 21:04
发表于 2017-6-11 21:04 | 显示全部楼层
芥末秋刀鱼 发表于 2017-6-11 20:16
标题打错了,这个是6轴融合和processing互动,本来准备和采集9轴写一起的,但决定重新开一篇采集9轴数据 ...

其实只要把updateIMU换成update就可以带入九轴数据了
 楼主| 发表于 2017-6-12 14:54 | 显示全部楼层
奈何col 发表于 2017-6-11 21:04
其实只要把updateIMU换成update就可以带入九轴数据了

不是,在processing中另外做一个采集9轴数据的图形互动
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|Archiver|手机版|Arduino中文社区

GMT+8, 2024-11-28 06:40 , Processed in 0.406385 second(s), 16 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表