Go to Post mabye this is a case of I AM JVN to the Extreme! - Tytus Gerrish [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
 
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 27-08-2016, 08:33
Joe Ross's Avatar Unsung FIRST Hero
Joe Ross Joe Ross is offline
Registered User
FRC #0330 (Beachbots)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1997
Location: Los Angeles, CA
Posts: 8,561
Joe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond repute
Yes, you need to make isFinished return true in that condition.
Reply With Quote
  #2   Spotlight this post!  
Unread 27-08-2016, 13:47
cpapplefamily cpapplefamily is offline
Registered User
FRC #3244 (Granite City Gearheads)
Team Role: Mentor
 
Join Date: May 2015
Rookie Year: 2015
Location: Minnesota
Posts: 243
cpapplefamily has a spectacular aura aboutcpapplefamily has a spectacular aura about
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
Reply With Quote
  #3   Spotlight this post!  
Unread 27-08-2016, 16:43
euhlmann's Avatar
euhlmann euhlmann is online now
CTO, Programmer
AKA: Erik Uhlmann
FRC #2877 (LigerBots)
Team Role: Leadership
 
Join Date: Dec 2015
Rookie Year: 2015
Location: United States
Posts: 322
euhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud of
Re: Cancel a command

Does Command.cancel() work?
__________________
Creator of SmartDashboard.js, an extensible nodejs/webkit replacement for SmartDashboard


https://ligerbots.org
Reply With Quote
  #4   Spotlight this post!  
Unread 27-08-2016, 18:38
cpapplefamily cpapplefamily is offline
Registered User
FRC #3244 (Granite City Gearheads)
Team Role: Mentor
 
Join Date: May 2015
Rookie Year: 2015
Location: Minnesota
Posts: 243
cpapplefamily has a spectacular aura aboutcpapplefamily has a spectacular aura about
Re: Cancel a command

We will try
Code:
this.Cancel()
but the JavaDocs say:
Quote:
void edu.wpi.first.wpilibj.command.Command.cancel()


This will cancel the current command.

This will cancel the current command eventually. It can be called multiple times. And it can be called when the command is not running. If the command is running though, then the command will be marked as canceled and eventually removed.

A command can not be canceled if it is a part of a command group, you must cancel the command group instead.
In bold we are at this time! Unless just this command is canceled with in the Command Group.
Reply With Quote
  #5   Spotlight this post!  
Unread 27-08-2016, 19:46
cpapplefamily cpapplefamily is offline
Registered User
FRC #3244 (Granite City Gearheads)
Team Role: Mentor
 
Join Date: May 2015
Rookie Year: 2015
Location: Minnesota
Posts: 243
cpapplefamily has a spectacular aura aboutcpapplefamily has a spectacular aura about
Re: Cancel a command

Quote:
Originally Posted by euhlmann View Post
Does Command.cancel() work?
NOPE! Tested and since its in a cammand Group it crashed the program and sent an error to the councle. I'm not going to type it out but in a nut shell it said
Quote:
....IllegalUseOfCommandException: Can not manually cancel a command in a command group....
But storing the status in m_CancelCommand and monitoring it in isFinished did work as we want it to.
Reply With Quote
  #6   Spotlight this post!  
Unread 28-08-2016, 23:21
euhlmann's Avatar
euhlmann euhlmann is online now
CTO, Programmer
AKA: Erik Uhlmann
FRC #2877 (LigerBots)
Team Role: Leadership
 
Join Date: Dec 2015
Rookie Year: 2015
Location: United States
Posts: 322
euhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud of
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();
  }
}
__________________
Creator of SmartDashboard.js, an extensible nodejs/webkit replacement for SmartDashboard


https://ligerbots.org
Reply With Quote
  #7   Spotlight this post!  
Unread 29-08-2016, 10:06
cpapplefamily cpapplefamily is offline
Registered User
FRC #3244 (Granite City Gearheads)
Team Role: Mentor
 
Join Date: May 2015
Rookie Year: 2015
Location: Minnesota
Posts: 243
cpapplefamily has a spectacular aura aboutcpapplefamily has a spectacular aura about
Re: Cancel a command

Good to know I'll have them add that part to the code as well.
Quote:
public void execute() {
if(isUnsafe) {
return;
// IMPORTANT. execute() will be called once regardless of isFinished() status
}

// execute as usual
}
Reply With Quote
  #8   Spotlight this post!  
Unread 29-08-2016, 10:27
euhlmann's Avatar
euhlmann euhlmann is online now
CTO, Programmer
AKA: Erik Uhlmann
FRC #2877 (LigerBots)
Team Role: Leadership
 
Join Date: Dec 2015
Rookie Year: 2015
Location: United States
Posts: 322
euhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud of
Re: Cancel a command

Quote:
Originally Posted by cpapplefamily View Post
Good to know I'll have them add that part to the code as well.
The key part is in isFinished(), which returns true if it's unsafe (so the command finishes)

I'm curious as to why a command can't be canceled in a commandgroup. Is there any particular reason for that?
__________________
Creator of SmartDashboard.js, an extensible nodejs/webkit replacement for SmartDashboard


https://ligerbots.org
Reply With Quote
  #9   Spotlight this post!  
Unread 29-08-2016, 23:48
cpapplefamily cpapplefamily is offline
Registered User
FRC #3244 (Granite City Gearheads)
Team Role: Mentor
 
Join Date: May 2015
Rookie Year: 2015
Location: Minnesota
Posts: 243
cpapplefamily has a spectacular aura aboutcpapplefamily has a spectacular aura about
Re: Cancel a command

Quote:
Originally Posted by euhlmann View Post
The key part is in isFinished(), which returns true if it's unsafe (so the command finishes)

I'm curious as to why a command can't be canceled in a commandgroup. Is there any particular reason for that?
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.
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 10:47.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi