Advertisement
Guest User

Untitled

a guest
Jul 20th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.47 KB | None | 0 0
  1. package org.firstinspires.ftc.teamcode.util;
  2.  
  3.  
  4. import com.qualcomm.hardware.bosch.BNO055IMU;
  5. import com.qualcomm.robotcore.hardware.HardwareMap;
  6.  
  7. import org.firstinspires.ftc.robotcore.external.navigation.AngleUnit;
  8. import org.firstinspires.ftc.robotcore.external.navigation.AxesOrder;
  9. import org.firstinspires.ftc.robotcore.external.navigation.AxesReference;
  10. import org.firstinspires.ftc.robotcore.external.navigation.Orientation;
  11.  
  12. public class Gyro {
  13.     // The IMU sensor object
  14.     public BNO055IMU imu;
  15.  
  16.     // State used for updating telemetry
  17.     Orientation angles;
  18.  
  19.     public Gyro(HardwareMap map){
  20.         initGyro(map);
  21.     }
  22.  
  23.     public Gyro(HardwareMap map, String name){
  24.         initGyro(map, name);
  25.     }
  26.  
  27.     public void initGyro(HardwareMap hardwareMap)
  28.     {
  29.         BNO055IMU.Parameters parameters = new BNO055IMU.Parameters();
  30.         parameters.angleUnit           = BNO055IMU.AngleUnit.DEGREES;
  31.         parameters.accelUnit           = BNO055IMU.AccelUnit.METERS_PERSEC_PERSEC;
  32.         parameters.calibrationDataFile = "BNO055IMUCalibration.json"; // see the calibration sample opmode
  33.         parameters.loggingEnabled      = true;
  34.         parameters.loggingTag          = "IMU";
  35.  
  36.         imu = hardwareMap.get(BNO055IMU.class, "imu");
  37.         imu.initialize(parameters);
  38.  
  39.     }
  40.  
  41.     public void initGyro(HardwareMap hardwareMap, String name)
  42.     {
  43.         BNO055IMU.Parameters parameters = new BNO055IMU.Parameters();
  44.         parameters.angleUnit           = BNO055IMU.AngleUnit.DEGREES;
  45.         parameters.accelUnit           = BNO055IMU.AccelUnit.METERS_PERSEC_PERSEC;
  46.         parameters.calibrationDataFile = "BNO055IMUCalibration.json"; // see the calibration sample opmode
  47.         parameters.loggingEnabled      = true;
  48.         parameters.loggingTag          = "IMU";
  49.  
  50.         imu = hardwareMap.get(BNO055IMU.class, name);
  51.         imu.initialize(parameters);
  52.  
  53.     }
  54.  
  55.     //TODO: CHANGE THE AXES BASED ON WHERE THE HUB IS PLACED
  56.     private void updateAngles() {
  57.         angles = imu.getAngularOrientation(AxesReference.INTRINSIC,AxesOrder.ZYX,AngleUnit.DEGREES);
  58.     }
  59.  
  60.  
  61.  
  62.     public double getRoll(){
  63.         updateAngles();
  64.         return angles.secondAngle;
  65.     }
  66.     public double getPitch(){
  67.         updateAngles();
  68.         return angles.thirdAngle;
  69.     }
  70.     public double getYaw() {
  71.         updateAngles();
  72.         return angles.firstAngle;
  73.     }
  74.  
  75.     public double getHeading() {
  76.         return getYaw();
  77.     }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement