Go to Post "FIRST" is not a verb (yet - give us time, and we will see what happens). - dlavery [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rating: Thread Rating: 4 votes, 5.00 average. Display Modes
  #1   Spotlight this post!  
Unread 09-02-2015, 19:49
pluto7443 pluto7443 is offline
Registered User
FRC #4917
 
Join Date: Mar 2014
Location: Canada
Posts: 17
pluto7443 is an unknown quantity at this point
Conditional Command Group?

We are trying to conditionally execute parts of our command group based on values read off of certain subsystems. However, we are unable to get access to any of the robot's initialized subsystems in the command group or in OI (where the command group is being called from).

How do we execute certain commands based on values read from the robot?
Reply With Quote
  #2   Spotlight this post!  
Unread 09-02-2015, 21:37
FleventyFive FleventyFive is offline
Registered User
FRC #4118
 
Join Date: Sep 2014
Location: Gainesville, FL
Posts: 23
FleventyFive is on a distinguished road
Re: Conditional Command Group?

In the header file for the command group (like PickupAndPlace.h) , include Robot.h or whatever your main robot file is. This will give you access to all of your subsystems and oi or anything else in your robot class.
Code:
#include "../Robot.h"
Reply With Quote
  #3   Spotlight this post!  
Unread 09-02-2015, 21:49
Ben Wolsieffer Ben Wolsieffer is offline
Dartmouth 2020
AKA: lopsided98
FRC #2084 (Robots by the C)
Team Role: Alumni
 
Join Date: Jan 2011
Rookie Year: 2011
Location: Manchester, MA (Hanover, NH)
Posts: 520
Ben Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud of
Re: Conditional Command Group?

You can put if statements around your addSequential/Parallel() calls so they will execute based on a condition, but this will only allow you to respond to values that are set when the robot starts. The initialization of the command group is only performed once when the robot starts, so if (for example) you want to respond to the value of a sensor when the command group is executed, this approach will not work.
__________________



2016 North Shore District - Semifinalists and Excellence in Engineering Award
2015 Northeastern University District - Semifinalists and Creativity Award
2014 Granite State District - Semifinalists and Innovation in Control Award
2012 Boston Regional - Finalists
Reply With Quote
  #4   Spotlight this post!  
Unread 09-02-2015, 21:52
kylelanman's Avatar
kylelanman kylelanman is online now
Programming Mentor
AKA: Kyle
FRC #2481 (Roboteers)
Team Role: Mentor
 
Join Date: Feb 2008
Rookie Year: 2007
Location: Tremont Il
Posts: 191
kylelanman is a name known to allkylelanman is a name known to allkylelanman is a name known to allkylelanman is a name known to allkylelanman is a name known to allkylelanman is a name known to all
Re: Conditional Command Group?

Assuming you are following the CommandBased template and defining your buttons in OI you can't conditionally run commands in a command group. Why? The command group is only ever constructed once and reused when ever the button is pressed.

If you are needing to do this you might need to rethink the design and structure of you code. We typically do the core of our control logic in state machines in the Subsystems and then uses commands to change the state.

A less elegant way is to code your commands with a short circuit path. See the example below. We used this on our 30 pt climber in 2013. If the shooter was up we couldn't raise the arm as it would run into the shooter and cause damage. To prevent this if the RaiseArm command was called with the shooter up we finished the command instantly. It is important not to set a mechanism in motion in the initialize method or it will run regardless of the additional condition.
Code:
class RaiseArm : public CommandBase {
public:
	RaiseArm() {}
	void Initialize() {}
	void Execute() {
		arm->Raise();
	}
	bool IsFinished() {
		//Finish instantly if the shooter is up so the arm 
		//won't hit it.
		return arm->isUp() || shooter->isUp();
	}
	void End(){}
	void Interrupted() {}
};
If this solution is not adequate or too messy then perhaps you could post a specific example of what you are hoping to do in the command group.
__________________
"May the coms be with you"

Is this a "programming error" or a "programmer error"?

Reply With Quote
  #5   Spotlight this post!  
Unread 10-02-2015, 10:31
microbuns's Avatar
microbuns microbuns is offline
Registered User
AKA: Sam Maier
FRC #4917
Team Role: Mentor
 
Join Date: Jan 2015
Rookie Year: 2014
Location: Elmira
Posts: 81
microbuns is an unknown quantity at this point
Re: Conditional Command Group?

I know I'm not OP, but I'm on his team - I'll show you specifically what we are doing:

We have a command group like so:
Code:
Grp1::Grp1() {
AddSequential(new Cmd1());
AddSequential(new Cmd2());
AddSequential(new Cmd3());
}
Which is called by a button in OI.cpp:
Code:
groupButton->WhenPressed(new Grp1());
However to speed things up, we can skip Cmd2 in Grp1 occasionally based off the state of the robot. This kind of thing would be nice:

Code:
Grp1::Grp1() {
AddSequential(new Cmd1());
if (!mDrivetrain->canSkip()) {
   AddSequential(new Cmd2());
}
AddSequential(new Cmd3());
}
One of our mentors (that I think you know, Kyle ) suggested we just make 2 separate command groups, and then have the button press call a new Command, which in turn checks the robot's state and calls the appropriate group based off of that. I was just wondering if there are any cleaner solutions?
Reply With Quote
  #6   Spotlight this post!  
Unread 10-02-2015, 11:36
kylelanman's Avatar
kylelanman kylelanman is online now
Programming Mentor
AKA: Kyle
FRC #2481 (Roboteers)
Team Role: Mentor
 
Join Date: Feb 2008
Rookie Year: 2007
Location: Tremont Il
Posts: 191
kylelanman is a name known to allkylelanman is a name known to allkylelanman is a name known to allkylelanman is a name known to allkylelanman is a name known to allkylelanman is a name known to all
Re: Conditional Command Group?

I didn't even pay attention to the team number of the OP. But yes I do believe I know one of your mentors.

If I'm understanding why you want to skip a command correctly then personally I would code the command to finish instantly if it didn't need to run. This is easier if you have sensors/feedback on all your mechanisms.

Ex.

Code:
class IntakeToteCommand: public CommandGroup
{
public:
	IntakeToteCommand(){
		AddSequential(new StackerGoToTopCommand());
		AddSequential(new IntakeTurnOn());

	}
};
Code:
class StackerGoToTopCommand: public CommandBase
{
public:
	StackerGoToTopCommand() : CommandBase() {
		Requires(stacker);
	}
	void Initialize(){
		if (!IsFinished()){
			CommandBase::stacker->SetPosition(15);			
		}
 	}
	void Execute() {}
	bool IsFinished(){
		return (CommandBase::stacker->GetPosition() > 15);
	}
	void End(){
		CommandBase::stacker->Disable();
	}
	void Interrupted(){
		End();
	}
};
Our stacker has to be at it's top position to intake a tote. 99% of the time the Stacker is already at the top of the robot when we start to intake a tote. However we still fire off the StackerGoToTopCommand() as a safety precaution because if we don't we won't be able to pickup a tote. If it is already at the top then the command finishes instantly.

With this approach you can take everything into account that would ever need to occur for the given action to run without error. In doing so you can call the command group at anytime by itself and not have to think about wrapping the call of the command in additional logic.
__________________
"May the coms be with you"

Is this a "programming error" or a "programmer error"?

Reply With Quote
  #7   Spotlight this post!  
Unread 10-02-2015, 19:34
microbuns's Avatar
microbuns microbuns is offline
Registered User
AKA: Sam Maier
FRC #4917
Team Role: Mentor
 
Join Date: Jan 2015
Rookie Year: 2014
Location: Elmira
Posts: 81
microbuns is an unknown quantity at this point
Re: Conditional Command Group?

I think I oversimplified our situation:

We actually wish to exclude a number of commands in this condition, some of which can (and should) be run in any and all states the robot can be in.
Reply With Quote
  #8   Spotlight this post!  
Unread 10-02-2015, 23:36
MrRoboSteve MrRoboSteve is offline
Mentor
AKA: Steve Peterson
FRC #3081 (Kennedy RoboEagles)
Team Role: Mentor
 
Join Date: Mar 2012
Rookie Year: 2011
Location: Bloomington, MN
Posts: 581
MrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond repute
Re: Conditional Command Group?

Having the command handle the logic still seems like the solution to your problem. You can write a new Cmd2IfSomeConditionExists command that wraps your original Cmd2 and only executes logic if the condition is true.

We're also fans of state machines for more complicated scenarios.
__________________
2016-17 events: 10000 Lakes Regional, Northern Lights Regional, FTC Burnsville Qualifying Tournament

2011 - present · FRC 3081 Kennedy RoboEagles mentor
2013 - present · event volunteer at 10000 Lakes Regional, Northern Lights Regional, North Star Regional, Lake Superior Regional, Minnesota State Tournament, PNW District 4 Glacier Peak, MN FTC, CMP
http://twitter.com/MrRoboSteve · www.linkedin.com/in/speterson
Reply With Quote
  #9   Spotlight this post!  
Unread 11-02-2015, 08:58
MrRoboSteve MrRoboSteve is offline
Mentor
AKA: Steve Peterson
FRC #3081 (Kennedy RoboEagles)
Team Role: Mentor
 
Join Date: Mar 2012
Rookie Year: 2011
Location: Bloomington, MN
Posts: 581
MrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond repute
Re: Conditional Command Group?

Remembered another option for you here -- one command can schedule another one.

See How to schedule a command from within a running command on https://wpilib.screenstepslive.com/s...uling-commands for details.
__________________
2016-17 events: 10000 Lakes Regional, Northern Lights Regional, FTC Burnsville Qualifying Tournament

2011 - present · FRC 3081 Kennedy RoboEagles mentor
2013 - present · event volunteer at 10000 Lakes Regional, Northern Lights Regional, North Star Regional, Lake Superior Regional, Minnesota State Tournament, PNW District 4 Glacier Peak, MN FTC, CMP
http://twitter.com/MrRoboSteve · www.linkedin.com/in/speterson
Reply With Quote
  #10   Spotlight this post!  
Unread 11-02-2015, 11:33
Pault's Avatar
Pault Pault is offline
Registered User
FRC #0246 (Overclocked)
Team Role: College Student
 
Join Date: Jan 2013
Rookie Year: 2012
Location: Boston
Posts: 618
Pault has a reputation beyond reputePault has a reputation beyond reputePault has a reputation beyond reputePault has a reputation beyond reputePault has a reputation beyond reputePault has a reputation beyond reputePault has a reputation beyond reputePault has a reputation beyond reputePault has a reputation beyond reputePault has a reputation beyond reputePault has a reputation beyond repute
Re: Conditional Command Group?

I'm not sure how much you know about inheritance (maybe your mentor can help you), but you could create a class that extends Cmd2 and overrides the isFinished method to stop immediately if the conditions are met.
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 13:32.

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