Compare commits
29 Commits
2025-2-1-s
...
9497e216d7
| Author | SHA1 | Date | |
|---|---|---|---|
| 9497e216d7 | |||
| 9cc9b993eb | |||
| 38dad2861d | |||
| 2275248f70 | |||
| 187e7385c8 | |||
| f0b7955faa | |||
| aff9a4f2cb | |||
| 619b3f4b7f | |||
| ed1ffe7044 | |||
| 96ad0ba088 | |||
| 56980d3772 | |||
| 6fa4377e52 | |||
| 89c1914d11 | |||
| 3af046f058 | |||
| 34a547026d | |||
| 0e91643b57 | |||
| 5fa4738b36 | |||
| ff3ecf6d1d | |||
| cef200a864 | |||
| dff4d0e04f | |||
| 9ab7ffad84 | |||
| a96d96fecb | |||
| edb95da65c | |||
| b90056f9ce | |||
| ce7246114f | |||
| 198d105741 | |||
| 8cbd9bb095 | |||
| 4d9aa82520 | |||
| c1dddcace5 |
13
.OutlineViewer/outlineviewer.json
Normal file
13
.OutlineViewer/outlineviewer.json
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"NetworkTables Settings": {
|
||||||
|
"mode": "Client (NT4)"
|
||||||
|
},
|
||||||
|
"transitory": {
|
||||||
|
"Shuffleboard": {
|
||||||
|
"Sensors Tab": {
|
||||||
|
"open": true
|
||||||
|
},
|
||||||
|
"open": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
25
src/main/deploy/pathplanner/autos/One Coral Left.auto
Normal file
25
src/main/deploy/pathplanner/autos/One Coral Left.auto
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
{
|
||||||
|
"version": "2025.0",
|
||||||
|
"command": {
|
||||||
|
"type": "sequential",
|
||||||
|
"data": {
|
||||||
|
"commands": [
|
||||||
|
{
|
||||||
|
"type": "path",
|
||||||
|
"data": {
|
||||||
|
"pathName": "Start to 60 Right"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "named",
|
||||||
|
"data": {
|
||||||
|
"name": "Shoot Coral L4"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"resetOdom": true,
|
||||||
|
"folder": null,
|
||||||
|
"choreoAuto": false
|
||||||
|
}
|
||||||
49
src/main/deploy/pathplanner/autos/Two Coral Left.auto
Normal file
49
src/main/deploy/pathplanner/autos/Two Coral Left.auto
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
{
|
||||||
|
"version": "2025.0",
|
||||||
|
"command": {
|
||||||
|
"type": "sequential",
|
||||||
|
"data": {
|
||||||
|
"commands": [
|
||||||
|
{
|
||||||
|
"type": "path",
|
||||||
|
"data": {
|
||||||
|
"pathName": "Start to 60 Right"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "named",
|
||||||
|
"data": {
|
||||||
|
"name": "Shoot Coral L4"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "path",
|
||||||
|
"data": {
|
||||||
|
"pathName": "60 Right to HP"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "named",
|
||||||
|
"data": {
|
||||||
|
"name": "Collect Coral"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "path",
|
||||||
|
"data": {
|
||||||
|
"pathName": "HP to 300 Left"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "named",
|
||||||
|
"data": {
|
||||||
|
"name": "Shoot Coral L4"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"resetOdom": true,
|
||||||
|
"folder": null,
|
||||||
|
"choreoAuto": false
|
||||||
|
}
|
||||||
1
src/main/deploy/pathplanner/navgrid.json
Normal file
1
src/main/deploy/pathplanner/navgrid.json
Normal file
File diff suppressed because one or more lines are too long
66
src/main/deploy/pathplanner/paths/300 Right to HP.path
Normal file
66
src/main/deploy/pathplanner/paths/300 Right to HP.path
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
{
|
||||||
|
"version": "2025.0",
|
||||||
|
"waypoints": [
|
||||||
|
{
|
||||||
|
"anchor": {
|
||||||
|
"x": 3.6061643835666786,
|
||||||
|
"y": 5.031720890416444
|
||||||
|
},
|
||||||
|
"prevControl": null,
|
||||||
|
"nextControl": {
|
||||||
|
"x": 3.065239726031196,
|
||||||
|
"y": 5.647773972598556
|
||||||
|
},
|
||||||
|
"isLocked": false,
|
||||||
|
"linkedName": null
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"anchor": {
|
||||||
|
"x": 1.2510679859194649,
|
||||||
|
"y": 7.0812357195448
|
||||||
|
},
|
||||||
|
"prevControl": {
|
||||||
|
"x": 1.6678510274010594,
|
||||||
|
"y": 6.6394691780780075
|
||||||
|
},
|
||||||
|
"nextControl": null,
|
||||||
|
"isLocked": false,
|
||||||
|
"linkedName": null
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"rotationTargets": [
|
||||||
|
{
|
||||||
|
"waypointRelativePos": 0.498997995991984,
|
||||||
|
"rotationDegrees": -52.46519085612145
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"constraintZones": [],
|
||||||
|
"pointTowardsZones": [],
|
||||||
|
"eventMarkers": [
|
||||||
|
{
|
||||||
|
"name": "HP Pickup",
|
||||||
|
"waypointRelativePos": 0.16666666666666663,
|
||||||
|
"endWaypointRelativePos": null,
|
||||||
|
"command": null
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"globalConstraints": {
|
||||||
|
"maxVelocity": 4.0,
|
||||||
|
"maxAcceleration": 4.0,
|
||||||
|
"maxAngularVelocity": 540.0,
|
||||||
|
"maxAngularAcceleration": 720.0,
|
||||||
|
"nominalVoltage": 12.0,
|
||||||
|
"unlimited": false
|
||||||
|
},
|
||||||
|
"goalEndState": {
|
||||||
|
"velocity": 0,
|
||||||
|
"rotation": -53.98486432191523
|
||||||
|
},
|
||||||
|
"reversed": false,
|
||||||
|
"folder": null,
|
||||||
|
"idealStartingState": {
|
||||||
|
"velocity": 0,
|
||||||
|
"rotation": -59.99999999999999
|
||||||
|
},
|
||||||
|
"useDefaultConstraints": true
|
||||||
|
}
|
||||||
61
src/main/deploy/pathplanner/paths/60 Right to HP.path
Normal file
61
src/main/deploy/pathplanner/paths/60 Right to HP.path
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
{
|
||||||
|
"version": "2025.0",
|
||||||
|
"waypoints": [
|
||||||
|
{
|
||||||
|
"anchor": {
|
||||||
|
"x": 4.988527397260274,
|
||||||
|
"y": 5.257106164383561
|
||||||
|
},
|
||||||
|
"prevControl": null,
|
||||||
|
"nextControl": {
|
||||||
|
"x": 5.649657534252619,
|
||||||
|
"y": 6.474186643842743
|
||||||
|
},
|
||||||
|
"isLocked": false,
|
||||||
|
"linkedName": null
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"anchor": {
|
||||||
|
"x": 1.3072345890410957,
|
||||||
|
"y": 7.135316780821918
|
||||||
|
},
|
||||||
|
"prevControl": {
|
||||||
|
"x": 2.1636986301369863,
|
||||||
|
"y": 6.188698630136986
|
||||||
|
},
|
||||||
|
"nextControl": null,
|
||||||
|
"isLocked": false,
|
||||||
|
"linkedName": "HP Left Position"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"rotationTargets": [],
|
||||||
|
"constraintZones": [],
|
||||||
|
"pointTowardsZones": [],
|
||||||
|
"eventMarkers": [
|
||||||
|
{
|
||||||
|
"name": "HP Pickup",
|
||||||
|
"waypointRelativePos": 0.20476190476190542,
|
||||||
|
"endWaypointRelativePos": null,
|
||||||
|
"command": null
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"globalConstraints": {
|
||||||
|
"maxVelocity": 4.0,
|
||||||
|
"maxAcceleration": 4.0,
|
||||||
|
"maxAngularVelocity": 540.0,
|
||||||
|
"maxAngularAcceleration": 720.0,
|
||||||
|
"nominalVoltage": 12.0,
|
||||||
|
"unlimited": false
|
||||||
|
},
|
||||||
|
"goalEndState": {
|
||||||
|
"velocity": 0,
|
||||||
|
"rotation": -53.97262661489646
|
||||||
|
},
|
||||||
|
"reversed": false,
|
||||||
|
"folder": null,
|
||||||
|
"idealStartingState": {
|
||||||
|
"velocity": 0,
|
||||||
|
"rotation": -120.06858282186238
|
||||||
|
},
|
||||||
|
"useDefaultConstraints": true
|
||||||
|
}
|
||||||
61
src/main/deploy/pathplanner/paths/HP to 300 Left.path
Normal file
61
src/main/deploy/pathplanner/paths/HP to 300 Left.path
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
{
|
||||||
|
"version": "2025.0",
|
||||||
|
"waypoints": [
|
||||||
|
{
|
||||||
|
"anchor": {
|
||||||
|
"x": 1.3072345890410957,
|
||||||
|
"y": 7.135316780821918
|
||||||
|
},
|
||||||
|
"prevControl": null,
|
||||||
|
"nextControl": {
|
||||||
|
"x": 2.5994434931506847,
|
||||||
|
"y": 6.909931506849315
|
||||||
|
},
|
||||||
|
"isLocked": false,
|
||||||
|
"linkedName": "HP Left Position"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"anchor": {
|
||||||
|
"x": 3.973766447368421,
|
||||||
|
"y": 5.246957236842105
|
||||||
|
},
|
||||||
|
"prevControl": {
|
||||||
|
"x": 3.6582270638067773,
|
||||||
|
"y": 5.772856209444845
|
||||||
|
},
|
||||||
|
"nextControl": null,
|
||||||
|
"isLocked": false,
|
||||||
|
"linkedName": null
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"rotationTargets": [],
|
||||||
|
"constraintZones": [],
|
||||||
|
"pointTowardsZones": [],
|
||||||
|
"eventMarkers": [
|
||||||
|
{
|
||||||
|
"name": "Lift L4",
|
||||||
|
"waypointRelativePos": 0.5,
|
||||||
|
"endWaypointRelativePos": null,
|
||||||
|
"command": null
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"globalConstraints": {
|
||||||
|
"maxVelocity": 4.0,
|
||||||
|
"maxAcceleration": 4.0,
|
||||||
|
"maxAngularVelocity": 540.0,
|
||||||
|
"maxAngularAcceleration": 720.0,
|
||||||
|
"nominalVoltage": 12.0,
|
||||||
|
"unlimited": false
|
||||||
|
},
|
||||||
|
"goalEndState": {
|
||||||
|
"velocity": 0,
|
||||||
|
"rotation": -59.69923999693802
|
||||||
|
},
|
||||||
|
"reversed": false,
|
||||||
|
"folder": null,
|
||||||
|
"idealStartingState": {
|
||||||
|
"velocity": 0,
|
||||||
|
"rotation": -53.97262661489646
|
||||||
|
},
|
||||||
|
"useDefaultConstraints": true
|
||||||
|
}
|
||||||
61
src/main/deploy/pathplanner/paths/Start to 60 Right.path
Normal file
61
src/main/deploy/pathplanner/paths/Start to 60 Right.path
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
{
|
||||||
|
"version": "2025.0",
|
||||||
|
"waypoints": [
|
||||||
|
{
|
||||||
|
"anchor": {
|
||||||
|
"x": 7.587970890410959,
|
||||||
|
"y": 6.143621575342466
|
||||||
|
},
|
||||||
|
"prevControl": null,
|
||||||
|
"nextControl": {
|
||||||
|
"x": 6.385916095890411,
|
||||||
|
"y": 6.158647260273973
|
||||||
|
},
|
||||||
|
"isLocked": false,
|
||||||
|
"linkedName": null
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"anchor": {
|
||||||
|
"x": 4.988527397260274,
|
||||||
|
"y": 5.227054794520548
|
||||||
|
},
|
||||||
|
"prevControl": {
|
||||||
|
"x": 5.574529109589041,
|
||||||
|
"y": 6.098544520547945
|
||||||
|
},
|
||||||
|
"nextControl": null,
|
||||||
|
"isLocked": false,
|
||||||
|
"linkedName": null
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"rotationTargets": [],
|
||||||
|
"constraintZones": [],
|
||||||
|
"pointTowardsZones": [],
|
||||||
|
"eventMarkers": [
|
||||||
|
{
|
||||||
|
"name": "Lift L4",
|
||||||
|
"waypointRelativePos": 0.4547619047619047,
|
||||||
|
"endWaypointRelativePos": null,
|
||||||
|
"command": null
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"globalConstraints": {
|
||||||
|
"maxVelocity": 4.0,
|
||||||
|
"maxAcceleration": 4.0,
|
||||||
|
"maxAngularVelocity": 540.0,
|
||||||
|
"maxAngularAcceleration": 720.0,
|
||||||
|
"nominalVoltage": 12.0,
|
||||||
|
"unlimited": false
|
||||||
|
},
|
||||||
|
"goalEndState": {
|
||||||
|
"velocity": 0,
|
||||||
|
"rotation": -121.60750224624898
|
||||||
|
},
|
||||||
|
"reversed": false,
|
||||||
|
"folder": null,
|
||||||
|
"idealStartingState": {
|
||||||
|
"velocity": 0,
|
||||||
|
"rotation": -90.0
|
||||||
|
},
|
||||||
|
"useDefaultConstraints": true
|
||||||
|
}
|
||||||
32
src/main/deploy/pathplanner/settings.json
Normal file
32
src/main/deploy/pathplanner/settings.json
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
{
|
||||||
|
"robotWidth": 0.8763,
|
||||||
|
"robotLength": 0.8763,
|
||||||
|
"holonomicMode": true,
|
||||||
|
"pathFolders": [],
|
||||||
|
"autoFolders": [],
|
||||||
|
"defaultMaxVel": 4.0,
|
||||||
|
"defaultMaxAccel": 4.0,
|
||||||
|
"defaultMaxAngVel": 540.0,
|
||||||
|
"defaultMaxAngAccel": 720.0,
|
||||||
|
"defaultNominalVoltage": 12.0,
|
||||||
|
"robotMass": 48.35,
|
||||||
|
"robotMOI": 6.883,
|
||||||
|
"robotTrackwidth": 0.546,
|
||||||
|
"driveWheelRadius": 0.038,
|
||||||
|
"driveGearing": 4.29,
|
||||||
|
"maxDriveSpeed": 5.45,
|
||||||
|
"driveMotorType": "krakenX60",
|
||||||
|
"driveCurrentLimit": 65.0,
|
||||||
|
"wheelCOF": 1.1,
|
||||||
|
"flModuleX": 0.31115,
|
||||||
|
"flModuleY": 0.31115,
|
||||||
|
"frModuleX": 0.31115,
|
||||||
|
"frModuleY": -0.31115,
|
||||||
|
"blModuleX": -0.31115,
|
||||||
|
"blModuleY": 0.31115,
|
||||||
|
"brModuleX": -0.31115,
|
||||||
|
"brModuleY": -0.31115,
|
||||||
|
"bumperOffsetX": 0.0,
|
||||||
|
"bumperOffsetY": 0.0,
|
||||||
|
"robotFeatures": []
|
||||||
|
}
|
||||||
@@ -4,27 +4,30 @@
|
|||||||
|
|
||||||
package frc.robot;
|
package frc.robot;
|
||||||
|
|
||||||
import frc.robot.constants.ArmConstants;
|
import frc.robot.constants.ManipulatorPivotConstants;
|
||||||
|
import frc.robot.constants.ClimberPivotConstants;
|
||||||
import frc.robot.constants.ElevatorConstants;
|
import frc.robot.constants.ElevatorConstants;
|
||||||
import frc.robot.constants.OIConstants;
|
import frc.robot.constants.OIConstants;
|
||||||
import frc.robot.subsystems.Arm;
|
import frc.robot.subsystems.ManipulatorPivot;
|
||||||
import frc.robot.subsystems.ClimberPivot;
|
import frc.robot.subsystems.ClimberPivot;
|
||||||
import frc.robot.subsystems.ClimberRollers;
|
import frc.robot.subsystems.ClimberRollers;
|
||||||
import frc.robot.subsystems.Drivetrain;
|
import frc.robot.subsystems.Drivetrain;
|
||||||
import frc.robot.subsystems.Elevator;
|
import frc.robot.subsystems.Elevator;
|
||||||
import frc.robot.subsystems.Indexer;
|
|
||||||
import frc.robot.subsystems.Manipulator;
|
import frc.robot.subsystems.Manipulator;
|
||||||
|
|
||||||
|
import com.pathplanner.lib.auto.AutoBuilder;
|
||||||
|
import com.pathplanner.lib.auto.NamedCommands;
|
||||||
|
|
||||||
|
import edu.wpi.first.math.MathUtil;
|
||||||
import edu.wpi.first.wpilibj.shuffleboard.BuiltInWidgets;
|
import edu.wpi.first.wpilibj.shuffleboard.BuiltInWidgets;
|
||||||
import edu.wpi.first.wpilibj.shuffleboard.Shuffleboard;
|
import edu.wpi.first.wpilibj.shuffleboard.Shuffleboard;
|
||||||
import edu.wpi.first.wpilibj.shuffleboard.ShuffleboardTab;
|
import edu.wpi.first.wpilibj.shuffleboard.ShuffleboardTab;
|
||||||
|
import edu.wpi.first.wpilibj.smartdashboard.SendableChooser;
|
||||||
import edu.wpi.first.wpilibj2.command.Command;
|
import edu.wpi.first.wpilibj2.command.Command;
|
||||||
import edu.wpi.first.wpilibj2.command.Commands;
|
import edu.wpi.first.wpilibj2.command.Commands;
|
||||||
import edu.wpi.first.wpilibj2.command.PrintCommand;
|
|
||||||
import edu.wpi.first.wpilibj2.command.button.CommandXboxController;
|
import edu.wpi.first.wpilibj2.command.button.CommandXboxController;
|
||||||
|
|
||||||
public class RobotContainer {
|
public class RobotContainer {
|
||||||
private Arm arm;
|
|
||||||
|
|
||||||
private ClimberPivot climberPivot;
|
private ClimberPivot climberPivot;
|
||||||
|
|
||||||
private ClimberRollers climberRollers;
|
private ClimberRollers climberRollers;
|
||||||
@@ -33,16 +36,16 @@ public class RobotContainer {
|
|||||||
|
|
||||||
private Elevator elevator;
|
private Elevator elevator;
|
||||||
|
|
||||||
private Indexer indexer;
|
|
||||||
|
|
||||||
private Manipulator manipulator;
|
private Manipulator manipulator;
|
||||||
|
|
||||||
|
private ManipulatorPivot manipulatorPivot;
|
||||||
|
|
||||||
private CommandXboxController driver;
|
private CommandXboxController driver;
|
||||||
private CommandXboxController operator;
|
private CommandXboxController operator;
|
||||||
|
|
||||||
public RobotContainer() {
|
private SendableChooser<Command> autoChooser;
|
||||||
arm = new Arm();
|
|
||||||
|
|
||||||
|
public RobotContainer() {
|
||||||
climberPivot = new ClimberPivot();
|
climberPivot = new ClimberPivot();
|
||||||
|
|
||||||
climberRollers = new ClimberRollers();
|
climberRollers = new ClimberRollers();
|
||||||
@@ -51,25 +54,26 @@ public class RobotContainer {
|
|||||||
|
|
||||||
elevator = new Elevator();
|
elevator = new Elevator();
|
||||||
|
|
||||||
indexer = new Indexer();
|
|
||||||
|
|
||||||
manipulator = new Manipulator();
|
manipulator = new Manipulator();
|
||||||
|
|
||||||
|
manipulatorPivot = new ManipulatorPivot();
|
||||||
|
|
||||||
driver = new CommandXboxController(OIConstants.kDriverControllerPort);
|
driver = new CommandXboxController(OIConstants.kDriverControllerPort);
|
||||||
operator = new CommandXboxController(OIConstants.kOperatorControllerPort);
|
operator = new CommandXboxController(OIConstants.kOperatorControllerPort);
|
||||||
|
|
||||||
|
autoChooser = AutoBuilder.buildAutoChooser();
|
||||||
|
|
||||||
configureButtonBindings();
|
configureButtonBindings();
|
||||||
|
|
||||||
|
configureNamedCommands();
|
||||||
|
|
||||||
configureShuffleboard();
|
configureShuffleboard();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void configureButtonBindings() {
|
private void configureButtonBindings() {
|
||||||
arm.setDefaultCommand(
|
//Default commands
|
||||||
arm.goToSetpoint(0, 1)
|
|
||||||
);
|
|
||||||
|
|
||||||
climberPivot.setDefaultCommand(
|
climberPivot.setDefaultCommand(
|
||||||
climberPivot.goToAngle(0, 1)
|
climberPivot.runPivot(0)
|
||||||
);
|
);
|
||||||
|
|
||||||
climberRollers.setDefaultCommand(
|
climberRollers.setDefaultCommand(
|
||||||
@@ -85,53 +89,81 @@ public class RobotContainer {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
elevator.setDefaultCommand(
|
//elevator.setDefaultCommand(
|
||||||
elevator.runElevator(operator::getLeftY)
|
//elevator.runAssistedElevator(operator::getLeftY)
|
||||||
);
|
// );
|
||||||
|
|
||||||
indexer.setDefaultCommand(
|
//elevator.setDefaultCommand(moveManipulator(ElevatorConstants.kCoralIntakePosition, ManipulatorPivotConstants.kCoralIntakePosition));
|
||||||
indexer.runIndexer(0)
|
elevator.setDefaultCommand(elevator.manualControl(() -> 0.0));
|
||||||
);
|
|
||||||
|
manipulatorPivot.setDefaultCommand(moveManipulator(ElevatorConstants.kCoralIntakePosition, ManipulatorPivotConstants.kCoralIntakePosition));
|
||||||
|
|
||||||
manipulator.setDefaultCommand(
|
manipulator.setDefaultCommand(
|
||||||
manipulator.runManipulator(0)
|
manipulator.defaultCommand()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
//manipulatorPivot.setDefaultCommand(
|
||||||
|
// manipulatorPivot.runAssistedPivot(operator::getRightY)
|
||||||
|
//);
|
||||||
|
|
||||||
//Driver inputs
|
//Driver inputs
|
||||||
driver.start().whileTrue(
|
driver.start().whileTrue(
|
||||||
drivetrain.setXCommand()
|
drivetrain.setXCommand()
|
||||||
);
|
);
|
||||||
|
|
||||||
driver.rightTrigger().whileTrue(
|
driver.rightTrigger().whileTrue(
|
||||||
manipulator.runManipulator(1)
|
manipulator.runManipulator(() -> 1, true)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
driver.leftTrigger().whileTrue(
|
||||||
|
manipulator.runUntilCollected(() -> 0.75)
|
||||||
|
);
|
||||||
|
|
||||||
|
driver.start().and(driver.back()).onTrue(
|
||||||
|
startingConfig()
|
||||||
|
);
|
||||||
|
|
||||||
|
driver.povDown().whileTrue(climberPivot.runPivot(-0.5));
|
||||||
|
driver.povUp().whileTrue(climberPivot.runPivot(0.5));
|
||||||
|
|
||||||
|
driver.povLeft().whileTrue(climberRollers.runRoller(0.5));
|
||||||
|
driver.povRight().whileTrue(climberRollers.runRoller(-0.5));
|
||||||
|
|
||||||
|
operator.povUp().whileTrue(
|
||||||
|
elevator.goToSetpoint(20)
|
||||||
|
);
|
||||||
|
|
||||||
|
//operator.a().whileTrue(elevator.manualControl(() -> 0.5));
|
||||||
|
|
||||||
|
//operator.b().whileTrue(elevator.manualControl(() ->-0.1));
|
||||||
|
|
||||||
|
/*
|
||||||
//Operator inputs
|
//Operator inputs
|
||||||
operator.povUp().onTrue(
|
operator.povUp().onTrue(
|
||||||
moveManipulator(
|
moveManipulator(
|
||||||
ElevatorConstants.kElevatorL4Position,
|
ElevatorConstants.kL4Position,
|
||||||
ArmConstants.kArmL4Position
|
ManipulatorPivotConstants.kL4Position
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
operator.povRight().onTrue(
|
operator.povRight().onTrue(
|
||||||
moveManipulator(
|
moveManipulator(
|
||||||
ElevatorConstants.kElevatorL3Position,
|
ElevatorConstants.kL3Position,
|
||||||
ArmConstants.kArmL3Position
|
ManipulatorPivotConstants.kL3Position
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
operator.povLeft().onTrue(
|
operator.povLeft().onTrue(
|
||||||
moveManipulator(
|
moveManipulator(
|
||||||
ElevatorConstants.kElevatorL2Position,
|
ElevatorConstants.kL2Position,
|
||||||
ArmConstants.kArmL2Position
|
ManipulatorPivotConstants.kL2Position
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
operator.povDown().onTrue(
|
operator.povDown().onTrue(
|
||||||
moveManipulator(
|
moveManipulator(
|
||||||
ElevatorConstants.kElevatorL1Position,
|
ElevatorConstants.kL1Position,
|
||||||
ArmConstants.kArmL1Position
|
ManipulatorPivotConstants.kL1Position
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -146,80 +178,184 @@ public class RobotContainer {
|
|||||||
operator.b().onTrue(
|
operator.b().onTrue(
|
||||||
algaeIntakeRoutine(false)
|
algaeIntakeRoutine(false)
|
||||||
);
|
);
|
||||||
|
*/
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void configureNamedCommands() {
|
||||||
|
NamedCommands.registerCommand("Drivetrain Set X", drivetrain.setXCommand());
|
||||||
}
|
}
|
||||||
|
|
||||||
//creates tabs and transforms them on the shuffleboard
|
//creates tabs and transforms them on the shuffleboard
|
||||||
private void configureShuffleboard() {
|
private void configureShuffleboard() {
|
||||||
|
ShuffleboardTab autoTab = Shuffleboard.getTab(OIConstants.kAutoTab);
|
||||||
ShuffleboardTab sensorTab = Shuffleboard.getTab(OIConstants.kSensorsTab);
|
ShuffleboardTab sensorTab = Shuffleboard.getTab(OIConstants.kSensorsTab);
|
||||||
|
|
||||||
|
Shuffleboard.selectTab(OIConstants.kAutoTab);
|
||||||
|
|
||||||
|
autoTab.add("Auto Selection", autoChooser)
|
||||||
|
.withSize(2, 1)
|
||||||
|
.withPosition(0, 0)
|
||||||
|
.withWidget(BuiltInWidgets.kComboBoxChooser);
|
||||||
|
|
||||||
sensorTab.addDouble("Elevator Position", elevator::getEncoderPosition)
|
sensorTab.addDouble("Elevator Position", elevator::getEncoderPosition)
|
||||||
.withSize(2, 1)
|
.withSize(2, 1)
|
||||||
.withPosition(0, 0)
|
.withPosition(0, 1)
|
||||||
.withWidget(BuiltInWidgets.kTextView);
|
.withWidget(BuiltInWidgets.kTextView);
|
||||||
|
|
||||||
sensorTab.addDouble("ArmPosition", arm::getEncoderPosition)
|
sensorTab.addDouble("Manipulator Position", manipulatorPivot::getEncoderPosition)
|
||||||
|
.withSize(2, 1)
|
||||||
|
.withPosition(2, 1)
|
||||||
|
.withWidget(BuiltInWidgets.kTextView);
|
||||||
|
|
||||||
|
sensorTab.addDouble("Climber Pivot Position", climberPivot::getEncoderPosition)
|
||||||
.withSize(2, 1)
|
.withSize(2, 1)
|
||||||
.withPosition(2, 0)
|
.withPosition(2, 0)
|
||||||
.withWidget(BuiltInWidgets.kTextView);
|
.withWidget(BuiltInWidgets.kTextView);
|
||||||
|
|
||||||
|
sensorTab.addBoolean("Coral Sensor", manipulator::getCoralBeamBreak)
|
||||||
|
.withSize(1, 1)
|
||||||
|
.withPosition(4, 1)
|
||||||
|
.withWidget(BuiltInWidgets.kBooleanBox);
|
||||||
|
|
||||||
|
sensorTab.addDouble("gyro angle", drivetrain::getGyroValue);
|
||||||
|
|
||||||
|
sensorTab.addBoolean("bottom limit switch", elevator::getBottomLimitSwitch);
|
||||||
|
|
||||||
|
sensorTab.addDouble("elevator position", elevator::getEncoderPosition);
|
||||||
|
|
||||||
|
/*
|
||||||
|
sensorTab.addBoolean("Algae Sensor", manipulator::getAlgaePhotoSwitch)
|
||||||
|
.withSize(1, 1)
|
||||||
|
.withPosition(4, 0)
|
||||||
|
.withWidget(BuiltInWidgets.kBooleanBox);
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
public Command getAutonomousCommand() {
|
public Command getAutonomousCommand() {
|
||||||
return new PrintCommand("NO AUTO DEFINED");
|
return autoChooser.getSelected();
|
||||||
}
|
}
|
||||||
|
|
||||||
//teleop routines
|
/**
|
||||||
|
* Moves the elevator and arm to the coral intake position, then runs the manipulator until collected
|
||||||
|
* @return Moves the elevator and arm, then intakes coral
|
||||||
|
*/
|
||||||
private Command coralIntakeRoutine() {
|
private Command coralIntakeRoutine() {
|
||||||
return moveManipulator(
|
return moveManipulator(
|
||||||
ElevatorConstants.kElevatorCoralIntakePosition,
|
ElevatorConstants.kCoralIntakePosition,
|
||||||
ArmConstants.kArmCoralIntakePosition
|
ManipulatorPivotConstants.kCoralIntakePosition
|
||||||
)
|
)
|
||||||
.andThen(manipulator.runUntilCollected(1, true));
|
.andThen(manipulator.runUntilCollected(() -> 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Moves the elevator and arm to the constant setpoints and runs the manipulator until collected
|
||||||
|
*
|
||||||
|
* @param l2 Is the algae on L2? (True = L2, False = L3)
|
||||||
|
* @return Moves the elevator and arm then intakes algae
|
||||||
|
*/
|
||||||
private Command algaeIntakeRoutine(boolean l2) {
|
private Command algaeIntakeRoutine(boolean l2) {
|
||||||
return moveManipulator(
|
return moveManipulator(
|
||||||
l2 ? ElevatorConstants.kElevatorL2AlgaePosition : ElevatorConstants.kElevatorL3AlgaePosition,
|
l2 ? ElevatorConstants.kL2AlgaePosition : ElevatorConstants.kL3AlgaePosition,
|
||||||
l2 ? ArmConstants.kArmL2AlgaePosition : ArmConstants.kArmL3AlgaePosition
|
l2 ? ManipulatorPivotConstants.kL2AlgaePosition : ManipulatorPivotConstants.kL3AlgaePosition
|
||||||
)
|
)
|
||||||
.andThen(manipulator.runUntilCollected(1, false));
|
.andThen(manipulator.runUntilCollected(() -> 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Moves the elevator and arm in different order based on target positions
|
||||||
|
*
|
||||||
|
* @param elevatorPosition The target position of the elevator
|
||||||
|
* @param armPosition The target rotation of the arm
|
||||||
|
* @return Moves the elevator and arm to the setpoints using the most efficient path
|
||||||
|
*/
|
||||||
private Command moveManipulator(double elevatorPosition, double armPosition) {
|
private Command moveManipulator(double elevatorPosition, double armPosition) {
|
||||||
// If the elevator current and target positions are above the brace, or the arm current and target position is in
|
// If the elevator current and target positions are above the brace, or the arm current and target position is in
|
||||||
// front of the brace, move together
|
// front of the brace, move together
|
||||||
if ((elevator.isMotionSafe() && elevator.isMotionSafe(elevatorPosition)) || (arm.isMotionSafe() && arm.isMotionSafe(armPosition))) {
|
if ((elevator.isMotionSafe() && elevator.isMotionSafe(elevatorPosition)) || (manipulatorPivot.isMotionSafe() && manipulatorPivot.isMotionSafe(armPosition))) {
|
||||||
return moveManipulatorUtil(elevatorPosition, armPosition, false, false);
|
return moveManipulatorUtil(elevatorPosition, armPosition, false, false);
|
||||||
// If the target position is behind the brace, and the arm is not behind the brace, move the arm to a safe position first,
|
// If the target position is behind the brace, and the arm is not behind the brace, move the arm to a safe position first,
|
||||||
// then the elevator, then the arm again
|
// then the elevator, then the arm again
|
||||||
} else if (!arm.isMotionSafe(armPosition) && !arm.isMotionSafe()) {
|
} else if (!manipulatorPivot.isMotionSafe(armPosition) && !manipulatorPivot.isMotionSafe()) {
|
||||||
return moveManipulatorUtil(elevatorPosition, ArmConstants.kArmSafeStowPosition, false, true)
|
return moveManipulatorUtil(elevatorPosition, ManipulatorPivotConstants.kArmSafeStowPosition, false, true)
|
||||||
.andThen(arm.goToSetpoint(armPosition, 2));
|
.andThen(manipulatorPivot.goToSetpoint(armPosition));
|
||||||
// If the target position is behind the brace, and the arm is behind the brace, move the elevator first, then the arm
|
// If the target position is behind the brace, and the arm is behind the brace, move the elevator first, then the arm
|
||||||
} else if (!arm.isMotionSafe(armPosition) && arm.isMotionSafe()) {
|
} else if (!manipulatorPivot.isMotionSafe(armPosition) && manipulatorPivot.isMotionSafe()) {
|
||||||
return moveManipulatorUtil(elevatorPosition, armPosition, true, true);
|
return moveManipulatorUtil(elevatorPosition, armPosition, true, true);
|
||||||
// If the arm is behind the brace, move the arm first, then the elevator
|
// If the arm is behind the brace, move the arm first, then the elevator
|
||||||
} else if (!arm.isMotionSafe()) {
|
} else if (!manipulatorPivot.isMotionSafe()) {
|
||||||
return moveManipulatorUtil(elevatorPosition, armPosition, false, true);
|
return moveManipulatorUtil(elevatorPosition, armPosition, false, true);
|
||||||
// Catch all command that's safe regardless of arm and elevator positions
|
// Catch all command that's safe regardless of arm and elevator positions
|
||||||
} else {
|
} else {
|
||||||
return moveManipulatorUtil(elevatorPosition, ArmConstants.kArmSafeStowPosition, false, true)
|
return moveManipulatorUtil(elevatorPosition, ManipulatorPivotConstants.kArmSafeStowPosition, false, true)
|
||||||
.andThen(arm.goToSetpoint(armPosition, 2));
|
.andThen(manipulatorPivot.goToSetpoint(armPosition));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Moves the elevator and arm in customizeable ways
|
||||||
|
*
|
||||||
|
* @param elevatorPosition The target elevator position
|
||||||
|
* @param armPosition The target arm position
|
||||||
|
* @param elevatorFirst Does the elevator move first? (True = Elevator first, False = Arm first)
|
||||||
|
* @param sequential Does the elevator and arm move separately? (True = .andThen, False = .alongWith)
|
||||||
|
* @return Moves the elevator and arm to the setpoints
|
||||||
|
*/
|
||||||
private Command moveManipulatorUtil(double elevatorPosition, double armPosition, boolean elevatorFirst, boolean sequential) {
|
private Command moveManipulatorUtil(double elevatorPosition, double armPosition, boolean elevatorFirst, boolean sequential) {
|
||||||
|
if (elevatorPosition <= ElevatorConstants.kBracePosition || elevatorPosition == 0) {
|
||||||
|
armPosition = MathUtil.clamp(
|
||||||
|
armPosition,
|
||||||
|
0,
|
||||||
|
ManipulatorPivotConstants.kRotationLimit
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return Commands.either(
|
return Commands.either(
|
||||||
Commands.either(
|
Commands.either(
|
||||||
elevator.goToSetpoint(elevatorPosition, 2).andThen(arm.goToSetpoint(armPosition, 2)),
|
elevator.goToSetpoint(elevatorPosition).andThen(manipulatorPivot.goToSetpoint(armPosition)),
|
||||||
elevator.goToSetpoint(elevatorPosition, 2).alongWith(arm.goToSetpoint(armPosition, 2)),
|
elevator.goToSetpoint(elevatorPosition).alongWith(manipulatorPivot.goToSetpoint(armPosition)),
|
||||||
() -> sequential
|
() -> sequential
|
||||||
),
|
),
|
||||||
Commands.either(
|
Commands.either(
|
||||||
arm.goToSetpoint(armPosition, 2).andThen(elevator.goToSetpoint(elevatorPosition, 2)),
|
manipulatorPivot.goToSetpoint(armPosition).andThen(elevator.goToSetpoint(elevatorPosition)),
|
||||||
arm.goToSetpoint(armPosition, 2).alongWith(elevator.goToSetpoint(elevatorPosition, 2)),
|
manipulatorPivot.goToSetpoint(armPosition).alongWith(elevator.goToSetpoint(elevatorPosition)),
|
||||||
() -> sequential
|
() -> sequential
|
||||||
),
|
),
|
||||||
() -> elevatorFirst
|
() -> elevatorFirst
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Command manipulatorSafeTravel(double elevatorPosition, double armPosition, boolean isL4){
|
||||||
|
if(!isL4){
|
||||||
|
return Commands.sequence(
|
||||||
|
manipulatorPivot.goToSetpoint(ManipulatorPivotConstants.kArmSafeStowPosition),
|
||||||
|
elevator.goToSetpoint(elevatorPosition),
|
||||||
|
manipulatorPivot.goToSetpoint(armPosition));
|
||||||
|
|
||||||
|
}else{
|
||||||
|
return Commands.sequence(
|
||||||
|
manipulatorPivot.goToSetpoint(ManipulatorPivotConstants.kArmSafeStowPosition),
|
||||||
|
elevator.goToSetpoint(elevatorPosition).until(() -> elevator.getEncoderPosition() > ElevatorConstants.kL4TransitionPosition),
|
||||||
|
Commands.parallel( manipulatorPivot.goToSetpoint(armPosition)), elevator.goToSetpoint(elevatorPosition));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Moves the arm and elevator in a safe way.
|
||||||
|
*
|
||||||
|
* @param elevatorPosition The target position of the elevator
|
||||||
|
* @param armPosition The target rotation of the arm
|
||||||
|
* @return Moves the elevator and arm to the setpoints
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
private Command safeMoveManipulator(double elevatorPosition, double armPosition) {
|
||||||
|
return moveManipulatorUtil(elevatorPosition, ManipulatorPivotConstants.kArmSafeStowPosition, false, true)
|
||||||
|
.andThen(manipulatorPivot.goToSetpoint(armPosition));
|
||||||
|
}
|
||||||
|
|
||||||
|
private Command startingConfig() {
|
||||||
|
return moveManipulatorUtil(0, 0, false, true)
|
||||||
|
.alongWith(climberPivot.climb(ClimberPivotConstants.kClimberStartingPosition, .1));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
package frc.robot.constants;
|
|
||||||
|
|
||||||
import com.ctre.phoenix6.configs.CANcoderConfiguration;
|
|
||||||
|
|
||||||
public class ArmConstants {
|
|
||||||
public static final int kArmMotorID = 0;
|
|
||||||
public static final int kCANcoderID = 0;
|
|
||||||
|
|
||||||
public static final double kEncoderConversionFactor = 0;
|
|
||||||
|
|
||||||
public static final double kArmMaxVelocity = 0;
|
|
||||||
|
|
||||||
public static final double kArmCoralIntakePosition = 0;
|
|
||||||
public static final double kArmL1Position = 0;
|
|
||||||
public static final double kArmL2Position = 0;
|
|
||||||
public static final double kArmL3Position = 0;
|
|
||||||
public static final double kArmL4Position = 0;
|
|
||||||
public static final double kArmL2AlgaePosition = 0;
|
|
||||||
public static final double kArmL3AlgaePosition = 0;
|
|
||||||
public static final double kArmSafeStowPosition = 0;
|
|
||||||
|
|
||||||
public static final CANcoderConfiguration canCoderConfig = new CANcoderConfiguration();
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,10 +1,18 @@
|
|||||||
package frc.robot.constants;
|
package frc.robot.constants;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.json.simple.parser.ParseException;
|
||||||
|
|
||||||
|
import com.pathplanner.lib.config.PIDConstants;
|
||||||
|
import com.pathplanner.lib.config.RobotConfig;
|
||||||
|
import com.pathplanner.lib.controllers.PPHolonomicDriveController;
|
||||||
|
|
||||||
import edu.wpi.first.math.trajectory.TrapezoidProfile;
|
import edu.wpi.first.math.trajectory.TrapezoidProfile;
|
||||||
|
|
||||||
public class AutoConstants {
|
public class AutoConstants {
|
||||||
public static final double kMaxSpeedMetersPerSecond = 3;
|
public static final double kMaxSpeedMetersPerSecond = 4;
|
||||||
public static final double kMaxAccelerationMetersPerSecondSquared = 3;
|
public static final double kMaxAccelerationMetersPerSecondSquared = 4;
|
||||||
public static final double kMaxAngularSpeedRadiansPerSecond = Math.PI;
|
public static final double kMaxAngularSpeedRadiansPerSecond = Math.PI;
|
||||||
public static final double kMaxAngularSpeedRadiansPerSecondSquared = Math.PI;
|
public static final double kMaxAngularSpeedRadiansPerSecondSquared = Math.PI;
|
||||||
|
|
||||||
@@ -15,4 +23,21 @@ public class AutoConstants {
|
|||||||
// Constraint for the motion profiled robot angle controller
|
// Constraint for the motion profiled robot angle controller
|
||||||
public static final TrapezoidProfile.Constraints kThetaControllerConstraints = new TrapezoidProfile.Constraints(
|
public static final TrapezoidProfile.Constraints kThetaControllerConstraints = new TrapezoidProfile.Constraints(
|
||||||
kMaxAngularSpeedRadiansPerSecond, kMaxAngularSpeedRadiansPerSecondSquared);
|
kMaxAngularSpeedRadiansPerSecond, kMaxAngularSpeedRadiansPerSecondSquared);
|
||||||
|
|
||||||
|
// TODO This is a constant being managed like a static rewriteable variable
|
||||||
|
public static RobotConfig kRobotConfig;
|
||||||
|
|
||||||
|
public static final PPHolonomicDriveController kPPDriveController = new PPHolonomicDriveController(
|
||||||
|
new PIDConstants(kPXController, 0, 0),
|
||||||
|
new PIDConstants(kPYController, 0, 0)
|
||||||
|
);
|
||||||
|
|
||||||
|
static {
|
||||||
|
try {
|
||||||
|
kRobotConfig = RobotConfig.fromGUISettings();
|
||||||
|
} catch (IOException | ParseException e) {
|
||||||
|
System.err.println("FAILED TO READ ROBOTCONFIG, WAS THE CONFIG SET UP IN PATHPLANNER?");
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
package frc.robot.constants;
|
package frc.robot.constants;
|
||||||
|
|
||||||
|
import com.revrobotics.spark.config.SparkMaxConfig;
|
||||||
|
|
||||||
public class ClimberPivotConstants {
|
public class ClimberPivotConstants {
|
||||||
public static final int kPivotMotorID = 0;
|
public static final int kPivotMotorID = 10;
|
||||||
|
|
||||||
public static final int kClimberLimitSwitchID = 0;
|
public static final int kClimberLimitSwitchID = 0;
|
||||||
|
|
||||||
@@ -10,4 +12,9 @@ public class ClimberPivotConstants {
|
|||||||
public static final double kPIDControllerP = 0;
|
public static final double kPIDControllerP = 0;
|
||||||
public static final double kPIDControllerI = 0;
|
public static final double kPIDControllerI = 0;
|
||||||
public static final double kPIDControllerD = 0;
|
public static final double kPIDControllerD = 0;
|
||||||
|
|
||||||
|
public static final double kClimberClimbPosition = 0;
|
||||||
|
public static final double kClimberStartingPosition = 0;
|
||||||
|
|
||||||
|
public static final SparkMaxConfig motorConfig = new SparkMaxConfig();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
package frc.robot.constants;
|
package frc.robot.constants;
|
||||||
|
|
||||||
|
import com.revrobotics.spark.config.SparkMaxConfig;
|
||||||
|
|
||||||
public class ClimberRollersConstants {
|
public class ClimberRollersConstants {
|
||||||
public static final int kRollerMotorID = 0;
|
public static final int kRollerMotorID = 9;
|
||||||
|
|
||||||
|
public static final SparkMaxConfig motorConfig = new SparkMaxConfig();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,15 +17,15 @@ public class DrivetrainConstants {
|
|||||||
public static final double kMaxAngularSpeed = 2 * Math.PI; // radians per second
|
public static final double kMaxAngularSpeed = 2 * Math.PI; // radians per second
|
||||||
|
|
||||||
// Chassis configuration
|
// Chassis configuration
|
||||||
public static final double kTrackWidth = Units.inchesToMeters(26.5);
|
public static final double kTrackWidth = Units.inchesToMeters(24.5);
|
||||||
// Distance between centers of right and left wheels on robot
|
// Distance between centers of right and left wheels on robot
|
||||||
public static final double kWheelBase = Units.inchesToMeters(26.5);
|
public static final double kWheelBase = Units.inchesToMeters(24.5);
|
||||||
|
|
||||||
// Angular offsets of the modules relative to the chassis in radians
|
// Angular offsets of the modules relative to the chassis in radians
|
||||||
public static final double kFrontLeftChassisAngularOffset = -Math.PI / 2;
|
public static final double kFrontLeftChassisAngularOffset = Math.PI;
|
||||||
public static final double kFrontRightChassisAngularOffset = 0;
|
public static final double kFrontRightChassisAngularOffset = -Math.PI / 2;
|
||||||
public static final double kBackLeftChassisAngularOffset = Math.PI;
|
public static final double kBackLeftChassisAngularOffset = Math.PI / 2;
|
||||||
public static final double kBackRightChassisAngularOffset = Math.PI / 2;
|
public static final double kBackRightChassisAngularOffset = 0;
|
||||||
|
|
||||||
// 1, 7, 10 is the default for these three values
|
// 1, 7, 10 is the default for these three values
|
||||||
public static final double kSysIDDrivingRampRate = 1;
|
public static final double kSysIDDrivingRampRate = 1;
|
||||||
@@ -38,17 +38,17 @@ public class DrivetrainConstants {
|
|||||||
public static final double kSysIDTurningTimeout = 10;
|
public static final double kSysIDTurningTimeout = 10;
|
||||||
|
|
||||||
// SPARK MAX CAN IDs
|
// SPARK MAX CAN IDs
|
||||||
public static final int kFrontLeftDrivingCanId = 11;
|
public static final int kFrontLeftDrivingCanId = 0;
|
||||||
public static final int kRearLeftDrivingCanId = 13;
|
public static final int kRearLeftDrivingCanId = 2;
|
||||||
public static final int kFrontRightDrivingCanId = 15;
|
public static final int kFrontRightDrivingCanId = 1;
|
||||||
public static final int kRearRightDrivingCanId = 17;
|
public static final int kRearRightDrivingCanId = 3;
|
||||||
|
|
||||||
public static final int kFrontLeftTurningCanId = 10;
|
public static final int kFrontLeftTurningCanId = 2;
|
||||||
public static final int kRearLeftTurningCanId = 12;
|
public static final int kRearLeftTurningCanId = 4;
|
||||||
public static final int kFrontRightTurningCanId = 14;
|
public static final int kFrontRightTurningCanId = 7;
|
||||||
public static final int kRearRightTurningCanId = 16;
|
public static final int kRearRightTurningCanId = 5;
|
||||||
|
|
||||||
public static final boolean kGyroReversed = false;
|
public static final boolean kGyroReversed = true;
|
||||||
|
|
||||||
// YOU SHOULDN'T NEED TO CHANGE ANYTHING BELOW THIS LINE UNLESS YOU'RE ADDING A NEW CONFIGURATION ITEM
|
// YOU SHOULDN'T NEED TO CHANGE ANYTHING BELOW THIS LINE UNLESS YOU'RE ADDING A NEW CONFIGURATION ITEM
|
||||||
|
|
||||||
|
|||||||
@@ -11,38 +11,47 @@ import edu.wpi.first.wpilibj2.command.sysid.SysIdRoutine;
|
|||||||
import edu.wpi.first.wpilibj2.command.sysid.SysIdRoutine.Config;
|
import edu.wpi.first.wpilibj2.command.sysid.SysIdRoutine.Config;
|
||||||
|
|
||||||
public class ElevatorConstants {
|
public class ElevatorConstants {
|
||||||
public static final int kElevatorMotor1ID = 0;
|
public static final int kElevatorMotor1ID = 8;
|
||||||
public static final int kElevatorMotor2ID = 0;
|
public static final int kElevatorMotor2ID = 6;
|
||||||
|
|
||||||
public static final int kTopLimitSwitchID = 0;
|
|
||||||
public static final int kBottomLimitSwitchID = 0;
|
public static final int kBottomLimitSwitchID = 0;
|
||||||
|
|
||||||
public static final double kEncoderConversionFactor = 0;
|
// 60/11 gearing multiplied by circumference of sprocket multiplied by 2 for carriage position
|
||||||
|
public static final double kEncoderConversionFactor = 11.0/60.0 * (22.0*0.25) * 2.0;
|
||||||
|
|
||||||
public static final int kMotorAmpsMax = 0;
|
public static final int kCurrentLimit = 40;
|
||||||
|
|
||||||
public static final double kPositionControllerP = 0;
|
public static final double kPositionControllerP = 0.3;
|
||||||
public static final double kPositionControllerI = 0;
|
public static final double kPositionControllerI = 0;
|
||||||
public static final double kPositionControllerD = 0;
|
public static final double kPositionControllerD = 0;
|
||||||
|
|
||||||
|
public static final double kAllowedError = 0.5;
|
||||||
|
|
||||||
|
/*
|
||||||
public static final double kVelocityControllerP = 0;
|
public static final double kVelocityControllerP = 0;
|
||||||
public static final double kVelocityControllerI = 0;
|
public static final double kVelocityControllerI = 0;
|
||||||
public static final double kVelocityControllerD = 0;
|
public static final double kVelocityControllerD = 0;
|
||||||
|
*/
|
||||||
|
|
||||||
public static final double kFeedForwardS = 0;
|
public static final double kFeedForwardS = 0;
|
||||||
public static final double kFeedForwardG = 0;
|
public static final double kFeedForwardG = 0.53; // calculated value
|
||||||
public static final double kFeedForwardV = 0;
|
public static final double kFeedForwardV = 4.78; // calculated value
|
||||||
|
|
||||||
public static final double kElevatorMaxVelocity = 0;
|
public static final double kMaxVelocity = 120.0; // 120 inches per second (COOKING) calculated max is 184 in/s
|
||||||
|
public static final double kMaxAcceleration = 500.0; // 400 inches per second^2 (also COOKING) calculated max is 600 in/s^2
|
||||||
|
|
||||||
public static final double kElevatorCoralIntakePosition = 0;
|
public static final double kCoralIntakePosition = 0;
|
||||||
public static final double kElevatorL1Position = 0;
|
public static final double kL1Position = 0;
|
||||||
public static final double kElevatorL2Position = 0;
|
public static final double kL2Position = 14.5;
|
||||||
public static final double kElevatorL3Position = 0;
|
public static final double kL3Position = 29.0;
|
||||||
public static final double kElevatorL4Position = 0;
|
public static final double kL4Position = 53.0;
|
||||||
public static final double kElevatorL2AlgaePosition = 0;
|
public static final double kL4TransitionPosition = 40.0;
|
||||||
public static final double kElevatorL3AlgaePosition = 0;
|
public static final double kL2AlgaePosition = 22.0;
|
||||||
public static final double kElevatorBracePosition = 0;
|
public static final double kL3AlgaePosition = 39.0;
|
||||||
|
public static final double kProcessorPosition = 4.0;
|
||||||
|
/**The position of the top of the elevator brace */
|
||||||
|
public static final double kBracePosition = 5.5;
|
||||||
|
public static final double kMaxHeight = 53.0;
|
||||||
|
|
||||||
// 1, 7, 10 are the defaults for these, change as necessary
|
// 1, 7, 10 are the defaults for these, change as necessary
|
||||||
public static final double kSysIDRampRate = 1;
|
public static final double kSysIDRampRate = 1;
|
||||||
@@ -63,10 +72,30 @@ public class ElevatorConstants {
|
|||||||
|
|
||||||
static {
|
static {
|
||||||
motorConfig
|
motorConfig
|
||||||
.smartCurrentLimit(kMotorAmpsMax)
|
.smartCurrentLimit(kCurrentLimit)
|
||||||
.idleMode(kIdleMode);
|
.idleMode(kIdleMode)
|
||||||
|
.inverted(false);
|
||||||
motorConfig.encoder
|
motorConfig.encoder
|
||||||
.positionConversionFactor(kEncoderConversionFactor)
|
.positionConversionFactor(kEncoderConversionFactor);
|
||||||
.velocityConversionFactor(kEncoderConversionFactor / 60.0);
|
motorConfig.closedLoop
|
||||||
|
.p(kPositionControllerP)
|
||||||
|
.i(kPositionControllerI)
|
||||||
|
.d(kPositionControllerD)
|
||||||
|
.velocityFF(0.0); // keep at zero for position pid
|
||||||
|
motorConfig.closedLoop.maxMotion
|
||||||
|
.maxAcceleration(kMaxAcceleration)
|
||||||
|
.maxVelocity(kMaxVelocity)
|
||||||
|
.allowedClosedLoopError(kAllowedError);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final SparkMaxConfig motorConfig2 = new SparkMaxConfig();
|
||||||
|
|
||||||
|
static {
|
||||||
|
motorConfig2
|
||||||
|
.smartCurrentLimit(kCurrentLimit)
|
||||||
|
.idleMode(kIdleMode)
|
||||||
|
.inverted(false);
|
||||||
|
motorConfig.encoder
|
||||||
|
.positionConversionFactor(kEncoderConversionFactor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
package frc.robot.constants;
|
|
||||||
|
|
||||||
public class IndexerConstants {
|
|
||||||
public static final int kIndexerMotorID = 0;
|
|
||||||
public static final int kIndexerBeamBreakID = 0;
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,10 @@
|
|||||||
package frc.robot.constants;
|
package frc.robot.constants;
|
||||||
|
|
||||||
|
import com.revrobotics.spark.config.SparkMaxConfig;
|
||||||
|
|
||||||
public class ManipulatorConstants {
|
public class ManipulatorConstants {
|
||||||
public static final int kManipulatorMotorID = 0;
|
public static final int kManipulatorMotorID = 12;
|
||||||
public static final int kCoralBeamBreakID = 0;
|
public static final int kCoralBeamBreakID = 2;
|
||||||
public static final int kAlgaeBeamBreakID = 0;
|
|
||||||
|
public static final SparkMaxConfig motorConfig = new SparkMaxConfig();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,87 @@
|
|||||||
|
package frc.robot.constants;
|
||||||
|
|
||||||
|
import static edu.wpi.first.units.Units.Volts;
|
||||||
|
import static edu.wpi.first.units.Units.Second;
|
||||||
|
import static edu.wpi.first.units.Units.Seconds;
|
||||||
|
|
||||||
|
import com.ctre.phoenix6.signals.SensorDirectionValue;
|
||||||
|
import com.revrobotics.spark.config.SparkMaxConfig;
|
||||||
|
import com.revrobotics.spark.config.SparkBaseConfig.IdleMode;
|
||||||
|
|
||||||
|
import edu.wpi.first.math.util.Units;
|
||||||
|
import edu.wpi.first.wpilibj2.command.sysid.SysIdRoutine;
|
||||||
|
import edu.wpi.first.wpilibj2.command.sysid.SysIdRoutine.Config;
|
||||||
|
|
||||||
|
public class ManipulatorPivotConstants {
|
||||||
|
public static final int kArmMotorID = 1;
|
||||||
|
|
||||||
|
public static final int kMotorCurrentMax = 40;
|
||||||
|
|
||||||
|
public static final double kPivotConversion = 12.0/60.0 * 20.0/60.0 * 12.0/28.0;
|
||||||
|
|
||||||
|
public static final double kPivotMaxVelocity = 0;
|
||||||
|
|
||||||
|
public static final double kPositionalP = 0;
|
||||||
|
public static final double kPositionalI = 0;
|
||||||
|
public static final double kPositionalD = 0;
|
||||||
|
public static final double kPositionalTolerance = Units.degreesToRadians(3.0);
|
||||||
|
|
||||||
|
public static final double kFeedForwardS = 0;
|
||||||
|
public static final double kFeedForwardG = 0.41; // calculated value
|
||||||
|
public static final double kFeedForwardV = 0.68; //calculated value
|
||||||
|
|
||||||
|
public static final double kFFGravityOffset = Units.degreesToRadians(-135.0);
|
||||||
|
|
||||||
|
public static final double kMaxAcceleration = Units.degreesToRadians(1000.0); // degrees per second^2 calculated max = 2100
|
||||||
|
public static final double kMaxVelocity = Units.degreesToRadians(100.0); // degrees per second calculated max = 168
|
||||||
|
|
||||||
|
public static final double kCoralIntakePosition = Units.degreesToRadians(175.0);
|
||||||
|
public static final double kL1Position = Units.degreesToRadians(0.0);
|
||||||
|
public static final double kL2Position = Units.degreesToRadians(25.0);
|
||||||
|
public static final double kL3Position = Units.degreesToRadians(60.0);
|
||||||
|
public static final double kL4Position = Units.degreesToRadians(45.0);
|
||||||
|
public static final double kL2AlgaePosition = Units.degreesToRadians(175.0);
|
||||||
|
public static final double kL3AlgaePosition = Units.degreesToRadians(175.0);
|
||||||
|
public static final double kProcesserPosition = Units.degreesToRadians(175.0);
|
||||||
|
/**The closest position to the elevator brace without hitting it */
|
||||||
|
public static final double kArmSafeStowPosition = Units.degreesToRadians(60.0);
|
||||||
|
/**The forward rotation limit of the arm */
|
||||||
|
public static final double kRotationLimit = Units.degreesToRadians(175.0);
|
||||||
|
|
||||||
|
public static final double kSysIDRampRate = 1;
|
||||||
|
public static final double kSysIDStepVolts = 7;
|
||||||
|
public static final double kSysIDTimeout = 10;
|
||||||
|
|
||||||
|
public static final SensorDirectionValue kSensorDirection = SensorDirectionValue.CounterClockwise_Positive;
|
||||||
|
|
||||||
|
public static final IdleMode kIdleMode = IdleMode.kBrake;
|
||||||
|
|
||||||
|
// YOU SHOULDN'T NEED TO CHANGE ANYTHING BELOW THIS LINE UNLESS YOU'RE ADDING A NEW CONFIG
|
||||||
|
|
||||||
|
public static final SysIdRoutine.Config kSysIDConfig = new Config(
|
||||||
|
Volts.of(kSysIDRampRate).per(Second),
|
||||||
|
Volts.of(kSysIDStepVolts),
|
||||||
|
Seconds.of(kSysIDTimeout)
|
||||||
|
);
|
||||||
|
|
||||||
|
public static final SparkMaxConfig motorConfig = new SparkMaxConfig();
|
||||||
|
|
||||||
|
static {
|
||||||
|
|
||||||
|
motorConfig
|
||||||
|
.smartCurrentLimit(kMotorCurrentMax)
|
||||||
|
.idleMode(kIdleMode);
|
||||||
|
motorConfig.absoluteEncoder.positionConversionFactor(kPivotConversion);
|
||||||
|
motorConfig.closedLoop
|
||||||
|
.p(kPositionalP)
|
||||||
|
.i(kPositionalI)
|
||||||
|
.d(kPositionalD)
|
||||||
|
.velocityFF(0.0); // keep at zero for position pid
|
||||||
|
motorConfig.closedLoop.maxMotion
|
||||||
|
.maxAcceleration(kMaxAcceleration)
|
||||||
|
.maxVelocity(kMaxVelocity)
|
||||||
|
.allowedClosedLoopError(kPositionalTolerance);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -2,6 +2,12 @@ package frc.robot.constants;
|
|||||||
|
|
||||||
import com.revrobotics.spark.config.ClosedLoopConfig.FeedbackSensor;
|
import com.revrobotics.spark.config.ClosedLoopConfig.FeedbackSensor;
|
||||||
import com.revrobotics.spark.config.SparkBaseConfig.IdleMode;
|
import com.revrobotics.spark.config.SparkBaseConfig.IdleMode;
|
||||||
|
import com.ctre.phoenix6.configs.CurrentLimitsConfigs;
|
||||||
|
import com.ctre.phoenix6.configs.FeedbackConfigs;
|
||||||
|
import com.ctre.phoenix6.configs.MotorOutputConfigs;
|
||||||
|
import com.ctre.phoenix6.configs.Slot0Configs;
|
||||||
|
import com.ctre.phoenix6.signals.InvertedValue;
|
||||||
|
import com.ctre.phoenix6.signals.NeutralModeValue;
|
||||||
import com.revrobotics.spark.config.SparkMaxConfig;
|
import com.revrobotics.spark.config.SparkMaxConfig;
|
||||||
|
|
||||||
public class ModuleConstants {
|
public class ModuleConstants {
|
||||||
@@ -20,52 +26,76 @@ public class ModuleConstants {
|
|||||||
public static final double kDriveWheelFreeSpeedRps = (kDrivingMotorFreeSpeedRps * kWheelCircumferenceMeters)
|
public static final double kDriveWheelFreeSpeedRps = (kDrivingMotorFreeSpeedRps * kWheelCircumferenceMeters)
|
||||||
/ kDrivingMotorReduction;
|
/ kDrivingMotorReduction;
|
||||||
|
|
||||||
public static final int kDriveMotorCurrentLimit = 40;
|
public static final double kDrivingFactor = kWheelDiameterMeters * Math.PI / kDrivingMotorReduction;
|
||||||
|
public static final double kTurningFactor = 2 * Math.PI;
|
||||||
|
public static final double kDrivingVelocityFeedForward = 1 / kDriveWheelFreeSpeedRps;
|
||||||
|
|
||||||
|
public static final double kDriveP = .04;
|
||||||
|
public static final double kDriveI = 0;
|
||||||
|
public static final double kDriveD = 0;
|
||||||
|
public static final double kDriveS = 0;
|
||||||
|
public static final double kDriveV = kDrivingVelocityFeedForward;
|
||||||
|
public static final double kDriveA = 0;
|
||||||
|
|
||||||
|
public static final double kTurnP = 1;
|
||||||
|
public static final double kTurnI = 0;
|
||||||
|
public static final double kTurnD = 0;
|
||||||
|
|
||||||
|
public static final int kDriveMotorStatorCurrentLimit = 100;
|
||||||
|
public static final int kDriveMotorSupplyCurrentLimit = 65;
|
||||||
public static final int kTurnMotorCurrentLimit = 20;
|
public static final int kTurnMotorCurrentLimit = 20;
|
||||||
|
|
||||||
|
public static final IdleMode kTurnIdleMode = IdleMode.kBrake;
|
||||||
|
|
||||||
|
public static final InvertedValue kDriveInversionState = InvertedValue.Clockwise_Positive;
|
||||||
|
public static final NeutralModeValue kDriveIdleMode = NeutralModeValue.Brake;
|
||||||
|
|
||||||
// YOU SHOULDN'T NEED TO CHANGE ANYTHING BELOW THIS LINE UNLESS YOU'RE ADDING A NEW CONFIGURATION ITEM
|
// YOU SHOULDN'T NEED TO CHANGE ANYTHING BELOW THIS LINE UNLESS YOU'RE ADDING A NEW CONFIGURATION ITEM
|
||||||
|
|
||||||
public static final SparkMaxConfig drivingConfig = new SparkMaxConfig();
|
|
||||||
public static final SparkMaxConfig turningConfig = new SparkMaxConfig();
|
public static final SparkMaxConfig turningConfig = new SparkMaxConfig();
|
||||||
|
|
||||||
static {
|
public static final FeedbackConfigs kDriveFeedConfig = new FeedbackConfigs();
|
||||||
// Use module constants to calculate conversion factors and feed forward gain.
|
public static final CurrentLimitsConfigs kDriveCurrentLimitConfig = new CurrentLimitsConfigs();
|
||||||
double drivingFactor = kWheelDiameterMeters * Math.PI / kDrivingMotorReduction;
|
public static final MotorOutputConfigs kDriveMotorConfig = new MotorOutputConfigs();
|
||||||
double turningFactor = 2 * Math.PI;
|
public static final Slot0Configs kDriveSlot0Config = new Slot0Configs();
|
||||||
double drivingVelocityFeedForward = 1 / kDriveWheelFreeSpeedRps;
|
|
||||||
|
|
||||||
drivingConfig
|
static {
|
||||||
.idleMode(IdleMode.kBrake)
|
kDriveFeedConfig.SensorToMechanismRatio = kDrivingMotorReduction;
|
||||||
.smartCurrentLimit(kDriveMotorCurrentLimit);
|
|
||||||
drivingConfig.encoder
|
kDriveCurrentLimitConfig.StatorCurrentLimitEnable = true;
|
||||||
.positionConversionFactor(drivingFactor) // meters
|
kDriveCurrentLimitConfig.SupplyCurrentLimitEnable = true;
|
||||||
.velocityConversionFactor(drivingFactor / 60.0); // meters per second
|
kDriveCurrentLimitConfig.StatorCurrentLimit = kDriveMotorStatorCurrentLimit;
|
||||||
drivingConfig.closedLoop
|
kDriveCurrentLimitConfig.SupplyCurrentLimit = kDriveMotorSupplyCurrentLimit;
|
||||||
.feedbackSensor(FeedbackSensor.kPrimaryEncoder)
|
|
||||||
// These are example gains you may need to them for your own robot!
|
kDriveMotorConfig.Inverted = kDriveInversionState;
|
||||||
.pid(0.04, 0, 0)
|
kDriveMotorConfig.NeutralMode = kDriveIdleMode;
|
||||||
.velocityFF(drivingVelocityFeedForward)
|
|
||||||
.outputRange(-1, 1);
|
kDriveSlot0Config.kP = kDriveP;
|
||||||
|
kDriveSlot0Config.kI = kDriveI;
|
||||||
|
kDriveSlot0Config.kD = kDriveD;
|
||||||
|
kDriveSlot0Config.kS = kDriveS;
|
||||||
|
kDriveSlot0Config.kV = kDriveV;
|
||||||
|
kDriveSlot0Config.kA = kDriveA;
|
||||||
|
|
||||||
turningConfig
|
turningConfig
|
||||||
.idleMode(IdleMode.kBrake)
|
.idleMode(kTurnIdleMode)
|
||||||
.smartCurrentLimit(20);
|
.smartCurrentLimit(kTurnMotorCurrentLimit);
|
||||||
turningConfig.absoluteEncoder
|
turningConfig.absoluteEncoder
|
||||||
// Invert the turning encoder, since the output shaft rotates in the opposite
|
// Invert the turning encoder, since the output shaft rotates in the opposite
|
||||||
// direction of the steering motor in the MAXSwerve Module.
|
// direction of the steering motor in the MAXSwerve Module.
|
||||||
.inverted(true)
|
.inverted(true)
|
||||||
.positionConversionFactor(turningFactor) // radians
|
.positionConversionFactor(kTurningFactor) // radians
|
||||||
.velocityConversionFactor(turningFactor / 60.0); // radians per second
|
.velocityConversionFactor(kTurningFactor / 60.0); // radians per second
|
||||||
turningConfig.closedLoop
|
turningConfig.closedLoop
|
||||||
.feedbackSensor(FeedbackSensor.kAbsoluteEncoder)
|
.feedbackSensor(FeedbackSensor.kAbsoluteEncoder)
|
||||||
// These are example gains you may need to them for your own robot!
|
// These are example gains you may need to them for your own robot!
|
||||||
.pid(1, 0, 0)
|
.pid(kTurnP, kTurnI, kTurnD)
|
||||||
.outputRange(-1, 1)
|
.outputRange(-1, 1)
|
||||||
// Enable PID wrap around for the turning motor. This will allow the PID
|
// Enable PID wrap around for the turning motor. This will allow the PID
|
||||||
// controller to go through 0 to get to the setpoint i.e. going from 350 degrees
|
// controller to go through 0 to get to the setpoint i.e. going from 350 degrees
|
||||||
// to 10 degrees will go through 0 rather than the other direction which is a
|
// to 10 degrees will go through 0 rather than the other direction which is a
|
||||||
// longer route.
|
// longer route.
|
||||||
.positionWrappingEnabled(true)
|
.positionWrappingEnabled(true)
|
||||||
.positionWrappingInputRange(0, turningFactor);
|
.positionWrappingInputRange(0, kTurningFactor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,5 +6,6 @@ public class OIConstants {
|
|||||||
|
|
||||||
public static final double kDriveDeadband = 0.05;
|
public static final double kDriveDeadband = 0.05;
|
||||||
|
|
||||||
|
public static final String kAutoTab = "Auto Tab";
|
||||||
public static final String kSensorsTab = "Sensors Tab";
|
public static final String kSensorsTab = "Sensors Tab";
|
||||||
}
|
}
|
||||||
|
|||||||
31
src/main/java/frc/robot/constants/VisionConstants.java
Normal file
31
src/main/java/frc/robot/constants/VisionConstants.java
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
package frc.robot.constants;
|
||||||
|
|
||||||
|
public class VisionConstants {
|
||||||
|
// global coordinate map of all tags. index is the tag id.
|
||||||
|
// Units: inches and degrees. {x, y, z, z-rotation, y-rotation}
|
||||||
|
// This is for ANDYMARK FIELDS found in NE. Not for WELDED FIELDS.
|
||||||
|
public static final double[][] globalTagCoords = {{},
|
||||||
|
{656.98, 24.73, 58.50, 126.0, 0},
|
||||||
|
{656.98, 291.90, 58.50, 234.0, 0},
|
||||||
|
{452.4, 316.21, 51.25, 270, 0},
|
||||||
|
{365.2, 241.44, 73.54, 0, 30},
|
||||||
|
{365.2, 75.19, 73.54, 0, 30},
|
||||||
|
{530.49, 129.97, 12.13, 300, 0},
|
||||||
|
{546.87, 158.3, 12.13, 0, 0},
|
||||||
|
{530.49, 186.63, 12.13, 60, 0},
|
||||||
|
{497.77, 186.63, 12.13, 120, 0},
|
||||||
|
{481.39, 158.3, 12.13, 180, 0},
|
||||||
|
{497.77, 129.97, 12.13, 240, 0},
|
||||||
|
{33.9, 24.73, 58.5, 54, 0},
|
||||||
|
{33.9, 291.9, 58.5, 306, 0},
|
||||||
|
{325.68, 241.44, 73.54, 180, 30},
|
||||||
|
{325.68, 75.19, 73.54, 180, 30},
|
||||||
|
{238.49, 0.42, 51.25, 90, 0},
|
||||||
|
{160.39, 129.97, 12.13, 240, 0},
|
||||||
|
{144.00, 158.3, 12.13, 180, 0},
|
||||||
|
{160.39, 186.63, 12.13, 120, 0},
|
||||||
|
{193.1, 186.63, 12.13, 60, 0},
|
||||||
|
{209.49, 158.3, 12.13, 0, 0},
|
||||||
|
{193.1, 129.97, 12.13, 300, 0},
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -1,94 +0,0 @@
|
|||||||
package frc.robot.subsystems;
|
|
||||||
|
|
||||||
import java.util.function.DoubleSupplier;
|
|
||||||
|
|
||||||
import com.ctre.phoenix6.hardware.CANcoder;
|
|
||||||
import com.revrobotics.spark.SparkMax;
|
|
||||||
import com.revrobotics.spark.SparkLowLevel.MotorType;
|
|
||||||
|
|
||||||
import edu.wpi.first.math.controller.ArmFeedforward;
|
|
||||||
import edu.wpi.first.math.controller.PIDController;
|
|
||||||
import edu.wpi.first.math.util.Units;
|
|
||||||
import edu.wpi.first.wpilibj2.command.Command;
|
|
||||||
import edu.wpi.first.wpilibj2.command.SubsystemBase;
|
|
||||||
import frc.robot.constants.ArmConstants;
|
|
||||||
|
|
||||||
public class Arm extends SubsystemBase {
|
|
||||||
private SparkMax armMotor;
|
|
||||||
|
|
||||||
private CANcoder canCoder;
|
|
||||||
|
|
||||||
private PIDController positionController;
|
|
||||||
private PIDController velocityController;
|
|
||||||
|
|
||||||
private ArmFeedforward feedForward;
|
|
||||||
|
|
||||||
public Arm() {
|
|
||||||
armMotor = new SparkMax(
|
|
||||||
ArmConstants.kArmMotorID,
|
|
||||||
MotorType.kBrushless
|
|
||||||
);
|
|
||||||
|
|
||||||
canCoder = new CANcoder(ArmConstants.kCANcoderID);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns whether or not the motion is safe relative to the encoder's current position
|
|
||||||
* and the arm safe stow position
|
|
||||||
*
|
|
||||||
* @return Is the motion safe
|
|
||||||
*/
|
|
||||||
public boolean isMotionSafe() {
|
|
||||||
return isMotionSafe(getEncoderPosition());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns whether or not the motion is safe relative to some target position and the
|
|
||||||
* arm safe stow position
|
|
||||||
*
|
|
||||||
* @param motionTarget The target position to determine the safety of
|
|
||||||
* @return Is the motion safe
|
|
||||||
*/
|
|
||||||
public boolean isMotionSafe(double motionTarget) {
|
|
||||||
return motionTarget > ArmConstants.kArmSafeStowPosition;
|
|
||||||
}
|
|
||||||
|
|
||||||
//manual command that keeps ouput speed consistent no matter the direction
|
|
||||||
public Command runArm(DoubleSupplier speed) {
|
|
||||||
return run(() -> {
|
|
||||||
double realSpeedTarget = speed.getAsDouble() * ArmConstants.kArmMaxVelocity;
|
|
||||||
|
|
||||||
double voltsOut = velocityController.calculate(
|
|
||||||
getEncoderVelocity(),
|
|
||||||
realSpeedTarget
|
|
||||||
) + feedForward.calculate(
|
|
||||||
getEncoderPosition(),
|
|
||||||
getEncoderVelocity()
|
|
||||||
);
|
|
||||||
|
|
||||||
armMotor.setVoltage(voltsOut);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public Command goToSetpoint(double setpoint, double timeout) {
|
|
||||||
return run(() -> {
|
|
||||||
double voltsOut = positionController.calculate(
|
|
||||||
getEncoderPosition(),
|
|
||||||
setpoint
|
|
||||||
) + feedForward.calculate(
|
|
||||||
getEncoderPosition(),
|
|
||||||
getEncoderVelocity()
|
|
||||||
);
|
|
||||||
|
|
||||||
armMotor.setVoltage(voltsOut);
|
|
||||||
}).until(positionController::atSetpoint).withTimeout(timeout);
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getEncoderPosition() {
|
|
||||||
return Units.rotationsToRadians(canCoder.getPosition().getValueAsDouble());
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getEncoderVelocity() {
|
|
||||||
return Units.rotationsToRadians(canCoder.getVelocity().getValueAsDouble());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -2,10 +2,10 @@ package frc.robot.subsystems;
|
|||||||
|
|
||||||
import com.revrobotics.RelativeEncoder;
|
import com.revrobotics.RelativeEncoder;
|
||||||
import com.revrobotics.spark.SparkMax;
|
import com.revrobotics.spark.SparkMax;
|
||||||
|
import com.revrobotics.spark.SparkBase.PersistMode;
|
||||||
|
import com.revrobotics.spark.SparkBase.ResetMode;
|
||||||
import com.revrobotics.spark.SparkLowLevel.MotorType;
|
import com.revrobotics.spark.SparkLowLevel.MotorType;
|
||||||
|
|
||||||
import edu.wpi.first.math.controller.PIDController;
|
|
||||||
import edu.wpi.first.wpilibj.DigitalInput;
|
|
||||||
import edu.wpi.first.wpilibj2.command.Command;
|
import edu.wpi.first.wpilibj2.command.Command;
|
||||||
import edu.wpi.first.wpilibj2.command.SubsystemBase;
|
import edu.wpi.first.wpilibj2.command.SubsystemBase;
|
||||||
import frc.robot.constants.ClimberPivotConstants;
|
import frc.robot.constants.ClimberPivotConstants;
|
||||||
@@ -15,9 +15,7 @@ public class ClimberPivot extends SubsystemBase {
|
|||||||
|
|
||||||
private RelativeEncoder neoEncoder;
|
private RelativeEncoder neoEncoder;
|
||||||
|
|
||||||
private DigitalInput cageLimitSwitch;
|
//private DigitalInput cageLimitSwitch;
|
||||||
|
|
||||||
private PIDController pidController;
|
|
||||||
|
|
||||||
public ClimberPivot() {
|
public ClimberPivot() {
|
||||||
pivotMotor = new SparkMax(
|
pivotMotor = new SparkMax(
|
||||||
@@ -25,15 +23,15 @@ public class ClimberPivot extends SubsystemBase {
|
|||||||
MotorType.kBrushless
|
MotorType.kBrushless
|
||||||
);
|
);
|
||||||
|
|
||||||
|
pivotMotor.configure(
|
||||||
|
ClimberPivotConstants.motorConfig,
|
||||||
|
ResetMode.kResetSafeParameters,
|
||||||
|
PersistMode.kPersistParameters
|
||||||
|
);
|
||||||
|
|
||||||
neoEncoder = pivotMotor.getEncoder();
|
neoEncoder = pivotMotor.getEncoder();
|
||||||
|
|
||||||
cageLimitSwitch = new DigitalInput(ClimberPivotConstants.kClimberLimitSwitchID);
|
//cageLimitSwitch = new DigitalInput(ClimberPivotConstants.kClimberLimitSwitchID);
|
||||||
|
|
||||||
pidController = new PIDController(
|
|
||||||
ClimberPivotConstants.kPIDControllerP,
|
|
||||||
ClimberPivotConstants.kPIDControllerI,
|
|
||||||
ClimberPivotConstants.kPIDControllerD
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Command runPivot(double speed) {
|
public Command runPivot(double speed) {
|
||||||
@@ -42,18 +40,29 @@ public class ClimberPivot extends SubsystemBase {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public Command goToAngle(double setpoint, double timeout) {
|
/**
|
||||||
|
* Runs the climber until it is at setpoint
|
||||||
|
*
|
||||||
|
* @param speed The speed at which the pivot runs
|
||||||
|
* @param setpoint The target position of the climber
|
||||||
|
* @return Sets the motor speed until at the target position
|
||||||
|
*/
|
||||||
|
public Command climb(double setpoint, double speed) {
|
||||||
return run(() -> {
|
return run(() -> {
|
||||||
pivotMotor.set(
|
pivotMotor.set(speed);
|
||||||
pidController.calculate(
|
}).until(() -> neoEncoder.getPosition() >= setpoint);
|
||||||
neoEncoder.getPosition(),
|
|
||||||
setpoint
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}).withTimeout(timeout);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean getCageLimitSwitch() {
|
/**
|
||||||
return cageLimitSwitch.get();
|
* Returns the limit switch attached to the climber. Detects if the cage is present
|
||||||
|
*
|
||||||
|
* @return Is the cage in the climber
|
||||||
|
*/
|
||||||
|
// public boolean getCageLimitSwitch() {
|
||||||
|
// return cageLimitSwitch.get();
|
||||||
|
//}
|
||||||
|
|
||||||
|
public double getEncoderPosition() {
|
||||||
|
return neoEncoder.getPosition();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,12 +1,15 @@
|
|||||||
package frc.robot.subsystems;
|
package frc.robot.subsystems;
|
||||||
|
|
||||||
import com.revrobotics.spark.SparkMax;
|
import com.revrobotics.spark.SparkMax;
|
||||||
|
import com.revrobotics.spark.SparkBase.PersistMode;
|
||||||
|
import com.revrobotics.spark.SparkBase.ResetMode;
|
||||||
import com.revrobotics.spark.SparkLowLevel.MotorType;
|
import com.revrobotics.spark.SparkLowLevel.MotorType;
|
||||||
|
|
||||||
import edu.wpi.first.wpilibj2.command.Command;
|
import edu.wpi.first.wpilibj2.command.Command;
|
||||||
import edu.wpi.first.wpilibj2.command.SubsystemBase;
|
import edu.wpi.first.wpilibj2.command.SubsystemBase;
|
||||||
import frc.robot.constants.ClimberRollersConstants;
|
import frc.robot.constants.ClimberRollersConstants;
|
||||||
|
|
||||||
|
//TODO Figure out a way to detect if we're at the top of the cage
|
||||||
public class ClimberRollers extends SubsystemBase {
|
public class ClimberRollers extends SubsystemBase {
|
||||||
private SparkMax rollerMotor;
|
private SparkMax rollerMotor;
|
||||||
|
|
||||||
@@ -15,8 +18,20 @@ public class ClimberRollers extends SubsystemBase {
|
|||||||
ClimberRollersConstants.kRollerMotorID,
|
ClimberRollersConstants.kRollerMotorID,
|
||||||
MotorType.kBrushless
|
MotorType.kBrushless
|
||||||
);
|
);
|
||||||
|
|
||||||
|
rollerMotor.configure(
|
||||||
|
ClimberRollersConstants.motorConfig,
|
||||||
|
ResetMode.kResetSafeParameters,
|
||||||
|
PersistMode.kPersistParameters
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Runs the rollers at a set speed
|
||||||
|
*
|
||||||
|
* @param speed The speed in which the roller runs
|
||||||
|
* @return Runs the rollers at a set speed
|
||||||
|
*/
|
||||||
public Command runRoller(double speed) {
|
public Command runRoller(double speed) {
|
||||||
return run(() -> {
|
return run(() -> {
|
||||||
rollerMotor.set(speed);
|
rollerMotor.set(speed);
|
||||||
|
|||||||
@@ -4,21 +4,26 @@
|
|||||||
|
|
||||||
package frc.robot.subsystems;
|
package frc.robot.subsystems;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.function.BooleanSupplier;
|
import java.util.function.BooleanSupplier;
|
||||||
import java.util.function.DoubleSupplier;
|
import java.util.function.DoubleSupplier;
|
||||||
|
|
||||||
|
import com.pathplanner.lib.auto.AutoBuilder;
|
||||||
|
import com.studica.frc.AHRS;
|
||||||
|
import com.studica.frc.AHRS.NavXComType;
|
||||||
|
|
||||||
import edu.wpi.first.math.MathUtil;
|
import edu.wpi.first.math.MathUtil;
|
||||||
|
import edu.wpi.first.math.estimator.SwerveDrivePoseEstimator;
|
||||||
import edu.wpi.first.math.geometry.Pose2d;
|
import edu.wpi.first.math.geometry.Pose2d;
|
||||||
import edu.wpi.first.math.geometry.Rotation2d;
|
import edu.wpi.first.math.geometry.Rotation2d;
|
||||||
import edu.wpi.first.math.kinematics.ChassisSpeeds;
|
import edu.wpi.first.math.kinematics.ChassisSpeeds;
|
||||||
import edu.wpi.first.math.kinematics.SwerveDriveKinematics;
|
import edu.wpi.first.math.kinematics.SwerveDriveKinematics;
|
||||||
import edu.wpi.first.math.kinematics.SwerveDriveOdometry;
|
|
||||||
import edu.wpi.first.math.kinematics.SwerveModulePosition;
|
import edu.wpi.first.math.kinematics.SwerveModulePosition;
|
||||||
import edu.wpi.first.math.kinematics.SwerveModuleState;
|
import edu.wpi.first.math.kinematics.SwerveModuleState;
|
||||||
import edu.wpi.first.wpilibj.ADIS16470_IMU;
|
import edu.wpi.first.wpilibj.DriverStation;
|
||||||
import edu.wpi.first.wpilibj.ADIS16470_IMU.IMUAxis;
|
|
||||||
import edu.wpi.first.wpilibj2.command.Command;
|
import edu.wpi.first.wpilibj2.command.Command;
|
||||||
import edu.wpi.first.wpilibj2.command.SubsystemBase;
|
import edu.wpi.first.wpilibj2.command.SubsystemBase;
|
||||||
|
import frc.robot.constants.AutoConstants;
|
||||||
import frc.robot.constants.DrivetrainConstants;
|
import frc.robot.constants.DrivetrainConstants;
|
||||||
import frc.robot.constants.OIConstants;
|
import frc.robot.constants.OIConstants;
|
||||||
|
|
||||||
@@ -30,10 +35,10 @@ public class Drivetrain extends SubsystemBase {
|
|||||||
protected MAXSwerveModule m_rearRight;
|
protected MAXSwerveModule m_rearRight;
|
||||||
|
|
||||||
// The gyro sensor
|
// The gyro sensor
|
||||||
private ADIS16470_IMU m_gyro;
|
private AHRS ahrs;
|
||||||
|
|
||||||
// Odometry class for tracking robot pose
|
// Odometry class for tracking robot pose
|
||||||
private SwerveDriveOdometry m_odometry;
|
private SwerveDrivePoseEstimator m_estimator;
|
||||||
|
|
||||||
/** Creates a new DriveSubsystem. */
|
/** Creates a new DriveSubsystem. */
|
||||||
public Drivetrain() {
|
public Drivetrain() {
|
||||||
@@ -61,11 +66,43 @@ public class Drivetrain extends SubsystemBase {
|
|||||||
DrivetrainConstants.kBackRightChassisAngularOffset
|
DrivetrainConstants.kBackRightChassisAngularOffset
|
||||||
);
|
);
|
||||||
|
|
||||||
m_gyro = new ADIS16470_IMU();
|
ahrs = new AHRS(NavXComType.kMXP_SPI);
|
||||||
|
|
||||||
m_odometry = new SwerveDriveOdometry(
|
m_estimator = new SwerveDrivePoseEstimator(
|
||||||
DrivetrainConstants.kDriveKinematics,
|
DrivetrainConstants.kDriveKinematics,
|
||||||
Rotation2d.fromDegrees(m_gyro.getAngle(IMUAxis.kZ)),
|
Rotation2d.fromDegrees(ahrs.getAngle()),
|
||||||
|
new SwerveModulePosition[] {
|
||||||
|
m_frontLeft.getPosition(),
|
||||||
|
m_frontRight.getPosition(),
|
||||||
|
m_rearLeft.getPosition(),
|
||||||
|
m_rearRight.getPosition()
|
||||||
|
},
|
||||||
|
new Pose2d()
|
||||||
|
);
|
||||||
|
|
||||||
|
AutoBuilder.configure(
|
||||||
|
this::getPose,
|
||||||
|
this::resetOdometry,
|
||||||
|
this::getCurrentChassisSpeeds,
|
||||||
|
this::driveWithChassisSpeeds,
|
||||||
|
AutoConstants.kPPDriveController,
|
||||||
|
AutoConstants.kRobotConfig,
|
||||||
|
() -> {
|
||||||
|
Optional<DriverStation.Alliance> alliance = DriverStation.getAlliance();
|
||||||
|
if (alliance.isPresent()) {
|
||||||
|
return alliance.get() == DriverStation.Alliance.Red;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
this
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void periodic() {
|
||||||
|
// Update the odometry in the periodic block
|
||||||
|
m_estimator.update(
|
||||||
|
Rotation2d.fromDegrees(getGyroValue()),
|
||||||
new SwerveModulePosition[] {
|
new SwerveModulePosition[] {
|
||||||
m_frontLeft.getPosition(),
|
m_frontLeft.getPosition(),
|
||||||
m_frontRight.getPosition(),
|
m_frontRight.getPosition(),
|
||||||
@@ -74,17 +111,21 @@ public class Drivetrain extends SubsystemBase {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public ChassisSpeeds getCurrentChassisSpeeds() {
|
||||||
public void periodic() {
|
return DrivetrainConstants.kDriveKinematics.toChassisSpeeds(
|
||||||
// Update the odometry in the periodic block
|
m_frontLeft.getState(),
|
||||||
m_odometry.update(
|
m_frontRight.getState(),
|
||||||
Rotation2d.fromDegrees(m_gyro.getAngle(IMUAxis.kZ)),
|
m_rearLeft.getState(),
|
||||||
new SwerveModulePosition[] {
|
m_rearRight.getState()
|
||||||
m_frontLeft.getPosition(),
|
);
|
||||||
m_frontRight.getPosition(),
|
}
|
||||||
m_rearLeft.getPosition(),
|
|
||||||
m_rearRight.getPosition()
|
public void driveWithChassisSpeeds(ChassisSpeeds speeds) {
|
||||||
});
|
ChassisSpeeds discreteSpeeds = ChassisSpeeds.discretize(speeds, 0.2);
|
||||||
|
SwerveModuleState[] newStates = DrivetrainConstants.kDriveKinematics.toSwerveModuleStates(discreteSpeeds);
|
||||||
|
SwerveDriveKinematics.desaturateWheelSpeeds(newStates, DrivetrainConstants.kMaxSpeedMetersPerSecond);
|
||||||
|
|
||||||
|
setModuleStates(newStates);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -93,7 +134,7 @@ public class Drivetrain extends SubsystemBase {
|
|||||||
* @return The pose.
|
* @return The pose.
|
||||||
*/
|
*/
|
||||||
public Pose2d getPose() {
|
public Pose2d getPose() {
|
||||||
return m_odometry.getPoseMeters();
|
return m_estimator.getEstimatedPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -102,14 +143,7 @@ public class Drivetrain extends SubsystemBase {
|
|||||||
* @param pose The pose to which to set the odometry.
|
* @param pose The pose to which to set the odometry.
|
||||||
*/
|
*/
|
||||||
public void resetOdometry(Pose2d pose) {
|
public void resetOdometry(Pose2d pose) {
|
||||||
m_odometry.resetPosition(
|
m_estimator.resetPose(
|
||||||
Rotation2d.fromDegrees(m_gyro.getAngle(IMUAxis.kZ)),
|
|
||||||
new SwerveModulePosition[] {
|
|
||||||
m_frontLeft.getPosition(),
|
|
||||||
m_frontRight.getPosition(),
|
|
||||||
m_rearLeft.getPosition(),
|
|
||||||
m_rearRight.getPosition()
|
|
||||||
},
|
|
||||||
pose
|
pose
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -144,7 +178,7 @@ public class Drivetrain extends SubsystemBase {
|
|||||||
var swerveModuleStates = DrivetrainConstants.kDriveKinematics.toSwerveModuleStates(
|
var swerveModuleStates = DrivetrainConstants.kDriveKinematics.toSwerveModuleStates(
|
||||||
fieldRelative
|
fieldRelative
|
||||||
? ChassisSpeeds.fromFieldRelativeSpeeds(xSpeedDelivered, ySpeedDelivered, rotDelivered,
|
? ChassisSpeeds.fromFieldRelativeSpeeds(xSpeedDelivered, ySpeedDelivered, rotDelivered,
|
||||||
Rotation2d.fromDegrees(m_gyro.getAngle(IMUAxis.kZ)))
|
Rotation2d.fromDegrees(getGyroValue()))
|
||||||
: new ChassisSpeeds(xSpeedDelivered, ySpeedDelivered, rotDelivered));
|
: new ChassisSpeeds(xSpeedDelivered, ySpeedDelivered, rotDelivered));
|
||||||
SwerveDriveKinematics.desaturateWheelSpeeds(
|
SwerveDriveKinematics.desaturateWheelSpeeds(
|
||||||
swerveModuleStates, DrivetrainConstants.kMaxSpeedMetersPerSecond);
|
swerveModuleStates, DrivetrainConstants.kMaxSpeedMetersPerSecond);
|
||||||
@@ -194,7 +228,11 @@ public class Drivetrain extends SubsystemBase {
|
|||||||
|
|
||||||
/** Zeroes the heading of the robot. */
|
/** Zeroes the heading of the robot. */
|
||||||
public void zeroHeading() {
|
public void zeroHeading() {
|
||||||
m_gyro.reset();
|
ahrs.reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getGyroValue() {
|
||||||
|
return ahrs.getAngle() * (DrivetrainConstants.kGyroReversed ? -1 : 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -203,7 +241,7 @@ public class Drivetrain extends SubsystemBase {
|
|||||||
* @return the robot's heading in degrees, from -180 to 180
|
* @return the robot's heading in degrees, from -180 to 180
|
||||||
*/
|
*/
|
||||||
public double getHeading() {
|
public double getHeading() {
|
||||||
return Rotation2d.fromDegrees(m_gyro.getAngle(IMUAxis.kZ)).getDegrees();
|
return Rotation2d.fromDegrees(getGyroValue()).getDegrees();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -212,6 +250,10 @@ public class Drivetrain extends SubsystemBase {
|
|||||||
* @return The turn rate of the robot, in degrees per second
|
* @return The turn rate of the robot, in degrees per second
|
||||||
*/
|
*/
|
||||||
public double getTurnRate() {
|
public double getTurnRate() {
|
||||||
return m_gyro.getRate(IMUAxis.kZ) * (DrivetrainConstants.kGyroReversed ? -1.0 : 1.0);
|
return ahrs.getRate() * (DrivetrainConstants.kGyroReversed ? -1.0 : 1.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addVisionMeasurement(Pose2d pose, double timestamp){
|
||||||
|
m_estimator.addVisionMeasurement(pose, timestamp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,13 +3,17 @@ package frc.robot.subsystems;
|
|||||||
import java.util.function.DoubleSupplier;
|
import java.util.function.DoubleSupplier;
|
||||||
|
|
||||||
import com.revrobotics.RelativeEncoder;
|
import com.revrobotics.RelativeEncoder;
|
||||||
|
import com.revrobotics.spark.ClosedLoopSlot;
|
||||||
|
import com.revrobotics.spark.SparkBase;
|
||||||
|
import com.revrobotics.spark.SparkClosedLoopController;
|
||||||
import com.revrobotics.spark.SparkMax;
|
import com.revrobotics.spark.SparkMax;
|
||||||
|
import com.revrobotics.spark.SparkBase.ControlType;
|
||||||
import com.revrobotics.spark.SparkBase.PersistMode;
|
import com.revrobotics.spark.SparkBase.PersistMode;
|
||||||
import com.revrobotics.spark.SparkBase.ResetMode;
|
import com.revrobotics.spark.SparkBase.ResetMode;
|
||||||
import com.revrobotics.spark.SparkLowLevel.MotorType;
|
import com.revrobotics.spark.SparkLowLevel.MotorType;
|
||||||
|
|
||||||
|
import edu.wpi.first.math.MathUtil;
|
||||||
import edu.wpi.first.math.controller.ElevatorFeedforward;
|
import edu.wpi.first.math.controller.ElevatorFeedforward;
|
||||||
import edu.wpi.first.math.controller.PIDController;
|
|
||||||
import edu.wpi.first.wpilibj.DigitalInput;
|
import edu.wpi.first.wpilibj.DigitalInput;
|
||||||
import edu.wpi.first.wpilibj2.command.Command;
|
import edu.wpi.first.wpilibj2.command.Command;
|
||||||
import edu.wpi.first.wpilibj2.command.SubsystemBase;
|
import edu.wpi.first.wpilibj2.command.SubsystemBase;
|
||||||
@@ -19,13 +23,12 @@ public class Elevator extends SubsystemBase {
|
|||||||
protected SparkMax elevatorMotor1;
|
protected SparkMax elevatorMotor1;
|
||||||
protected SparkMax elevatorMotor2;
|
protected SparkMax elevatorMotor2;
|
||||||
|
|
||||||
|
private SparkClosedLoopController elevatorClosedLoop;
|
||||||
|
|
||||||
protected RelativeEncoder encoder;
|
protected RelativeEncoder encoder;
|
||||||
|
|
||||||
private DigitalInput bottomLimitSwitch;
|
private DigitalInput bottomLimitSwitch;
|
||||||
|
|
||||||
private PIDController positionController;
|
|
||||||
private PIDController velocityController;
|
|
||||||
|
|
||||||
private ElevatorFeedforward feedForward;
|
private ElevatorFeedforward feedForward;
|
||||||
|
|
||||||
public Elevator() {
|
public Elevator() {
|
||||||
@@ -45,8 +48,10 @@ public class Elevator extends SubsystemBase {
|
|||||||
PersistMode.kPersistParameters
|
PersistMode.kPersistParameters
|
||||||
);
|
);
|
||||||
|
|
||||||
|
elevatorClosedLoop = elevatorMotor1.getClosedLoopController();
|
||||||
|
|
||||||
elevatorMotor2.configure(
|
elevatorMotor2.configure(
|
||||||
ElevatorConstants.motorConfig.follow(ElevatorConstants.kElevatorMotor1ID),
|
ElevatorConstants.motorConfig2.follow(ElevatorConstants.kElevatorMotor1ID),
|
||||||
ResetMode.kResetSafeParameters,
|
ResetMode.kResetSafeParameters,
|
||||||
PersistMode.kPersistParameters
|
PersistMode.kPersistParameters
|
||||||
);
|
);
|
||||||
@@ -57,17 +62,13 @@ public class Elevator extends SubsystemBase {
|
|||||||
ElevatorConstants.kBottomLimitSwitchID
|
ElevatorConstants.kBottomLimitSwitchID
|
||||||
);
|
);
|
||||||
|
|
||||||
positionController = new PIDController(
|
/*
|
||||||
ElevatorConstants.kPositionControllerP,
|
|
||||||
ElevatorConstants.kPositionControllerI,
|
|
||||||
ElevatorConstants.kPositionControllerD
|
|
||||||
);
|
|
||||||
|
|
||||||
velocityController = new PIDController(
|
velocityController = new PIDController(
|
||||||
ElevatorConstants.kVelocityControllerP,
|
ElevatorConstants.kVelocityControllerP,
|
||||||
ElevatorConstants.kVelocityControllerI,
|
ElevatorConstants.kVelocityControllerI,
|
||||||
ElevatorConstants.kVelocityControllerD
|
ElevatorConstants.kVelocityControllerD
|
||||||
);
|
);
|
||||||
|
*/
|
||||||
|
|
||||||
feedForward = new ElevatorFeedforward(
|
feedForward = new ElevatorFeedforward(
|
||||||
ElevatorConstants.kFeedForwardS,
|
ElevatorConstants.kFeedForwardS,
|
||||||
@@ -76,6 +77,13 @@ public class Elevator extends SubsystemBase {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void periodic() {
|
||||||
|
if (!getBottomLimitSwitch()) {
|
||||||
|
encoder.setPosition(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether or not the motion is safe relative to the encoder's current position
|
* Returns whether or not the motion is safe relative to the encoder's current position
|
||||||
* and the elevator brace position
|
* and the elevator brace position
|
||||||
@@ -94,13 +102,30 @@ public class Elevator extends SubsystemBase {
|
|||||||
* @return Is the motion safe
|
* @return Is the motion safe
|
||||||
*/
|
*/
|
||||||
public boolean isMotionSafe(double motionTarget) {
|
public boolean isMotionSafe(double motionTarget) {
|
||||||
return motionTarget > ElevatorConstants.kElevatorBracePosition;
|
return motionTarget > ElevatorConstants.kBracePosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
//manual command that keeps ouput speed consistent no matter the direction
|
/**
|
||||||
public Command runElevator(DoubleSupplier speed) {
|
* A manual translation command that uses feed forward calculation to maintain position
|
||||||
|
*
|
||||||
|
* @param speed The speed at which the elevator translates
|
||||||
|
* @return Sets motor voltage to translate the elevator and maintain position
|
||||||
|
*/
|
||||||
|
public Command runManualElevator(double speed) {
|
||||||
return run(() -> {
|
return run(() -> {
|
||||||
double realSpeedTarget = speed.getAsDouble() * ElevatorConstants.kElevatorMaxVelocity;
|
elevatorMotor1.set(speed);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A manual translation command that will move the elevator using a consistent velocity disregarding direction
|
||||||
|
*
|
||||||
|
* @param speed How fast the elevator moves
|
||||||
|
* @return Sets motor voltage to move the elevator relative to the speed parameter
|
||||||
|
*
|
||||||
|
public Command runAssistedElevator(DoubleSupplier speed) {
|
||||||
|
return run(() -> {
|
||||||
|
double realSpeedTarget = speed.getAsDouble() * ElevatorConstants.kMaxVelocity;
|
||||||
|
|
||||||
double voltsOut = velocityController.calculate(
|
double voltsOut = velocityController.calculate(
|
||||||
encoder.getVelocity(),
|
encoder.getVelocity(),
|
||||||
@@ -108,16 +133,64 @@ public class Elevator extends SubsystemBase {
|
|||||||
) + feedForward.calculate(realSpeedTarget);
|
) + feedForward.calculate(realSpeedTarget);
|
||||||
|
|
||||||
elevatorMotor1.setVoltage(voltsOut);
|
elevatorMotor1.setVoltage(voltsOut);
|
||||||
}).until(bottomLimitSwitch::get);
|
}).until(
|
||||||
|
() -> bottomLimitSwitch.get() || encoder.getPosition() >= ElevatorConstants.kMaxHeight);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
public Command manualControl(DoubleSupplier speed){
|
||||||
|
return run(() -> {
|
||||||
|
elevatorClosedLoop.setReference(speed.getAsDouble(), ControlType.kDutyCycle);
|
||||||
|
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Moves the elevator to a target destination (setpoint).
|
||||||
|
* If the setpoint is 0, the elevator will creep down to hit the limit switch
|
||||||
|
*
|
||||||
|
* @param setpoint Target destination of the subsystem
|
||||||
|
* @param timeout Time to achieve the setpoint before quitting
|
||||||
|
* @return Sets motor voltage to achieve the target destination
|
||||||
|
*/
|
||||||
|
public Command goToSetpoint(double setpoint) {
|
||||||
|
double clampedSetpoint = MathUtil.clamp(
|
||||||
|
setpoint,
|
||||||
|
0,
|
||||||
|
ElevatorConstants.kMaxHeight
|
||||||
|
);
|
||||||
|
|
||||||
//go to setpoint command
|
return run(() -> {
|
||||||
public Command goToSetpoint(double setpoint, double timeout) {
|
|
||||||
|
elevatorClosedLoop.setReference(clampedSetpoint,
|
||||||
|
SparkBase.ControlType.kMAXMotionPositionControl,
|
||||||
|
ClosedLoopSlot.kSlot0,
|
||||||
|
feedForward.calculate(0)
|
||||||
|
);
|
||||||
|
|
||||||
|
});
|
||||||
|
/*
|
||||||
|
if (clampedSetpoint == 0) {
|
||||||
return run(() -> {
|
return run(() -> {
|
||||||
double voltsOut = positionController.calculate(
|
double voltsOut = positionController.calculate(
|
||||||
encoder.getPosition(),
|
encoder.getPosition(),
|
||||||
setpoint
|
clampedSetpoint
|
||||||
|
) + feedForward.calculate(0);
|
||||||
|
|
||||||
|
elevatorMotor1.setVoltage(voltsOut);
|
||||||
|
}).until(
|
||||||
|
() -> positionController.atSetpoint() || bottomLimitSwitch.get()
|
||||||
|
).withTimeout(timeout)
|
||||||
|
.andThen(Commands.either(
|
||||||
|
runAssistedElevator(() -> 0),
|
||||||
|
runAssistedElevator(() -> -.2),
|
||||||
|
bottomLimitSwitch::get
|
||||||
|
)).withTimeout(timeout);
|
||||||
|
} else {
|
||||||
|
return run(() -> {
|
||||||
|
double voltsOut = positionController.calculate(
|
||||||
|
encoder.getPosition(),
|
||||||
|
clampedSetpoint
|
||||||
) + feedForward.calculate(0);
|
) + feedForward.calculate(0);
|
||||||
|
|
||||||
elevatorMotor1.setVoltage(voltsOut);
|
elevatorMotor1.setVoltage(voltsOut);
|
||||||
@@ -125,8 +198,26 @@ public class Elevator extends SubsystemBase {
|
|||||||
() -> positionController.atSetpoint() || bottomLimitSwitch.get()
|
() -> positionController.atSetpoint() || bottomLimitSwitch.get()
|
||||||
).withTimeout(timeout);
|
).withTimeout(timeout);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the current encoder position
|
||||||
|
*
|
||||||
|
* @return Current encoder position
|
||||||
|
*/
|
||||||
public double getEncoderPosition() {
|
public double getEncoderPosition() {
|
||||||
return encoder.getPosition();
|
return encoder.getPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the value of the bottom limit switch on the elevator (false = disabled, true = enabled)
|
||||||
|
*
|
||||||
|
* @return The value of bottomLimitSwitch
|
||||||
|
*/
|
||||||
|
public boolean getBottomLimitSwitch() {
|
||||||
|
return bottomLimitSwitch.get();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
package frc.robot.subsystems;
|
|
||||||
|
|
||||||
import com.revrobotics.spark.SparkMax;
|
|
||||||
import com.revrobotics.spark.SparkLowLevel.MotorType;
|
|
||||||
|
|
||||||
import edu.wpi.first.wpilibj.DigitalInput;
|
|
||||||
import edu.wpi.first.wpilibj2.command.Command;
|
|
||||||
import edu.wpi.first.wpilibj2.command.SubsystemBase;
|
|
||||||
import frc.robot.constants.IndexerConstants;
|
|
||||||
|
|
||||||
public class Indexer extends SubsystemBase {
|
|
||||||
private SparkMax indexerMotor;
|
|
||||||
|
|
||||||
private DigitalInput indexerBeamBreak;
|
|
||||||
|
|
||||||
public Indexer() {
|
|
||||||
indexerMotor = new SparkMax(
|
|
||||||
IndexerConstants.kIndexerMotorID,
|
|
||||||
MotorType.kBrushless
|
|
||||||
);
|
|
||||||
|
|
||||||
indexerBeamBreak = new DigitalInput(IndexerConstants.kIndexerBeamBreakID);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Command runIndexer(double speed) {
|
|
||||||
return run(() -> {
|
|
||||||
indexerMotor.set(speed);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public Command indexCoral(double speed) {
|
|
||||||
return run(() -> {
|
|
||||||
indexerMotor.set(speed);
|
|
||||||
}).until(indexerBeamBreak::get);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -15,21 +15,22 @@ import com.revrobotics.spark.SparkBase.ControlType;
|
|||||||
import com.revrobotics.spark.SparkBase.PersistMode;
|
import com.revrobotics.spark.SparkBase.PersistMode;
|
||||||
import com.revrobotics.spark.SparkBase.ResetMode;
|
import com.revrobotics.spark.SparkBase.ResetMode;
|
||||||
import com.revrobotics.spark.SparkLowLevel.MotorType;
|
import com.revrobotics.spark.SparkLowLevel.MotorType;
|
||||||
|
import com.ctre.phoenix6.controls.VelocityVoltage;
|
||||||
|
import com.ctre.phoenix6.hardware.TalonFX;
|
||||||
import com.revrobotics.AbsoluteEncoder;
|
import com.revrobotics.AbsoluteEncoder;
|
||||||
import com.revrobotics.RelativeEncoder;
|
|
||||||
|
|
||||||
import frc.robot.constants.ModuleConstants;
|
import frc.robot.constants.ModuleConstants;
|
||||||
|
|
||||||
public class MAXSwerveModule {
|
public class MAXSwerveModule {
|
||||||
private final SparkMax m_drivingSpark;
|
private final TalonFX m_drive;
|
||||||
private final SparkMax m_turningSpark;
|
private final SparkMax m_turningSpark;
|
||||||
|
|
||||||
private final RelativeEncoder m_drivingEncoder;
|
|
||||||
private final AbsoluteEncoder m_turningEncoder;
|
private final AbsoluteEncoder m_turningEncoder;
|
||||||
|
|
||||||
private final SparkClosedLoopController m_drivingClosedLoopController;
|
|
||||||
private final SparkClosedLoopController m_turningClosedLoopController;
|
private final SparkClosedLoopController m_turningClosedLoopController;
|
||||||
|
|
||||||
|
private final VelocityVoltage driveVelocityRequest;
|
||||||
|
|
||||||
private double m_chassisAngularOffset = 0;
|
private double m_chassisAngularOffset = 0;
|
||||||
private SwerveModuleState m_desiredState = new SwerveModuleState(0.0, new Rotation2d());
|
private SwerveModuleState m_desiredState = new SwerveModuleState(0.0, new Rotation2d());
|
||||||
|
|
||||||
@@ -40,26 +41,29 @@ public class MAXSwerveModule {
|
|||||||
* Encoder.
|
* Encoder.
|
||||||
*/
|
*/
|
||||||
public MAXSwerveModule(int drivingCANId, int turningCANId, double chassisAngularOffset) {
|
public MAXSwerveModule(int drivingCANId, int turningCANId, double chassisAngularOffset) {
|
||||||
m_drivingSpark = new SparkMax(drivingCANId, MotorType.kBrushless);
|
m_drive = new TalonFX(drivingCANId);
|
||||||
m_turningSpark = new SparkMax(turningCANId, MotorType.kBrushless);
|
m_turningSpark = new SparkMax(turningCANId, MotorType.kBrushless);
|
||||||
|
|
||||||
m_drivingEncoder = m_drivingSpark.getEncoder();
|
|
||||||
m_turningEncoder = m_turningSpark.getAbsoluteEncoder();
|
m_turningEncoder = m_turningSpark.getAbsoluteEncoder();
|
||||||
|
|
||||||
m_drivingClosedLoopController = m_drivingSpark.getClosedLoopController();
|
|
||||||
m_turningClosedLoopController = m_turningSpark.getClosedLoopController();
|
m_turningClosedLoopController = m_turningSpark.getClosedLoopController();
|
||||||
|
|
||||||
|
driveVelocityRequest = new VelocityVoltage(0).withSlot(0);
|
||||||
|
|
||||||
// Apply the respective configurations to the SPARKS. Reset parameters before
|
// Apply the respective configurations to the SPARKS. Reset parameters before
|
||||||
// applying the configuration to bring the SPARK to a known good state. Persist
|
// applying the configuration to bring the SPARK to a known good state. Persist
|
||||||
// the settings to the SPARK to avoid losing them on a power cycle.
|
// the settings to the SPARK to avoid losing them on a power cycle.
|
||||||
m_drivingSpark.configure(ModuleConstants.drivingConfig, ResetMode.kResetSafeParameters,
|
m_drive.getConfigurator().apply(ModuleConstants.kDriveCurrentLimitConfig);
|
||||||
PersistMode.kPersistParameters);
|
m_drive.getConfigurator().apply(ModuleConstants.kDriveFeedConfig);
|
||||||
|
m_drive.getConfigurator().apply(ModuleConstants.kDriveMotorConfig);
|
||||||
|
m_drive.getConfigurator().apply(ModuleConstants.kDriveSlot0Config);
|
||||||
|
|
||||||
m_turningSpark.configure(ModuleConstants.turningConfig, ResetMode.kResetSafeParameters,
|
m_turningSpark.configure(ModuleConstants.turningConfig, ResetMode.kResetSafeParameters,
|
||||||
PersistMode.kPersistParameters);
|
PersistMode.kPersistParameters);
|
||||||
|
|
||||||
m_chassisAngularOffset = chassisAngularOffset;
|
m_chassisAngularOffset = chassisAngularOffset;
|
||||||
m_desiredState.angle = new Rotation2d(m_turningEncoder.getPosition());
|
m_desiredState.angle = new Rotation2d(m_turningEncoder.getPosition());
|
||||||
m_drivingEncoder.setPosition(0);
|
m_drive.setPosition(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -70,7 +74,7 @@ public class MAXSwerveModule {
|
|||||||
public SwerveModuleState getState() {
|
public SwerveModuleState getState() {
|
||||||
// Apply chassis angular offset to the encoder position to get the position
|
// Apply chassis angular offset to the encoder position to get the position
|
||||||
// relative to the chassis.
|
// relative to the chassis.
|
||||||
return new SwerveModuleState(m_drivingEncoder.getVelocity(),
|
return new SwerveModuleState(m_drive.getVelocity().getValueAsDouble(),
|
||||||
new Rotation2d(m_turningEncoder.getPosition() - m_chassisAngularOffset));
|
new Rotation2d(m_turningEncoder.getPosition() - m_chassisAngularOffset));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,8 +86,7 @@ public class MAXSwerveModule {
|
|||||||
public SwerveModulePosition getPosition() {
|
public SwerveModulePosition getPosition() {
|
||||||
// Apply chassis angular offset to the encoder position to get the position
|
// Apply chassis angular offset to the encoder position to get the position
|
||||||
// relative to the chassis.
|
// relative to the chassis.
|
||||||
return new SwerveModulePosition(
|
return new SwerveModulePosition(m_drive.getPosition().getValueAsDouble(),
|
||||||
m_drivingEncoder.getPosition(),
|
|
||||||
new Rotation2d(m_turningEncoder.getPosition() - m_chassisAngularOffset));
|
new Rotation2d(m_turningEncoder.getPosition() - m_chassisAngularOffset));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,14 +105,21 @@ public class MAXSwerveModule {
|
|||||||
correctedDesiredState.optimize(new Rotation2d(m_turningEncoder.getPosition()));
|
correctedDesiredState.optimize(new Rotation2d(m_turningEncoder.getPosition()));
|
||||||
|
|
||||||
// Command driving and turning SPARKS towards their respective setpoints.
|
// Command driving and turning SPARKS towards their respective setpoints.
|
||||||
m_drivingClosedLoopController.setReference(correctedDesiredState.speedMetersPerSecond, ControlType.kVelocity);
|
m_drive.setControl(
|
||||||
|
driveVelocityRequest.withVelocity(
|
||||||
|
correctedDesiredState.speedMetersPerSecond
|
||||||
|
).withFeedForward(
|
||||||
|
correctedDesiredState.speedMetersPerSecond
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
m_turningClosedLoopController.setReference(correctedDesiredState.angle.getRadians(), ControlType.kPosition);
|
m_turningClosedLoopController.setReference(correctedDesiredState.angle.getRadians(), ControlType.kPosition);
|
||||||
|
|
||||||
m_desiredState = desiredState;
|
m_desiredState = desiredState;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setVoltageDrive(double voltage){
|
public void setVoltageDrive(double voltage){
|
||||||
m_drivingSpark.setVoltage(voltage);
|
m_drive.setVoltage(voltage);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setVoltageTurn(double voltage) {
|
public void setVoltageTurn(double voltage) {
|
||||||
@@ -117,7 +127,7 @@ public class MAXSwerveModule {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public double getVoltageDrive() {
|
public double getVoltageDrive() {
|
||||||
return m_drivingSpark.get() * RobotController.getBatteryVoltage();
|
return m_drive.get() * RobotController.getBatteryVoltage();
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getVoltageTurn() {
|
public double getVoltageTurn() {
|
||||||
@@ -126,6 +136,6 @@ public class MAXSwerveModule {
|
|||||||
|
|
||||||
/** Zeroes all the SwerveModule encoders. */
|
/** Zeroes all the SwerveModule encoders. */
|
||||||
public void resetEncoders() {
|
public void resetEncoders() {
|
||||||
m_drivingEncoder.setPosition(0);
|
m_drive.setPosition(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
package frc.robot.subsystems;
|
package frc.robot.subsystems;
|
||||||
|
|
||||||
|
import java.util.function.DoubleSupplier;
|
||||||
|
|
||||||
import com.revrobotics.spark.SparkMax;
|
import com.revrobotics.spark.SparkMax;
|
||||||
|
import com.revrobotics.spark.SparkBase.PersistMode;
|
||||||
|
import com.revrobotics.spark.SparkBase.ResetMode;
|
||||||
import com.revrobotics.spark.SparkLowLevel.MotorType;
|
import com.revrobotics.spark.SparkLowLevel.MotorType;
|
||||||
|
|
||||||
import edu.wpi.first.wpilibj.DigitalInput;
|
import edu.wpi.first.wpilibj.DigitalInput;
|
||||||
@@ -12,7 +16,7 @@ public class Manipulator extends SubsystemBase {
|
|||||||
private SparkMax manipulatorMotor;
|
private SparkMax manipulatorMotor;
|
||||||
|
|
||||||
private DigitalInput coralBeamBreak;
|
private DigitalInput coralBeamBreak;
|
||||||
private DigitalInput algaeBeamBreak;
|
// private DigitalInput algaeBeamBreak;
|
||||||
|
|
||||||
public Manipulator() {
|
public Manipulator() {
|
||||||
manipulatorMotor = new SparkMax(
|
manipulatorMotor = new SparkMax(
|
||||||
@@ -20,19 +24,60 @@ public class Manipulator extends SubsystemBase {
|
|||||||
MotorType.kBrushless
|
MotorType.kBrushless
|
||||||
);
|
);
|
||||||
|
|
||||||
|
manipulatorMotor.configure(
|
||||||
|
ManipulatorConstants.motorConfig,
|
||||||
|
ResetMode.kResetSafeParameters,
|
||||||
|
PersistMode.kPersistParameters
|
||||||
|
);
|
||||||
|
|
||||||
coralBeamBreak = new DigitalInput(ManipulatorConstants.kCoralBeamBreakID);
|
coralBeamBreak = new DigitalInput(ManipulatorConstants.kCoralBeamBreakID);
|
||||||
algaeBeamBreak = new DigitalInput(ManipulatorConstants.kAlgaeBeamBreakID);
|
// algaeBeamBreak = new DigitalInput(ManipulatorConstants.kAlgaeBeamBreakID);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Command runManipulator(double speed) {
|
/**
|
||||||
|
* The default command for the manipulator that either stops the manipulator or slowly
|
||||||
|
* runs the manipulator to retain the algae
|
||||||
|
*
|
||||||
|
* @return Returns a command that sets the speed of the motor
|
||||||
|
*/
|
||||||
|
public Command defaultCommand() {
|
||||||
return run(() -> {
|
return run(() -> {
|
||||||
manipulatorMotor.set(speed);
|
//runUntilCollected(0.1);
|
||||||
|
manipulatorMotor.set(0);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public Command runUntilCollected(double speed, boolean coral) {
|
/**
|
||||||
|
* Runs the manipulator at a set speed with the direction based on the coral parameter
|
||||||
|
*
|
||||||
|
* @param speed The speed at which the manipulator runs
|
||||||
|
* @param coral Is the manipulator manipulating a coral? (True = Coral, False = Algae)
|
||||||
|
* @return Returns a command that sets the speed of the motor
|
||||||
|
*/
|
||||||
|
public Command runManipulator(DoubleSupplier speed, boolean coral) {
|
||||||
return run(() -> {
|
return run(() -> {
|
||||||
manipulatorMotor.set(coral ? speed : speed * -1);
|
manipulatorMotor.set(
|
||||||
}).until(() -> coralBeamBreak.get() || algaeBeamBreak.get());
|
coral ? speed.getAsDouble() : speed.getAsDouble() * -1
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Runs the manipulator until either the algae or coral beam break reads true
|
||||||
|
*
|
||||||
|
* @param speed The speed at which the manipulator is run
|
||||||
|
* @param coral Is the object a coral? (True = Coral, False = Algae)
|
||||||
|
* @return Returns a command that sets the speed of the motor
|
||||||
|
*/
|
||||||
|
public Command runUntilCollected(DoubleSupplier speed) {
|
||||||
|
return run(() -> {
|
||||||
|
manipulatorMotor.set(
|
||||||
|
speed.getAsDouble()
|
||||||
|
);
|
||||||
|
}).until(() -> !coralBeamBreak.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getCoralBeamBreak() {
|
||||||
|
return coralBeamBreak.get();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
136
src/main/java/frc/robot/subsystems/ManipulatorPivot.java
Normal file
136
src/main/java/frc/robot/subsystems/ManipulatorPivot.java
Normal file
@@ -0,0 +1,136 @@
|
|||||||
|
package frc.robot.subsystems;
|
||||||
|
|
||||||
|
import com.revrobotics.spark.SparkMax;
|
||||||
|
import com.revrobotics.spark.ClosedLoopSlot;
|
||||||
|
import com.revrobotics.spark.SparkAbsoluteEncoder;
|
||||||
|
import com.revrobotics.spark.SparkBase;
|
||||||
|
import com.revrobotics.spark.SparkBase.PersistMode;
|
||||||
|
import com.revrobotics.spark.SparkBase.ResetMode;
|
||||||
|
import com.revrobotics.spark.SparkClosedLoopController;
|
||||||
|
import com.revrobotics.spark.SparkLowLevel.MotorType;
|
||||||
|
|
||||||
|
import edu.wpi.first.math.MathUtil;
|
||||||
|
import edu.wpi.first.math.controller.ArmFeedforward;
|
||||||
|
import edu.wpi.first.wpilibj2.command.Command;
|
||||||
|
import edu.wpi.first.wpilibj2.command.SubsystemBase;
|
||||||
|
import frc.robot.constants.ManipulatorPivotConstants;
|
||||||
|
|
||||||
|
public class ManipulatorPivot extends SubsystemBase {
|
||||||
|
protected SparkMax armMotor;
|
||||||
|
|
||||||
|
private ArmFeedforward feedForward;
|
||||||
|
|
||||||
|
private SparkClosedLoopController pivotClosedLoopController;
|
||||||
|
private SparkAbsoluteEncoder absoluteEncoder;
|
||||||
|
|
||||||
|
public ManipulatorPivot() {
|
||||||
|
armMotor = new SparkMax(
|
||||||
|
ManipulatorPivotConstants.kArmMotorID,
|
||||||
|
MotorType.kBrushless
|
||||||
|
);
|
||||||
|
|
||||||
|
armMotor.configure(
|
||||||
|
ManipulatorPivotConstants.motorConfig,
|
||||||
|
ResetMode.kResetSafeParameters,
|
||||||
|
PersistMode.kPersistParameters
|
||||||
|
);
|
||||||
|
|
||||||
|
pivotClosedLoopController = armMotor.getClosedLoopController();
|
||||||
|
absoluteEncoder = armMotor.getAbsoluteEncoder();
|
||||||
|
|
||||||
|
feedForward = new ArmFeedforward(
|
||||||
|
ManipulatorPivotConstants.kFeedForwardS,
|
||||||
|
ManipulatorPivotConstants.kFeedForwardG,
|
||||||
|
ManipulatorPivotConstants.kFeedForwardV
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether or not the motion is safe relative to the encoder's current position
|
||||||
|
* and the arm safe stow position
|
||||||
|
*
|
||||||
|
* @return Is the motion safe
|
||||||
|
*/
|
||||||
|
public boolean isMotionSafe() {
|
||||||
|
return isMotionSafe(getEncoderPosition());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether or not the motion is safe relative to some target position and the
|
||||||
|
* arm safe stow position
|
||||||
|
*
|
||||||
|
* @param motionTarget The target position to determine the safety of
|
||||||
|
* @return Is the motion safe
|
||||||
|
*/
|
||||||
|
public boolean isMotionSafe(double motionTarget) {
|
||||||
|
return motionTarget > ManipulatorPivotConstants.kArmSafeStowPosition;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A manual rotation command that will move the elevator using a consistent velocity disregarding direction
|
||||||
|
*
|
||||||
|
* @param speed The velocity at which the arm rotates
|
||||||
|
* @return Sets motor voltage to achieve the target velocity
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
public Command runAssistedPivot(DoubleSupplier speed) {
|
||||||
|
double clampedSpeed = MathUtil.clamp(
|
||||||
|
speed.getAsDouble(),
|
||||||
|
-1,
|
||||||
|
1
|
||||||
|
);
|
||||||
|
|
||||||
|
return run(() -> {
|
||||||
|
double realSpeedTarget = clampedSpeed * ManipulatorPivotConstants.kPivotMaxVelocity;
|
||||||
|
|
||||||
|
double voltsOut = velocityController.calculate(
|
||||||
|
getEncoderVelocity(),
|
||||||
|
realSpeedTarget
|
||||||
|
) + feedForward.calculate(
|
||||||
|
getEncoderPosition(),
|
||||||
|
getEncoderVelocity()
|
||||||
|
);
|
||||||
|
|
||||||
|
armMotor.setVoltage(voltsOut);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* Moves the arm to a target destination (setpoint)
|
||||||
|
*
|
||||||
|
* @param setpoint Target destination of the subsystem
|
||||||
|
* @param timeout Time to achieve the setpoint before quitting
|
||||||
|
* @return Sets motor voltage to achieve the target destination
|
||||||
|
*/
|
||||||
|
public Command goToSetpoint(double setpoint) {
|
||||||
|
double clampedSetpoint = MathUtil.clamp(
|
||||||
|
setpoint,
|
||||||
|
0,
|
||||||
|
ManipulatorPivotConstants.kRotationLimit
|
||||||
|
);
|
||||||
|
|
||||||
|
return run(() -> {
|
||||||
|
pivotClosedLoopController.setReference(clampedSetpoint,
|
||||||
|
SparkBase.ControlType.kMAXMotionPositionControl,
|
||||||
|
ClosedLoopSlot.kSlot0,
|
||||||
|
feedForward.calculate(absoluteEncoder.getPosition() + ManipulatorPivotConstants.kFFGravityOffset, absoluteEncoder.getVelocity()));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the CANCoder's position in radians
|
||||||
|
*
|
||||||
|
* @return CANCoder's position in radians
|
||||||
|
*/
|
||||||
|
public double getEncoderPosition() {
|
||||||
|
return absoluteEncoder.getPosition();
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Returns the CANCoder's velocity in radians per second
|
||||||
|
*
|
||||||
|
* @return CANCoder's velocity in radians per second
|
||||||
|
*/
|
||||||
|
public double getEncoderVelocity() {
|
||||||
|
return absoluteEncoder.getVelocity();
|
||||||
|
}
|
||||||
|
}
|
||||||
146
src/main/java/frc/robot/subsystems/Vision.java
Normal file
146
src/main/java/frc/robot/subsystems/Vision.java
Normal file
@@ -0,0 +1,146 @@
|
|||||||
|
package frc.robot.subsystems;
|
||||||
|
|
||||||
|
import java.util.function.DoubleSupplier;
|
||||||
|
|
||||||
|
import edu.wpi.first.math.geometry.Pose2d;
|
||||||
|
import edu.wpi.first.math.geometry.Rotation2d;
|
||||||
|
import edu.wpi.first.math.geometry.Transform2d;
|
||||||
|
import edu.wpi.first.math.geometry.Translation2d;
|
||||||
|
import edu.wpi.first.networktables.BooleanSubscriber;
|
||||||
|
import edu.wpi.first.networktables.DoubleSubscriber;
|
||||||
|
import edu.wpi.first.networktables.NetworkTable;
|
||||||
|
import edu.wpi.first.networktables.NetworkTableInstance;
|
||||||
|
import frc.robot.constants.VisionConstants;
|
||||||
|
|
||||||
|
public class Vision{
|
||||||
|
|
||||||
|
private DoubleSubscriber blackRobotRelativeX;
|
||||||
|
private DoubleSubscriber blackRobotRelativeY;
|
||||||
|
private DoubleSubscriber blackRobotRelativeZ;
|
||||||
|
|
||||||
|
private DoubleSubscriber blackClosestTag;
|
||||||
|
private BooleanSubscriber blackTagDetected;
|
||||||
|
|
||||||
|
private DoubleSubscriber blackFramerate;
|
||||||
|
|
||||||
|
private DoubleSubscriber orangeRobotRelativeX;
|
||||||
|
private DoubleSubscriber orangeRobotRelativeY;
|
||||||
|
private DoubleSubscriber orangeRobotRelativeZ;
|
||||||
|
|
||||||
|
private DoubleSubscriber orangeClosestTag;
|
||||||
|
private BooleanSubscriber orangeTagDetected;
|
||||||
|
|
||||||
|
private DoubleSubscriber orangeFramerate;
|
||||||
|
|
||||||
|
private DoubleSupplier gyroAngle;
|
||||||
|
|
||||||
|
public Vision(DoubleSupplier gyroAngle){
|
||||||
|
NetworkTableInstance inst = NetworkTableInstance.getDefault();
|
||||||
|
|
||||||
|
NetworkTable blackVisionTable = inst.getTable("black_Fiducial");
|
||||||
|
NetworkTable orangeVisionTable = inst.getTable("orange_Fiducial");
|
||||||
|
|
||||||
|
blackRobotRelativeX = orangeVisionTable.getDoubleTopic("blackRelativeX").subscribe(0.0);
|
||||||
|
blackRobotRelativeY = orangeVisionTable.getDoubleTopic("blackRelativeY").subscribe(0.0);
|
||||||
|
blackRobotRelativeZ = orangeVisionTable.getDoubleTopic("blackRelativeZ").subscribe(0.0);
|
||||||
|
|
||||||
|
blackClosestTag = blackVisionTable.getDoubleTopic("blackClosestTag").subscribe(0.0);
|
||||||
|
blackTagDetected = blackVisionTable.getBooleanTopic("blackTagDetected").subscribe(false);
|
||||||
|
|
||||||
|
blackFramerate = blackVisionTable.getDoubleTopic("blackFPS").subscribe(0.0);
|
||||||
|
|
||||||
|
orangeRobotRelativeX = orangeVisionTable.getDoubleTopic("orangeRelativeX").subscribe(0.0);
|
||||||
|
orangeRobotRelativeY = orangeVisionTable.getDoubleTopic("orangeRelativeY").subscribe(0.0);
|
||||||
|
orangeRobotRelativeZ = orangeVisionTable.getDoubleTopic("orangeRelativeZ").subscribe(0.0);
|
||||||
|
|
||||||
|
orangeClosestTag = orangeVisionTable.getDoubleTopic("orangeClosestTag").subscribe(0.0);
|
||||||
|
orangeTagDetected = orangeVisionTable.getBooleanTopic("orangeTagDetected").subscribe(false);
|
||||||
|
|
||||||
|
orangeFramerate = orangeVisionTable.getDoubleTopic("orangeFPS").subscribe(0.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Pose2d relativeToGlobalPose2d(int tagID, Translation2d relativeCoords, Rotation2d gyroAngle){
|
||||||
|
Pose2d tag2dPose = new Pose2d(VisionConstants.globalTagCoords[tagID][0],
|
||||||
|
VisionConstants.globalTagCoords[tagID][1],
|
||||||
|
new Rotation2d());
|
||||||
|
|
||||||
|
Pose2d relative = new Pose2d(relativeCoords, gyroAngle);
|
||||||
|
|
||||||
|
Transform2d relative2dTransformation = new Transform2d(relative.getTranslation(), relative.getRotation());
|
||||||
|
|
||||||
|
Pose2d globalPose = tag2dPose.transformBy(relative2dTransformation.inverse());
|
||||||
|
|
||||||
|
return new Pose2d(globalPose.getTranslation(), gyroAngle);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Pose2d getBlackGlobalPose(){
|
||||||
|
|
||||||
|
return relativeToGlobalPose2d(getBlackClosestTag(),
|
||||||
|
new Translation2d(getBlackRelativeX(), getBlackRelativeY()),
|
||||||
|
new Rotation2d(gyroAngle.getAsDouble()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getBlackRelativeX(){
|
||||||
|
return blackRobotRelativeX.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getBlackRelativeY(){
|
||||||
|
return blackRobotRelativeY.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getBlackRelativeZ(){
|
||||||
|
return blackRobotRelativeZ.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getBlackClosestTag(){
|
||||||
|
return (int) blackClosestTag.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getBlackTimeStamp(){
|
||||||
|
return blackRobotRelativeX.getLastChange();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getBlackTagDetected(){
|
||||||
|
return blackTagDetected.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getBlackFPS(){
|
||||||
|
return blackFramerate.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Pose2d getOrangeGlobalPose(){
|
||||||
|
|
||||||
|
return relativeToGlobalPose2d(getBlackClosestTag(),
|
||||||
|
new Translation2d(getBlackRelativeX(), getBlackRelativeY()),
|
||||||
|
new Rotation2d(gyroAngle.getAsDouble()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getOrangeRelativeX(){
|
||||||
|
return orangeRobotRelativeX.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getOrangeRelativeY(){
|
||||||
|
return orangeRobotRelativeY.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getOrangeRelativeZ(){
|
||||||
|
return orangeRobotRelativeZ.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getOrangeClosestTag(){
|
||||||
|
return (int) orangeClosestTag.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getOrangeTimeStamp(){
|
||||||
|
return orangeRobotRelativeX.getLastChange();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getOrangeTagDetected(){
|
||||||
|
return orangeTagDetected.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getOrangeFPS(){
|
||||||
|
return orangeFramerate.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
package frc.robot.subsystems.sysid;
|
||||||
|
|
||||||
|
import static edu.wpi.first.units.Units.Volts;
|
||||||
|
import static edu.wpi.first.units.Units.Radians;
|
||||||
|
import static edu.wpi.first.units.Units.RadiansPerSecond;
|
||||||
|
|
||||||
|
import edu.wpi.first.units.measure.MutAngle;
|
||||||
|
import edu.wpi.first.units.measure.MutAngularVelocity;
|
||||||
|
import edu.wpi.first.units.measure.MutVoltage;
|
||||||
|
import edu.wpi.first.wpilibj.RobotController;
|
||||||
|
import edu.wpi.first.wpilibj2.command.Command;
|
||||||
|
import edu.wpi.first.wpilibj2.command.sysid.SysIdRoutine;
|
||||||
|
import frc.robot.constants.ManipulatorPivotConstants;
|
||||||
|
import frc.robot.subsystems.ManipulatorPivot;
|
||||||
|
|
||||||
|
public class ManipulatorPivotSysID extends ManipulatorPivot {
|
||||||
|
private MutVoltage appliedVoltage;
|
||||||
|
|
||||||
|
private MutAngle pivotPosition;
|
||||||
|
|
||||||
|
private MutAngularVelocity pivotVelocity;
|
||||||
|
|
||||||
|
private SysIdRoutine routine;
|
||||||
|
|
||||||
|
public ManipulatorPivotSysID() {
|
||||||
|
super();
|
||||||
|
|
||||||
|
appliedVoltage = Volts.mutable(0);
|
||||||
|
|
||||||
|
pivotPosition = Radians.mutable(0);
|
||||||
|
|
||||||
|
pivotVelocity = RadiansPerSecond.mutable(0);
|
||||||
|
|
||||||
|
routine = new SysIdRoutine(
|
||||||
|
ManipulatorPivotConstants.kSysIDConfig,
|
||||||
|
new SysIdRoutine.Mechanism(
|
||||||
|
armMotor::setVoltage,
|
||||||
|
(log) -> {
|
||||||
|
log.motor("armMotor")
|
||||||
|
.voltage(appliedVoltage.mut_replace(
|
||||||
|
armMotor.get() * RobotController.getBatteryVoltage(), Volts
|
||||||
|
))
|
||||||
|
.angularPosition(pivotPosition.mut_replace(
|
||||||
|
getEncoderPosition(), Radians
|
||||||
|
))
|
||||||
|
.angularVelocity(pivotVelocity.mut_replace(
|
||||||
|
getEncoderVelocity(), RadiansPerSecond
|
||||||
|
));
|
||||||
|
},
|
||||||
|
this
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Command sysIdQuasistatic(SysIdRoutine.Direction direction) {
|
||||||
|
return routine.quasistatic(direction);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Command sysIdDynamic(SysIdRoutine.Direction direction) {
|
||||||
|
return routine.dynamic(direction);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user