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

Draft
wants to merge 28 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 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
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
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,5 @@
"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 -Xmx4G -Xms100m -Xlog:disable"
}
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(),
null
);
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;
}
}
19 changes: 13 additions & 6 deletions src/main/java/frc/robot/RobotContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
import edu.wpi.first.wpilibj2.command.RunCommand;
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.swerve.SwerveSubsystem;

/**
Expand All @@ -33,8 +31,8 @@ public class RobotContainer {

private final SwerveSubsystem swerveSubsystem = new SwerveSubsystem();

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

/** The container for the robot. Contains subsystems, OI devices, and commands. */
public RobotContainer() {
Expand All @@ -58,6 +56,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 Down Expand Up @@ -93,6 +100,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 +117,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());

}
}
52 changes: 52 additions & 0 deletions src/main/java/frc/robot/subsystems/ClimbSubsystem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// 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.wpilibj2.command.SubsystemBase;
import static frc.robot.Constants.ClimbConstants.TOP_MOTOR_CONFIG;
import static frc.robot.Constants.ClimbConstants.BOT_MOTOR_CONFIG;
import static frc.robot.Constants.DebugConstants.REV_DEBUG;
import frc.robot.util.Motors.LoggedSparkMax;

public class ClimbSubsystem extends SubsystemBase {

private final LoggedSparkMax topMotor;
private final LoggedSparkMax botMotor;
private double targetSpeed;

/** Creates a new ExampleSubsystem. */
public ClimbSubsystem() {
topMotor = new LoggedSparkMax(TOP_MOTOR_CONFIG);
botMotor = new LoggedSparkMax(BOT_MOTOR_CONFIG);
}

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

/**
* 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 topMotor.getPosition();
}

/**
* Sets the speed of the motors
* @param speed target speed from -1.0 to 1.0
*/
public void setSpeed(double speed){
targetSpeed = speed;
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package frc.robot.subsystems.PhoenixLoggingSubsystem;

import javax.xml.crypto.Data;

import com.ctre.phoenix6.SignalLogger;

import edu.wpi.first.wpilibj.DataLogManager;
import edu.wpi.first.wpilibj.DriverStation;
import edu.wpi.first.wpilibj2.command.SubsystemBase;
import frc.robot.subsystems.FieldManagementSubsystem.FieldManagementSubsystem;
import frc.robot.subsystems.FieldManagementSubsystem.MatchStatus;
import frc.robot.subsystems.FieldManagementSubsystem.RobotStatus;

public class PhoenixLoggingSubsystem extends SubsystemBase{

Expand All @@ -13,19 +18,31 @@ public class PhoenixLoggingSubsystem extends SubsystemBase{

public PhoenixLoggingSubsystem(FieldManagementSubsystem fieldManagementSubsystem){
this.fieldManagementSubsystem = fieldManagementSubsystem;
SignalLogger.setPath("/media/sda1/ctre-logs/");
SignalLogger.setPath("/u/ctre-logs/");
SignalLogger.start();
}

@Override
public void periodic(){
MatchStatus currentMatchStatus = fieldManagementSubsystem.getMatchStatus();
if(currentMatchStatus == MatchStatus.AUTON
|| currentMatchStatus == MatchStatus.TELEOP
&& !isLogging){
SignalLogger.start();
}
else if(currentMatchStatus == MatchStatus.ENDED){
SignalLogger.stop();
}
// MatchStatus currentMatchStatus = fieldManagementSubsystem.getMatchStatus();
// if(currentMatchStatus == MatchStatus.AUTON
// || currentMatchStatus == MatchStatus.TELEOP
// && !isLogging){
// SignalLogger.start();
// DataLogManager.start();
// // DriverStation.startDataLog(DataLogManager.getLog());
// isLogging = true;
// }
// else if(currentMatchStatus == MatchStatus.ENDED){
// SignalLogger.stop();
// DataLogManager.stop();
// isLogging = false;
// }
// else if(fieldManagementSubsystem.getRobotStatus() == RobotStatus.DISABLED){
// DataLogManager.stop();
// SignalLogger.stop();
// isLogging = false;
// }
// System.out.println("Log Dir: " + DataLogManager.getLogDir());
}
}
60 changes: 59 additions & 1 deletion src/main/java/frc/robot/subsystems/swerve/KrakenDriveMotor.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
import edu.wpi.first.units.measure.AngularVelocity;
import edu.wpi.first.units.measure.Current;
import edu.wpi.first.units.measure.Voltage;
import edu.wpi.first.util.datalog.DoubleLogEntry;
import edu.wpi.first.wpilibj.DataLogManager;
import frc.robot.util.GRTUtil;

public class KrakenDriveMotor {

Expand All @@ -43,6 +46,14 @@ public class KrakenDriveMotor {
private StatusSignal<Current> supplyCurrentSignal;
private StatusSignal<Current> statorCurrentSignal; //torqueCurrent is Pro

private DoubleLogEntry positionLogEntry;
private DoubleLogEntry veloErrorLogEntry;
private DoubleLogEntry veloLogEntry;
private DoubleLogEntry targetVeloEntry;
private DoubleLogEntry appliedVoltsLogEntry;
private DoubleLogEntry supplyCurrLogEntry;
private DoubleLogEntry statorCurrLogEntry;
private DoubleLogEntry temperatureLogEntry;

/** A kraken drive motor for swerve.
*
Expand All @@ -64,6 +75,7 @@ public KrakenDriveMotor(int canId) {

initNT(canId);
initSignals();
initLogs(canId);
}

/**
Expand Down Expand Up @@ -97,6 +109,21 @@ private void initSignals(){
motor.optimizeBusUtilization(0, 1.0);
}

/**
* Initializes log entries
* @param canId drive motor's CAN ID
*/
private void initLogs(int canId){
positionLogEntry = new DoubleLogEntry(DataLogManager.getLog(), canId + "position");
veloErrorLogEntry = new DoubleLogEntry(DataLogManager.getLog(), canId + "veloError");
veloLogEntry = new DoubleLogEntry(DataLogManager.getLog(), canId + "velo");
targetVeloEntry = new DoubleLogEntry(DataLogManager.getLog(), canId + "targetVelo");
appliedVoltsLogEntry = new DoubleLogEntry(DataLogManager.getLog(), canId + "appliedVolts");
supplyCurrLogEntry = new DoubleLogEntry(DataLogManager.getLog(), canId + "supplyCurrent");
statorCurrLogEntry = new DoubleLogEntry(DataLogManager.getLog(), canId + "statorCurrent");
temperatureLogEntry = new DoubleLogEntry(DataLogManager.getLog(), canId + "temperature");
}

/**
* Set motor velo to target velo
* @param metersPerSec target velo in m/s
Expand Down Expand Up @@ -162,4 +189,35 @@ public void publishStats(){
statorCurrentPublisher.set(motor.getStatorCurrent().getValueAsDouble());
}

}
public void logStats(){
positionLogEntry.append(
motor.getPosition().getValueAsDouble(), GRTUtil.getFPGATime()
);

veloErrorLogEntry.append(
motor.getClosedLoopError().getValueAsDouble(), GRTUtil.getFPGATime()
);

veloLogEntry.append(
motor.getVelocity().getValueAsDouble(), GRTUtil.getFPGATime()
);

targetVeloEntry.append(targetRps, GRTUtil.getFPGATime());

appliedVoltsLogEntry.append(
motor.getMotorVoltage().getValueAsDouble(), GRTUtil.getFPGATime()
);

supplyCurrLogEntry.append(
motor.getSupplyCurrent().getValueAsDouble(), GRTUtil.getFPGATime()
);

statorCurrLogEntry.append(
motor.getStatorCurrent().getValueAsDouble(), GRTUtil.getFPGATime()
);

temperatureLogEntry.append(
motor.getDeviceTemp().getValueAsDouble(), GRTUtil.getFPGATime()
);
}
}
Loading