No announcement yet.

Gyro Help

  • Filter
  • Time
  • Show
Clear All
new posts

  • Gyro Help

    Our team was trying to use the gyro to get our robot to align ourselves. We are using the heading to make sure that we are aligned at zero which means that we are straight. Whenever we use our program to align our robot it goes a little bit extra but that senses it as zero. If you guys had this same problem or some way to help that would be great if you could share it with me.

  • #2
    Could you share a little bit more about your situation (as in gyro type, code, whether you use OBJ, Blocks or Android Studio)? I would personally recommend a PID loop that would maintain your heading based on the input from the gyro, but if the gyro is incorrect, this will not work. I can post something to Github if that would help you.


    • #3
      I am using the gyro that is on the rev expansion hub. I am also using Android Studio. I'm pretty sure the gyro I use is an IMU.

      package org.firstinspires.ftc.teamcode; import; import com.qualcomm.robotcore.eventloop.opmode.LinearOpMo de; import com.qualcomm.robotcore.eventloop.opmode.TeleOp; import org.firstinspires.ftc.robotcore.external.navigatio n.Acceleration; import org.firstinspires.ftc.robotcore.external.navigatio n.AngleUnit; import org.firstinspires.ftc.robotcore.external.navigatio n.AxesOrder; import org.firstinspires.ftc.robotcore.external.navigatio n.AxesReference; import org.firstinspires.ftc.robotcore.external.navigatio n.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)); } }


      • #4

        This document shows the same code. It is more easier to read this way. This is the program that we use to initialize the gyro and sense that the location that the robot is in, is 0. I'll send the GyroDrive method shortly. I just want to make sure that there is nothing wrong with this program itself.