Skip to content

Commit

Permalink
Merge branch 'origin/arm-subsystem-scaffolding'
Browse files Browse the repository at this point in the history
  • Loading branch information
MeowAzalea committed Feb 19, 2024
2 parents 2c97fad + 709282d commit 9aadee6
Show file tree
Hide file tree
Showing 7 changed files with 326 additions and 53 deletions.
75 changes: 36 additions & 39 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,40 +1,37 @@
{
"java.configuration.updateBuildConfiguration": "automatic",
"java.server.launchMode": "Standard",
"files.exclude": {
"**/.git": true,
"**/.svn": true,
"**/.hg": true,
"**/CVS": true,
"**/.DS_Store": true,
"bin/": true,
"**/.classpath": true,
"**/.project": true,
"**/.settings": true,
"**/.factorypath": true,
"**/*~": true
},
"java.test.config": [
{
"name": "WPIlibUnitTests",
"workingDirectory": "${workspaceFolder}/build/jni/release",
"vmargs": [
"-Djava.library.path=${workspaceFolder}/build/jni/release"
],
"env": {
"LD_LIBRARY_PATH": "${workspaceFolder}/build/jni/release",
"DYLD_LIBRARY_PATH": "${workspaceFolder}/build/jni/release"
}
},
],
"java.test.defaultConfig": "WPIlibUnitTests",
// Style guide - most of this came from clicking buttons and then copying from my user settings.json
// General editor stuff
"editor.formatOnSave": true, // So you cant forget
"editor.tabSize": 4, // 4 char width indentation
"editor.detectIndentation": false, // Prevent above from being overridden
"editor.insertSpaces": false, // use tab character instead of spaces
"java.cleanup.actionsOnSave": [
"addOverride",
]
}
"java.configuration.updateBuildConfiguration": "automatic",
"java.server.launchMode": "Standard",
"files.exclude": {
"**/.git": true,
"**/.svn": true,
"**/.hg": true,
"**/CVS": true,
"**/.DS_Store": true,
"bin/": true,
"**/.classpath": true,
"**/.project": true,
"**/.settings": true,
"**/.factorypath": true,
"**/*~": true
},
"java.test.config": [
{
"name": "WPIlibUnitTests",
"workingDirectory": "${workspaceFolder}/build/jni/release",
"vmargs": [ "-Djava.library.path=${workspaceFolder}/build/jni/release" ],
"env": {
"LD_LIBRARY_PATH": "${workspaceFolder}/build/jni/release" ,
"DYLD_LIBRARY_PATH": "${workspaceFolder}/build/jni/release"
}
},
],
"java.test.defaultConfig": "WPIlibUnitTests",
"cSpell.words": [
"AHRS",
"Deadzone",
"Odometry",
"setpoint",
"velociticities"
]
}

