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

Climb subsystem #6

Closed
wants to merge 44 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
83d140e
BackAlgaeSubsystem finish + hypthetical contro sch
Tonyxwu Jan 15, 2025
9568ab3
BackAlgaeSubsystem done + hypothetical control sch
Tonyxwu Jan 15, 2025
beac2fc
goofy minor fixes
Tonyxwu Jan 15, 2025
c95aaa1
climb command
siyoyoCode Jan 15, 2025
c8411b7
fixed sparkmax follow errors
siyoyoCode Jan 17, 2025
e36601c
fixed climb logic
siyoyoCode Jan 17, 2025
46cb6ff
fixed climb logic
siyoyoCode Jan 17, 2025
1b2d812
removed pid stuff
siyoyoCode Jan 18, 2025
dcf071e
change max speed back to 6000
6kn4eakfr4s Jan 18, 2025
5155c23
Fix PS5 controller can't rotate after power cycle issue
6kn4eakfr4s Jan 20, 2025
b5a9800
make PID arrays to allow different PIDs across modules
6kn4eakfr4s Jan 20, 2025
daa8872
add debug for drive and steer
6kn4eakfr4s Jan 20, 2025
75d8015
remove shuffleboard tab since using advantage scope
6kn4eakfr4s Jan 20, 2025
ef71d47
added constants to toggle debug for drive and steer
6kn4eakfr4s Jan 20, 2025
5585d6a
initializes nt
6kn4eakfr4s Jan 20, 2025
fba320c
sync, timestamp seems weird
6kn4eakfr4s Jan 21, 2025
16a288a
Add position as part of the kraken log
6kn4eakfr4s Jan 22, 2025
588ba45
Only start log once and don't use phoenix signal logs
6kn4eakfr4s Jan 22, 2025
dc8c2c1
remove phoenix signal logs
6kn4eakfr4s Jan 22, 2025
aa5a783
Untested class
6kn4eakfr4s Jan 28, 2025
ee59994
Untested Talon Class
6kn4eakfr4s Jan 28, 2025
612f914
Added methods to accomodate usages in existing branches
6kn4eakfr4s Jan 29, 2025
681abdd
Enable PIDF tuning through NT + Logging more things for spark max.
6kn4eakfr4s Jan 29, 2025
560def0
Allows changing talon pid through NT
6kn4eakfr4s Jan 29, 2025
88dd0ab
fixed typo
6kn4eakfr4s Jan 29, 2025
1870d90
Added comments & allowed one spark max to follow another
6kn4eakfr4s Jan 30, 2025
ccd95ce
Using optional int to represent the can ID to follow
6kn4eakfr4s Jan 30, 2025
aa0ced7
Redo climb through logged motors. Use trigget to set speed instead of…
6kn4eakfr4s Jan 30, 2025
dd97819
Init targetSpeed to 0
6kn4eakfr4s Feb 2, 2025
0ca186a
use OptionalInt.empty() instead of null
6kn4eakfr4s Feb 2, 2025
9992e9b
add binding for climb
CrolineCrois Feb 5, 2025
2541274
rumble in robot container
swaswa999 Feb 5, 2025
0877d12
using kraken-climb using option and create button
CrolineCrois Feb 5, 2025
eb5866c
fix rumble
swaswa999 Feb 5, 2025
44d3644
increase speed
swaswa999 Feb 5, 2025
1521708
qucik rumble fix
swaswa999 Feb 6, 2025
c2c7328
small changes
swaswa999 Feb 6, 2025
98a38b6
flip navx
CrolineCrois Feb 6, 2025
befc29d
climb to not use logged sparkmax for more configs tmp
CrolineCrois Feb 7, 2025
faa1a98
added reverse
swaswa999 Feb 7, 2025
9b7df20
quick changes for rumble :D
swaswa999 Feb 7, 2025
04b7919
softlimit added, it is 53, but need to double check again
swaswa999 Feb 8, 2025
5e735da
fixed soft limit, forks great now
swaswa999 Feb 10, 2025
29ad2d4
formatted climb subsystem file
siyoyoCode Feb 19, 2025
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
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,6 @@
"edu.wpi.first.math.**.struct.*",
],
"wpilib.autoStartRioLog": true,
"java.jdt.ls.vmargs": "-XX:+UseParallelGC -XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90 -Dsun.zip.disableMemoryMapping=true -Xmx2G -Xms100m -Xlog:disable"
"java.jdt.ls.vmargs": "-XX:+UseParallelGC -XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90 -Dsun.zip.disableMemoryMapping=true -Xmx8G -Xms100m -Xlog:disable",
"java.checkstyle.configuration": "/google_checks.xml"
}
74 changes: 63 additions & 11 deletions src/main/java/frc/robot/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,15 @@

