Code Monkey home page Code Monkey logo

Comments (5)

nickgoza avatar nickgoza commented on May 27, 2024

As an afterthought, it might be helpful to mention this applies to the X,Y, and Z axis on both

from invensense-imu.

flybrianfly avatar flybrianfly commented on May 27, 2024

Hi Nick,

Can you attach your code?

Thanks,
Brian

from invensense-imu.

nickgoza avatar nickgoza commented on May 27, 2024

Here is my code to test the X axis on the Gyro. This one is showing accelerometer results, as in the value increases when I put the unit into motion and goes back to zero when I stop regardless of its rotational position. It does this without my filter added as well.

The accelerometer is the exact same code except with the function for getting accelerometer data. It works well with the magnetometer and the filter give a nice smooth curve with the filter added.

Forgive me if this doesn't show up right I am new to Github, but here is my code.

`#include "MPU9250.h"

// an MPU9250 object with the MPU-9250 sensor on I2C bus 0 with address 0x68
MPU9250 IMU(Wire,0x68);
int status;

void setup() {
Serial.begin(115200);
while(!Serial) {}

// start communication with IMU
status = IMU.begin();
if (status < 0) {
Serial.println("IMU initialization unsuccessful");
Serial.println("Check IMU wiring or try cycling power");
Serial.print("Status: ");
Serial.println(status);
while(1) {}
}
// setting the accelerometer full scale range to +/-8G
IMU.setAccelRange(MPU9250::ACCEL_RANGE_8G);
// setting the gyroscope full scale range to +/-500 deg/s
IMU.setGyroRange(MPU9250::GYRO_RANGE_1000DPS);
// setting DLPF bandwidth to 20 Hz
IMU.setDlpfBandwidth(MPU9250::DLPF_BANDWIDTH_20HZ);
// setting SRD to 19 for a 50 Hz update rate
IMU.setSrd(19);
}

//Constants for RAF
const int RunningAverageCount=16;
float RunningAverageBuffer[RunningAverageCount];
int NextRunningAverage;

void loop() {
// read the sensor
IMU.readSensor();

//Running Average Filter--------------------------------------------------------------------------
float rawGyroX = IMU.getGyroX_rads();

RunningAverageBuffer[NextRunningAverage++] = rawGyroX;
if (NextRunningAverage >= RunningAverageCount)
{
NextRunningAverage=0;
}
float RunningAverageGyroX = 0;
for(int i=0; i<RunningAverageCount; ++i)
{
RunningAverageGyroX += RunningAverageBuffer[i];
}
RunningAverageGyroX /= RunningAverageCount;
//----------------------------------------------------------------------------------------------

//Print Data
Serial.print(RunningAverageGyroX,6);
Serial.print("\n");
delay(50);
}`

from invensense-imu.

flybrianfly avatar flybrianfly commented on May 27, 2024

Hi Nick,
A gyro measures rotational rate (i.e. deg/s or rad/s), not rotational position (i.e. deg or rad). So, I would expect the gyro to give a value when it is in motion and 0 when it is at rest. I was able to compile and run your code on a Teensy and the IMU.getGyroX_rads() method is returning the gyro value. I can tell that it is the gyro value and not the accelerometer, because if I leave the X axis pointed up or down it is returning 0 still (no motion) rather than +/- 9.8 (apparent acceleration due to gravity).

In order to estimate rotational position, you'll need something like a complimentary, kalman, or extended kalman filter.

Brian

from invensense-imu.

nickgoza avatar nickgoza commented on May 27, 2024

Wow, everything makes sense now...I misunderstood what the sensors did...haha. I am new to this. Thank you for your help and your code has been very helpful to me!

Nick

from invensense-imu.

Related Issues (20)

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.