Announcement

Collapse

Technology Forum Has Moved!

The FIRST Tech Challenge Technology forum has moved to a new location! Please take a look at our forum blog for links and instructions on how to access the new forum.

https://firsttechchallenge.blogspot....orum-blog.html

Note that volunteers (except for FTA/WTA/CSA will still access their role specific forum through this site. The blog also outlines how to access the volunteer forums.
See more
See less

Adafruit IMU Gyro; initial value not 0

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Adafruit IMU Gyro; initial value not 0

    We used the Adafruit IMU (Bosch BNO055) last year and used AlanG's library with great success. This year, because FIRST included this as part of it's library, we moved over to it for continued support.

    One thing we noticed was after initialization, the gyro starting angle is always different; sometimes starting at 50, sometimes -140, etc. Last year, it always started at 0. While turning the robot, the angles changes are accurate, but offset from the starting value.

    Is there a way in code to have it start at 0 after initialization? Is it just us observing this?

    Here is a sample of our code. The composeTelemetry function is from the AdafruitIMU Sample code included with the SDK.

    public class foo extends LinearOpMode {
    BNO055IMU imu;
    Orientation angles;
    Acceleration gravity;
    int x = 1;

    public void runOpMode() throws InterruptedException {
    BNO055IMU.Parameters parameters = new BNO055IMU.Parameters();
    parameters.angleUnit = BNO055IMU.AngleUnit.DEGREES;
    parameters.accelUnit = BNO055IMU.AccelUnit.METERS_PERSEC_PERSEC;
    parameters.calibrationDataFile = "AdafruitIMUCalibration.json";
    parameters.loggingEnabled = true;
    parameters.loggingTag = "IMU";
    parameters.accelerationIntegrationAlgorithm = new JustLoggingAccelerationIntegrator();

    imu = hardwareMap.get(BNO055IMU.class, "gyro");
    imu.initialize(parameters);
    composeTelemetry();

    angles = imu.getAngularOrientation().toAxesReference(AxesRe ference.INTRINSIC).toAxesOrder(AxesOrder.ZYX); //get gyro values

    waitForStart();

    while ((opModeIsActive()) && (x == 1)) {
    angles = imu.getAngularOrientation().toAxesReference(AxesRe ference.INTRINSIC).toAxesOrder(AxesOrder.ZYX);
    telemetry.addData("angle", angles.firstAngle);
    telemetry.update();
    }
    }
    }

  • #2
    That sounds like you have the gyro in NDOF mode. (Meaning it integrates the compass for an absolute heading, rather than a relative heading)

    Comment


    • #3
      Originally posted by 4634 Programmer View Post
      That sounds like you have the gyro in NDOF mode. (Meaning it integrates the compass for an absolute heading, rather than a relative heading)
      Thanks for the response. But wouldn't that provide a "consistent" start point based on the robot direction? What we're seeing is a random starting angle even if the robot is starting at the same spot/same direction.

      Comment


      • #4
        Originally posted by FTC8681 View Post
        Thanks for the response. But wouldn't that provide a "consistent" start point based on the robot direction? What we're seeing is a random starting angle even if the robot is starting at the same spot/same direction.
        That would be the expected behavior, if the magnetometer has been fully calibrated.

        That's a big if. The Adafruit IMU provides calibration status, ranging from 0-3. (0 being not calibrated, 3 being fully calibrated). You can send the calibration status to the driver station's telemetry. If it reports a calibration status of 0, then the magnetometer hasn't found north yet, and all data should be discarded until the calibration reaches at least 1.

        HOWEVER!


        I don't think that using NDOF mode is a good idea. Relying on the magnetometer means that if there's any magnetic interference, your heading will get screwed up in a hurry. I'll bet there's a lot of interference at competition. The IMU mode does a very good job without the magnetometer, because it is still integrating the accelerometer with the gyro.

        See this code for how to use it in IMU mode: https://github.com/MasqedMarauder/FTC-Masq-Samples

        Comment

        Working...
        X