package frc.robot;

import java.util.OptionalInt;

import com.revrobotics.spark.config.ClosedLoopConfig;
import com.revrobotics.spark.config.EncoderConfig;
import com.revrobotics.spark.config.ClosedLoopConfig.FeedbackSensor;

import edu.wpi.first.math.geometry.Translation2d;
import edu.wpi.first.math.util.Units;
import frc.robot.util.Motors.LoggedSparkMaxConfig;

/**
* The Constants class provides a convenient place for teams to hold robot-wide numerical or boolean
Expand All @@ -20,7 +27,42 @@ public static class OperatorConstants {
public static final int kDriverControllerPort = 0;
}

/** Constants for the swerve subsystem. */
public static class BackAlgaeConstants{
public static final int ROLLER_MOTOR_ID = 1;//Placeholder
public static final int PIVOT_MOTOR_ID = 2;//Placeholder
public static final double PIVOT_P = 0.01;//placeholder value
public static final double PIVOT_I = 0;//placeholder value
public static final double PIVOT_D = 0;//placeholder value

public static final int SENSOR_ID = 0;//placeholder value
public static final double PIVOT_POSITION_1 = 0;//placeholder value
public static final double PIVOT_POSITION_2 = 0;//placeholder value
}

public static class ClimbConstants{
public static final int TOP_MOTOR_ID = 9;//Placeholder
public static final int BOT_MOTOR_ID = 10;//Placeholder
public static final LoggedSparkMaxConfig TOP_MOTOR_CONFIG =
new LoggedSparkMaxConfig(
TOP_MOTOR_ID,
new ClosedLoopConfig()
.feedbackSensor(FeedbackSensor.kPrimaryEncoder)
.outputRange(0, 1),
new EncoderConfig(),
OptionalInt.empty()
);
public static final LoggedSparkMaxConfig BOT_MOTOR_CONFIG =
new LoggedSparkMaxConfig(
BOT_MOTOR_ID,
new ClosedLoopConfig()
.feedbackSensor(FeedbackSensor.kPrimaryEncoder)
.outputRange(0, 1),
new EncoderConfig(),
OptionalInt.of(TOP_MOTOR_ID)
);
}

/** Constants for the swerve subsystem. */
public static class SwerveConstants {
public static final int FL_DRIVE = 0;
public static final int FL_STEER = 1;
Expand All @@ -46,22 +88,32 @@ public static class SwerveConstants {

public static final double DRIVE_GEAR_REDUCTION = 9. * 20. / 26.;
public static final double DRIVE_WHEEL_CIRCUMFERENCE = Units.inchesToMeters(4 * Math.PI);
public static final double MAX_VEL = 4200. / 6.923 / 60. * 2. * 2. * Math.PI * .0254; // Kraken speed / gear ratio / reduced to per second * circumference * convert to meters
public static final double MAX_VEL = 6000. / 6.923 / 60. * 2. * 2. * Math.PI * .0254; // Kraken speed / gear ratio / reduced to per second * circumference * convert to meters
public static final double MAX_OMEGA = MAX_VEL / FL_POS.getNorm();

public static final double DRIVE_P = 0.32; // temporary value
public static final double DRIVE_I = 0;
public static final double DRIVE_D = 0;
public static final double DRIVE_S = 0.1499;
public static final double DRIVE_V = 0.112;
public static final double[] DRIVE_P = new double[] {0.32, 0.32, 0.32, 0.32};
public static final double[] DRIVE_I = new double[] {0, 0, 0, 0};
public static final double[] DRIVE_D = new double[] {0, 0, 0, 0};
public static final double[] DRIVE_S = new double[] {0.1499, 0.1499, 0.1499, 0.1499};
public static final double[] DRIVE_V = new double[] {0.112, 0.112, 0.112, 0.112};

public static final double STEER_P = 5.8;
public static final double STEER_I = 0;
public static final double STEER_D = 0;
public static final double STEER_FF = 0;
public static final double[] STEER_P = new double[] {5.4, 5.4, 5.4, 5.4};
public static final double[] STEER_I = new double[] {0, 0, 0, 0};
public static final double[] STEER_D = new double[] {0, 0, 0, 0};
public static final double[] STEER_FF = new double[] {0.036, 0.024, 0.0182, 0.05};
}

public static class LoggingConstants{
public static final String SWERVE_TABLE = "SwerveStats";
public static final String REV_TABLE = "MotorStats";
public static final String CTRE_TABLE = "MotorStats";
}

public static class DebugConstants{
public static final boolean STATE_DEBUG = false;
public static final boolean DRIVE_DEBUG = false;
public static final boolean STEER_DEBUG = false;
public static final boolean REV_DEBUG = false;
public static final boolean CTRE_DEBUG = false;
}
}
75 changes: 69 additions & 6 deletions src/main/java/frc/robot/RobotContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

