Page 1 of 1

AHRS filter with STM32F3

Posted: Sat Jul 13, 2013 1:14 am
by RoccoMarco
Hi,
I'm introducing my project. It uses an STM32F3 and his MEMS to compute the orientation of board referring to Earth Frame... My settings are still imperfect but it seems to work

this is the code for a processing sketch to test my code

Code: Select all

/*
 * Processing sketch for AHRS filter with STM32F3
 */

import processing.serial.*;

int cr = 13; //Carriage return in ASCII
int spc = 32; // Space in ASCII
int x = 0, y = 0, z = 0;
String myString = null;
String temporary;
String tokens [];
int pitch = 0, roll = 0, yaw = 0;
float pf = 0, rf = 0, yf = 0;
float pigrec = 3.14159265358979;
float degtorad = pigrec / 180;
Serial myPort;  // The serial port
PImage img;
float value = 0, value2 = 0;
float offsetx = 0;          //roll
float offsety = -pigrec / 2;          //pitch
float offsetz = pigrec / 2; //yaw

void setup() {
  size(800, 800, P3D);
  img = loadImage("Texture.jpg");
  // List all the available serial ports
  println(Serial.list());
  // Open the port you are using at the rate you want:
  if (Serial.list()[0] != null){
   myPort = new Serial(this, Serial.list()[0], 9600);
   myPort.clear();
   tokens = new String [7];
  }
  else{
  println("/n No device found");
  }
  // Throw out the first reading, in case we started reading
  // in the middle of a string from the sender.
  myString = myPort.readStringUntil(cr);
  myString = null;
}

void draw() {
  pf = (float) degtorad * pitch / 1000;
  rf = (float) degtorad * roll / 1000;
  yf = (float) degtorad * yaw / 1000;
  println ("Pi:"+ pitch + " Ro:"+ roll + "Ya:" + yaw);
  println ("P: "+ pf + " R: "+ rf + " Y: " + yf);
  translate(400,400,0);
 
 
 
  value = value + degtorad;
  value2 = value2 + degtorad / 2;
 
  rotateZ(-yf);
  rotateY(pf);
  rotateX(-rf); 
 
 
 

     
  background(255);
  image(img, 0, 0);
  imageMode(CENTER);
//  stroke(255, 128, 0);   
//  rect(0, 0, 200, 200);
  while (myPort.available() > 0){
    myString = myPort.readStringUntil(cr);
    if (myString != null){
      tokens = myString.split(" ");
      roll = Integer.parseInt(tokens[1]);
      pitch = Integer.parseInt(tokens[3]);
      yaw = Integer.parseInt(tokens[5]);
    }
  }
}


In time i'll improve it.

Re: AHRS filter with STM32F3

Posted: Sat Jul 13, 2013 1:09 pm
by Tectu
As always, I don't have a usecase yet, but thank you very much for sharing! Contributions will always be helpful for some people at some point :)


~ Tectu

Re: AHRS filter with STM32F3

Posted: Sat Jul 13, 2013 2:24 pm
by RoccoMarco
ahhahaha!
Dear Tectu, my contributions would cause a lot of confusion for new users, because bugs proliferate in my sources. ;) :mrgreen:

- The Lord of the Bugs

Re: AHRS filter with STM32F3

Posted: Thu Jul 25, 2013 4:18 am
by RoccoMarco
Some updates

[youtube]sx_kNCwGS8E[/youtube]

Re: AHRS filter with STM32F3

Posted: Sat Jul 27, 2013 1:12 pm
by RoccoMarco
this is processing sketchfolder. just copy it in sketchbook folder in c:\Processing 2.0, and ask if you need.

Re: AHRS filter with STM32F3

Posted: Sat Jul 27, 2013 1:40 pm
by Tectu
This looks quite funny - I dream of the time where stuff like this can be part of uGFX :D

~ Tectu