Skip to content
Open

Dev #29

Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
0fad1ac
Intake
Strflightmight09 Sep 30, 2025
7b281c2
Commit so people can continue
Strflightmight09 Sep 30, 2025
aff073d
arm tuned
Strflightmight09 Oct 2, 2025
a45d106
fix kg and vis offset
Strflightmight09 Oct 2, 2025
a93400d
fix arm setpoints
Strflightmight09 Oct 2, 2025
8c3a876
changed arm position
Strflightmight09 Oct 3, 2025
48875b7
cleaned intakeCOmmands
Strflightmight09 Oct 3, 2025
f6c5a7c
tuned elevator
Strflightmight09 Oct 3, 2025
6522d8a
Merge branch 'main' into dev
Strflightmight09 Oct 3, 2025
53fc6e1
fix
Strflightmight09 Oct 3, 2025
bfcc454
fixed intake sim
Strflightmight09 Oct 3, 2025
883add7
Merge branch 'main' into dev
Strflightmight09 Oct 3, 2025
5604fa0
increased current limit to 120
ShmayaR Oct 3, 2025
6bdc83d
Merge branch 'dev' of https://github.com/Programming-TRIGON/RobotCode…
ShmayaR Oct 3, 2025
89a72a6
stuff
ShmayaR Oct 3, 2025
a3a6d42
LOTS OF GOOD STUFF
ShmayaR Oct 3, 2025
456e939
canus on canivore
ShmayaR Oct 5, 2025
3f4d646
push
ShmayaR Oct 5, 2025
204470b
fixed algae
levyishai Oct 5, 2025
779c470
FIX
ShmayaR Oct 5, 2025
26a4e70
Merge branch 'dev' of https://github.com/Programming-TRIGON/RobotCode…
ShmayaR Oct 5, 2025
ef1d29f
proccessor works
levyishai Oct 5, 2025
d18c2ee
fixec coral and lolipop intake
levyishai Oct 5, 2025
8780d1e
all good
ShmayaR Oct 5, 2025
c09aefc
Update AlgaeManipulationCommands.java
levyishai Oct 5, 2025
c177ea3
Merge branch 'dev' of https://github.com/Programming-TRIGON/RobotCode…
levyishai Oct 5, 2025
5fe7509
more changes
ShmayaR Oct 5, 2025
98f9216
load coral while driving to pose
levyishai Oct 6, 2025
247c198
PUSH
ShmayaR Oct 6, 2025
94e4b5b
Merge branch 'dev' of https://github.com/Programming-TRIGON/RobotCode…
ShmayaR Oct 6, 2025
a88fb13
fix some sim stuff and alternate align
levyishai Oct 6, 2025
0f718f0
ji
ShmayaR Oct 6, 2025
0399a40
added more conditions for load coral and added continue trigger for a…
levyishai Oct 7, 2025
937117c
fix
levyishai Oct 7, 2025
8f463be
good changes
levyishai Oct 7, 2025
1c60f7d
added no loading toggle
levyishai Oct 7, 2025
8738ba1
fix load
levyishai Oct 7, 2025
1e5ba97
added reset position commands
levyishai Oct 7, 2025
b3f844c
AHAHAHAHAHAH
levyishai Oct 7, 2025
de3c682
COmmit
ShmayaR Oct 8, 2025
9ee334c
commit
ShmayaR Oct 8, 2025
b15b4dd
faster
ShmayaR Oct 8, 2025
41a47b5
fixed resetting elevator position to not hit print
ShmayaR Oct 8, 2025
7387872
big ass commit
Strflightmight09 Oct 8, 2025
a23d92d
Merge branch 'dev' of https://github.com/Programming-TRIGON/RobotCode…
Strflightmight09 Oct 8, 2025
401e263
lower predict time
Strflightmight09 Oct 8, 2025
73f8672
log stuff
ShmayaR Oct 8, 2025
f72905c
Merge branch 'dev' of https://github.com/Programming-TRIGON/RobotCode…
ShmayaR Oct 8, 2025
b30244a
more logging
ShmayaR Oct 8, 2025
0e65033
more log changes
ShmayaR Oct 8, 2025
ac2ca04
fix
ShmayaR Oct 8, 2025
ea633be
p8
ShmayaR Oct 8, 2025
2c0ce29
fix arm falling asleep
ShmayaR Oct 8, 2025
ff18479
fix algae position
ShmayaR Oct 8, 2025
fec5163
dang bro that's 11 files changed. not what you want to see after firs…
ShmayaR Oct 8, 2025
4be96a4
fix
ShmayaR Oct 9, 2025
ab141c8
COMMIT STUFF
ShmayaR Oct 9, 2025
a876e79
fix
levyishai Oct 9, 2025
fa8494f
stupid zBook
levyishai Oct 9, 2025
7ebdf2a
dfretf
ShmayaR Oct 9, 2025
3355f90
Merge branch 'dev' of https://github.com/Programming-TRIGON/RobotCode…
ShmayaR Oct 9, 2025
1a5275c
Update FieldConstants.java
levyishai Oct 9, 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
Empty file removed src/main/deploy/logs/.gitkeep
Empty file.
2 changes: 1 addition & 1 deletion src/main/deploy/pathplanner/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"driveGearing": 6.12,
"maxDriveSpeed": 4.4,
"driveMotorType": "krakenX60FOC",
"driveCurrentLimit": 100.0,
"driveCurrentLimit": 120.0,
"wheelCOF": 1.6,
"flModuleX": 0.172,
"flModuleY": 0.273,
Expand Down
8 changes: 3 additions & 5 deletions src/main/java/frc/trigon/robot/RobotContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@
import frc.trigon.robot.subsystems.MotorSubsystem;
import frc.trigon.robot.subsystems.armelevator.ArmElevator;
import frc.trigon.robot.subsystems.armelevator.ArmElevatorCommands;
import frc.trigon.robot.subsystems.armelevator.ArmElevatorConstants;
import frc.trigon.robot.subsystems.climber.Climber;
import frc.trigon.robot.subsystems.climber.ClimberCommands;
import frc.trigon.robot.subsystems.climber.ClimberConstants;
import frc.trigon.robot.subsystems.endeffector.EndEffector;
import frc.trigon.robot.subsystems.endeffector.EndEffectorCommands;
import frc.trigon.robot.subsystems.endeffector.EndEffectorConstants;
Expand All @@ -38,6 +35,7 @@
import frc.trigon.robot.subsystems.transporter.Transporter;
import frc.trigon.robot.subsystems.transporter.TransporterCommands;
import frc.trigon.robot.subsystems.transporter.TransporterConstants;
import lib.commands.WheelRadiusCharacterizationCommand;
import lib.utilities.flippable.Flippable;
import org.littletonrobotics.junction.networktables.LoggedDashboardChooser;

