AHRS filter with STM32F3

This forum is about you. Feel free to discuss anything is related to embedded and electronics, your awesome projects, your ideas, your announcements, not necessarily related to ChibiOS but to embedded in general. This forum is NOT for support.
User avatar
RoccoMarco
Posts: 635
Joined: Wed Apr 24, 2013 4:11 pm
Location: Salerno (Italy)
Has thanked: 78 times
Been thanked: 60 times
Contact:

AHRS filter with STM32F3

Postby RoccoMarco » 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

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.
Attachments
ARMCM4-STM32F303-DISCOVERY-AHRS-9DOF_000.7z
(1.32 MiB) Downloaded 222 times

User avatar
Tectu
Posts: 1226
Joined: Thu May 10, 2012 9:50 am
Location: Switzerland
Contact:

Re: AHRS filter with STM32F3

Postby Tectu » Sat Jul 13, 2013 1:09 pm

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

User avatar
RoccoMarco
Posts: 635
Joined: Wed Apr 24, 2013 4:11 pm
Location: Salerno (Italy)
Has thanked: 78 times
Been thanked: 60 times
Contact:

Re: AHRS filter with STM32F3

Postby RoccoMarco » Sat Jul 13, 2013 2:24 pm

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

User avatar
RoccoMarco
Posts: 635
Joined: Wed Apr 24, 2013 4:11 pm
Location: Salerno (Italy)
Has thanked: 78 times
Been thanked: 60 times
Contact:

Re: AHRS filter with STM32F3

Postby RoccoMarco » Thu Jul 25, 2013 4:18 am

Some updates

[youtube]sx_kNCwGS8E[/youtube]
Attachments
ARMCM4-STM32F303-DISCOVERY-AHRS-9DOF_000.7z
(1.3 MiB) Downloaded 243 times

User avatar
RoccoMarco
Posts: 635
Joined: Wed Apr 24, 2013 4:11 pm
Location: Salerno (Italy)
Has thanked: 78 times
Been thanked: 60 times
Contact:

Re: AHRS filter with STM32F3

Postby RoccoMarco » Sat Jul 27, 2013 1:12 pm

this is processing sketchfolder. just copy it in sketchbook folder in c:\Processing 2.0, and ask if you need.
Attachments
Guglielmi_Rocco_Marco_0610400223.7z
(265.84 KiB) Downloaded 188 times

User avatar
Tectu
Posts: 1226
Joined: Thu May 10, 2012 9:50 am
Location: Switzerland
Contact:

Re: AHRS filter with STM32F3

Postby Tectu » Sat Jul 27, 2013 1:40 pm

This looks quite funny - I dream of the time where stuff like this can be part of uGFX :D

~ Tectu


Return to “User Projects”

Who is online

Users browsing this forum: No registered users and 4 guests