Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update PointAtNoteCommand to use new SCL field oriented gamepad vectors #255

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,12 @@ protected boolean additionalAtGoalChecks() {
@Override
protected Double getHumanInput() {
double fundamentalInput = MathUtils.deadband(
oi.operatorFundamentalsGamepad.getLeftVector().y,
oi.operatorFundamentalsGamepad.getLeftVector().getY(),
oi.getOperatorGamepadTypicalDeadband(),
(x) -> x);

double advancedInput = MathUtils.deadband(
oi.operatorGamepadAdvanced.getLeftVector().y,
oi.operatorGamepadAdvanced.getLeftVector().getY(),
oi.getOperatorGamepadTypicalDeadband(),
(x) -> x);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ public void execute() {
// if we're very close to the note, stop trying to rotate, it gets wonky

var movement = MathUtils.deadband(
getDriveIntent(toNoteTranslation, oi.driverGamepad.getLeftVector(),
DriverStation.getAlliance().orElse(DriverStation.Alliance.Blue)),
getDriveIntent(toNoteTranslation, oi.driverGamepad.getLeftFieldOrientedVector()),
oi.getDriverGamepadTypicalDeadband(), (x) -> x);
double rotationPower = 0;
// if we're far enough away, rotate towards the note (if we're too close, the )
Expand All @@ -96,14 +95,9 @@ public void execute() {
drive.move(new XYPair(-movement, 0), rotationPower);
}

public static double getDriveIntent(Translation2d fieldTranslationToTarget, XYPair driveJoystick, Alliance alliance) {
public static double getDriveIntent(Translation2d fieldTranslationToTarget, Translation2d driveJoystick) {
var toNoteVector = fieldTranslationToTarget.toVector().unit();
var driverVector = VecBuilder.fill(driveJoystick.y, -driveJoystick.x);
if(alliance == DriverStation.Alliance.Red) {
// invert both axis
driverVector = driverVector.div(-1);
}
var dot = toNoteVector.dot(driverVector);
var dot = toNoteVector.dot(driveJoystick.toVector());

return dot;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public void initialize() {
@Override
public void execute() {
driveSubsystem.tankDrive(
MathUtils.deadband(oi.driverGamepad.getLeftVector().y, 0.15),
MathUtils.deadband(oi.driverGamepad.getRightVector().y, 0.15)
MathUtils.deadband(oi.driverGamepad.getLeftVector().getY(), 0.15),
MathUtils.deadband(oi.driverGamepad.getRightVector().getY(), 0.15)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,46 +14,24 @@
public class PointAtNoteCommandTest extends BaseCompetitionTest {

@Test
public void testGetDriveIntentBlue() {
var alliance = Alliance.Blue;
public void testGetDriveIntent() {
// completely aligned with the direction we want to go
// exact y
assertEquals( 1.0, PointAtNoteCommand.getDriveIntent(new Translation2d(0, 5), new XYPair(-1, 0), alliance), 0.001);
assertEquals( 1.0, PointAtNoteCommand.getDriveIntent(new Translation2d(0, 5), new Translation2d(0, 1)), 0.001);
// exact x
assertEquals( 1.0, PointAtNoteCommand.getDriveIntent(new Translation2d(5, 0), new XYPair(0, 1), alliance), 0.001);
assertEquals( 1.0, PointAtNoteCommand.getDriveIntent(new Translation2d(5, 0), new Translation2d(1, 0)), 0.001);


// exact opposite y
assertEquals(-1, PointAtNoteCommand.getDriveIntent(new Translation2d(0, 5), new XYPair(1, 0), alliance), 0.001);
assertEquals(-1, PointAtNoteCommand.getDriveIntent(new Translation2d(0, 5), new Translation2d(0, -1)), 0.001);
// exact opposite x
assertEquals(-1, PointAtNoteCommand.getDriveIntent(new Translation2d(5, 0), new XYPair(0, -1), alliance), 0.001);
assertEquals(-1, PointAtNoteCommand.getDriveIntent(new Translation2d(5, 0), new Translation2d(-1, 0)), 0.001);

// 45 degrees should be half power
assertEquals(0.5, PointAtNoteCommand.getDriveIntent(new Translation2d(5, 0), new XYPair(0.5, 0.5), alliance), 0.001);
assertEquals(0.5, PointAtNoteCommand.getDriveIntent(new Translation2d(5, 0), new Translation2d(0.5, 0.5)), 0.001);

// small floating joystick number
assertTrue(Math.abs(PointAtNoteCommand.getDriveIntent(new Translation2d(5, 0), new XYPair(0.01, 0.01), alliance)) < 0.02);
assertTrue(Math.abs(PointAtNoteCommand.getDriveIntent(new Translation2d(5, 0), new Translation2d(0.01, 0.01))) < 0.02);
}

@Test
public void testGetDriveIntentRed() {
var alliance = Alliance.Red;
// completely aligned with the direction we want to go
// exact y
assertEquals( 1.0, PointAtNoteCommand.getDriveIntent(new Translation2d(0, -5), new XYPair(-1, 0), alliance), 0.001);
// exact x
assertEquals( 1.0, PointAtNoteCommand.getDriveIntent(new Translation2d(-5, 0), new XYPair(0, 1), alliance), 0.001);


// exact opposite y
assertEquals(-1, PointAtNoteCommand.getDriveIntent(new Translation2d(0, -5), new XYPair(1, 0), alliance), 0.001);
// exact opposite x
assertEquals(-1, PointAtNoteCommand.getDriveIntent(new Translation2d(-5, 0), new XYPair(0, -1), alliance), 0.001);

// 45 degrees should be half power
assertEquals(0.5, PointAtNoteCommand.getDriveIntent(new Translation2d(-5, 0), new XYPair(0.5, 0.5), alliance), 0.001);

// small floating joystick number
assertTrue(Math.abs(PointAtNoteCommand.getDriveIntent(new Translation2d(-5, 0), new XYPair(0.01, 0.01), alliance)) < 0.02);
}
}
Loading