Skip to content

Commit

Permalink
Add odometry commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Keobkeig committed Jan 10, 2024
1 parent 4f883c1 commit 5f694af
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/main/java/com/stuypulse/robot/RobotContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@
import com.stuypulse.robot.commands.launcher.LaunchPrepare;
import com.stuypulse.robot.commands.launcher.LauncherIntakeNote;
import com.stuypulse.robot.commands.launcher.LauncherStop;
import com.stuypulse.robot.commands.odometry.OdometryRealign;
import com.stuypulse.robot.constants.Ports;
import com.stuypulse.robot.subsystems.drivetrain.Drivetrain;
import com.stuypulse.robot.subsystems.launcher.Launcher;
import com.stuypulse.stuylib.input.Gamepad;
import com.stuypulse.stuylib.input.gamepads.AutoGamepad;

import edu.wpi.first.math.geometry.Rotation2d;
import edu.wpi.first.wpilibj.smartdashboard.SendableChooser;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj2.command.Command;
Expand Down Expand Up @@ -54,6 +56,11 @@ private void configureDefaultCommands() {
/***************/

private void configureButtonBindings() {
configureDriverBindings();
configureOperatorBindings();
}

private void configureDriverBindings() {
operator.getLeftBumper()
.onTrue(new LauncherIntakeNote())
.onFalse(new LauncherStop());
Expand All @@ -64,6 +71,14 @@ private void configureButtonBindings() {
.onFalse(new LauncherStop());
}

private void configureOperatorBindings() {
// odometry
driver.getDPadUp().onTrue(new OdometryRealign(Rotation2d.fromDegrees(180)));
driver.getDPadLeft().onTrue(new OdometryRealign(Rotation2d.fromDegrees(-90)));
driver.getDPadDown().onTrue(new OdometryRealign(Rotation2d.fromDegrees(0)));
driver.getDPadRight().onTrue(new OdometryRealign(Rotation2d.fromDegrees(90)));
}

/**************/
/*** AUTONS ***/
/**************/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.stuypulse.robot.commands.odometry;

import com.stuypulse.robot.subsystems.odometry.AbstractOdometry;

import edu.wpi.first.math.geometry.Pose2d;
import edu.wpi.first.math.geometry.Rotation2d;
import edu.wpi.first.wpilibj2.command.InstantCommand;

import java.util.function.Supplier;

public class OdometryRealign extends InstantCommand {
private final AbstractOdometry odometry;
private final Supplier<Rotation2d> references;

public OdometryRealign(Supplier<Rotation2d> references) {
odometry = AbstractOdometry.getInstance();
this.references = references;

// addRequirements(odometry);
}

public OdometryRealign(Rotation2d reference) {
this(() -> reference);
}

public OdometryRealign() {
this(Rotation2d.fromDegrees(0));
}

@Override
public void initialize() {
Pose2d pose = odometry.getPose();
odometry.resetOdometery(new Pose2d(pose.getTranslation(), references.get()));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.stuypulse.robot.commands.odometry;

import com.stuypulse.robot.subsystems.odometry.AbstractOdometry;

import edu.wpi.first.math.geometry.Pose2d;
import edu.wpi.first.wpilibj2.command.InstantCommand;

import java.util.function.Supplier;

public class OdometryReset extends InstantCommand {
private final AbstractOdometry odometry;
private final Supplier<Pose2d> references;

public OdometryReset(Supplier<Pose2d> references) {
odometry = AbstractOdometry.getInstance();
this.references = references;

// addRequirements(null);
}

public OdometryReset(Pose2d reference) {
this(() -> reference);
}

@Override
public void initialize() {
odometry.resetOdometery(references.get());
}

}

0 comments on commit 5f694af

Please sign in to comment.