From 69e256f731895570bd7abb713d1995de3740a8cd Mon Sep 17 00:00:00 2001 From: Shaina Chen Date: Tue, 9 Feb 2016 20:25:36 -0800 Subject: [PATCH] create and fill setArmToAngle command --- .../robot/commands/SetArmToAngle.java | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100755 src/org/usfirst/frc/team3501/robot/commands/SetArmToAngle.java diff --git a/src/org/usfirst/frc/team3501/robot/commands/SetArmToAngle.java b/src/org/usfirst/frc/team3501/robot/commands/SetArmToAngle.java new file mode 100755 index 00000000..02d6e827 --- /dev/null +++ b/src/org/usfirst/frc/team3501/robot/commands/SetArmToAngle.java @@ -0,0 +1,60 @@ +package org.usfirst.frc.team3501.robot.commands; + +import org.usfirst.frc.team3501.robot.Robot; + +import edu.wpi.first.wpilibj.command.Command; + +public class SetArmToAngle extends Command { + private static final double THRESHOLD = 0.1; + private double speed; + private double targetPosition; + private double currentPosition; + private boolean isDecreasing = false; + + public SetArmToAngle(double speed, double targetPosition) { + requires(Robot.defenseArm); + + this.speed = speed; + this.targetPosition = targetPosition; + } + + @Override + public void initialize() { + currentPosition = Robot.defenseArm.getArmPotAngle(); + + if (currentPosition > targetPosition) { + Robot.defenseArm.setArmSpeed(-speed); + isDecreasing = true; + } else { + Robot.defenseArm.setArmSpeed(speed); + isDecreasing = false; + } + } + + @Override + public void execute() { + + } + + @Override + public boolean isFinished() { + currentPosition = Robot.defenseArm.getArmPotAngle(); + + if (isDecreasing == true) { + return (currentPosition <= targetPosition + THRESHOLD); + } else { + return (currentPosition >= targetPosition - THRESHOLD); + } + } + + @Override + public void end() { + Robot.defenseArm.setArmSpeed(0); + } + + @Override + protected void interrupted() { + end(); + } + +} -- 2.30.2