Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Robot configuration #24

Merged
merged 3 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion src/main/java/frc/robot/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ public class CANDevices{
public static final int backRightRotationEncoderID = 11;
}

public enum ChassisMode {
B_TEAM,
C_TEAM
}

public enum DriveMode {
TANKDRIVE,
ARCADEDRIVE
}

public static final class DriveConstants {

public static final double[] driveKps = {0.7, 0.4, 0.7, 0.7};
Expand Down Expand Up @@ -58,12 +68,27 @@ public static final class DriveConstants {
public static final double poseMoveRotationMaxAccel = Math.PI;


public static final double autoDrivePercent = 0.6;
}

public static final class B_Configs {
public static final int frontLeftID = 4;
public static final int backLeftID = 5;
public static final int frontRightID = 6;
public static final int backRightID = 7;

public static final double autoDrivePercent = 0.6;
}


public static final class C_Configs {

public static final int frontLeftID = 1;
public static final int frontRightID = 2;
public static final int backLeftID = 3;
public static final int backRightID = 4;


}


}
34 changes: 34 additions & 0 deletions src/main/java/frc/robot/RobotConfiguration.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package frc.robot;

import frc.robot.Constants.ChassisMode;
import frc.robot.Constants.DriveMode;

public class RobotConfiguration {

private DriveMode driveMode;
private ChassisMode chassisMode;
private boolean armEnabled;

public RobotConfiguration(ChassisMode chassisConfig, DriveMode driveConfig) {
this.driveMode = driveConfig;
this.chassisMode = chassisConfig;

armEnabled = (chassisConfig == ChassisMode.B_TEAM);

}

public DriveMode driveConfig() {
return driveMode;
}

public ChassisMode chassisConfig() {
return chassisMode;
}


public boolean armEnabled() {
return armEnabled;
}


}
26 changes: 18 additions & 8 deletions src/main/java/frc/robot/RobotContainer.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
package frc.robot;

import edu.wpi.first.wpilibj.GenericHID;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.XboxController;
import edu.wpi.first.wpilibj.XboxController.Button;
import edu.wpi.first.wpilibj.smartdashboard.SendableChooser;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.button.JoystickButton;
import frc.robot.commands.drive.TankDrive;
import frc.robot.subsystems.DriveSubsystem;
import frc.robot.subsystems.ArmSubsystem;
import edu.wpi.first.wpilibj2.command.InstantCommand;
import frc.robot.commands.Intake;
import edu.wpi.first.wpilibj.XboxController;
import edu.wpi.first.wpilibj2.command.button.JoystickButton;
import frc.robot.subsystems.ArmSubsystem;
import frc.robot.Constants.ChassisMode;
import frc.robot.Constants.DriveMode;
import frc.robot.commands.drive.ArcadeDrive;
import frc.robot.commands.drive.TankDrive;
import frc.robot.subsystems.drive.DriveSubsystem;

