|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||
|
|||
|
Re: Cancel a command
Thank you. We will give this a go.
Code:
private boolean m_CancelCommand = false; Code:
protected void initialize() {
43 m_CancelCommand = false;
44 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
45 // Not Allow movement if Wrist Is up !
46 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
47 if(m_setpoint>70 && Robot.wristPID.getSetpoint()>30){
48 System.out.println("Scissor Cancled Wrist > 30");
49 m_CancelCommand = true;
50 }else{
51 if(m_setpoint>30 && Robot.wristPID.getSetpoint()>55){
52 System.out.println("Scissor Cancled Wrist > 55");
53 m_CancelCommand = true;
54
55 }else{
56
57 Robot.scissorPID.enable();
58 Robot.scissorPID.setSetpoint(m_setpoint);
59
60
61 }
62 }
Code:
72 protected boolean isFinished() {
73
74 return Robot.scissorPID.onTarget() || m_CancelCommand ;
75
76
77 }
78
|
|
#2
|
||||
|
||||
|
Re: Cancel a command
Does Command.cancel() work?
|
|
#3
|
|||
|
|||
|
Re: Cancel a command
We will try
Code:
this.Cancel() Quote:
|
|
#4
|
|||
|
|||
|
Re: Cancel a command
Quote:
Quote:
|
|
#5
|
||||
|
||||
|
Re: Cancel a command
Whoops, didn't see that section of the docs
![]() There's an easy way to do what you want in your situation though. Code:
public class ScissorToPosition extends Command {
// ...
boolean isUnsafe = false;
public void initialize() {
if(m_setpoint > 70 && Robot.wristPID.getSetpoint() > 30) {
System.out.println("Scissor canceled since wrist > 30");
isUnsafe = true;
} else {
isUnsafe = false;
// init as usual
}
}
// ...
public void execute() {
if(isUnsafe) {
return;
// IMPORTANT. execute() will be called once regardless of isFinished() status
}
// execute as usual
}
public void isFinished() {
if(isUnsafe) {
return true;
}
return Robot.scissorPID.onTarget();
}
}
|
|
#6
|
|||
|
|||
|
Re: Cancel a command
Good to know I'll have them add that part to the code as well.
Quote:
|
|
#7
|
||||
|
||||
|
Re: Cancel a command
Quote:
I'm curious as to why a command can't be canceled in a commandgroup. Is there any particular reason for that? |
|
#8
|
|||
|
|||
|
Re: Cancel a command
Right! Seems like you should be able to cancel a running command anywhere. maybe when its in a Command group its not its own object anymore. I guess for now we will just have to play by the rules.
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|