Skip to content

Commit

Permalink
Rename LazyImu drive members
Browse files Browse the repository at this point in the history
Also makes sure the mecanum drive localizer fetches the IMU
on construction.
  • Loading branch information
rbrott committed Feb 21, 2024
1 parent 9d2cd48 commit 03d95d7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
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 +110,7 @@ kinematics.new WheelVelConstraint(PARAMS.maxWheelVel),

public final VoltageSensor voltageSensor;

public final LazyImu imu;
public final LazyImu lazyImu;

public final Localizer localizer;
public Pose2d pose;
Expand All @@ -123,6 +124,7 @@ kinematics.new WheelVelConstraint(PARAMS.maxWheelVel),

public class DriveLocalizer implements Localizer {
public final Encoder leftFront, leftBack, rightBack, rightFront;
public final IMU imu;

private int lastLeftFrontPos, lastLeftBackPos, lastRightBackPos, lastRightFrontPos;
private Rotation2d lastHeading;
Expand All @@ -134,6 +136,8 @@ public DriveLocalizer() {
rightBack = new OverflowEncoder(new RawEncoder(MecanumDrive.this.rightBack));
rightFront = new OverflowEncoder(new RawEncoder(MecanumDrive.this.rightFront));

imu = lazyImu.get();

// TODO: reverse encoders if needed
// leftFront.setDirection(DcMotorSimple.Direction.REVERSE);
}
Expand All @@ -145,7 +149,7 @@ public Twist2dDual<Time> update() {
PositionVelocityPair rightBackPosVel = rightBack.getPositionAndVelocity();
PositionVelocityPair rightFrontPosVel = rightFront.getPositionAndVelocity();

YawPitchRollAngles angles = imu.get().getRobotYawPitchRollAngles();
YawPitchRollAngles angles = imu.getRobotYawPitchRollAngles();

FlightRecorder.write("MECANUM_LOCALIZER_INPUTS", new MecanumLocalizerInputsMessage(
leftFrontPosVel, leftBackPosVel, rightBackPosVel, rightFrontPosVel, angles));
Expand Down Expand Up @@ -228,7 +232,7 @@ 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 = new LazyImu(hardwareMap, "imu", new RevHubOrientationOnRobot(
lazyImu = new LazyImu(hardwareMap, "imu", new RevHubOrientationOnRobot(
PARAMS.logoFacingDirection, PARAMS.usbFacingDirection));

voltageSensor = hardwareMap.voltageSensor.iterator().next();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ kinematics.new WheelVelConstraint(PARAMS.maxWheelVel),

public final List<DcMotorEx> leftMotors, rightMotors;

public final LazyImu imu;
public final LazyImu lazyImu;

public final VoltageSensor voltageSensor;

Expand Down Expand Up @@ -237,7 +237,7 @@ 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 = new LazyImu(hardwareMap, "imu", new RevHubOrientationOnRobot(
lazyImu = new LazyImu(hardwareMap, "imu", new RevHubOrientationOnRobot(
PARAMS.logoFacingDirection, PARAMS.usbFacingDirection));

voltageSensor = hardwareMap.voltageSensor.iterator().next();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public static void register(OpModeManager manager) {
rightEncs,
parEncs,
perpEncs,
md.imu,
md.lazyImu,
md.voltageSensor,
() -> new MotorFeedforward(MecanumDrive.PARAMS.kS,
MecanumDrive.PARAMS.kV / MecanumDrive.PARAMS.inPerTick,
Expand Down Expand Up @@ -140,7 +140,7 @@ public static void register(OpModeManager manager) {
rightEncs,
parEncs,
perpEncs,
td.imu,
td.lazyImu,
td.voltageSensor,
() -> new MotorFeedforward(TankDrive.PARAMS.kS,
TankDrive.PARAMS.kV / TankDrive.PARAMS.inPerTick,
Expand Down

0 comments on commit 03d95d7

Please sign in to comment.