SensorFusion Calibration

edited August 2018 in C#

Hello Eric,
We are streaming data through the C# SDK with SensorFusion. However, it seems that the values of the Quaternium are not consistent, even if i always start from the same position, i.e., we get different values when doing the same motion (e.g. pitch or role). so i have a couple of questions:

  1. I saw that in the Android SDK you have some methods for calibration. Do you have something similar for the C# SDK ?
  2. I saw that in last firmware update (1.4.1) you "Exposed sensor fusion calibration state" - can you please elaborate more about what is this state and how do i use it? Is it part of SDK ?
  3. should i assume that the sensrFusion is calibrated?
  4. what is the "best practice" to do in order to get accurate constant streaming in each connection?
    Thanks,

Comments

    1. No
    2. It is exactly as stated, there isn't more to say about it. The method you are talking about in your first question is how you use it.
    3. No
    4. Calibrate the sensors before collecting data.
  • edited August 2018

    .So Can you please explain how to calibrate the sensor if i use the c# sdk? What are my options here?
    2. Is the android sdk doing calibration or it is just reading status?

  • Watch the sensor fusion calibration video linked in the documentation:
    https://mbientlab.com/androiddocs/latest/sensor_fusion.html#calibration

  • edited August 2018

    Hi,
    1. The video describes the calibration of **BNO055 **sensor, which is not the case of MetaMotion sensor R according to your data sheet (which is BMI160 / BMM150 ). Do I miss something?
    2. According to BNO55 documentation, the calibration should be performed "after every ‘Power on Reset". Can you explain what it I mean in Metawaer terms? should we do the calibration described in the movie after each "Initialize -teardown" session in C# SDK, or just once for all life cycle of the sensor? i.e., if i connect to sensor use the SensorFusion, and then disconnect, should i do the calibration BEFORE each connection ? . If not, when should I start the calibration? how do I know that the calibration was OK with C# SDK ? i understand this is not supported, but are you planning to do this in next SDK version ?
    4. The video describes how the technician works with Botch software in the sensor level using botch's designated service tools. Do you expect that users should do the calibrations with these tools by themselves? How we can do that as we bought SW Module and not HW component? and if yes, a can you please elaborate more about this process rather a youTube video?

  • edited September 2018
    1. It doesn't matter, do the physical motions demonstrated in the video for each IMU.
    2. It means exactly as stated; when the device is powered on, start the sensor fusion algorithm then calibrate the sensors before you collect the data.

      Calibration state will be added.

    3. You don't need the software used in the video.
  • Hi,
    1.OK
    2."when the device is powered on" -> do you mean at the first time when Unboxing? how do i start the " the sensor algorithm in C#?
    3. Another question - In my app, when starting i want to create a "reference" to some absolute orientation (e.g. 0,0,0.7,0.7), but the data coming from Quaternion is depend on the initial physical orientation if the sensor. How can i make an "offset" to achieve this orientation? e,g, when user start with (0,0,-0.8) i want it to be offset into be aligned with (0,0,0.7,0.7).

  • No, it means exactly as stated. The second quote is a typo, should be "sensor fusion algorithm" and has been corrected in my previous post.

    Post unrelated questions in their own thread.

    1. Thanks, should i do the calibration process only once when receiving the sensor from mbient (unboxing) or at each sensor fusion algorithm start ?
    2. OK
  • You do it if the calibration state is not at high accuracy.

  • Yes but once it is high accuracy , it can be unreliable again after some time ?

  • edited October 2018

    Yes, when the device powers on. You should also check the calibration state every time you start sensor fusion.

  • edited April 2019

    Hello,
    can you show the C# code of the calibration process represented in 5.2 section as you did for c++ and phyton?
    I try to write code that represents the steps , however, I need help to write the correct code blocks.
    Currently, my code looks like this :

    //read calibration status once
     var actual = await sensorFusion.ReadCalibrationStateAsync();
     //poll status stream 
     var result =  await sensorFusion.Calibrate( CancellationToken.None, 100, source => 
     Console.WriteLine("Accelerometer = {0}  gyro =  {1}  magnometer =  {2}",source.accelerometer, source.gyroscope,source.magnetometer));
     //start data steama and do the 45 thing 
      await sensorFusion.Quaternion.AddRouteAsync(source =>
      source.Stream(data => Console.WriteLine("Quaternion = " + data.Value<Quaternion>())));
     sensorFusion.Quaternion.Start();
    sensorFusion.Start();
    //??? where to do this?
    sensorFusion.WriteCalibrationData(result);
    

    My questions:
    1. For example, in step 3 you wrote: " Then the App should stream values for the CalibrationState -> MblMwCalibrationState."
    --- do you mean " sensorFusion.ReadCalibrationStateAsync()" method? Cause This method just returns value and not streams
    -- Is it Calibrate like the following code? If yes should I do the 45 degrees thing during this stream? (cause you wrote to do this with data stream)

    await sensorFusion.Calibrate( CancellationToken.None, 100, source => 
                             Console.WriteLine("Accelerometer = " + source.accelerometer.ToString() + " gyro = " + source.gyroscope.ToString()  
                             + " magnometer=" + source.magnetometer.ToString()));
    

    2.. Then in step 4 you wrote: " While the App is streaming values, …. until you get high accuracy on Calibration state"
    I assume you mean to do the 45 degrees thing during data stream( not state stream) ?

    await sensorFusion.Quaternion.AddRouteAsync(source =>
                         source.Stream(data => Console.WriteLine("Quaternion = " + data.Value<Quaternion>())));
    
                        sensorFusion.Quaternion.Start();
                        sensorFusion.Start();
    

    --how I can get the streaming status while streaming data?

    3.should I do the "8 movements" to calibrate the magnetometer? (cause you say just to do the 45 degrees)

    1. after calibration – i must write the value to the board? How do I do that?
  • @abcd said:
    Hello,
    can you show the C# code of the calibration process represented in 5.2 section as you did for c++ and phyton?
    I try to write code that represents the steps , however, I need help to write the correct code blocks.
    Currently, my code looks like this :

    The calibration process is directly implemented in the C# SDK.
    https://mbientlab.com/csdocs/1/sensor_fusion.html#calibration

    My questions:
    1. For example, in step 3 you wrote: " Then the App should stream values for the CalibrationState -> MblMwCalibrationState."
    --- do you mean " sensorFusion.ReadCalibrationStateAsync()" method? Cause This method just returns value and not streams
    -- Is it Calibrate like the following code? If yes should I do the 45 degrees thing during this stream? (cause you wrote to do this with data stream)

    Refer to the previously linked C# documentation

    2.. Then in step 4 you wrote: " While the App is streaming values, …. until you get high accuracy on Calibration state"
    I assume you mean to do the 45 degrees thing during data stream( not state stream) ?

    await sensorFusion.Quaternion.AddRouteAsync(source =>
                         source.Stream(data => Console.WriteLine("Quaternion = " + data.Value<Quaternion>())));
    
                        sensorFusion.Quaternion.Start();
                        sensorFusion.Start();
    

    --how I can get the streaming status while streaming data?

    No where in the calibration tutorial is a data stream mentioned.

    3.should I do the "8 movements" to calibrate the magnetometer? (cause you say just to do the 45 degrees)

    The instruction says to start with the 45 degree rotations not only do those rotations, though it can be worded better.

    1. after calibration – i must write the value to the board? How do I do that?

    Refer to the previously linked C# documentation

  • edited April 2019

    Thanks,
    1.Can you please confirm that this code is calibrating the sensors and write the calibration data to the board?

    var sensorFusion = metawear.GetModule<ISensorFusionBosch>();
    //start Fusion algorithm
    sensorFusion.Start();
    //get cancel token
    CancellationToken cts = new CancellationToken();
    //poll status stream -> do the 45 degrees and 8 rotations
    var result =  await sensorFusion.Calibrate(cts, 1000, source => Log(source.ToString()));
    //start Macro
    IMacro macro = metawear.GetModule<IMacro>();
    macro.StartRecord();
    //write calibration data 
    sensorFusion.WriteCalibrationData(result);
    //get ID 
    var id= macro.EndRecordAsync();
    
    1. I run this script and sensors where calibrated. i also wrote the data to the board. However, after few hours i noticed that mgnometer is not calibrated again. Is this possible ? what is the best proctice here assuming iit will be impossible to do the clibration in each algorithm start
  • @abcd said:
    Thanks,
    1.Can you please confirm that this code is calibrating the sensors and write the calibration data to the board?

    Looks fine.

    1. I run this script and sensors where calibrated. i also wrote the data to the board. However, after few hours i noticed that mgnometer is not calibrated again. Is this possible ? what is the best proctice here assuming iit will be impossible to do the clibration in each algorithm start

    Try rewriting the calibration data.

  • edited April 2019

    @Eric said:

    @abcd said:
    Thanks,
    1.Can you please confirm that this code is calibrating the sensors and write the calibration data to the board?

    Looks fine.

    1. I run this script and sensors where calibrated. i also wrote the data to the board. However, after few hours i noticed that mgnometer is not calibrated again. Is this possible ? what is the best proctice here assuming iit will be impossible to do the clibration in each algorithm start

    Try rewriting the calibration data.

    Here is the code i wrote . note that i put in a comment the macro cause i did it allready once.

    <br />            metawear = Application.GetMetaWearBoard(mac);
                metawear.InitializeAsync().Wait();
                var  sensorFusion = metawear.GetModule<ISensorFusionBosch>();
                sensorFusion.Start();
                bool isCalibrated = false;
                while (!isCalibrated)
                { 
    
                    var state = await sensorFusion.ReadCalibrationStateAsync();
                    Console.WriteLine("Before calibration state: {0}", state);
            isCalibrated = state.accelerometer == CalibrationAccuracy.HighAccuracy &&
                                    state.gyroscope == CalibrationAccuracy.HighAccuracy &&
                                    state.magnetometer == CalibrationAccuracy.HighAccuracy;    
                    CancellationToken cts = new CancellationToken();
                    //poll status stream 
                    result = await sensorFusion.Calibrate(cts, 1000, source => Console.WriteLine(source.ToString()));
                    Console.WriteLine("calibrated!");
                    //start Macro
                   // IMacro macro = metawear.GetModule<IMacro>();
                  //  macro.StartRecord();
                    sensorFusion.WriteCalibrationData(result);
                 //   await macro.EndRecordAsync();
                    state = await sensorFusion.ReadCalibrationStateAsync();
                    Console.WriteLine("After calibration state: {0}", state);
    
                }
                sensorFusion.Stop();
                await metawear.GetModule<IDebug>().DisconnectAsync();
    

    But i get this still :

    1. Can you please explain what is "power cycle" - when this happening?
  • is there any answer here?

  • @abcd said:

    @Eric said:

    @abcd said:
    Thanks,
    1.Can you please confirm that this code is calibrating the sensors and write the calibration data to the board?

    Looks fine.

    1. I run this script and sensors where calibrated. i also wrote the data to the board. However, after few hours i noticed that mgnometer is not calibrated again. Is this possible ? what is the best proctice here assuming iit will be impossible to do the clibration in each algorithm start

    Try rewriting the calibration data.

    Here is the code i wrote . note that i put in a comment the macro cause i did it allready once.

    Separate the macro setup from the calibration process. Stop sensor fusion first then write the calibration macro.

    1. Can you please explain what is "power cycle" - when this happening?

    You can find the definition with a simple internet query:
    https://lmgtfy.com/?q=power+cycle

Sign In or Register to comment.