package frc.robot;

import frc.robot.Constants.ClimbConstants;
import frc.robot.controllers.BaseDriveController;
import frc.robot.controllers.DualJoystickDriveController;
import frc.robot.controllers.PS5DriveController;
Expand All @@ -13,12 +14,15 @@

import edu.wpi.first.wpilibj.DataLogManager;
import edu.wpi.first.wpilibj.DriverStation;
import edu.wpi.first.wpilibj.GenericHID;
import edu.wpi.first.wpilibj.PS5Controller;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.InstantCommand;
import edu.wpi.first.wpilibj2.command.RunCommand;
import edu.wpi.first.wpilibj2.command.button.CommandPS5Controller;
import edu.wpi.first.wpilibj2.command.button.CommandXboxController;
import edu.wpi.first.wpilibj2.command.button.Trigger;
import frc.robot.subsystems.FieldManagementSubsystem.FieldManagementSubsystem;
import frc.robot.subsystems.PhoenixLoggingSubsystem.PhoenixLoggingSubsystem;
import frc.robot.subsystems.ClimbSubsystem;
import frc.robot.subsystems.swerve.SwerveSubsystem;

/**
Expand All @@ -30,15 +34,28 @@
public class RobotContainer {

private BaseDriveController driveController;
private CommandPS5Controller mechController = new CommandPS5Controller(1);

private final SwerveSubsystem swerveSubsystem = new SwerveSubsystem();
private final ClimbSubsystem climbSubsystem = new ClimbSubsystem();

private final FieldManagementSubsystem fieldManagementSubsystem = new FieldManagementSubsystem();
private final PhoenixLoggingSubsystem phoenixLoggingSubsystem = new PhoenixLoggingSubsystem(fieldManagementSubsystem);
private final Trigger createTrigger;
private final Trigger optionTrigger;
private final Trigger xbutton;

// private final PhoenixLoggingSubsystem phoenixLoggingSubsystem =
// new PhoenixLoggingSubsystem(fieldManagementSubsystem);

/** The container for the robot. Contains subsystems, OI devices, and commands. */
public RobotContainer() {
constructDriveController();

createTrigger = new Trigger(mechController.create());
optionTrigger = new Trigger(mechController.options());
xbutton = new Trigger(mechController.cross());

climbSubsystem.resetEncoderPos();

startLog();
configureBindings();
}
Expand All @@ -58,6 +75,15 @@ private void configureBindings() {
* the robot is controlled along its own axes, otherwise controls apply to the field axes by default. If the
* swerve aim button is held down, the robot will rotate automatically to always face a target, and only
* translation will be manually controllable. */

//HYPOTHETICAL BACK ALGAE CODE
/*
* Bind a button to move pivot into intaking position, rollers start rolling automatically
* Rollers stop when you press the button again or when distance sensor detects ball
*
* Bind a button to move pivot into outtaking position
* Pressing that button twice spits the algae out
*/
swerveSubsystem.setDefaultCommand(
new RunCommand(() -> {
swerveSubsystem.setDrivePowers(
Expand All @@ -77,8 +103,45 @@ private void configureBindings() {
},
swerveSubsystem
);

// climbSubsystem.setDefaultCommand(
// new InstantCommand(() -> {
// climbSubsystem.setSpeed(mechcontroller.getL2Axis());
// setRum(mechcontroller.getL2Axis());

// }, climbSubsystem)
// );

createTrigger.and(optionTrigger).whileTrue(
new RunCommand(() -> {
climbSubsystem.setSpeed(0.3);
System.out.println(climbSubsystem.getPosition());

}, climbSubsystem)
).onFalse(
new RunCommand(() -> {
climbSubsystem.setSpeed(0);

}, climbSubsystem)
);

xbutton.whileTrue(
new RunCommand(() -> {
climbSubsystem.setSpeed(-0.3);
System.out.println(climbSubsystem.getPosition());

}, climbSubsystem)
).onFalse(
new RunCommand(() -> {
climbSubsystem.setSpeed(0);

}, climbSubsystem)
);
}




/**
* Use this to pass the autonomous command to the main {@link Robot} class.
*
Expand All @@ -93,6 +156,7 @@ public Command getAutonomousCommand() {
* 0
*/
private void constructDriveController(){
DriverStation.refreshData();
if(DriverStation.getJoystickName(0).equals("Controller (Xbox One For Windows)")) {
driveController = new XboxDriveController();
}
Expand All @@ -109,8 +173,7 @@ else if(DriverStation.getJoystickName(0).equals("DualSense Wireless Controller")
* Starts datalog at /media/sda1/robotLogs
*/
private void startLog(){
DataLogManager.start("/media/sda1/robotLogs");
DataLogManager.start();
DriverStation.startDataLog(DataLogManager.getLog());

}
}
124 changes: 124 additions & 0 deletions src/main/java/frc/robot/subsystems/ClimbSubsystem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
// 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.subsystems;

import edu.wpi.first.wpilibj.Encoder;
import edu.wpi.first.wpilibj2.command.SubsystemBase;
import static frc.robot.Constants.ClimbConstants.TOP_MOTOR_CONFIG;
import static frc.robot.Constants.ClimbConstants.TOP_MOTOR_ID;
import static frc.robot.Constants.ClimbConstants.BOT_MOTOR_CONFIG;
import static frc.robot.Constants.ClimbConstants.BOT_MOTOR_ID;
import static frc.robot.Constants.DebugConstants.REV_DEBUG;

import com.revrobotics.RelativeEncoder;
import com.revrobotics.spark.SparkMax;
import com.revrobotics.spark.config.ClosedLoopConfig;
import com.revrobotics.spark.config.ClosedLoopConfig.FeedbackSensor;
import com.revrobotics.spark.config.SparkBaseConfig.IdleMode;
import com.revrobotics.spark.config.EncoderConfig;
import com.revrobotics.spark.config.SoftLimitConfig;
import com.revrobotics.spark.config.SparkMaxConfig;
import com.revrobotics.spark.SparkBase.PersistMode;
import com.revrobotics.spark.SparkBase.ResetMode;
import com.revrobotics.spark.SparkLowLevel.MotorType;

import frc.robot.util.Motors.LoggedSparkMax;

public class ClimbSubsystem extends SubsystemBase {

private final SparkMax topMotor;
private final SparkMax botMotor;
private double targetSpeed = 0;

private ClosedLoopConfig closedLoopConfig;
private EncoderConfig encoderConfig;
private SoftLimitConfig softLimitConfig;

private RelativeEncoder encoder;
private SparkMaxConfig topSparkMaxConfig, botSparkMaxConfig;

/** Creates a new ExampleSubsystem. */
public ClimbSubsystem() {
topMotor = new SparkMax(TOP_MOTOR_ID, MotorType.kBrushless);
botMotor = new SparkMax(BOT_MOTOR_ID, MotorType.kBrushless);


closedLoopConfig = new ClosedLoopConfig()
.feedbackSensor(FeedbackSensor.kPrimaryEncoder)
.outputRange(0, 1);
encoderConfig = new EncoderConfig();
encoder = topMotor.getEncoder();

softLimitConfig = new SoftLimitConfig();
softLimitConfig.forwardSoftLimitEnabled(true)
.forwardSoftLimit(67)
.reverseSoftLimitEnabled(true)
.reverseSoftLimit(0);


topSparkMaxConfig = new SparkMaxConfig();
topSparkMaxConfig.apply(closedLoopConfig)
.apply(softLimitConfig)
.inverted(true);

botSparkMaxConfig = new SparkMaxConfig();
botSparkMaxConfig.apply(closedLoopConfig)
.inverted(true)
.apply(softLimitConfig)
.follow(TOP_MOTOR_ID);

topMotor.configure(topSparkMaxConfig,
ResetMode.kResetSafeParameters, PersistMode.kPersistParameters
);
botMotor.configure(botSparkMaxConfig,
ResetMode.kResetSafeParameters, PersistMode.kPersistParameters
);

}

@Override
public void periodic() {
topMotor.set(targetSpeed);
// topMotor.logStats();
// botMotor.logStats();
if(REV_DEBUG){
// topMotor.publishStats();
// botMotor.publishStats();
}
}

/**
* Set encoder position to 0
*/
public void resetEncoderPos(){
encoder.setPosition(0);
}


/**
* Gets the position of the top motor
* @return position of the top motor in rotations after taking the position
* conversion factor into account
*/
public double getPosition() {
return encoder.getPosition();
}
/**
* Gets the velocity of the top motor
* @return velocity of the top motor in RPM after taking the velocity
* conversion factor into account
*/
public double getVelocity() {
return encoder.getVelocity();
}

/**
* Sets the speed of the motors
* @param speed target speed from -1.0 to 1.0
*/
public void setSpeed(double speed){
targetSpeed = speed;
}
}
Loading