AHRS filter with STM32F3
Posted: Sat Jul 13, 2013 1:14 am
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
In time i'll improve it.
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.