-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRobotContainer.java
More file actions
130 lines (110 loc) · 6.03 KB
/
RobotContainer.java
File metadata and controls
130 lines (110 loc) · 6.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
package frc.robot;
import com.kauailabs.navx.frc.AHRS;
import com.pathplanner.lib.auto.AutoBuilder;
import com.pathplanner.lib.auto.NamedCommands;
import com.pathplanner.lib.util.HolonomicPathFollowerConfig;
import com.pathplanner.lib.util.PIDConstants;
import com.pathplanner.lib.util.ReplanningConfig;
import edu.wpi.first.math.trajectory.TrapezoidProfile;
import edu.wpi.first.wpilibj.DriverStation;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.shuffleboard.Shuffleboard;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj2.command.Command;
import frc.robot.autochooser.chooser.AutoChooser;
import frc.robot.commands.RampMove;
import frc.robot.commands.ReportErrorCommand;
import frc.robot.autochooser.chooser.AutoChooser2024;
import frc.robot.commands.SetInitOdom;
import frc.robot.commands.drive.WheelAlign;
import frc.robot.subsystems.Ramp;
import frc.robot.subsystems.swervev2.KinematicsConversionConfig;
import frc.robot.subsystems.swervev2.SwerveDrivetrain;
import frc.robot.subsystems.swervev2.SwerveIdConfig;
import frc.robot.subsystems.swervev2.SwervePidConfig;
import frc.robot.utils.smartshuffleboard.SmartShuffleboard;
import java.util.Optional;
/**
* This class is where the bulk of the robot should be declared. Since Command-based is a
* "declarative" paradigm, very little robot logic should actually be handled in the {@link Robot}
* periodic methods (other than the scheduler calls). Instead, the structure of the robot (including
* subsystems, commands, and trigger mappings) should be declared here.
*/
public class RobotContainer {
private final Joystick joyleft = new Joystick(Constants.LEFT_JOYSICK_ID);
private final Joystick joyright = new Joystick(Constants.RIGHT_JOYSTICK_ID);
private SwerveDrivetrain drivetrain;
private final Ramp ramp;
private final AutoChooser2024 autoChooser;
public RobotContainer() {
setupDriveTrain();
registerPathPlanableCommands();
setupPathPlaning();
autoChooser = new AutoChooser2024();
autoChooser.addOnValidationCommand(()->new SetInitOdom(drivetrain,autoChooser));
autoChooser.forceRefresh();
ramp = new Ramp();
configureBindings();
putShuffleboardCommands();
}
/**
* NamedCommands
*/
private void registerPathPlanableCommands() {
NamedCommands.registerCommand(ReportErrorCommand.class.getName(), new ReportErrorCommand()); //place holder
}
private void setupPathPlaning() {
AutoBuilder.configureHolonomic(drivetrain::getPose,
drivetrain::resetOdometry,
drivetrain::speedsFromStates,
drivetrain::drive,
new HolonomicPathFollowerConfig(
new PIDConstants(5, 0.0, 0), // Translation PID constants
new PIDConstants(5, 0.0, 0), // Rotation PID constants
3, // Max module speed, in m/s
0.5, // Drive base radius in meters. Distance from robot center to the furthest module.
new ReplanningConfig()
), RobotContainer::shouldFlip, drivetrain);
}
private void setupDriveTrain() {
SwerveIdConfig frontLeftIdConf = new SwerveIdConfig(Constants.DRIVE_FRONT_LEFT_D, Constants.DRIVE_FRONT_LEFT_S, Constants.DRIVE_CANCODER_FRONT_LEFT);
SwerveIdConfig frontRightIdConf = new SwerveIdConfig(Constants.DRIVE_FRONT_RIGHT_D, Constants.DRIVE_FRONT_RIGHT_S, Constants.DRIVE_CANCODER_FRONT_RIGHT);
SwerveIdConfig backLeftIdConf = new SwerveIdConfig(Constants.DRIVE_BACK_LEFT_D, Constants.DRIVE_BACK_LEFT_S, Constants.DRIVE_CANCODER_BACK_LEFT);
SwerveIdConfig backRightIdConf = new SwerveIdConfig(Constants.DRIVE_BACK_RIGHT_D, Constants.DRIVE_BACK_RIGHT_S, Constants.DRIVE_CANCODER_BACK_RIGHT);
TrapezoidProfile.Constraints constraints = new TrapezoidProfile.Constraints(Constants.MAX_ANGULAR_SPEED * 4, 2 * Math.PI * 10);
PID drivePid = PID.of(Constants.DRIVE_PID_P, Constants.DRIVE_PID_I, Constants.DRIVE_PID_D);
PID steerPid = PID.of(Constants.STEER_PID_P, Constants.STEER_PID_I, Constants.STEER_PID_D);
Gain driveGain = Gain.of(Constants.DRIVE_PID_FF_V, Constants.DRIVE_PID_FF_S);
Gain steerGain = Gain.of(Constants.STEER_PID_FF_V, Constants.STEER_PID_FF_S);
KinematicsConversionConfig kinematicsConversionConfig = new KinematicsConversionConfig(Constants.WHEEL_RADIUS, Constants.CHASSIS_DRIVE_GEAR_RATIO, Constants.CHASSIS_STEER_GEAR_RATIO);
SwervePidConfig pidConfig = new SwervePidConfig(drivePid, steerPid, driveGain, steerGain, constraints);
AHRS navxGyro = new AHRS();
this.drivetrain = new SwerveDrivetrain(frontLeftIdConf, frontRightIdConf, backLeftIdConf, backRightIdConf, kinematicsConversionConfig, pidConfig, navxGyro);
}
public void putShuffleboardCommands() {
SmartShuffleboard.putCommand("Ramp", "SetArmPID400", new RampMove(ramp, 400));
SmartShuffleboard.putCommand("Ramp", "SetArmPID500", new RampMove(ramp, 500));
SmartShuffleboard.put("Test", "P", Constants.STEER_PID_P);
SmartShuffleboard.put("Test", "I", Constants.STEER_PID_I);
SmartShuffleboard.put("Test", "D", Constants.STEER_PID_D);
}
private void configureBindings() {
drivetrain.setDefaultCommand(new Drive(drivetrain, joyleft::getY, joyleft::getX, joyright::getX));
}
public SwerveDrivetrain getDrivetrain() {
return drivetrain;
}
public Command getAutoCommand() {
return autoChooser.getAutoCommand();
}
public static boolean shouldFlip(){
Optional<DriverStation.Alliance> alliance = DriverStation.getAlliance();
return alliance.filter(value -> value == DriverStation.Alliance.Red).isPresent();
}
public AutoChooser getAutoChooser() {
return autoChooser;
}
}