Giter Site home page Giter Site logo

sfwa / trical Goto Github PK

View Code? Open in Web Editor NEW
34.0 34.0 18.0 422 KB

Straightforward UKF-based scale and bias calibration for magnetometers (and other tri-axial field sensors).

Home Page: http://au.tono.my/log/20131213-trical-magnetometer-calibration.html

License: MIT License

Perl 1.49% Ruby 26.30% C++ 26.32% Python 14.55% C 31.33%

trical's People

Contributors

bendyer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

trical's Issues

Usage in a mobile app

I have manage to interact with the library to some degree from C#.

The raw magnetometer on iphone11 on the left and the calibrated_reading float array values to the right as System.Numerics.Vector3:

<-83.00697, 16.52205, -389.2053> ---> <-80.01025, 17.02175, -388.8991>
50.01
<-83.33554, 16.6873, -389.5024> ---> <NaN, NaN, NaN>
50.02
Thread started: #19
<-83.27498, 16.83936, -388.3975> ---> <NaN, NaN, NaN>
50.02999
<-82.71381, 16.61551, -389.6036> ---> <NaN, NaN, NaN>
50.03999

I can set and get norm just fine.
The first app update I get values back, but then there is only NaN values.

Here is the update code in the C# wrapper library:

public float[] Update(float[] raw)
{
    TRICALWrapper.TRICAL_estimate_update(handle, raw, ExpectedField);

    float[] calibrated_reading = new float[3];
    TRICALWrapper.TRICAL_measurement_calibrate(handle, raw, calibrated_reading);
    return calibrated_reading;
}

The handle is some sort of pointer to the TRICAL_instance.t, being of TRICALSafeHandle : SafeHandleZeroOrMinusOneIsInvalid in C#

// added two wrapper methods in TRICAL.cpp
TRICAL_instance_t* CreateTRICAL()
{
    return new TRICAL_instance_t();
}

void DisposeTRICAL(TRICAL_instance_t* ptr)
{
    if (ptr != nullptr)
    {
        delete ptr;
        ptr = nullptr;
    }
}

Also I had to change c -> cpp and remove retsrict keyword to remove error. The dll building guide seem to require cpp.

So is this problem, communicating between C# <---> C++, or what could be the problem?

Make error on restrict pointer: need C99 mode

I got the following error when building:

error: expected ‘;’, ‘,’ or ‘)’ before ‘instance’
 void TRICAL_measurement_calibrate(TRICAL_instance_t *restrict instance,

I was able to fix this by including -std=c99 in the set(CMAKE_C_FLAGS string in CMakeLists.txt

Unable to compile under Ubuntu 14.04 with cmake 2.8.12.2 and GCC 4.7.3

Dear all,

Thanks for making your code available to the public! I was trying to compile your software, but wasn't able to get it to run under Linux (Ubuntu 14.04) ... if I simply try with

mkdir TRICAL_build
cd TRICAL_build
cmake ..
make

I get the following error:

Scanning dependencies of target TRICAL
[ 25%]
Building C object CMakeFiles/TRICAL.dir/src/TRICAL.c.o
cc: error: unrecognized command line option ‘-Weverything’
make[2]: *** [CMakeFiles/TRICAL.dir/src/TRICAL.c.o] Error 1
make[1]: *** [CMakeFiles/TRICAL.dir/all] Error 2
make: *** [all] Error 2

If I change the flags in CMakeLists.txt to

set(CMAKE_C_FLAGS "-O3 -Werror -Wno-padded -Wno-unknown-pragmas -fPIC")

as suggested in #2

I get the following error:

/home/auerl/TRICAL/src/TRICAL.c:154:54: error: expected ‘;’, ‘,’ or ‘)’ before ‘instance’
/home/auerl/TRICAL/src/TRICAL.c:173:58: error: expected ‘;’, ‘,’ or ‘)’ before ‘instance’
/home/auerl/TRICAL/src/TRICAL.c:215:63: error: expected ‘;’, ‘,’ or ‘)’ before ‘instance’
make[2]: *** [CMakeFiles/TRICAL.dir/src/TRICAL.c.o] Error 1
make[1]: *** [CMakeFiles/TRICAL.dir/all] Error 2
make: *** [all] Error 2

Does anybody have an idea what the issue could be? My compiler is GCC 4.7.

Best wishes and thanks in advance,

Ludwig

I always get non-positive-definite covariance matrix

I always get non-positive-definite covariance matrix in the c ++ algorithm. The range of input values mx, my, mz from -1 to 1.
The coefficients are defined as
#define TRICAL_ALPHA_2 (1.0f)
#define TRICAL_BETA (0.0f)
#define TRICAL_KAPPA (1.0f)
what should i change?

Clarification about using TRICAL_estimate_update()

Hi,

I am getting X, Y, Z values from magnetometer in uT units.

I am using following tool to identify magnetic field in my location, and the value is 50uT (though my calibrated reading are usually around ~55uT).

I don't understand which value should be used for expected_field argument in TRICAL_estimate_update(&global_instance, sensor_reading, expected_field). Can you please tell me what values should be put there?

Below is the pseudocode that I am using, can you please check that the usage is correct?

TRICAL_instance_t global_instance;

int main(void) {
  TRICAL_init(&global_instance);
  TRICAL_norm_set(&global_instance, 50.0);
  TRICAL_noise_set(&global_instance, 1.5);

  float bias_estimate[3];
  float scale_estimate[9];
  float sensor_reading[3];
  float expected_field[3];

  // for holding data received from magnetometer, in uT.
  float mag_x, mag_y, mag_z;

  while(true) {
    // get the latest sensor reading
    read_magnetometer(mag_x, mag_y, mag_z);
    sensor_reading[0] = mag_x;
    sensor_reading[1] = mag_y;
    sensor_reading[2] = mag_z;

    // What should be passed to expected field?
    TRICAL_estimate_update(&global_instance, sensor_reading, expected_field);

    TRICAL_estimate_get(&global_instance, bias_estimate, scale_estimate);

    printf("[%f %f %f]\n", bias_estimate[0], bias_estimate[1], bias_estimate[2]);
   }

return 0;
}

Memory corruption

When I try to run TRICAL, I get a memory corruption error:

ipython -m TRICAL 9.81 1e-4 html accel_multiaxis.csv accel_multiaxis.html
*** Error in `/usr/bin/python': malloc(): memory corruption: 0x0000000001a6db20 ***
Aborted (core dumped)

I'm using Ubuntu 14.04. I modified __main__.py to look for an .so file instead of .dylib

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.