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

Initial YAGSL based swerve implementation #13

Merged
merged 20 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
9a51907
Added YAGSL 2024 vendordeps
BrownGenius Jan 19, 2024
38e847d
YAGSL config for swerve practice bot (need correct dimensions and abs…
BrownGenius Jan 19, 2024
c7a540c
Basic Swerve YAGSL implementation
BrownGenius Jan 19, 2024
c2ad424
Add joystick deadband
BrownGenius Jan 19, 2024
1c4e7c4
Updated swerve module offsets to match actual swerve practice bot
BrownGenius Jan 19, 2024
fa8779b
Merge branch 'main' of https://github.com/DevilBotz2876/Crescendo2024…
BrownGenius Jan 20, 2024
4e40e4c
adjust offset values
CodeSalvageO Jan 20, 2024
df36f5f
Merge branch 'SwerveYAGSL' of https://github.com/DevilBotz2876/Cresce…
CodeSalvageO Jan 20, 2024
17d0831
Merge branch 'main' of https://github.com/DevilBotz2876/Crescendo2024…
BrownGenius Jan 20, 2024
3b35d05
Merge branch 'main' of https://github.com/DevilBotz2876/Crescendo2024…
BrownGenius Jan 20, 2024
5497e9a
Disable logging to /media/sda1
BrownGenius Jan 20, 2024
634139e
Tweak swerve module locations to be from center to each module...not …
BrownGenius Jan 20, 2024
c57101b
Merge branch 'main' into SwerveYAGSL
BrownGenius Jan 22, 2024
e34110c
spotlessApply
BrownGenius Jan 22, 2024
2d5c709
Updated offsets/inversion state
BrownGenius Jan 23, 2024
8b6862c
Invert NavX
BrownGenius Jan 23, 2024
ddfd556
Update angle conversion factor to use MK4i 150/7:1 steering ratio
BrownGenius Jan 23, 2024
8b849a5
Updated vendor libs
BrownGenius Jan 24, 2024
df0c5e7
Revert "Updated vendor libs"
BrownGenius Jan 25, 2024
d9a2fba
Actual Values
BrownGenius Jan 25, 2024
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
8 changes: 8 additions & 0 deletions src/main/deploy/swervePracticeBot/controllerproperties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"angleJoystickRadiusDeadband": 0.5,
"heading": {
"p": 0.4,
"i": 0,
"d": 0.01
}
}
30 changes: 30 additions & 0 deletions src/main/deploy/swervePracticeBot/modules/backleft.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"location": {
"front": -9.75,
"left": 9.75
},
"absoluteEncoderOffset": -257.2,
"drive": {
"type": "sparkmax",
"id": 12,
"canbus": null
},
"inverted": {
"drive": false,
"angle": true
},
"angle": {
"type": "sparkmax",
"id": 16,
"canbus": null
},
"conversionFactor": {
"angle": 0,
"drive": 0
},
"encoder": {
"type": "cancoder",
"id": 20,
"canbus": null
}
}
30 changes: 30 additions & 0 deletions src/main/deploy/swervePracticeBot/modules/backright.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"location": {
"front": -9.75,
"left": -9.75
},
"absoluteEncoderOffset": -293,
"drive": {
"type": "sparkmax",
"id": 13,
"canbus": null
},
"inverted": {
"drive": true,
"angle": true
},
"angle": {
"type": "sparkmax",
"id": 17,
"canbus": null
},
"conversionFactor": {
"angle": 0,
"drive": 0
},
"encoder": {
"type": "cancoder",
"id": 21,
"canbus": null
}
}
30 changes: 30 additions & 0 deletions src/main/deploy/swervePracticeBot/modules/frontleft.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"location": {
"front": 9.75,
"left": 9.75
},
"absoluteEncoderOffset": -230,
"drive": {
"type": "sparkmax",
"id": 10,
"canbus": null
},
"inverted": {
"drive": false,
"angle": true
},
"angle": {
"type": "sparkmax",
"id": 14,
"canbus": null
},
"conversionFactor": {
"angle": 0,
"drive": 0
},
"encoder": {
"type": "cancoder",
"id": 18,
"canbus": null
}
}
30 changes: 30 additions & 0 deletions src/main/deploy/swervePracticeBot/modules/frontright.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"location": {
"front": 9.75,
"left": -9.75
},
"absoluteEncoderOffset": -290,
"drive": {
"type": "sparkmax",
"id": 11,
"canbus": null
},
"inverted": {
"drive": false,
"angle": true
},
"angle": {
"type": "sparkmax",
"id": 15,
"canbus": null
},
"conversionFactor": {
"angle": 0,
"drive": 0
},
"encoder": {
"type": "cancoder",
"id": 19,
"canbus": null
}
}
16 changes: 16 additions & 0 deletions src/main/deploy/swervePracticeBot/modules/physicalproperties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"optimalVoltage": 12,
"wheelGripCoefficientOfFriction": 1.19,
"currentLimit": {
"drive": 40,
"angle": 20
},
"conversionFactor": {
"angle": 16.8,
"drive": 0.047286787200699704
},
"rampRate": {
"drive": 0.25,
"angle": 0.25
}
}
16 changes: 16 additions & 0 deletions src/main/deploy/swervePracticeBot/modules/pidfproperties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"drive": {
"p": 0.0020645,
"i": 0,
"d": 0,
"f": 0,
"iz": 0
},
"angle": {
"p": 0.01,
"i": 0,
"d": 0,
"f": 0,
"iz": 0
}
}
14 changes: 14 additions & 0 deletions src/main/deploy/swervePracticeBot/swervedrive.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"imu": {
"type": "navx_mxp",
"id": 0,
"canbus": null
},
"invertedIMU": true,
"modules": [
"frontleft.json",
"frontright.json",
"backleft.json",
"backright.json"
]
}
2 changes: 1 addition & 1 deletion src/main/java/frc/robot/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void robotInit() {
} else {*/
if (isReal()) {
// Running on real robot
Logger.addDataReceiver(new WPILOGWriter("/media/sda1/")); // Log to a USB stick
// Logger.addDataReceiver(new WPILOGWriter("/media/sda1/")); // Log to a USB stick
Logger.addDataReceiver(new NT4Publisher()); // Publish data to NetworkTables
} else {
// Running in simulation
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/frc/robot/RobotContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@

package frc.robot;

import edu.wpi.first.math.MathUtil;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.Commands;
import edu.wpi.first.wpilibj2.command.InstantCommand;
import edu.wpi.first.wpilibj2.command.button.CommandXboxController;
import frc.robot.commands.IntakeBaseCommand;
import frc.robot.commands.ShooterEnable;
import frc.robot.commands.drive.DriveCommand;
import frc.robot.subsystems.drive.DriveSwerveYAGSL;
import frc.robot.subsystems.intake.IntakeBase;
import frc.robot.subsystems.intake.IntakeIOSim;
import frc.robot.subsystems.intake.IntakeIOSparkMax;
Expand All @@ -21,6 +24,7 @@ public class RobotContainer {
public final CommandXboxController controller;
public final ShooterSubsystem shooter;
public final IntakeBase intake;
public final DriveSwerveYAGSL drive;

public RobotContainer() {
controller = new CommandXboxController(0);
Expand All @@ -40,6 +44,8 @@ public RobotContainer() {
intake = new IntakeBase(new IntakeIOSim());
}

drive = new DriveSwerveYAGSL();

configureBindings();
}

Expand All @@ -52,6 +58,19 @@ private void configureBindings() {
intake,
() -> controller.rightBumper().getAsBoolean(),
() -> controller.leftBumper().getAsBoolean()));

drive.setDefaultCommand(
new DriveCommand(
drive,
() -> MathUtil.applyDeadband(-controller.getLeftY(), 0.01),
() -> MathUtil.applyDeadband(-controller.getLeftX(), 0.01),
() -> MathUtil.applyDeadband(-controller.getRightX(), 0.01)));
// TODO: Move deadband to constants file

controller
.start()
.onTrue(
new InstantCommand(() -> drive.setFieldOrientedDrive(!drive.isFieldOrientedDrive())));
}

public Command getAutonomousCommand() {
Expand Down
34 changes: 34 additions & 0 deletions src/main/java/frc/robot/commands/drive/DriveCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package frc.robot.commands.drive;

import edu.wpi.first.math.kinematics.ChassisSpeeds;
import edu.wpi.first.wpilibj2.command.Command;
import frc.robot.subsystems.drive.DriveBase;
import java.util.function.DoubleSupplier;

public class DriveCommand extends Command {
DriveBase drive;
DoubleSupplier speedX;
DoubleSupplier speedY;
DoubleSupplier rot;

public DriveCommand(
DriveBase drive, DoubleSupplier speedX, DoubleSupplier speedY, DoubleSupplier rot) {
this.drive = drive;
this.speedX = speedX;
this.speedY = speedY;
this.rot = rot;

addRequirements(drive);
}

@Override
public void execute() {
ChassisSpeeds speeds =
new ChassisSpeeds(
speedX.getAsDouble() * drive.getMaxLinearSpeed(),
speedY.getAsDouble() * drive.getMaxLinearSpeed(),
rot.getAsDouble() * drive.getMaxAngularSpeed());

drive.runVelocity(speeds);
}
}
26 changes: 26 additions & 0 deletions src/main/java/frc/robot/subsystems/drive/Drive.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package frc.robot.subsystems.drive;

import edu.wpi.first.math.kinematics.ChassisSpeeds;

public interface Drive {
/**
* Sets the desired chassis speed
*
* @param velocity specifies the setpoint velocity for the chassis
*/
public void runVelocity(ChassisSpeeds velocity);

/**
* This returns the robot's max linear speed in meter/sec
*
* @return speed in meter/sec
*/
public double getMaxLinearSpeed();

/**
* This returns the robot's max angular speed in radian/sec
*
* @return speed in radian/sec
*/
public double getMaxAngularSpeed();
}
19 changes: 19 additions & 0 deletions src/main/java/frc/robot/subsystems/drive/DriveBase.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package frc.robot.subsystems.drive;

import edu.wpi.first.math.kinematics.ChassisSpeeds;
import edu.wpi.first.wpilibj2.command.SubsystemBase;

public class DriveBase extends SubsystemBase implements Drive {
@Override
public void runVelocity(ChassisSpeeds velocity) {}

@Override
public double getMaxLinearSpeed() {
return 0;
}

@Override
public double getMaxAngularSpeed() {
return 0;
}
}
52 changes: 52 additions & 0 deletions src/main/java/frc/robot/subsystems/drive/DriveSwerveYAGSL.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package frc.robot.subsystems.drive;

import edu.wpi.first.math.kinematics.ChassisSpeeds;
import edu.wpi.first.math.util.Units;
import edu.wpi.first.wpilibj.Filesystem;
import java.io.File;
import swervelib.SwerveDrive;
import swervelib.parser.SwerveParser;

public class DriveSwerveYAGSL extends DriveBase {
private final double maximumSpeed =
Units.feetToMeters(4.5); // * TODO: Calculate actual max speed */
private final File swerveJsonDirectory =
new File(Filesystem.getDeployDirectory(), "swervePracticeBot");
private SwerveDrive swerveDrive;
private boolean fieldOrientedDrive = false;

public DriveSwerveYAGSL() {
try {
swerveDrive = new SwerveParser(swerveJsonDirectory).createSwerveDrive(maximumSpeed);
} catch (Exception e) {
throw new RuntimeException(e);
}
}

@Override
public void runVelocity(ChassisSpeeds velocity) {
if (fieldOrientedDrive) {
swerveDrive.driveFieldOriented(velocity);
} else {
swerveDrive.drive(velocity);
}
}

@Override
public double getMaxLinearSpeed() {
return swerveDrive.getMaximumVelocity();
}

@Override
public double getMaxAngularSpeed() {
return swerveDrive.getMaximumAngularVelocity();
}

public void setFieldOrientedDrive(boolean enable) {
fieldOrientedDrive = enable;
}

public boolean isFieldOrientedDrive() {
return fieldOrientedDrive;
}
}
Loading