Skip to content

Commit cef7286

Browse files
authored
Merge pull request #3 from StuyPulse/ian
Fix CANCoder IDS and reorganize swerve module initialization
2 parents 3fab6ca + 3b5d129 commit cef7286

File tree

15 files changed

+260
-311
lines changed

15 files changed

+260
-311
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
{
2+
"version": "2025.0",
3+
"waypoints": [
4+
{
5+
"anchor": {
6+
"x": 2.0,
7+
"y": 7.0
8+
},
9+
"prevControl": null,
10+
"nextControl": {
11+
"x": 3.0,
12+
"y": 7.0
13+
},
14+
"isLocked": false,
15+
"linkedName": null
16+
},
17+
{
18+
"anchor": {
19+
"x": 4.0,
20+
"y": 6.0
21+
},
22+
"prevControl": {
23+
"x": 3.0,
24+
"y": 6.0
25+
},
26+
"nextControl": null,
27+
"isLocked": false,
28+
"linkedName": null
29+
}
30+
],
31+
"rotationTargets": [],
32+
"constraintZones": [],
33+
"pointTowardsZones": [],
34+
"eventMarkers": [],
35+
"globalConstraints": {
36+
"maxVelocity": 3.0,
37+
"maxAcceleration": 3.0,
38+
"maxAngularVelocity": 540.0,
39+
"maxAngularAcceleration": 720.0,
40+
"nominalVoltage": 12.0,
41+
"unlimited": false
42+
},
43+
"goalEndState": {
44+
"velocity": 0,
45+
"rotation": 0.0
46+
},
47+
"reversed": false,
48+
"folder": null,
49+
"idealStartingState": {
50+
"velocity": 0,
51+
"rotation": 0.0
52+
},
53+
"useDefaultConstraints": true
54+
}

src/main/deploy/pathplanner/settings.json

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"robotWidth": 0.9,
3-
"robotLength": 0.9,
2+
"robotWidth": 0.7366,
3+
"robotLength": 0.7366,
44
"holonomicMode": true,
55
"pathFolders": [],
66
"autoFolders": [],
@@ -12,20 +12,20 @@
1212
"robotMass": 74.088,
1313
"robotMOI": 6.0,
1414
"robotTrackwidth": 0.546,
15-
"driveWheelRadius": 0.048,
16-
"driveGearing": 5.143,
15+
"driveWheelRadius": 0.051,
16+
"driveGearing": 6.857,
1717
"maxDriveSpeed": 5.45,
18-
"driveMotorType": "krakenX60",
18+
"driveMotorType": "vortex",
1919
"driveCurrentLimit": 60.0,
2020
"wheelCOF": 1.2,
21-
"flModuleX": 0.273,
22-
"flModuleY": 0.273,
23-
"frModuleX": 0.273,
24-
"frModuleY": -0.273,
25-
"blModuleX": -0.273,
26-
"blModuleY": 0.273,
27-
"brModuleX": -0.273,
28-
"brModuleY": -0.273,
21+
"flModuleX": 0.2804033,
22+
"flModuleY": 0.28,
23+
"frModuleX": 0.28,
24+
"frModuleY": -0.28,
25+
"blModuleX": -0.28,
26+
"blModuleY": 0.28,
27+
"brModuleX": -0.28,
28+
"brModuleY": -0.28,
2929
"bumperOffsetX": 0.0,
3030
"bumperOffsetY": 0.0,
3131
"robotFeatures": []

src/main/java/com/stuypulse/robot/commands/AutoPilot.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,24 @@
88
import com.stuypulse.robot.constants.Settings;
99
import com.stuypulse.robot.constants.Field.CoralBranch;
1010

11+
import edu.wpi.first.math.geometry.Rotation2d;
12+
import edu.wpi.first.math.geometry.Transform2d;
1113
import edu.wpi.first.wpilibj2.command.Command;
1214
import edu.wpi.first.wpilibj2.command.SequentialCommandGroup;
1315
import edu.wpi.first.wpilibj2.command.WaitCommand;
1416

