Announcement

Collapse
No announcement yet.

Mounting the RevHub vertically

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

  • Mounting the RevHub vertically

    Like many people on the forum, we have had issues with initializing the RevHub in any position except horizontally. Yaw seems to always be initialized at 0, but both pitch and roll start out at weird numbers. We've been messing around with it for a while, and these numbers seem to be the angle the RevHub is at, relative to horizontal (i.e. initializing vertically starts out at about 90 degrees for pitch and about 0 for roll, where as a 45 degree angle is 45 for pitch and 0 for roll). Whenever we place the RevHub horizontally after initializing it at a different angle, it goes back to 0,0,0. The weird part comes in when we initialize it vertically and rotate it. Just spinning it around the axis pointing up changes all three variables. We tried messing around with the AXIS_REMAP_CONFIG variable, but it had no effect. Is there any other fix for this?

  • #2
    we tried many setting and end up mounting horizontally.

    Comment


    • #3
      Originally posted by FTC12676 View Post
      we tried many setting and end up mounting horizontally.
      That is probably what we will end up doing, but it seems weird that the RevHub can only work horizontally - I was curious as to if anybody has found a fix to this issue.

      Comment


      • #4
        We were able to fix this tonight, by remapping axes:

        byte AXIS_MAP_CONFIG_BYTE = 0x6; //This is what to write to the AXIS_MAP_CONFIG register to swap x and z axes
        byte AXIS_MAP_SIGN_BYTE = 0x1; //This is what to write to the AXIS_MAP_SIGN register to negate the z axis

        //Need to be in CONFIG mode to write to registers
        imu.write8(BNO055IMU.Register.OPR_MODE,BNO055IMU.S ensorMode.CONFIG.bVal & 0x0F);

        sleep(100); //Changing modes requires a delay before doing anything else

        //Write to the AXIS_MAP_CONFIG register
        imu.write8(BNO055IMU.Register.AXIS_MAP_CONFIG,AXIS _MAP_CONFIG_BYTE & 0x0F);

        //Write to the AXIS_MAP_SIGN register
        imu.write8(BNO055IMU.Register.AXIS_MAP_SIGN,AXIS_M AP_SIGN_BYTE & 0x0F);

        //Need to change back into the IMU mode to use the gyro
        imu.write8(BNO055IMU.Register.OPR_MODE,BNO055IMU.S ensorMode.IMU.bVal & 0x0F);

        sleep(100); //Changing modes again requires a delay

        Then we used the REV unit just as we had when it was horizontal, using the z axis (now remapped to x) for heading.

        This allowed us to get good heading data with the REV unit mounted vertically. We didn't have time to look closely at roll and pitch, but we really only care about the heading.

        Depending on how you turn it vertical, you need to either swap (x with z) or (y with z).

        The AXIS_MAP_CONFIG and AXIS_MAP_SIGN registers are documented in the BNO055 datasheet available on the Adafruit website.

        I'd like to refine this; maybe put it into a new class that overrides the BNO055Impl class.

        Comment


        • #5
          This worked! Thank you so much!

          Comment


          • #6
            Here's some code that works without doing all the remapping stuff: https://gist.github.com/FROGbots-463...4c16e52616f35c

            Comment


            • #7
              Aha, finally figured out how to post code correctly. This is the same thing as in the Gist above:

              Code:
              package org.firstinspires.ftc.teamcode;
              
              import com.qualcomm.hardware.bosch.BNO055IMU;
              import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
              import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
              import org.firstinspires.ftc.robotcore.external.navigation.Acceleration;
              import org.firstinspires.ftc.robotcore.external.navigation.AngleUnit;
              import org.firstinspires.ftc.robotcore.external.navigation.AxesOrder;
              import org.firstinspires.ftc.robotcore.external.navigation.AxesReference;
              import org.firstinspires.ftc.robotcore.external.navigation.Orientation;
              import java.util.Locale;
              
              @TeleOp(name = "IMUtest", group = "Sensor")
              //@Disabled
              public class IMUtest extends LinearOpMode
              {
                  private BNO055IMU imu;
              
                  private Orientation angles;
                  private Acceleration gravity;
              
                  @Override
                  public void runOpMode()
                  {
              
                      BNO055IMU.Parameters parameters = new BNO055IMU.Parameters();
                      parameters.angleUnit            = BNO055IMU.AngleUnit.DEGREES;
                      parameters.accelUnit            = BNO055IMU.AccelUnit.METERS_PERSEC_PERSEC;
                      parameters.loggingEnabled       = true;
                      parameters.useExternalCrystal   = true;
                      parameters.mode                 = BNO055IMU.SensorMode.IMU;
                      parameters.loggingTag           = "IMU";
                      imu                             = hardwareMap.get(BNO055IMU.class, "imu");
              
                      imu.initialize(parameters);
                      telemetry.setMsTransmissionInterval(100);
                      waitForStart();
              
                      while (opModeIsActive())
                      {
                          angles  = imu.getAngularOrientation(AxesReference.INTRINSIC, AxesOrder.ZYX, AngleUnit.DEGREES);
                          gravity = imu.getGravity();
                          sendTelemetry();
                      }
                  }
              
                  void sendTelemetry()
                  {
                      telemetry.addData("Status", imu.getSystemStatus().toString());
                      telemetry.addData("Calib", imu.getCalibrationStatus().toString());
                      telemetry.addData("Heading", formatAngle(angles.angleUnit, angles.firstAngle));
                      telemetry.addData("Roll", formatAngle(angles.angleUnit, angles.secondAngle));
                      telemetry.addData("Pitch", formatAngle(angles.angleUnit, angles.thirdAngle));
                      telemetry.addData("Grav", gravity.toString());
                      telemetry.update();
                  }
              
                  String formatAngle(AngleUnit angleUnit, double angle)
                  {
                      return formatDegrees(AngleUnit.DEGREES.fromUnit(angleUnit, angle));
                  }
              
                  String formatDegrees(double degrees)
                  {
                      return String.format(Locale.getDefault(), "%.1f", AngleUnit.DEGREES.normalize(degrees));
                  }
              }

              Comment


              • #8
                Realized I have a mistake in the axis remapping code above. It works for swapping x and z axes, but if one needed to swap y and z it would break.

                To swap x and z, the AXIS_MAP_CONFIG register must be written to 0x6, or 0b000110.
                To swap y and z, the AXIS_MAP_CONFIG register must be written to 0x18, or 0b011000.

                The mask I put in for each of the write statements in the code ( 0x0F, or 0b001111) wouldn't work for swapping y and z, because it would mask out the first '1'. The masks probably aren't necessary at all, but I should have used: 0b111111 for the AXIS_MAP_CONFIG write; 0b111 for the AXIS_MAP_SIGN write; and 0b1111 for the OPR_MODE writes.

                Comment


                • #9
                  Originally posted by 4634 Programmer View Post
                  Here's some code that works without doing all the remapping stuff: https://gist.github.com/FROGbots-463...4c16e52616f35c
                  This code looks like the vanilla code.

                  What is different here that deals with a vertical module ?

                  Comment


                  • #10
                    Originally posted by Philbot View Post

                    This code looks like the vanilla code.

                    What is different here that deals with a vertical module ?
                    To be completely honest I don't really know what exactly fixed it. I was messing around trying to get it to work, and eventually I got it working properly with that code...

                    Comment


                    • #11
                      Can someone please post a picture of which axes are which on the Expansion HUB for the IMU? I looked all over the place and can't seem to find anything that tells me which is which for mounting purposes. I recall seeing one, somewhere, but didn't save it and now The Google is letting me down for finding it again.

                      Comment


                      • #12
                        Originally posted by gorpong View Post
                        Can someone please post a picture of which axes are which on the Expansion HUB for the IMU? I looked all over the place and can't seem to find anything that tells me which is which for mounting purposes. I recall seeing one, somewhere, but didn't save it and now The Google is letting me down for finding it again.
                        Here you go. http://i.imgur.com/uBz3oyj.png

                        Comment


                        • #13
                          Originally posted by 4634 Programmer View Post
                          Thank you for posting, but when I click on it and copy/paste it directly into a browser, I get a 404 error in Chrome and in Firefox it tells me it can't be displayed because it contains errors.

                          Comment


                          • #14
                            The link works fine for me. Here is a copy of the image retrieved and embedded in this message:

                            uBz3oyj.png

                            Comment


                            • #15
                              Originally posted by 5294-jjkd View Post
                              The link works fine for me. Here is a copy of the image retrieved and embedded in this message:

                              uBz3oyj.png
                              Sorry about that, my router at home's parental controls got in the way. I can see it now, thanks!

                              Comment

                              Working...
                              X