Skip to content

Commit

Permalink
Update to lazy IMU (fixes FIRST-Tech-Challenge#346)
Browse files Browse the repository at this point in the history
  • Loading branch information
rbrott committed Jan 26, 2024
1 parent 5cf1596 commit c6ef075
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
2 changes: 1 addition & 1 deletion TeamCode/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ dependencies {
implementation project(':FtcRobotController')
annotationProcessor files('lib/OpModeAnnotationProcessor.jar')

implementation "com.acmerobotics.roadrunner:ftc:0.1.11"
implementation "com.acmerobotics.roadrunner:ftc:0.1.12"
implementation "com.acmerobotics.dashboard:dashboard:0.4.14"
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.acmerobotics.roadrunner.ftc.DownsampledWriter;
import com.acmerobotics.roadrunner.ftc.Encoder;
import com.acmerobotics.roadrunner.ftc.FlightRecorder;
import com.acmerobotics.roadrunner.ftc.LazyImu;
import com.acmerobotics.roadrunner.ftc.LynxFirmware;
import com.acmerobotics.roadrunner.ftc.OverflowEncoder;
import com.acmerobotics.roadrunner.ftc.PositionVelocityPair;
Expand All @@ -36,7 +37,6 @@
import com.qualcomm.robotcore.hardware.DcMotorEx;
import com.qualcomm.robotcore.hardware.DcMotorSimple;
import com.qualcomm.robotcore.hardware.HardwareMap;
import com.qualcomm.robotcore.hardware.IMU;
import com.qualcomm.robotcore.hardware.VoltageSensor;

import org.firstinspires.ftc.robotcore.external.navigation.AngleUnit;
Expand Down Expand Up @@ -109,7 +109,7 @@ kinematics.new WheelVelConstraint(PARAMS.maxWheelVel),

public final VoltageSensor voltageSensor;

public final IMU imu;
public final LazyImu imu;

public final Localizer localizer;
public Pose2d pose;
Expand Down Expand Up @@ -141,7 +141,7 @@ public DriveLocalizer() {
lastRightBackPos = rightBack.getPositionAndVelocity().position;
lastRightFrontPos = rightFront.getPositionAndVelocity().position;

lastHeading = Rotation2d.exp(imu.getRobotYawPitchRollAngles().getYaw(AngleUnit.RADIANS));
lastHeading = Rotation2d.exp(imu.get().getRobotYawPitchRollAngles().getYaw(AngleUnit.RADIANS));
}

@Override
Expand All @@ -154,7 +154,7 @@ public Twist2dDual<Time> update() {
FlightRecorder.write("MECANUM_ENCODERS", new MecanumEncodersMessage(
leftFrontPosVel, leftBackPosVel, rightBackPosVel, rightFrontPosVel));

Rotation2d heading = Rotation2d.exp(imu.getRobotYawPitchRollAngles().getYaw(AngleUnit.RADIANS));
Rotation2d heading = Rotation2d.exp(imu.get().getRobotYawPitchRollAngles().getYaw(AngleUnit.RADIANS));
double headingDelta = heading.minus(lastHeading);

Twist2dDual<Time> twist = kinematics.forward(new MecanumKinematics.WheelIncrements<>(
Expand Down Expand Up @@ -216,10 +216,8 @@ public MecanumDrive(HardwareMap hardwareMap, Pose2d pose) {

// TODO: make sure your config has an IMU with this name (can be BNO or BHI)
// see https://ftc-docs.firstinspires.org/en/latest/hardware_and_software_configuration/configuring/index.html
imu = hardwareMap.get(IMU.class, "imu");
IMU.Parameters parameters = new IMU.Parameters(new RevHubOrientationOnRobot(
imu = new LazyImu(hardwareMap, "imu", new RevHubOrientationOnRobot(
PARAMS.logoFacingDirection, PARAMS.usbFacingDirection));
imu.initialize(parameters);

voltageSensor = hardwareMap.voltageSensor.iterator().next();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.acmerobotics.roadrunner.ftc.DownsampledWriter;
import com.acmerobotics.roadrunner.ftc.Encoder;
import com.acmerobotics.roadrunner.ftc.FlightRecorder;
import com.acmerobotics.roadrunner.ftc.LazyImu;
import com.acmerobotics.roadrunner.ftc.LynxFirmware;
import com.acmerobotics.roadrunner.ftc.OverflowEncoder;
import com.acmerobotics.roadrunner.ftc.PositionVelocityPair;
Expand All @@ -42,7 +43,6 @@
import com.qualcomm.robotcore.hardware.DcMotorEx;
import com.qualcomm.robotcore.hardware.DcMotorSimple;
import com.qualcomm.robotcore.hardware.HardwareMap;
import com.qualcomm.robotcore.hardware.IMU;
import com.qualcomm.robotcore.hardware.VoltageSensor;

import org.firstinspires.ftc.teamcode.messages.DriveCommandMessage;
Expand Down Expand Up @@ -110,7 +110,7 @@ kinematics.new WheelVelConstraint(PARAMS.maxWheelVel),

public final List<DcMotorEx> leftMotors, rightMotors;

public final IMU imu;
public final LazyImu imu;

public final VoltageSensor voltageSensor;

Expand Down Expand Up @@ -234,10 +234,8 @@ public TankDrive(HardwareMap hardwareMap, Pose2d pose) {

// TODO: make sure your config has an IMU with this name (can be BNO or BHI)
// see https://ftc-docs.firstinspires.org/en/latest/hardware_and_software_configuration/configuring/index.html
imu = hardwareMap.get(IMU.class, "imu");
IMU.Parameters parameters = new IMU.Parameters(new RevHubOrientationOnRobot(
imu = new LazyImu(hardwareMap, "imu", new RevHubOrientationOnRobot(
PARAMS.logoFacingDirection, PARAMS.usbFacingDirection));
imu.initialize(parameters);

voltageSensor = hardwareMap.voltageSensor.iterator().next();

Expand Down

0 comments on commit c6ef075

Please sign in to comment.