mirror of
https://github.com/TimeCrafters/FTC_2022
synced 2025-12-15 16:42:35 +00:00
Rework Arm state to be able to use 'tuning' variables for arm angle
This commit is contained in:
@@ -8,8 +8,9 @@ public class Arm extends CyberarmState {
|
|||||||
private final String groupName, actionName;
|
private final String groupName, actionName;
|
||||||
|
|
||||||
private final double targetVelocity, timeInMS;
|
private final double targetVelocity, timeInMS;
|
||||||
private final int tolerance, halfTolerance, targetPosition;
|
private final int tolerance, halfTolerance, position, manualPosition;
|
||||||
private final boolean stateDisabled;
|
private final boolean positionManually, stateDisabled;
|
||||||
|
private final String positionLookupLabel;
|
||||||
|
|
||||||
public Arm(Robot robot, String groupName, String actionName) {
|
public Arm(Robot robot, String groupName, String actionName) {
|
||||||
this.robot = robot;
|
this.robot = robot;
|
||||||
@@ -20,18 +21,27 @@ public class Arm extends CyberarmState {
|
|||||||
robot.getConfiguration().variable(groupName, actionName, "targetVelocityInDegreesPerSecond").value());
|
robot.getConfiguration().variable(groupName, actionName, "targetVelocityInDegreesPerSecond").value());
|
||||||
tolerance = robot.angleToTicks(
|
tolerance = robot.angleToTicks(
|
||||||
robot.getConfiguration().variable(groupName, actionName, "toleranceInDegrees").value());
|
robot.getConfiguration().variable(groupName, actionName, "toleranceInDegrees").value());
|
||||||
targetPosition = robot.angleToTicks(
|
|
||||||
robot.getConfiguration().variable(groupName, actionName, "targetAngle").value());
|
|
||||||
timeInMS = robot.getConfiguration().variable(groupName, actionName, "timeInMS").value();
|
timeInMS = robot.getConfiguration().variable(groupName, actionName, "timeInMS").value();
|
||||||
|
|
||||||
|
positionLookupLabel = robot.getConfiguration().variable(groupName, actionName, "positionLookupLabel").value();
|
||||||
|
positionManually = robot.getConfiguration().variable(groupName, actionName, "positionManually").value();
|
||||||
|
manualPosition = robot.angleToTicks(
|
||||||
|
robot.getConfiguration().variable(groupName, actionName, "manualTargetAngle").value());
|
||||||
|
|
||||||
stateDisabled = !robot.getConfiguration().action(groupName, actionName).enabled;
|
stateDisabled = !robot.getConfiguration().action(groupName, actionName).enabled;
|
||||||
|
|
||||||
halfTolerance = Math.round(tolerance / 2.0f);
|
halfTolerance = Math.round(tolerance / 2.0f);
|
||||||
|
|
||||||
|
if (positionManually) {
|
||||||
|
position = manualPosition;
|
||||||
|
} else {
|
||||||
|
position = robot.angleToTicks(robot.tuningConfig(positionLookupLabel).value());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start() {
|
public void start() {
|
||||||
robot.arm.setTargetPosition(targetPosition);
|
robot.arm.setTargetPosition(position);
|
||||||
robot.arm.setTargetPositionTolerance(tolerance);
|
robot.arm.setTargetPositionTolerance(tolerance);
|
||||||
robot.arm.setVelocity(targetVelocity);
|
robot.arm.setVelocity(targetVelocity);
|
||||||
}
|
}
|
||||||
@@ -52,8 +62,8 @@ public class Arm extends CyberarmState {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int position = robot.arm.getCurrentPosition();
|
int currentPosition = robot.arm.getCurrentPosition();
|
||||||
if (robot.isBetween(position, position - halfTolerance, position + halfTolerance)) {
|
if (robot.isBetween(currentPosition, currentPosition - halfTolerance, currentPosition + halfTolerance)) {
|
||||||
setHasFinished(true);
|
setHasFinished(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user