-
Notifications
You must be signed in to change notification settings - Fork 0
Dev #29
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
base: main
Are you sure you want to change the base?
Dev #29
Changes from 10 commits
0fad1ac
7b281c2
aff073d
a45d106
a93400d
8c3a876
48875b7
f6c5a7c
6522d8a
53fc6e1
bfcc454
883add7
5604fa0
6bdc83d
89a72a6
a3a6d42
456e939
3f4d646
204470b
779c470
26a4e70
ef1d29f
d18c2ee
8780d1e
c09aefc
c177ea3
5fe7509
98f9216
247c198
94e4b5b
a88fb13
0f718f0
0399a40
937117c
8f463be
1c60f7d
8738ba1
1e5ba97
b3f844c
de3c682
9ee334c
b15b4dd
41a47b5
7387872
a23d92d
401e263
73f8672
f72905c
b30244a
0e65033
ac2ca04
ea633be
2c0ce29
ff18479
fec5163
4be96a4
ab141c8
a876e79
fa8494f
7ebdf2a
3355f90
1a5275c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -19,6 +19,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; | ||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -45,14 +46,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 | ||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -63,21 +65,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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix SysId elevator logging units.
- 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
Suggested change
🤖 Prompt for AI Agents
|
||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chainVerify arm angular velocity calculation. Line 76 divides rotor velocity by 🏁 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:
💡 Result: If FeedbackSensorSource = RemoteCANcoder and RotorToSensorRatio = gear_ratio then:
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 🤖 Prompt for AI Agents
|
||||||||||||||||||||||||||||||||||||||||||||||
.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(), | ||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -101,8 +106,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() { | ||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -125,7 +133,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); | ||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -144,7 +152,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() { | ||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -187,7 +195,7 @@ void setTargetState(ArmElevatorConstants.ArmElevatorState targetState, boolean i | |||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
void setTargetArmState(ArmElevatorConstants.ArmElevatorState targetState, boolean isStateReversed) { | ||||||||||||||||||||||||||||||||||||||||||||||
if (isStateReversed) { | ||||||||||||||||||||||||||||||||||||||||||||||
setTargetArmAngle(subtractFrom360Degrees(targetState.targetAngle), targetState.ignoreConstraints); | ||||||||||||||||||||||||||||||||||||||||||||||
setTargetArmAngle(subtractFrom180Degrees(targetState.targetAngle), targetState.ignoreConstraints); | ||||||||||||||||||||||||||||||||||||||||||||||
return; | ||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||
setTargetArmAngle(targetState.targetAngle, targetState.ignoreConstraints); | ||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -199,7 +207,8 @@ 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) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -215,12 +224,12 @@ private Rotation2d calculateMinimumArmSafeAngle() { | |||||||||||||||||||||||||||||||||||||||||||||
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() | ||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -233,14 +242,14 @@ 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); | ||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment.
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()
totrue
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 totrue
, enabling costly logging on real hardware (CPU, network, storage). Since it’s already exposed via SmartDashboard, disable it at runtime or revert the default tofalse
before competition.🤖 Prompt for AI Agents