-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial YAGSL based swerve implementation (#13)
* Basic Swerve YAGSL implementation --------- Co-authored-by: Alex <[email protected]>
- Loading branch information
1 parent
07e6709
commit 350645a
Showing
20 changed files
with
968 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
16
src/main/deploy/swervePracticeBot/modules/physicalproperties.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
16
src/main/deploy/swervePracticeBot/modules/pidfproperties.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
52
src/main/java/frc/robot/subsystems/drive/DriveSwerveYAGSL.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
Oops, something went wrong.