Quote:
Originally Posted by WilliamR
Here is the code that we are using to test the latching of our winch after a limit switch is activated.
Code:
void shoot() {
latchPneumatic.set(DoubleSolenoid.Value.kReverse);
}
void winch(int direction, double unwindTime) {
if (direction == 1) {
while (catapultLimitSwitch.get() == true) {
winchMotor.set(1);
}
//latchPneumatic.set(DoubleSolenoid.Value.kReverse);
winchMotor.set(0);
}
else if (direction == -1) {
for (int i = 0; i < unwindTime*10000; i++) winchMotor.set(-1);
winchMotor.set(0);
}
else winchMotor.set(0);
}
|
What you are doing here is very dangerous when using the Command Based approach. Long acting while loops are a big no no and should be avoided at all costs. What you want to do is use a single command for each action and combine them into a command group to get them to work in sequence. Your command for moving the wench should be similar to this:
Code:
public void execute() {
shooter.winch(1);
}
public boolean isFinished() {
if (timeNow - startTime > unwindTime) {
return true;
}
}
public void end() {
shooter.winch(0);
}
This will run the shooter motor at the power level provided in the parameter:
You will use this to tell the command when it is finished:
Code:
public boolean isFinished() {
if (timeNow - startTime > unwindTime) {
return true;
}
}
This will stop the motor once the command is finished (the winch runs for the specified time):
Code:
public void end() {
shooter.winch(0);
}