Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
Luís Afonso
Published © GPL3+

Yaw, Pitch and Roll. From Values to Visual Interface

Create a simple interface in processing to show the output of 9 degrees of freedom IMU.

IntermediateShowcase (no instructions)8,917
Yaw, Pitch and Roll. From Values to Visual Interface

Things used in this project

Hardware components

STM32 Nucleo STM32F072 Nucleo Board
×1
Adafruit HMC5883L board
×1
Adafruit MPU6050 board
×1
Breadboard (generic)
Breadboard (generic)
×1

Story

Read more

Code

Processing Rotation visual interface

Java
You need processing 3 and of course a microcontroller communicating with it.
/*

  Rotation visual interface


  To use you require a microcontroler sending yaw, pich and roll in this order:
    yaw least significant byte
    yaw most significant byte
    Pitch (1 byte)
    Roll (1 byte)
    
  This in a cycle. Be carefull to not send it too fast or it will start lagging.
  
  Made by: Lus Afonso
*/


import processing.serial.*;
Serial myPort;  // Create object from Serial class

PFont f;


int Yaw_H;      // Data received from the serial port
int Yaw_L = 0;
int Pitch_H;      // Data received from the serial port
int Pitch_L = 0;
int Roll_H;      // Data received from the serial port
int Roll_L = 0;

float r;

// Angle and angular velocity, accleration
float F_Yaw;
float F_Pitch;
float F_Roll;

int xi = 0, yi=0;
void setup() 
{
  //size(1300, 720);
  fullScreen();

  // Initialize all values
  r = height * 0.45;

  // I know that the first port in the serial list on my mac
  // is always my  FTDI adaptor, so I open Serial.list()[0].
  // On Windows machines, this generally opens COM1.
  // Open whatever port is the one you're using.
  String portName = Serial.list()[0];
  myPort = new Serial(this, portName, 115200);

  /* 
      Change the text font to make it bigger
      You need to go to "Tools->Create font" to be able to use this. Just comment these 2 lines out
    if you don't feel like it.
  */
  f = createFont("SourceCodePro-Regular.vlw", 20);
  textFont(f);
}

void draw()
{

  /* 
    Wait for at least 4 values to be available to receive.
    It should be in order:
    yaw least significant byte
    yaw most significant byte
    Pitch 
    Roll 
    
    Pitch and Roll can be just 1 byte since they go in a 180 range, while yaw is 360 (360 doesn't fit in 8bit number)
  */
  if (myPort.available() >= 4) {  // If data is available,
    Yaw_L = myPort.read();         // read it and store it in val
    Yaw_H = myPort.read();         // read it and store it in val
    Pitch_L = myPort.read();         // read it and store it in val
    //Pitch_H = myPort.read();         // read it and store it in val
    Roll_L = myPort.read();         // read it and store it in val
    //Roll_H = myPort.read();         // read it and store it in val

    /* Just for debug purposes, prints in text console */
    print(Yaw_L);
    print(" ");
    print(Yaw_H);
    print(" ");
    print(Pitch_L);
    print(" ");
    print(Roll_L);
    println(" ");
  }

  //Set background to black (will erase previous drawing that was there in each cycle)
  background(0);

  // Translate the origin point to the center of the screen
  translate(width/2, height/2);
  int Yaw;
  Yaw = (Yaw_H <<8)|Yaw_L;

  int Pitch = 1*(Pitch_L-90);

  int Roll = 1*(Roll_L-90);


  F_Yaw = ((Yaw+90)*PI/180.0);

  // Convert polar to cartesian
  float x = -r * cos(F_Yaw);
  float y = r * sin(F_Yaw);

  // Draw the ellipse at the cartesian coordinate
  ellipseMode(CENTER);
  noStroke();
  fill(0, 255, 255);
  ellipse(x, y, 32, 32);
  fill(200);
  ellipse(0, 0, 10, 10);


  float F_Roll = Roll * PI /180;
  y = sin(F_Roll) * 300;
  x = cos(F_Roll)*300;
  stroke(0, 255, 0);
  line(xi, yi, x+xi, y+yi);
  line(xi, yi, xi-x, yi-y);

  float F_Pitch = Pitch * PI /180;
  float  y_P=  yi + sin(F_Pitch)*100;
  stroke(255, 0, 0);
  line(0, y_P, 300, y_P);
  line(0, y_P, -300, y_P);
  
  
  textAlign(RIGHT);
  fill(0, 255, 0);
  text("Roll:", 300, 200);
  text(Roll, 350, 200);
  fill(255, 0, 0);
  text("Pitch:", 300, 240);
  text(Pitch, 350, 240);
  fill(0, 100, 255);
  text("Yaw:", 300, 280);
  text(Yaw, 350, 280);
}

Credits

Luís Afonso

Luís Afonso

7 projects • 11 followers

Comments