Expand Down Expand Up @@ -85,8 +83,8 @@ private void configureBindings() {
private void bindDefaultCommands() {
SWERVE.setDefaultCommand(GeneralCommands.getFieldRelativeDriveCommand());
ARM_ELEVATOR.setDefaultCommand(ArmElevatorCommands.getDefaultCommand());
CLIMBER.setDefaultCommand(ClimberCommands.getSetTargetStateCommand(ClimberConstants.ClimberState.REST));
END_EFFECTOR.setDefaultCommand(EndEffectorCommands.getSetTargetStateCommand(EndEffectorConstants.EndEffectorState.REST));
// CLIMBER.setDefaultCommand(ClimberCommands.getSetTargetStateCommand(ClimberConstants.ClimberState.REST));
END_EFFECTOR.setDefaultCommand(EndEffectorCommands.getDefaultCommand());
INTAKE.setDefaultCommand(IntakeCommands.getSetTargetStateCommand(IntakeConstants.IntakeState.REST));
TRANSPORTER.setDefaultCommand(TransporterCommands.getSetTargetStateCommand(TransporterConstants.TransporterState.REST));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public static Command getDriveToReefAndScoreCommand() {

public static Command getCollectCoralCommand(boolean isRight) {
return new ParallelCommandGroup(
CoralCollectionCommands.getIntakeSequenceCommand(),
CoralCollectionCommands.getIntakeCoralCommand(),
ArmElevatorCommands.getPrepareForStateCommand(() -> ArmElevatorConstants.ArmElevatorState.LOAD_CORAL),
getDriveToCoralCommand(isRight)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
public class CoralCollectionCommands {
public static Command getCoralCollectionCommand() {
return new SequentialCommandGroup(
getIntakeSequenceCommand(),
getIntakeCoralCommand().until(RobotContainer.TRANSPORTER::hasCoral),
getCollectionConfirmationCommand(),
new InstantCommand(
() -> {
if (!AlgaeManipulationCommands.isHoldingAlgae())
Expand All @@ -33,7 +34,7 @@ public static Command getLoadCoralCommand() {
return new ParallelCommandGroup(
ArmElevatorCommands.getSetTargetStateCommand(ArmElevatorConstants.ArmElevatorState.LOAD_CORAL),
EndEffectorCommands.getSetTargetStateCommand(EndEffectorConstants.EndEffectorState.LOAD_CORAL)
).until(RobotContainer.END_EFFECTOR::hasGamePiece);
).until(RobotContainer.END_EFFECTOR::hasGamePiece).unless(RobotContainer.END_EFFECTOR::hasGamePiece);
}

public static Command getUnloadCoralCommand() {
Expand All @@ -43,23 +44,13 @@ public static Command getUnloadCoralCommand() {
).until(() -> !RobotContainer.END_EFFECTOR.hasGamePiece());
}

static Command getIntakeSequenceCommand() {
return getInitiateCollectionCommand().until(RobotContainer.TRANSPORTER::hasCoral);
}

private static Command getInitiateCollectionCommand() {
public static Command getIntakeCoralCommand() {
return new ParallelCommandGroup(
IntakeCommands.getSetTargetStateCommand(IntakeConstants.IntakeState.COLLECT),
TransporterCommands.getSetTargetStateWithPulsesCommand(TransporterConstants.TransporterState.COLLECT)
TransporterCommands.getSetTargetStateCommand(TransporterConstants.TransporterState.COLLECT)
);
}

private static Command getAlignCoralCommand() {
return new SequentialCommandGroup(
TransporterCommands.getSetTargetStateWithPulsesCommand(TransporterConstants.TransporterState.ALIGN_CORAL).until(RobotContainer.TRANSPORTER::hasCoral),
TransporterCommands.getSetTargetStateWithPulsesCommand(TransporterConstants.TransporterState.HOLD_CORAL)
);
}

private static Command getCollectionConfirmationCommand() {
return new InstantCommand(() -> OperatorConstants.DRIVER_CONTROLLER.rumble(OperatorConstants.RUMBLE_DURATION_SECONDS, OperatorConstants.RUMBLE_POWER));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import lib.utilities.flippable.FlippableTranslation2d;

public class CoralPlacingCommands {
public static boolean SHOULD_SCORE_AUTONOMOUSLY = true;
public static boolean SHOULD_SCORE_AUTONOMOUSLY = false;
static final ReefChooser REEF_CHOOSER = OperatorConstants.REEF_CHOOSER;

public static Command getScoreInReefCommand(boolean shouldScoreRight) {
Expand All @@ -44,7 +44,7 @@ private static Command getAutonomouslyScoreCommand(boolean shouldScoreRight) {

private static Command getScoreCommand(boolean shouldScoreRight) {
return new SequentialCommandGroup(
getAutonomouslyPrepareScoreCommand(shouldScoreRight).until(OperatorConstants.CONTINUE_TRIGGER),
getPrepareArmElevatorIfWontHitReef(shouldScoreRight).until(OperatorConstants.CONTINUE_TRIGGER),
new ParallelCommandGroup(
GeneralCommands.getFlippableOverridableArmCommand(REEF_CHOOSER::getArmElevatorState, false, CoralPlacingCommands::shouldReverseScore),
EndEffectorCommands.getSetTargetStateCommand(EndEffectorConstants.EndEffectorState.SCORE_CORAL)
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/frc/trigon/robot/subsystems/MotorSubsystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import edu.wpi.first.wpilibj2.command.button.Trigger;
import edu.wpi.first.wpilibj2.command.sysid.SysIdRoutine;
import frc.trigon.robot.RobotContainer;
import org.littletonrobotics.junction.networktables.LoggedNetworkBoolean;
import lib.hardware.RobotHardwareStats;
import org.littletonrobotics.junction.networktables.LoggedNetworkBoolean;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -27,7 +27,7 @@ public abstract class MotorSubsystem extends edu.wpi.first.wpilibj2.command.Subs
private static final List<MotorSubsystem> REGISTERED_SUBSYSTEMS = new ArrayList<>();
private static final Trigger DISABLED_TRIGGER = new Trigger(DriverStation::isDisabled);
private static final Executor BRAKE_MODE_EXECUTOR = Executors.newFixedThreadPool(8);
private static final LoggedNetworkBoolean ENABLE_EXTENSIVE_LOGGING = new LoggedNetworkBoolean("/SmartDashboard/EnableExtensiveLogging", RobotHardwareStats.isSimulation());
private static final LoggedNetworkBoolean ENABLE_EXTENSIVE_LOGGING = new LoggedNetworkBoolean("/SmartDashboard/EnableExtensiveLogging", true);//TODO: AHAHAHAHAHHA
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion | 🟠 Major

❓ Verification inconclusive

Verify this is intentional and track for reversion.

Changing the default from RobotHardwareStats.isSimulation() to true enables extensive logging unconditionally on real hardware, which increases resource consumption (CPU, network bandwidth, storage). The TODO comment suggests this is temporary.

If this is for debugging, consider reverting before competition or making it configurable via NetworkTables at runtime.

Based on learnings


Revert or disable extensive logging default before deployment.

The default for ENABLE_EXTENSIVE_LOGGING was changed to true, enabling costly logging on real hardware (CPU, network, storage). Since it’s already exposed via SmartDashboard, disable it at runtime or revert the default to false before competition.

🤖 Prompt for AI Agents
In src/main/java/frc/trigon/robot/subsystems/MotorSubsystem.java around line 30,
the LoggedNetworkBoolean ENABLE_EXTENSIVE_LOGGING is defaulted to true which
enables heavy logging on real hardware; change its default back to false (or
programmatically force it off at startup) so extensive logging is disabled by
default while leaving the SmartDashboard key available for debugging. Update the
constructor or static initializer to use false as the default value (or call
ENABLE_EXTENSIVE_LOGGING.set(false) during robot init) and add a brief comment
reminding to enable it only for debugging.


static {
DISABLED_TRIGGER.onTrue(new InstantCommand(() -> forEach(MotorSubsystem::stop)).ignoringDisable(true));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import edu.wpi.first.wpilibj.sysid.SysIdRoutineLog;
import edu.wpi.first.wpilibj2.command.sysid.SysIdRoutine;
import frc.trigon.robot.RobotContainer;
import frc.trigon.robot.commands.commandfactories.CoralCollectionCommands;
import frc.trigon.robot.commands.commandfactories.CoralPlacingCommands;
import frc.trigon.robot.subsystems.MotorSubsystem;
import lib.hardware.phoenix6.cancoder.CANcoderEncoder;
Expand All @@ -19,6 +18,7 @@
import org.littletonrobotics.junction.Logger;

public class ArmElevator extends MotorSubsystem {
private static final boolean SHOULD_CALIBRATE_ELEVATOR = true;
private final TalonFXMotor
armMasterMotor = ArmElevatorConstants.ARM_MASTER_MOTOR,
elevatorMasterMotor = ArmElevatorConstants.ELEVATOR_MASTER_MOTOR;
Expand All @@ -30,7 +30,7 @@ public class ArmElevator extends MotorSubsystem {
ArmElevatorConstants.ARM_DEFAULT_MAXIMUM_ACCELERATION,
ArmElevatorConstants.ARM_DEFAULT_MAXIMUM_JERK
).withEnableFOC(ArmElevatorConstants.FOC_ENABLED);
private final DynamicMotionMagicVoltage positionRequest = new DynamicMotionMagicVoltage(
private final DynamicMotionMagicVoltage elevatorPositionRequest = new DynamicMotionMagicVoltage(
0,
ArmElevatorConstants.ELEVATOR_DEFAULT_MAXIMUM_VELOCITY,
ArmElevatorConstants.ELEVATOR_DEFAULT_MAXIMUM_ACCELERATION,
Expand All @@ -45,14 +45,15 @@ public ArmElevator() {

@Override
public SysIdRoutine.Config getSysIDConfig() {
return ArmElevatorConstants.ARM_SYSID_CONFIG;
//return ArmElevatorConstants.ELEVATOR_SYSID_CONFIG;
return SHOULD_CALIBRATE_ELEVATOR ? ArmElevatorConstants.ELEVATOR_SYSID_CONFIG : ArmElevatorConstants.ARM_SYSID_CONFIG;
}

@Override
public void setBrake(boolean brake) {
armMasterMotor.setBrake(brake);
ArmElevatorConstants.ARM_FOLLOWER_MOTOR.setBrake(brake);
elevatorMasterMotor.setBrake(brake);
ArmElevatorConstants.ELEVATOR_FOLLOWER_MOTOR.setBrake(brake);
}

@Override
Expand All @@ -63,21 +64,24 @@ public void stop() {

@Override
public void updateLog(SysIdRoutineLog log) {
if (SHOULD_CALIBRATE_ELEVATOR) {
log.motor("Elevator")
.linearPosition(Units.Meters.of(getElevatorPositionRotations()))
.linearVelocity(Units.MetersPerSecond.of(elevatorMasterMotor.getSignal(TalonFXSignal.ROTOR_VELOCITY) / ArmElevatorConstants.ELEVATOR_GEAR_RATIO))
.voltage(Units.Volts.of(elevatorMasterMotor.getSignal(TalonFXSignal.MOTOR_VOLTAGE)));
return;
Comment on lines +68 to +73
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Fix SysId elevator logging units.

linearPosition/linearVelocity must be in meters, but you’re passing raw rotations (and rotor RPS). That will produce bogus SysId fits for the elevator.

-            log.motor("Elevator")
-                    .linearPosition(Units.Meters.of(getElevatorPositionRotations()))
-                    .linearVelocity(Units.MetersPerSecond.of(elevatorMasterMotor.getSignal(TalonFXSignal.ROTOR_VELOCITY) / ArmElevatorConstants.ELEVATOR_GEAR_RATIO))
+            final double elevatorPositionMeters = rotationsToMeters(getElevatorPositionRotations());
+            final double elevatorVelocityMetersPerSecond = rotationsToMeters(
+                    elevatorMasterMotor.getSignal(TalonFXSignal.ROTOR_VELOCITY) / ArmElevatorConstants.ELEVATOR_GEAR_RATIO
+            );
+            log.motor("Elevator")
+                    .linearPosition(Units.Meters.of(elevatorPositionMeters))
+                    .linearVelocity(Units.MetersPerSecond.of(elevatorVelocityMetersPerSecond))
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (SHOULD_CALIBRATE_ELEVATOR) {
log.motor("Elevator")
.linearPosition(Units.Meters.of(getElevatorPositionRotations()))
.linearVelocity(Units.MetersPerSecond.of(elevatorMasterMotor.getSignal(TalonFXSignal.ROTOR_VELOCITY) / ArmElevatorConstants.ELEVATOR_GEAR_RATIO))
.voltage(Units.Volts.of(elevatorMasterMotor.getSignal(TalonFXSignal.MOTOR_VOLTAGE)));
return;
if (SHOULD_CALIBRATE_ELEVATOR) {
final double elevatorPositionMeters = rotationsToMeters(getElevatorPositionRotations());
final double elevatorVelocityMetersPerSecond = rotationsToMeters(
elevatorMasterMotor.getSignal(TalonFXSignal.ROTOR_VELOCITY)
/ ArmElevatorConstants.ELEVATOR_GEAR_RATIO
);
log.motor("Elevator")
- .linearPosition(Units.Meters.of(getElevatorPositionRotations()))
- .linearVelocity(Units.MetersPerSecond.of(
- elevatorMasterMotor.getSignal(TalonFXSignal.ROTOR_VELOCITY)
- / ArmElevatorConstants.ELEVATOR_GEAR_RATIO
.linearPosition(Units.Meters.of(elevatorPositionMeters))
.linearVelocity(Units.MetersPerSecond.of(elevatorVelocityMetersPerSecond))
.voltage(Units.Volts.of(elevatorMasterMotor.getSignal(TalonFXSignal.MOTOR_VOLTAGE)));
return;
}
🤖 Prompt for AI Agents
In src/main/java/frc/trigon/robot/subsystems/armelevator/ArmElevator.java around
lines 66 to 71, the SysId logging is passing raw rotations and rotor velocity
into linearPosition/linearVelocity (which expect meters and m/s). Convert
rotations to linear meters and rotor velocity to meters/second before calling
Units.Meters.of and Units.MetersPerSecond.of: compute positionMeters =
(rotations / ArmElevatorConstants.ELEVATOR_GEAR_RATIO) * (2 * Math.PI *
ArmElevatorConstants.DRUM_RADIUS) (or use a spool circumference constant) and
velocityMps = (rotorVelocityRPS / ArmElevatorConstants.ELEVATOR_GEAR_RATIO) * (2
* Math.PI * ArmElevatorConstants.DRUM_RADIUS); then pass those values to the
logging calls and keep the voltage log as-is.

}
log.motor("Arm")
.angularPosition(Units.Rotations.of(getCurrentArmAngle().getRotations()))
.angularVelocity(Units.RotationsPerSecond.of(armMasterMotor.getSignal(TalonFXSignal.VELOCITY)))
.angularPosition(Units.Rotations.of(armMasterMotor.getSignal(TalonFXSignal.POSITION)))
.angularVelocity(Units.RotationsPerSecond.of(armMasterMotor.getSignal(TalonFXSignal.ROTOR_VELOCITY) / ArmElevatorConstants.ARM_GEAR_RATIO))
Comment on lines +76 to +77
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

Verify arm angular velocity calculation.

Line 76 divides rotor velocity by ARM_GEAR_RATIO to get angular velocity, but the arm uses a remote CANcoder for feedback (not the rotor). Verify this calculation matches the actual mechanical angular velocity of the arm.


🏁 Script executed:

#!/bin/bash
# Check if arm motor is configured to use remote CANcoder feedback
rg -n "FeedbackSensorSource.*RemoteCANcoder" --type java -A2 -B2

Length of output: 713


🏁 Script executed:

#!/bin/bash
rg -n "enum TalonFXSignal" -n src/main/java

Length of output: 93


🏁 Script executed:

#!/bin/bash
sed -n '1,200p' src/main/java/lib/hardware/phoenix6/talonfx/TalonFXSignal.java

Length of output: 1098


🌐 Web query:

In CTRE Phoenix 6 Java, when a TalonFX is configured with FeedbackSensorSource = RemoteCANcoder and RotorToSensorRatio = gear_ratio, what do TalonFX.getPosition() and TalonFX.getVelocity() return?

💡 Result:

If FeedbackSensorSource = RemoteCANcoder and RotorToSensorRatio = gear_ratio then:

  • TalonFX.getPosition() returns the position in mechanism rotations (i.e., the remote CANcoder-reported rotations adjusted by RotorToSensorRatio / SensorToMechanismRatio as configured). [1][2]
  • TalonFX.getVelocity() returns the velocity in mechanism rotations per second (again affected by RotorToSensorRatio / SensorToMechanismRatio). [1][2]

References: CTRE Phoenix 6 API: CoreTalonFX getPosition/getVelocity and Feedback/RotorToSensorRatio docs. [1] https://api.ctr-electronics.com/phoenix6/release/java/com/ctre/phoenix6/hardware/core/CoreTalonFX.html [2] https://api.ctr-electronics.com/phoenix6/release/java/com/ctre/phoenix6/configs/FeedbackConfigs.html


Use primary sensor velocity, not rotor velocity division

ArmElevator.java:76: replace

armMasterMotor.getSignal(TalonFXSignal.ROTOR_VELOCITY) / ArmElevatorConstants.ARM_GEAR_RATIO

with

armMasterMotor.getSignal(TalonFXSignal.VELOCITY)

since FeedbackSensorSource = RemoteCANcoder with RotorToSensorRatio = ARM_GEAR_RATIO already returns arm rotations per second.

🤖 Prompt for AI Agents
In src/main/java/frc/trigon/robot/subsystems/armelevator/ArmElevator.java around
lines 75-76, the code uses
armMasterMotor.getSignal(TalonFXSignal.ROTOR_VELOCITY) divided by
ArmElevatorConstants.ARM_GEAR_RATIO; replace this with
armMasterMotor.getSignal(TalonFXSignal.VELOCITY) so you read the primary sensor
velocity (which already accounts for RemoteCANcoder RotorToSensorRatio =
ARM_GEAR_RATIO) and pass that value into Units.RotationsPerSecond.of — i.e.
remove the manual division and use the VELOCITY signal.

.voltage(Units.Volts.of(armMasterMotor.getSignal(TalonFXSignal.MOTOR_VOLTAGE)));
// log.motor("Elevator")
// .linearPosition(Units.Meters.of(getPositionRotations()))
// .linearVelocity(Units.MetersPerSecond.of(masterMotor.getSignal(TalonFXSignal.VELOCITY)))
// .voltage(Units.Volts.of(masterMotor.getSignal(TalonFXSignal.MOTOR_VOLTAGE)));
}

@Override
public void updateMechanism() {
ArmElevatorConstants.ARM_MECHANISM.update(
Rotation2d.fromRotations(getCurrentArmAngle().getRotations() + ArmElevatorConstants.POSITION_OFFSET_FROM_GRAVITY_OFFSET),
Rotation2d.fromRotations(armMasterMotor.getSignal(TalonFXSignal.CLOSED_LOOP_REFERENCE) + ArmElevatorConstants.POSITION_OFFSET_FROM_GRAVITY_OFFSET)
Rotation2d.fromRotations(getCurrentArmAngle().getRotations()),
Rotation2d.fromRotations(armMasterMotor.getSignal(TalonFXSignal.CLOSED_LOOP_REFERENCE) + ArmElevatorConstants.ARM_POSITION_OFFSET_FROM_GRAVITY_OFFSET)
);
ArmElevatorConstants.ELEVATOR_MECHANISM.update(
getCurrentElevatorPositionMeters(),
Expand All @@ -101,8 +105,11 @@ public void updatePeriodically() {

@Override
public void sysIDDrive(double targetVoltage) {
if (SHOULD_CALIBRATE_ELEVATOR) {
elevatorMasterMotor.setControl(voltageRequest.withOutput(targetVoltage));
return;
}
armMasterMotor.setControl(voltageRequest.withOutput(targetVoltage));
// elevatorMasterMotor.setControl(voltageRequest.withOutput(targetVoltage));
}

public Pose3d calculateGamePieceCollectionPose() {
Expand All @@ -125,7 +132,7 @@ public boolean atState(ArmElevatorConstants.ArmElevatorState targetState) {
public boolean atState(ArmElevatorConstants.ArmElevatorState targetState, boolean isStateReversed) {
if (targetState == null)
return false;
return armAtAngle(isStateReversed ? subtractFrom360Degrees(targetState.targetAngle) : targetState.targetAngle)
return armAtAngle(isStateReversed ? subtractFrom180Degrees(targetState.targetAngle) : targetState.targetAngle)
&& elevatorAtPosition(targetState.targetPositionMeters);
}

Expand All @@ -144,7 +151,7 @@ public boolean elevatorAtPosition(double positionMeters) {
}

public Rotation2d getCurrentArmAngle() {
return Rotation2d.fromRotations(angleEncoder.getSignal(CANcoderSignal.POSITION));
return Rotation2d.fromRotations(angleEncoder.getSignal(CANcoderSignal.POSITION) + ArmElevatorConstants.ARM_POSITION_OFFSET_FROM_GRAVITY_OFFSET);
}

public double getCurrentElevatorPositionMeters() {
Expand Down Expand Up @@ -186,8 +193,9 @@ void setTargetState(ArmElevatorConstants.ArmElevatorState targetState, boolean i
}

void setTargetArmState(ArmElevatorConstants.ArmElevatorState targetState, boolean isStateReversed) {
scaleArmPositionRequestSpeed(targetState.speedScalar);
if (isStateReversed) {
setTargetArmAngle(subtractFrom360Degrees(targetState.targetAngle), targetState.ignoreConstraints);
setTargetArmAngle(subtractFrom180Degrees(targetState.targetAngle), targetState.ignoreConstraints);
return;
}
setTargetArmAngle(targetState.targetAngle, targetState.ignoreConstraints);
Expand All @@ -199,28 +207,29 @@ void setTargetElevatorState(ArmElevatorConstants.ArmElevatorState targetState) {
}

void setTargetArmAngle(Rotation2d targetAngle, boolean ignoreConstraints) {
armMasterMotor.setControl(armPositionRequest.withPosition(ignoreConstraints ? targetAngle.getRotations() : Math.max(targetAngle.getRotations(), calculateMinimumArmSafeAngle().getRotations())));
final double targetPosition = ignoreConstraints ? targetAngle.getRotations() : Math.max(targetAngle.getRotations(), calculateMinimumArmSafeAngle().getRotations());
armMasterMotor.setControl(armPositionRequest.withPosition(targetPosition - ArmElevatorConstants.ARM_POSITION_OFFSET_FROM_GRAVITY_OFFSET));
}

void setTargetElevatorPositionMeters(double targetPositionMeters, boolean ignoreConstraints) {
setTargetElevatorPositionRotations(metersToRotations(targetPositionMeters), ignoreConstraints);
}

void setTargetElevatorPositionRotations(double targetPositionRotations, boolean ignoreConstraints) {
elevatorMasterMotor.setControl(positionRequest.withPosition(ignoreConstraints ? targetPositionRotations : Math.max(targetPositionRotations, calculateMinimumSafeElevatorHeightRotations())));
elevatorMasterMotor.setControl(elevatorPositionRequest.withPosition(ignoreConstraints ? targetPositionRotations : Math.max(targetPositionRotations, calculateMinimumSafeElevatorHeightRotations())));
}

private Rotation2d calculateMinimumArmSafeAngle() {
final double heightFromSafeZone = getElevatorHeightFromMinimumSafeZone();
final double cosOfMinimumSafeAngle = MathUtil.clamp(heightFromSafeZone / ArmElevatorConstants.ARM_LENGTH_METERS, 0, 1);
final double acos = Math.acos(cosOfMinimumSafeAngle);
return Double.isNaN(acos)
? Rotation2d.fromRadians(0)
: Rotation2d.fromRadians(acos);
? Rotation2d.fromDegrees(-90)
: Rotation2d.fromRadians(acos).minus(Rotation2d.kCCW_90deg);
}

private double calculateMinimumSafeElevatorHeightRotations() {
final double armCos = RobotContainer.ARM_ELEVATOR.getCurrentArmAngle().getCos();
final double armCos = RobotContainer.ARM_ELEVATOR.getCurrentArmAngle().plus(Rotation2d.kCCW_90deg).getCos();
final double elevatorHeightFromArm = armCos * ArmElevatorConstants.ARM_LENGTH_METERS;
final double minimumElevatorSafeZone = ArmElevatorConstants.MINIMUM_ELEVATOR_SAFE_ZONE_METERS;
final double minimumSafeHeightMeters = (RobotContainer.ARM_ELEVATOR.isArmAboveSafeAngle()
Expand All @@ -233,22 +242,28 @@ private double getElevatorHeightFromMinimumSafeZone() {
return getCurrentElevatorPositionMeters() - ArmElevatorConstants.MINIMUM_ELEVATOR_SAFE_ZONE_METERS;
}

private static Rotation2d subtractFrom360Degrees(Rotation2d angleToSubtract) {
return Rotation2d.fromDegrees(Rotation2d.k180deg.getDegrees() * 2 - angleToSubtract.getDegrees());
private static Rotation2d subtractFrom180Degrees(Rotation2d angleToSubtract) {
return Rotation2d.fromDegrees(Rotation2d.k180deg.getDegrees() - angleToSubtract.getDegrees());
}

private Pose3d calculateVisualizationPose() {
final Transform3d armTransform = new Transform3d(
new Translation3d(0, 0, getCurrentElevatorPositionMeters()),
new Rotation3d(0, getCurrentArmAngle().getRadians(), 0)
new Rotation3d(0, getCurrentArmAngle().getRadians() + Math.PI / 2, 0)
);
return ArmElevatorConstants.ARM_VISUALIZATION_ORIGIN_POINT.transformBy(armTransform);
}

private void scaleArmPositionRequestSpeed(double speedScalar) {
armPositionRequest.Velocity = ArmElevatorConstants.ARM_DEFAULT_MAXIMUM_VELOCITY * speedScalar;
armPositionRequest.Acceleration = ArmElevatorConstants.ARM_DEFAULT_MAXIMUM_ACCELERATION * speedScalar;
armPositionRequest.Jerk = armPositionRequest.Acceleration * 10;
}

private void scaleElevatorPositionRequestSpeed(double speedScalar) {
positionRequest.Velocity = ArmElevatorConstants.ELEVATOR_DEFAULT_MAXIMUM_VELOCITY * speedScalar;
positionRequest.Acceleration = ArmElevatorConstants.ELEVATOR_DEFAULT_MAXIMUM_ACCELERATION * speedScalar;
positionRequest.Jerk = positionRequest.Acceleration * 10;
elevatorPositionRequest.Velocity = ArmElevatorConstants.ELEVATOR_DEFAULT_MAXIMUM_VELOCITY * speedScalar;
elevatorPositionRequest.Acceleration = ArmElevatorConstants.ELEVATOR_DEFAULT_MAXIMUM_ACCELERATION * speedScalar;
elevatorPositionRequest.Jerk = elevatorPositionRequest.Acceleration * 10;
}

private Pose3d getFirstStageComponentPose() {
Expand Down
Loading
Loading