public class RobotContainer {
private final DriveSubsystem drive = new DriveSubsystem();

private final RobotConfiguration robot = new RobotConfiguration(ChassisMode.B_TEAM, DriveMode.ARCADEDRIVE);

private final DriveSubsystem drive;

private final Joystick leftStick = new Joystick(0);
private final Joystick rightStick = new Joystick(1);
private final XboxController gamepad = new XboxController(2);
Expand All @@ -26,14 +33,17 @@ public class RobotContainer {

//private XboxController gamepad = new XboxController(0);

SendableChooser<String> autoChooser = new SendableChooser<String>();
private Command activeAutoCommand = null;
private String activeAutoName = null;
public RobotContainer(){

drive = new DriveSubsystem(robot.chassisConfig(), robot.driveConfig());
//fix

public RobotContainer() {
drive.setDefaultCommand(new TankDrive(drive,
drive.setDefaultCommand(new TankDrive(drive,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default command should match the drive mode

() -> leftStick.getRawAxis(1),
() -> rightStick.getRawAxis(0)));
SendableChooser<String> autoChooser = new SendableChooser<String>();
//private Command activeAutoCommand = null;
//private String activeAutoName = null;
configureButtonBindings();

}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/frc/robot/commands/drive/ArcadeDrive.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj2.command.CommandBase;
import frc.robot.subsystems.DriveSubsystem;
import frc.robot.subsystems.drive.DriveSubsystem;

public class ArcadeDrive extends CommandBase{
private final DriveSubsystem drivesub;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/frc/robot/commands/drive/TankDrive.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.util.function.DoubleSupplier;

import edu.wpi.first.wpilibj2.command.CommandBase;
import frc.robot.subsystems.DriveSubsystem;
import frc.robot.subsystems.drive.DriveSubsystem;

public class TankDrive extends CommandBase{

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package frc.robot.subsystems;
package frc.robot.subsystems.drive;

import com.ctre.phoenix.sensors.PigeonIMU;

import edu.wpi.first.wpilibj.drive.DifferentialDrive;
import edu.wpi.first.wpilibj.motorcontrol.MotorControllerGroup;
import frc.robot.Constants;

public class DriveHardware {

protected MotorControllerGroup rightMotorControllerGroup;
protected MotorControllerGroup leftMotorControllerGroup;
protected DifferentialDrive drive;
//protected final PigeonIMU pigeon = new PigeonIMU(Constants.pigeonID);
protected final double angleOffset = 0;

public DriveHardware() {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package frc.robot.subsystems;
package frc.robot.subsystems.drive;

import com.revrobotics.CANSparkMax;
import com.revrobotics.CANSparkMax.IdleMode;
import com.revrobotics.CANSparkMaxLowLevel.MotorType;
import edu.wpi.first.wpilibj.drive.DifferentialDrive;
import edu.wpi.first.wpilibj.motorcontrol.MotorControllerGroup;

public class DriveSparkMAX extends DriveHardware {

private final CANSparkMax driveMotorFrontLeft;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
package frc.robot.subsystems;
package frc.robot.subsystems.drive;
import edu.wpi.first.wpilibj2.command.SubsystemBase;
import frc.robot.Constants;
import frc.robot.Constants.DriveConstants;
import frc.robot.Constants.B_Configs;
import frc.robot.Constants.C_Configs;
import frc.robot.Constants.DriveMode;
import frc.robot.Constants.ChassisMode;;

public class DriveSubsystem extends SubsystemBase{

public enum ChassisMode {
B_TEAM,
C_TEAM
}

public enum DriveMode {
TANKDRIVE,
ARCADEDRIVE
}

private DriveHardware driveHardware;

Expand All @@ -25,9 +18,9 @@ public enum DriveMode {

public DriveSubsystem(ChassisMode chassisMode, DriveMode driveMode) {
if (chassisMode == ChassisMode.B_TEAM) {
driveHardware = new DriveSparkMAX(DriveConstants.frontLeftID, DriveConstants.frontRightID, DriveConstants.backLeftID, DriveConstants.backRightID);
driveHardware = new DriveSparkMAX(B_Configs.frontLeftID, B_Configs.frontRightID, B_Configs.backLeftID, B_Configs.backRightID);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't all these configs be passed in via the robot configuration class rather than these constants

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the DriveSubsystem constructor have all of the motor controller ids then?

} else {
driveHardware = new DriveTalon(DriveConstants.frontLeftID, DriveConstants.frontRightID, DriveConstants.backLeftID, DriveConstants.backRightID);
driveHardware = new DriveTalon(C_Configs.frontLeftID, C_Configs.frontRightID, C_Configs.backLeftID, C_Configs.backRightID);
}
mode = driveMode;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package frc.robot.subsystems;
package frc.robot.subsystems.drive;

import com.ctre.phoenix.motorcontrol.NeutralMode;
import com.ctre.phoenix.motorcontrol.can.WPI_TalonFX;
Expand Down