magnetometer calibration errors

Hello guys, i wan't to calibrate my 9DUF, accelerometer, magnetometer and gyroscope.

I have succesfully calibrated the accelerometer so far, but when calibrating the magnetometer I'm receiving some errors which I'm not able to solve.

The EJML library is imported correctly as mentioned in the tutorial provided by the designer of the software:
https://dev.qu.tu-berlin.de/projects/sf-razor-9dof-ahrs/wiki/Tutorial#Extended-magnetometer-calibration

I hope someone can help me out.

Here is the beginning code i'm trying to compile which gives me errors:
It seems that the import is going wrong, but I can't figure out why.

System: Windows 7 x64 ultimate
Arduino: 1.0.4 and 1.5.1 tested, does the same

import org.ejml.data.*;
import org.ejml.simple.*;
import org.ejml.ops.*;

final static int SERIAL_PORT_NUM = 3;

import processing.opengl.*;
import processing.serial.*;

final static int SERIAL_PORT_BAUD_RATE = 57600;

final static int NUM_MAGN_SAMPLES = 10000;
float magnetom[][] = new float[NUM_MAGN_SAMPLES][3];
int magnetomIndex = 0;

PFont font;
Serial serial;

boolean synched = false;

// Skip incoming serial stream data until token is found
boolean readToken(Serial serial, String token) {
  // Wait until enough bytes are available
  if (serial.available() < token.length())
    return false;
  
  // Check if incoming bytes match token
  for (int i = 0; i < token.length(); i++) {
    if (serial.read() != token.charAt(i))
      return false;
  }
  
  return true;
}

// Global setup
void setup() {
  // Setup graphics
  size(800, 800, OPENGL);
  smooth();
  noStroke();
  frameRate(50);
  colorMode(HSB);
  
  // Load font
  font = loadFont("Univers-66.vlw");
  textFont(font);
  
  // Setup serial port I/O
  println("AVAILABLE SERIAL PORTS:");
  println(Serial.list());
  String portName = Serial.list()[SERIAL_PORT_NUM];
  println();
  println("HAVE A LOOK AT THE LIST ABOVE AND SET THE RIGHT SERIAL PORT NUMBER IN THE CODE!");
  println("  -> Using port " + SERIAL_PORT_NUM + ": " + portName);
  serial = new Serial(this, portName, SERIAL_PORT_BAUD_RATE);
}

void setupRazor() {
  println("Trying to setup and synch Razor...\n");
  
  // On Mac OSX and Linux (Windows too?) the board will do a reset when we connect, which is really bad.
  // See "Automatic (Software) Reset" on http://www.arduino.cc/en/Main/ArduinoBoardProMini
  // So we have to wait until the bootloader is finished and the Razor firmware can receive commands.
  // To prevent this, disconnect/cut/unplug the DTR line going to the board. This also has the advantage,
  // that the angles you receive are stable right from the beginning. 
  delay(3000);  // 3 seconds should be enough
  
  // Set Razor output parameters
  serial.write("#osrb");  // Turn on binary output of raw sensor data
  serial.write("#o1");    // Turn on continuous streaming output
  serial.write("#oe0");   // Disable error message output
  
  // Synch with Razor
  serial.clear();  // Clear input buffer up to here
  serial.write("#s00");  // Request synch token
}

float readFloat(Serial s) {
  // Convert from little endian (Razor) to big endian (Java) and interpret as float
  return Float.intBitsToFloat(s.read() + (s.read() << 8) + (s.read() << 16) + (s.read() << 24));
}
Magnetometer_calibration:2: error: expected `)' before 'serial'
Magnetometer_calibration:2: error: expected primary-expression before 'token'
Magnetometer_calibration:2: error: initializer expression list treated as compound expression
Magnetometer_calibration:5: error: expected `)' before 's'
Magnetometer_calibration:6: error: variable or field 'skipBytes' declared void
Magnetometer_calibration:6: error: expected `)' before 's'
Magnetometer_calibration:6: error: expected primary-expression before 'int'
Magnetometer_calibration:1: error: 'import' does not name a type
Magnetometer_calibration:2: error: 'import' does not name a type
Magnetometer_calibration:3: error: 'import' does not name a type
Magnetometer_calibration:5: error: expected constructor, destructor, or type conversion before 'static'
Magnetometer_calibration:7: error: 'import' does not name a type
Magnetometer_calibration:8: error: 'import' does not name a type
Magnetometer_calibration:10: error: expected constructor, destructor, or type conversion before 'static'
Magnetometer_calibration:12: error: expected constructor, destructor, or type conversion before 'static'
Magnetometer_calibration:13: error: declaration of 'magnetom' as multidimensional array must have bounds for all dimensions except the first
Magnetometer_calibration:13: error: 'NUM_MAGN_SAMPLES' was not declared in this scope
Magnetometer_calibration:16: error: 'PFont' does not name a type
Magnetometer_calibration:17: error: 'Serial' does not name a type
Magnetometer_calibration:22: error: redefinition of 'boolean readToken'
Magnetometer_calibration:2: error: 'boolean readToken' previously defined here
Magnetometer_calibration:22: error: expected `)' before 'serial'
Magnetometer_calibration:22: error: expected primary-expression before 'token'

That's Java / Processing - you're not trying to compile for Arduino, are you?

Thank you, this solved the most of the errors! :slight_smile:

But unfortunately I received the following error when compiled in processing 2.0

Cannot find a class or type named "FileOutputStream"

which comes out of the line:

FileOutputStream fos = new FileOutputStream(sketchPath("magnetom.float"));

I assume my sketchpad is the place where the .pde file is located: C:\Magnetometer_calibration

Mayby someone can help me again :slight_smile:

 /* OUTPUT RESULTS */
  // Output magnetometer samples file
  try {
    println("Trying to write " + magnetomIndex + " sample points to file magnetom.float ...");
    FileOutputStream fos = new FileOutputStream(sketchPath("magnetom.float"));
    DataOutputStream dos = new DataOutputStream(fos);
    for (int i = 0; i < magnetomIndex; i++) {
      dos.writeFloat(magnetom[i][0]);
      dos.writeFloat(magnetom[i][1]);
      dos.writeFloat(magnetom[i][2]);
    }

Mayby someone can help me again

Perhaps someone at the Processing forum.

Hey There

Did you find a fix for this ?

I can run the test sketch in "Processing" and see the 3D animation (red box with green arrow) rotating around in the window. So I know that my Processing app and Serial port are configured correctly.

but when I run the Magnometer Calibration sketch in "Processing" I get the complie error

Cannot find the class or type named "FileOutputStream"

Hi have you find a solution for the problem?
how are you downloading the jar file?
how to get the .ejml file?

thanks