26 changes: 26 additions & 0 deletions src/main/java/frc/robot/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public static enum Bot {
public static class DriverConstants {
public static final int DRIVER_JOYSTICK_PORT = 0;

public static final int OPERATOR_JOYSTICK_PORT = 1;

public static final double DEAD_ZONE = 0.25;

// Names of options for displaying
Expand All @@ -65,6 +67,30 @@ public static class DriverConstants {
public static final double[] maxSpeedOptionsRotation = { 0.25, 0.75, 1 };
}

public static class ArmConstants {

public static final double MAXIMUM_ARM_DEGREES = 1;
public static final double MINIMUM_ARM_DEGREES = 0;

public static final double ARM_AMP_SHOOTING_DEGREES = -20;
public static final double ARM_SPEAKER_SHOOTING_DEGREES = 45;
public static final double ARM_INTAKE_DEGREES = -40;

public static final int LEFT_MOTOR_ID = 5;
//public static final int LEFT_ENCODER_ID = 0;
public static final int RIGHT_MOTOR_ID = 19;
public static final int RIGHT_ENCODER_ID = 6;

public static final boolean ARE_MOTORS_REVERSED = false;

public static final double DEGREES_PER_SECOND = 2.0;

public static final double ELEVATION_PID_P = 15;
public static final double ELEVATION_PID_I = 0;
public static final double ELEVATION_PID_D = 0;

}

public static class RobotMovementConstants {
public static final double POSITION_TOLERANCE_METERS = Units.inchesToMeters(0.0001);
public static final double ANGLE_TOLERANCE_RADIANS = Units.degreesToRadians(1);
Expand Down
52 changes: 49 additions & 3 deletions src/main/java/frc/robot/RobotContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
import frc.robot.Constants.DriverConstants;
import frc.robot.Constants.SwerveDrivetrainConstants;
import frc.robot.Constants.SwerveModuleConstants;
import frc.robot.Constants.ArmConstants;
import frc.robot.subsystems.Arm;
import frc.robot.commands.Autos;
import frc.robot.commands.ArmRemoteControl;
import frc.robot.commands.ArmRotateTo;
import frc.robot.commands.ChassisRemoteControl;
import frc.robot.Constants.VisionConstants;
import frc.robot.subsystems.SwerveDrivetrain;
import frc.robot.subsystems.SwerveModule;
Expand All @@ -16,6 +22,8 @@
import com.kauailabs.navx.frc.AHRS;

import edu.wpi.first.wpilibj.GenericHID;
import edu.wpi.first.wpilibj.I2C;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.GenericHID.HIDType;
import edu.wpi.first.wpilibj.smartdashboard.SendableChooser;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
Expand Down Expand Up @@ -67,6 +75,12 @@ public class RobotContainer {
-SwerveDrivetrainConstants.MODULE_LOCATION_Y));

private final AHRS gyro = new AHRS();
private final Arm arm = new Arm(
ArmConstants.LEFT_MOTOR_ID,
ArmConstants.RIGHT_MOTOR_ID,
ArmConstants.RIGHT_ENCODER_ID,
ArmConstants.ARE_MOTORS_REVERSED);


private final SwerveDrivetrain drivetrain = new SwerveDrivetrain(gyro, swerveModuleFL, swerveModuleFR,
swerveModuleBL, swerveModuleBR);
Expand All @@ -75,6 +89,11 @@ public class RobotContainer {

private final Vision vision = new Vision(VisionConstants.CAMERA_NAME, VisionConstants.CAMERA_POSE);


private final ArmRotateTo armToIntake = new ArmRotateTo(arm, ArmConstants.ARM_INTAKE_DEGREES);
private final ArmRotateTo armToAmp = new ArmRotateTo(arm, ArmConstants.ARM_AMP_SHOOTING_DEGREES);
private final ArmRotateTo armToSpeaker = new ArmRotateTo(arm, ArmConstants.ARM_SPEAKER_SHOOTING_DEGREES);

/**
* The container for the robot. Contains subsystems, OI devices, and commands.
*/
Expand All @@ -100,11 +119,14 @@ public void setUpDriveController() {
final GenericHID genericHID = new GenericHID(DriverConstants.DRIVER_JOYSTICK_PORT);
final HIDType genericHIDType = genericHID.getType();

final CommandJoystick operatorJoystick = new CommandJoystick(DriverConstants.OPERATOR_JOYSTICK_PORT);

SmartDashboard.putString("Drive Controller", genericHIDType.toString());
SmartDashboard.putString("Bot Name", Constants.currentBot.toString() + " - " + Constants.serialNumber);

drivetrain.removeDefaultCommand();

ArmRemoteControl armInputs;
ChassisDriveInputs inputs;
OptionButtonInput preciseModeButton, boostModeButton, fieldRelativeButton;

Expand All @@ -117,14 +139,26 @@ public void setUpDriveController() {
joystick::getTwist, -1,
Constants.DriverConstants.DEAD_ZONE);

armInputs = new ArmRemoteControl(arm,
new OptionButtonInput(joystick,11, ActivationMode.HOLD),
new OptionButtonInput(joystick,12, ActivationMode.HOLD),

new OptionButtonInput(joystick, 4, ActivationMode.HOLD),
new OptionButtonInput(joystick, 5, ActivationMode.HOLD),
new OptionButtonInput(joystick, 6, ActivationMode.HOLD)
);

preciseModeButton = new OptionButtonInput(joystick, 2, ActivationMode.TOGGLE);
boostModeButton = new OptionButtonInput(joystick, 1, ActivationMode.HOLD);
fieldRelativeButton = new OptionButtonInput(joystick, 3, ActivationMode.TOGGLE);

joystick.button(10).onTrue(Commands.sequence(
Commands.runOnce(drivetrain::toDefaultStates, drivetrain),
Commands.waitSeconds(0.5)));
//This bypasses arm remote control, arm remote control is incompatible with autonomous commands
operatorJoystick.button(4).onTrue(armToIntake);
operatorJoystick.button(5).onTrue(armToAmp);
operatorJoystick.button(6).onTrue(armToSpeaker);

joystick.button(9).onTrue(Commands.run(drivetrain::brakeMode, drivetrain));
joystick.button(10).onTrue(Commands.run(drivetrain::toDefaultStates, drivetrain));
} else {
final CommandXboxController xbox = new CommandXboxController(genericHID.getPort());

Expand All @@ -134,6 +168,18 @@ public void setUpDriveController() {
xbox::getRightX, -1,
Constants.DriverConstants.DEAD_ZONE);

armInputs = new ArmRemoteControl(arm,
new OptionButtonInput(xbox::rightBumper, ActivationMode.HOLD),
new OptionButtonInput(xbox::leftBumper, ActivationMode.HOLD),

new OptionButtonInput(xbox::povLeft, ActivationMode.HOLD),
new OptionButtonInput(xbox::povRight, ActivationMode.HOLD),
new OptionButtonInput(xbox::povDown, ActivationMode.HOLD)
);




preciseModeButton = new OptionButtonInput(xbox::b, ActivationMode.TOGGLE);
boostModeButton = new OptionButtonInput(xbox::leftStick, ActivationMode.HOLD);
fieldRelativeButton = new OptionButtonInput(xbox::povUp, ActivationMode.TOGGLE);
Expand Down
77 changes: 77 additions & 0 deletions src/main/java/frc/robot/commands/ArmRemoteControl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package frc.robot.commands;

import frc.robot.Constants.ArmConstants;
import frc.robot.subsystems.Arm;
import frc.robot.subsystems.ExampleSubsystem;
import frc.robot.inputs.OptionButtonInput;
import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.Commands;
import edu.wpi.first.wpilibj2.command.Subsystem;


public class ArmRemoteControl extends Command {
private final Arm arm;

private final OptionButtonInput raiseArmButton;
private final OptionButtonInput lowerArmButton;

private final OptionButtonInput speakerPositionButton;
private final OptionButtonInput ampPositionButton;
private final OptionButtonInput intakePositionButton;


public ArmRemoteControl(Arm arm, OptionButtonInput raiseArmButton, OptionButtonInput lowerArmButton,
OptionButtonInput speakerPositionButton, OptionButtonInput ampPositionButton, OptionButtonInput intakePositionButton) {
this.arm = arm;

this.raiseArmButton = raiseArmButton;
this.lowerArmButton = lowerArmButton;

this.speakerPositionButton = speakerPositionButton;
this.ampPositionButton = ampPositionButton;
this.intakePositionButton = intakePositionButton;


addRequirements(arm);
}



@Override
public void initialize() {
}

/**
* execute() is called repeatedly while a command is scheduled, about every
* 20ms.
*/
@Override
public void execute() {

// Arm Motor
arm.changeArmAngleDegreesBy(Double.valueOf(raiseArmButton.getStateAsInt()) * TimedRobot.kDefaultPeriod * ArmConstants.DEGREES_PER_SECOND);
arm.changeArmAngleDegreesBy(Double.valueOf(-lowerArmButton.getStateAsInt()) * TimedRobot.kDefaultPeriod * ArmConstants.DEGREES_PER_SECOND);

// Arm Povs
if (speakerPositionButton.getState()) {
arm.setArmToSpeakerPosition();
}
if (ampPositionButton.getState()) {
arm.setArmToAmpPosition();
}
if (intakePositionButton.getState()) {
arm.setArmToIntakePosition();
}

}

@Override
public boolean isFinished() {
return false;
}

@Override
public void end(boolean interrupted) {
}
}
28 changes: 28 additions & 0 deletions src/main/java/frc/robot/commands/ArmRotateTo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package frc.robot.commands;

import edu.wpi.first.wpilibj2.command.Command;
import frc.robot.subsystems.Arm;

public class ArmRotateTo extends Command{

private final double setpoint;
private final Arm arm;

public ArmRotateTo(Arm arm, double degree){
this.setpoint = degree;
this.arm = arm;

addRequirements(arm);

}

@Override
public void initialize() {
arm.setSetpoint(setpoint);
}

@Override
public boolean isFinished() {
return arm.isAtDesiredPosition();
}
}
7 changes: 7 additions & 0 deletions src/main/java/frc/robot/commands/ChassisRemoteControl.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package frc.robot.commands;

import edu.wpi.first.math.kinematics.ChassisSpeeds;
import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj2.command.Command;
import frc.robot.Constants.ArmConstants;
import frc.robot.Constants.DriverConstants;
import frc.robot.subsystems.Arm;
import frc.robot.inputs.OptionButtonInput;
import frc.robot.inputs.ChassisDriveInputs;
import frc.robot.subsystems.SwerveDrivetrain;
Expand Down Expand Up @@ -36,6 +39,10 @@ public ChassisRemoteControl(SwerveDrivetrain drivetrain, ChassisDriveInputs chas

this.drivetrain = drivetrain;





// Tell the command schedular we are using the drivetrain
addRequirements(drivetrain);
}
Expand Down
Loading

0 comments on commit 9aadee6

Please sign in to comment.