psiphi75/ahrs

Not working

Closed this issue · 23 comments

I tried to use AHRS but the data what i got in return is not right.
I have an LSM9DS1 chip and i get data every 10Hz. But if i try to use getEulerAngles or getQuaternion() it returns not any correct data.

with the quaternion its from 2 to -2 to 0 and that goes on forever.

    const accel_x = array['accel_x_mg']/9.8, //raw data
        accel_y = array['accel_z_mg']/9.8,
        accel_z = array['accel_y_mg']/9.8,
        gyro_x = array['gyro_x_dps']*0.07,
        gyro_y = array['gyro_z_dps']*0.07,
        gyro_z = array['gyro_y_dps']*0.07,

This is the data (also raw magnetometer)

Oke nvm i made a mistake, i added accel before i shouldve added gyro.
But it still does not work entirely.

        const madgwick = new AHRS({
            /*
             * The sample interval, in Hz.
             *
             * Default: 20
             */
            sampleInterval: 10,
          
            /*
             * Choose from the `Madgwick` or `Mahony` filter.
             *
             * Default: 'Madgwick'
             */
            algorithm: 'Mahony',
          
            /*
             * The filter noise value, smaller values have
             * smoother estimates, but have higher latency.
             * This only works for the `Madgwick` filter.
             *
             * Default: 0.4
             */
            beta: 0.4,
          
            /*
             * The filter noise values for the `Mahony` filter.
             */
            kp: 0.5, // Default: 0.5
            ki: 0, // Default: 0.0
          
            /*
             * When the AHRS algorithm runs for the first time and this value is
             * set to true, then initialisation is done.
             *
             * Default: false
             */
            doInitialisation: false,
          });

          madgwick.update(gyro_x, gyro_y, gyro_z, accel_x, accel_y, accel_z, magn_x, magn_y, magn_z);
          let quat= madgwick.getQuaternion();
        //   console.log(axes.pitch*57.295779513, axes.roll*57.295779513, axes.heading*57.295779513);
        console.log(quat)

When i do this, it goes back to its first value, and that should not be the case.

I don't know what you mean "it goes back to its first value". You have turned of doInitialisation, this means you will need run to the uptate() function many times (around 100) until you get sensible values.

Unless you understand quarternions, I don't think you would want the print out the quaternion. The Euler angles make more sense.

So if i turn my object the euler angles goes to like 1.2 or something and if i hold it still it goes back to 0.1 or something. It doesnt stay at the angle. I get data every 10 Hz because i use Serialport and i get there data every 10 Hz from

What do your raw input and output values look like? I'd also suggest using the Madgwick filter.

My raw input is from 1350 to -1350 or something

I need more detail. 1350 is what? What are your raw x,y,z values for the accelerometer, gyroscope and magnetometer input? The values that you put into update().

    madgwick.update(gyro_x, gyro_y, gyro_z, accel_x, accel_y, accel_z, magn_x, magn_y, magn_z);

This is what i put in, i have the chip LSM9DS1TR (simular to LSM9DS1)

This is what i found

The LSM9DS1 is a high-resolution (16-bit) 9-axis motion sensor (accelerometer, gyroscope, and magnetometer) in a 3 mm x 3.5 mm LGA 28 pin package. Coupled with the fine 24-bit Measurement Specialties MS5611 altimeter, the Teensy 3.1 add-on/breakout board offers 10 degrees of freedom in a compact size for many motion control applications.

Thank you, but what the actual values of gyro_x, gyro_y, gyro_z, accel_x, accel_y, accel_z, magn_x, magn_y, and magn_z?
For example accel_z might be something like 1.0.

Its an integer, its never a float (by default values)

afbeelding
here u go

Finally. Those values are not going to work. You need to convert them to the correct units. Your LSM9DS1 spec documentation will detail what units it outputs. See the Units section in the Readme.

So i should devide the accelerometer by 9.81 and gyroscope by 0.07 (dps)

        let accel_x = data.accel_x_mg/9.81, //velocity
            accel_y = data.accel_z_mg/9.81, //velocity
            accel_z = data.accel_y_mg/9.81, //velocity
            gyro_x = data.gyro_x_dps*0.07/57.295779513, //degrees per radians.
            gyro_y = data.gyro_z_dps*0.07/57.295779513, //degrees per radians.
            gyro_z = data.gyro_y_dps*0.07/57.295779513, //degrees per radians.

So i should do this?

Your LSM9DS1 spec documentation will detail what "units" it outputs and you need to convert that to units suitable for this AHRS implementation.

Just multiplying the numbers "randomly" will not fix the issue.

This is not the place to ask about the LSM9DS1 output. I'm closing this issue, since this is not a bug in AHRS.

Also if i do this

let thetaM = Math.atan2(accel_x, Math.sqrt(accel_y*accel_y+accel_z*accel_z));
        let phiM = Math.atan2(accel_y, Math.sqrt(accel_x*accel_x+accel_z*accel_z))
        console.log(thetaM*57.295779513, phiM*57.295779513)

I get correct angles

Please understand, I'm not here to support you for unrelated issues. This forum is for logging bugs against AHRS. If you have questions like this you can go to stackoverflow.com, or similar.

its kinda a bug tho, because it works with that formula and not with your thing

afbeelding
This are my units, so i divide them correctly

This is my last comment on this thread. The units you have shown me are wrong. The page you show me tells me you don't understand the problem. Your problem is with the output of the LSM9SD1, not this library. You should use "duckduckgo" and search for "LSM9DS1 tutorial".

The units of required by AHRS is are as follows:

  • gyroscope: in radians per second, so when stationary these average around zero, typically around +/-0.001 just due to noise. When you constantly rotate it 180 degrees in 1 second one axis will go up to PI/2.0.
  • accelerometer - in g, so the values when stationary will range from -1.0 to 1.0. Such that sqrt(a_x*a_x + a_y*a_y + a_z*a_z) is around 1.0.
  • Magnetometer - values are proportional to the Earth's magnetic field. These units you have look reasonable.