Last active
December 3, 2017 17:47
-
-
Save kskrueger/eb8b06112c41c4bd97c959c5208f9922 to your computer and use it in GitHub Desktop.
Example code for reading the IMU
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//you will need to import these | |
import com.qualcomm.hardware.bosch.BNO055IMU; | |
import com.qualcomm.hardware.bosch.JustLoggingAccelerationIntegrator; | |
import com.qualcomm.robotcore.hardware.HardwareMap; | |
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; | |
//this code goes before the init portion | |
BNO055IMU imu; | |
//this code needs to go inside the init portion | |
BNO055IMU.Parameters parameters = new BNO055IMU.Parameters(); | |
parameters.angleUnit = BNO055IMU.AngleUnit.DEGREES; | |
parameters.accelUnit = BNO055IMU.AccelUnit.METERS_PERSEC_PERSEC; | |
parameters.calibrationDataFile = "BNO055IMUCalibration.json"; | |
parameters.loggingEnabled = true; | |
parameters.loggingTag = "IMU"; | |
parameters.accelerationIntegrationAlgorithm = new JustLoggingAccelerationIntegrator(); | |
imu = hwMap.get(BNO055IMU.class, "IMU"); | |
imu.initialize(parameters); | |
//Here is the code you will need for reading the heading of the IMU | |
//you may have to adjust which of X, Y, and Z you are reading based on your orientation of the hub | |
//you can use this wherever you need to use the heading value in teleop loop or inside an autonomous loop for turning for example | |
Orientation angles = imu.getAngularOrientation(AxesReference.INTRINSIC, AxesOrder.ZYX, AngleUnit.DEGREES); | |
double heading = (angles.firstAngle+360+offset)%360; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment