-
Notifications
You must be signed in to change notification settings - Fork 0
Arm logic #16
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
Arm logic #16
Changes from 12 commits
26ede8b
b969772
b93b24d
8bcbe19
cbf1359
d3546dd
4b60ce6
f327b94
bd98958
eb64ed0
024fb62
d1c4d2d
4dd87f5
379867e
1b9c09f
4820ccc
bbe7ac4
140137d
2b0037f
482bd8f
1aeb7bb
07b24f6
94c264b
936826d
9b9fc93
c2591b7
8159e68
dc3319b
d748b5e
248ca5c
3a8dc54
c0db5e1
43757f9
62fcd32
440dc79
fae2066
33beb6d
cf68be9
d1c7edc
5bf8194
bd19f72
4ea93e3
df0a3f4
fb1233d
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 |
---|---|---|
|
@@ -6,7 +6,9 @@ | |
import edu.wpi.first.units.Units; | ||
import edu.wpi.first.wpilibj.sysid.SysIdRoutineLog; | ||
import edu.wpi.first.wpilibj2.command.sysid.SysIdRoutine; | ||
import frc.trigon.robot.RobotContainer; | ||
import frc.trigon.robot.subsystems.MotorSubsystem; | ||
import frc.trigon.robot.subsystems.elevator.ElevatorConstants; | ||
import lib.hardware.phoenix6.cancoder.CANcoderEncoder; | ||
import lib.hardware.phoenix6.cancoder.CANcoderSignal; | ||
import lib.hardware.phoenix6.talonfx.TalonFXMotor; | ||
|
@@ -81,6 +83,10 @@ public void sysIDDrive(double targetVoltage) { | |
armMasterMotor.setControl(voltageRequest.withOutput(targetVoltage)); | ||
} | ||
|
||
public boolean isArmAboveSafeZone() { | ||
return getAngle().getDegrees() >= 90; | ||
ShmayaR marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
} | ||
|
||
public boolean atState(ArmConstants.ArmState targetState, boolean isStateReversed) { | ||
if (isStateReversed) | ||
return this.targetState == targetState && atTargetAngle(isStateReversed); | ||
|
@@ -93,7 +99,7 @@ public boolean atState(ArmConstants.ArmState targetState) { | |
|
||
public boolean atTargetAngle(boolean isStateReversed) { | ||
ShmayaR marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
if (isStateReversed) { | ||
final double currentToTargetStateDifferenceDegrees = Math.abs(ArmConstants.FULL_ROTATION.minus(targetState.targetAngle).minus(getAngle()).getDegrees()); | ||
final double currentToTargetStateDifferenceDegrees = Math.abs(subtractFrom360(targetState.targetAngle).minus(getAngle()).getDegrees()); | ||
return currentToTargetStateDifferenceDegrees < ArmConstants.ANGLE_TOLERANCE.getDegrees(); | ||
} | ||
return atTargetAngle(); | ||
|
@@ -104,8 +110,8 @@ public boolean atTargetAngle() { | |
return currentToTargetStateDifferenceDegrees < ArmConstants.ANGLE_TOLERANCE.getDegrees(); | ||
} | ||
|
||
public boolean hasGamePiece() { | ||
return ArmConstants.COLLECTION_DETECTION_BOOLEAN_EVENT.getAsBoolean(); | ||
public Rotation2d getAngle() { | ||
return Rotation2d.fromRotations(angleEncoder.getSignal(CANcoderSignal.POSITION)); | ||
ShmayaR marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
void setTargetState(ArmConstants.ArmState targetState) { | ||
|
@@ -120,7 +126,7 @@ void setTargetState(ArmConstants.ArmState targetState, boolean isStateReversed) | |
|
||
if (isStateReversed) { | ||
setTargetState( | ||
ArmConstants.FULL_ROTATION.minus(targetState.targetAngle) | ||
subtractFrom360(targetState.targetAngle) | ||
, targetState.targetEndEffectorVoltage | ||
); | ||
return; | ||
|
@@ -142,30 +148,33 @@ void prepareForState(ArmConstants.ArmState targetState) { | |
void prepareForState(ArmConstants.ArmState targetState, boolean isStateReversed) { | ||
this.isStateReversed = isStateReversed; | ||
this.targetState = targetState; | ||
|
||
if (isStateReversed) { | ||
setTargetAngle(ArmConstants.FULL_ROTATION.minus(targetState.targetAngle)); | ||
setTargetAngle(subtractFrom360(targetState.targetAngle)); | ||
return; | ||
} | ||
setTargetAngle(targetState.targetAngle); | ||
} | ||
|
||
private Rotation2d getAngle() { | ||
return Rotation2d.fromRotations(angleEncoder.getSignal(CANcoderSignal.POSITION)); | ||
} | ||
|
||
private void setTargetAngle(Rotation2d targetAngle) { | ||
armMasterMotor.setControl(positionRequest.withPosition(targetAngle.getRotations())); | ||
final double heightFromSafeZone = RobotContainer.ELEVATOR.getPositionMeters() - ElevatorConstants.MINIMUM_ELEVATOR_SAFE_ZONE_METERS; | ||
ShmayaR marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
ShmayaR marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
final double cosMinimumAngle = heightFromSafeZone / ArmConstants.ARM_LENGTH_METERS; | ||
final Rotation2d minimumSafeAngle = Rotation2d.fromRadians(RobotContainer.ELEVATOR.isElevatorAboveSafeZone() ? 0 : Math.acos(cosMinimumAngle)); | ||
ShmayaR marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
armMasterMotor.setControl(positionRequest.withPosition(Math.max(targetAngle.getRotations(), minimumSafeAngle.getRotations()))); | ||
ShmayaR marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
} | ||
ShmayaR marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
private void setTargetVoltage(double targetVoltage) { | ||
ShmayaR marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
ArmConstants.END_EFFECTOR_MECHANISM.setTargetVelocity(targetVoltage); | ||
endEffectorMotor.setControl(voltageRequest.withOutput(targetVoltage)); | ||
} | ||
|
||
public static Rotation2d subtractFrom360(Rotation2d angleToSubtract) { | ||
Nummun14 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
return Rotation2d.fromDegrees(360 - angleToSubtract.getDegrees()); | ||
Nummun14 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
ShmayaR marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
} | ||
|
||
|
||
private Pose3d calculateVisualizationPose() { | ||
ShmayaR marked this conversation as resolved.
Show resolved
Hide resolved
|
||
final Transform3d armTransform = new Transform3d( | ||
new Translation3d(), | ||
new Translation3d(0, 0, RobotContainer.ELEVATOR.getPositionMeters()), | ||
new Rotation3d(0, getAngle().getRadians(), 0) | ||
); | ||
return ArmConstants.ARM_VISUALIZATION_ORIGIN_POINT.transformBy(armTransform); | ||
|
Uh oh!
There was an error while loading. Please reload this page.