15-
public class AutoPilot extends SequentialCommandGroup{
17+
public class AutoPilot extends SequentialCommandGroup {
1618

1719
public AutoPilot() {
1820
ArrayList<Command> commands = new ArrayList<>();
1921
for (CoralBranch branch : CoralBranch.values()) {
2022
Command command = new SequentialCommandGroup(
23+
SwervePathFind.toPose(Field.getTargetPoseForCoralBranch(branch).transformBy(new Transform2d(-1.0, 0, new Rotation2d())))
24+
.onlyIf(() -> !branch.onDriverStationSide()),
2125
SwervePathFind.toPose(Field.getTargetPoseForCoralBranch(branch)),
2226
new DropperShootSequence(),
27+
SwervePathFind.toPose(Field.getTargetPoseForCoralBranch(branch).transformBy(new Transform2d(-1.0, 0, new Rotation2d())))
28+
.onlyIf(() -> !branch.onDriverStationSide()),
2329
SwervePathFind.toNearestCoralStation(),
2430
new WaitCommand(Settings.Dropper.WAIT_TIME_AT_CORAL_STATION)
2531
);

src/main/java/com/stuypulse/robot/commands/swerve/SwerveDriveDrive.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.stuypulse.stuylib.input.Gamepad;
44
import com.stuypulse.stuylib.math.SLMath;
5+
import com.stuypulse.stuylib.math.Vector2D;
56
import com.stuypulse.stuylib.streams.numbers.IStream;
67
import com.stuypulse.stuylib.streams.numbers.filters.LowPassFilter;
78
import com.stuypulse.stuylib.streams.vectors.VStream;
@@ -27,7 +28,7 @@ public class SwerveDriveDrive extends Command {
2728
public SwerveDriveDrive(Gamepad driver) {
2829
swerve = SwerveDrive.getInstance();
2930

30-
speed = VStream.create(driver::getLeftStick)
31+
speed = VStream.create(this::getDriverInputAsVelocity)
3132
.filtered(
3233
new VDeadZone(Drive.DEADBAND),
3334
x -> x.clamp(1),
@@ -48,6 +49,10 @@ public SwerveDriveDrive(Gamepad driver) {
4849
addRequirements(swerve);
4950
}
5051

52+
private Vector2D getDriverInputAsVelocity() {
53+
return new Vector2D(driver.getLeftStick().y, -driver.getLeftStick().x);
54+
}
55+
5156
@Override
5257
public void execute() {
5358
swerve.drive(speed.get(), turn.get());
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.stuypulse.robot.commands.swerve;
2+
3+
import com.stuypulse.stuylib.input.Gamepad;
4+
import com.stuypulse.stuylib.math.SLMath;
5+
import com.stuypulse.stuylib.math.Vector2D;
6+
import com.stuypulse.stuylib.streams.numbers.IStream;
7+
import com.stuypulse.stuylib.streams.numbers.filters.LowPassFilter;
8+
import com.stuypulse.stuylib.streams.vectors.VStream;
9+
import com.stuypulse.stuylib.streams.vectors.filters.VDeadZone;
10+
import com.stuypulse.stuylib.streams.vectors.filters.VLowPassFilter;
11+
import com.stuypulse.stuylib.streams.vectors.filters.VRateLimit;
12+
import com.stuypulse.robot.constants.Field;
13+
import com.stuypulse.robot.constants.Settings.Driver.Drive;
14+
import com.stuypulse.robot.constants.Settings.Driver.Turn;
15+
import com.stuypulse.robot.subsystems.odometry.Odometry;
16+
import com.stuypulse.robot.subsystems.swerve.SwerveDrive;
17+
18+
import edu.wpi.first.math.geometry.Translation2d;
19+
import edu.wpi.first.wpilibj2.command.Command;
20+
21+
public class SwerveDriveDriveAwayFromReef extends Command {
22+
23+
private final SwerveDrive swerve;
24+
25+
public SwerveDriveDriveAwayFromReef() {
26+
swerve = SwerveDrive.getInstance();
27+
addRequirements(swerve);
28+
}
29+
30+
@Override
31+
public void execute() {
32+
Translation2d robot = Odometry.getInstance().getPose().getTranslation();
33+
Translation2d reefToRobot = robot.minus(Field.REEF_CENTER);
34+
Vector2D velocity = new Vector2D(reefToRobot).normalize().mul(1.5);
35+
swerve.drive(velocity, 0);
36+
}
37+
}

src/main/java/com/stuypulse/robot/commands/swerve/SwervePIDToPose.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
import com.stuypulse.robot.constants.Field;
88
import com.stuypulse.robot.constants.Settings.Swerve;
99
import com.stuypulse.robot.constants.Settings.Swerve.Alignment;
10-
import com.stuypulse.robot.constants.Settings.Swerve.Controllers.Chassis.Theta;
11-
import com.stuypulse.robot.constants.Settings.Swerve.Controllers.Chassis.XY;
10+
import com.stuypulse.robot.constants.Settings.Swerve.Alignment.Theta;
11+
import com.stuypulse.robot.constants.Settings.Swerve.Alignment.XY;
1212
import com.stuypulse.robot.subsystems.odometry.Odometry;
1313
import com.stuypulse.robot.subsystems.swerve.SwerveDrive;
1414
import com.stuypulse.robot.util.HolonomicController;

src/main/java/com/stuypulse/robot/commands/swerve/SwervePathFind.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.util.function.Supplier;
44

55
import com.pathplanner.lib.auto.AutoBuilder;
6+
import com.pathplanner.lib.path.PathConstraints;
67
import com.stuypulse.robot.constants.Field;
78
import com.stuypulse.robot.constants.Settings;
89
import com.stuypulse.robot.subsystems.odometry.Odometry;

src/main/java/com/stuypulse/robot/constants/Field.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ public static boolean isValidAprilTagId(int id) {
130130

131131
/*** REEF POSITIONS ***/
132132

133+
Translation2d REEF_CENTER = new Translation2d(Units.inchesToMeters(144.0 + 93.5 / 2), WIDTH / 2);
133134
double CENTER_OF_TROUGH_TO_BRANCH = Units.inchesToMeters(13.0/2.0);
134135

135136
public enum CoralBranch {
@@ -159,6 +160,24 @@ public boolean isLeftPeg() {
159160
return false;
160161
}
161162
}
163+
164+
/**
165+
* Represents the half of the reef facing the driver station.
166+
* The other half is facing the barge / the opposite alliance
167+
*/
168+
public boolean onDriverStationSide() {
169+
switch (this) {
170+
case A:
171+
case B:
172+
case C:
173+
case D:
174+
case L:
175+
case K:
176+
return true;
177+
default:
178+
return false;
179+
}
180+
}
162181
}
163182

164183
public static Pose2d getTargetPoseForCoralBranch(CoralBranch position) {

src/main/java/com/stuypulse/robot/constants/Motors.java

Lines changed: 0 additions & 111 deletions
This file was deleted.

src/main/java/com/stuypulse/robot/constants/Ports.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ public interface Turn {
2828
}
2929
public interface CANCoderIds {
3030
int FRONT_LEFT = 1;
31-
int FRONT_RIGHT = 2;
32-
int BACK_LEFT = 3;
33-
int BACK_RIGHT = 4;
31+
int BACK_LEFT = 2;
32+
int BACK_RIGHT = 3;
33+
int FRONT_RIGHT = 4;
3434
}
3535
}
3636

0 commit comments

Comments
 (0)