Go to Post We're 30 pounds over LOL. I probably shouldn't be lol'ing, but it is 11:52PM, I just got home from a 15 hour build session, and I find the word 'potato' funny. - ZakuAce [more]
Home
Go Back   Chief Delphi > Technical > Programming
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 30-03-2016, 22:19
cpapplefamily cpapplefamily is offline
Registered User
FRC #3244 (Granite City Gearheads)
Team Role: Mentor
 
Join Date: May 2015
Rookie Year: 2015
Location: Minnesota
Posts: 242
cpapplefamily has a spectacular aura aboutcpapplefamily has a spectacular aura about
Run a command with conditions

I have 2 sendableChoosers for our Autonomous. One picks the obstacle we are going to attempt. (works well) The other picks the wrist angle of our shooter for High goal or low goal. We came up with the idea after milling over the code shared in the thread More than 1 Sendablechooser where we can run a line of code in a command like

Code:
/* The goalChooser construction 
*goalChooser.addDefault("0: No Shoot",0);
*goalChooser.addOption("1: Low goal",1);
*goalChooser.addOption("2: High Goal",2);
*/


protected void initialize() {
Integer goalChoice = (Integer) Robot.goalChooser.getSelected();
angle = findAngle(goalChoice);
Robot.wristSubsystem.setAngle(angle);
}

private double findAngle(integer Choice){
if(Choice == 1){
return 15;
}else if(Choice == 2{
return 75;
}else{
return 90;
}
}
The syntax may be off here but the real code worked every time. If goalChooser was 1 wrist set to 15deg, 2 then 75deg.

Now comes the trouble I'm trying to resolve. Our AutonomousChooser selects a command group that looks like

Code:
addSequential(new drive());
addSequential(new setWristAngle()); //Above code

//*************  Code Focus ************

addSequential(new Auto_ShootDecide()); //New shoot or Not
//addSequential(new shootBall()); //Old always shoots ball

//***********************************
In Auto_ShootDecide I have
Code:
protected void initialize() {
Integer goalChoice = (Integer) Robot.goalChooser.getSelected();
if (goalChoice == 0){//don't shoot
end();
}else{
new shootBall(); This is where the code does not run
}
}
new shootBall(); This is where the code does not run.

We use shootBall() tied to a button and the code is proven and I don't think I what to add conditions to it to check the goalChoice like "Auto_ShootDecide()".

Maybe Auto_ShootDecide() needs to be a mirror of shootBall but with the conditions. I just thought why recreate a chunk of code. What do you think?
Reply With Quote
  #2   Spotlight this post!  
Unread 31-03-2016, 07:23
kylelanman's Avatar
kylelanman kylelanman is offline
Programming Mentor
AKA: Kyle
FRC #2481 (Roboteers)
Team Role: Mentor
 
Join Date: Feb 2008
Rookie Year: 2007
Location: Tremont Il
Posts: 186
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: Run a command with conditions

Code:
new ShootBall()
Simply creates an instance of the command. That instance needs to be scheduled by running ->Start()

Code:
Command* c = new ShootBall()
c->Start()
Another option is to build the command group on the fly. Here is an example of how we do this.

Code:
m_defenseChooser = new SendableChooser();
		//Group A
		m_defenseChooser->AddObject("Portcullis", new TraversePortcullisCommandGroup());
		m_defenseChooser->AddObject("Cheval de Friese", new TraverseChevalFrieseCommandGroup());

		//Group B
		m_defenseChooser->AddObject("Moat", new TraverseMoatCommandGroup());
		m_defenseChooser->AddObject("Ramparts", new TraverseRampartsCommandGroup());

		//Group C
		m_defenseChooser->AddObject("Drawbridge", new TraverseDrawbridgeCommandGroup());
		m_defenseChooser->AddObject("Sally Port", new TraversePortCommandGroup());

		//Group D
		m_defenseChooser->AddObject("Rock Wall", new TraverseWallCommandGroup());
		m_defenseChooser->AddObject("Rough Terrain", new TraverseTerrainCommandGroup());

		m_defenseChooser->AddDefault("Nothing", (void*)0);

		SmartDashboard::PutData("Defense Chooser",m_defenseChooser);

		m_posChooser = new SendableChooser();
		m_posChooser->AddDefault("Nothing", NULL);
//		m_posChooser->AddObject("Pos 1 (Low Bar)", (void*)1);
		m_posChooser->AddObject("Pos 2", (void*)2);
		m_posChooser->AddObject("Pos 3", (void*)3);
		m_posChooser->AddObject("Pos 4", (void*)4);
		m_posChooser->AddObject("Pos 5", (void*)5);

		SmartDashboard::PutData("Position Chooser", m_posChooser);
Code:
void AutonomousInit()
	{
		autonomousCommand.reset(new GeneratedAutoCommandGroup((Command*)m_defenseChooser->GetSelected(),
				(int)m_posChooser->GetSelected(),
				(int)m_backChooser->GetSelected()));
		if (autonomousCommand != NULL)
			autonomousCommand->Start();
}
Code:
class GeneratedAutoCommandGroup: public CommandGroup
{
public:
	GeneratedAutoCommandGroup(Command* traverseCommand, int position, int driveBack)
		: CommandGroup("GeneratedAutoCommandGroup"){
		double angleArray[6] = {0, 0, 30, 0, 0, -25};
		if (traverseCommand){
			AddSequential(new AutoBlockOneCommandGroup());
			AddSequential(traverseCommand);
			AddSequential(new RotateToAngleCommand(angleArray[position]));    //disabling for middle pos
			if (position == 2) {
				AddSequential(new LockOnTargetCommand(CameraProcessor::LEFT_TARGET));
			} else {
				AddSequential(new LockOnTargetCommand(CameraProcessor::RIGHT_TARGET));
			}
			AddSequential(new AutoBlockTwoCommandGroup());
			AddSequential(new RotateToAngleCommand(0));
			AddSequential(new DriveDistanceCommand(.5, .5, 2000));	
			AddSequential(new Rotate180Command());
			if (driveBack==1) {
				AddSequential(new DriveDistanceCommand(.5, .5, 2000));
				AddSequential(traverseCommand);
			}
		}
	}
};
__________________
"May the coms be with you"

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

Reply With Quote
  #3   Spotlight this post!  
Unread 31-03-2016, 08:00
rich2202 rich2202 is offline
Registered User
FRC #2202 (BEAST Robotics)
Team Role: Mentor
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Wisconsin
Posts: 1,151
rich2202 has a reputation beyond reputerich2202 has a reputation beyond reputerich2202 has a reputation beyond reputerich2202 has a reputation beyond reputerich2202 has a reputation beyond reputerich2202 has a reputation beyond reputerich2202 has a reputation beyond reputerich2202 has a reputation beyond reputerich2202 has a reputation beyond reputerich2202 has a reputation beyond reputerich2202 has a reputation beyond repute
Re: Run a command with conditions

If you don't want to modify shoot, then copy it to create auto_shoot, and modify that to remove checking the button. What is your reluctance? It may not be elegant, but you have more than enough code space for it.

Last edited by rich2202 : 31-03-2016 at 08:03.
Reply With Quote
  #4   Spotlight this post!  
Unread 31-03-2016, 22:24
cpapplefamily cpapplefamily is offline
Registered User
FRC #3244 (Granite City Gearheads)
Team Role: Mentor
 
Join Date: May 2015
Rookie Year: 2015
Location: Minnesota
Posts: 242
cpapplefamily has a spectacular aura aboutcpapplefamily has a spectacular aura about
Re: Run a command with conditions

Quote:
Originally Posted by rich2202 View Post
If you don't want to modify shoot, then copy it to create auto_shoot, and modify that to remove checking the button. What is your reluctance? It may not be elegant, but you have more than enough code space for it.
"not be elegant" is the point. This is the way we might go but I will try some build on the fly since it seems to be possible. I will have to try and copy the code style in JAVA.

Thanks for the direction.
Reply With Quote
  #5   Spotlight this post!  
Unread 29-04-2016, 15:40
cpapplefamily cpapplefamily is offline
Registered User
FRC #3244 (Granite City Gearheads)
Team Role: Mentor
 
Join Date: May 2015
Rookie Year: 2015
Location: Minnesota
Posts: 242
cpapplefamily has a spectacular aura aboutcpapplefamily has a spectacular aura about
Re: Run a command with conditions

Quote:
Originally Posted by kylelanman View Post
Code:
new ShootBall()
Simply creates an instance of the command. That instance needs to be scheduled by running ->Start()

Code:
Command* c = new ShootBall()
c->Start()
Another option is to build the command group on the fly. Here is an example of how we do this.

Code:
m_defenseChooser = new SendableChooser();
		//Group A
		m_defenseChooser->AddObject("Portcullis", new TraversePortcullisCommandGroup());
		m_defenseChooser->AddObject("Cheval de Friese", new TraverseChevalFrieseCommandGroup());

		//Group B
		m_defenseChooser->AddObject("Moat", new TraverseMoatCommandGroup());
		m_defenseChooser->AddObject("Ramparts", new TraverseRampartsCommandGroup());

		//Group C
		m_defenseChooser->AddObject("Drawbridge", new TraverseDrawbridgeCommandGroup());
		m_defenseChooser->AddObject("Sally Port", new TraversePortCommandGroup());

		//Group D
		m_defenseChooser->AddObject("Rock Wall", new TraverseWallCommandGroup());
		m_defenseChooser->AddObject("Rough Terrain", new TraverseTerrainCommandGroup());

		m_defenseChooser->AddDefault("Nothing", (void*)0);

		SmartDashboard::PutData("Defense Chooser",m_defenseChooser);

		m_posChooser = new SendableChooser();
		m_posChooser->AddDefault("Nothing", NULL);
//		m_posChooser->AddObject("Pos 1 (Low Bar)", (void*)1);
		m_posChooser->AddObject("Pos 2", (void*)2);
		m_posChooser->AddObject("Pos 3", (void*)3);
		m_posChooser->AddObject("Pos 4", (void*)4);
		m_posChooser->AddObject("Pos 5", (void*)5);

		SmartDashboard::PutData("Position Chooser", m_posChooser);
Code:
void AutonomousInit()
	{
		autonomousCommand.reset(new GeneratedAutoCommandGroup((Command*)m_defenseChooser->GetSelected(),
				(int)m_posChooser->GetSelected(),
				(int)m_backChooser->GetSelected()));
		if (autonomousCommand != NULL)
			autonomousCommand->Start();
}
Code:
class GeneratedAutoCommandGroup: public CommandGroup
{
public:
	GeneratedAutoCommandGroup(Command* traverseCommand, int position, int driveBack)
		: CommandGroup("GeneratedAutoCommandGroup"){
		double angleArray[6] = {0, 0, 30, 0, 0, -25};
		if (traverseCommand){
			AddSequential(new AutoBlockOneCommandGroup());
			AddSequential(traverseCommand);
			AddSequential(new RotateToAngleCommand(angleArray[position]));    //disabling for middle pos
			if (position == 2) {
				AddSequential(new LockOnTargetCommand(CameraProcessor::LEFT_TARGET));
			} else {
				AddSequential(new LockOnTargetCommand(CameraProcessor::RIGHT_TARGET));
			}
			AddSequential(new AutoBlockTwoCommandGroup());
			AddSequential(new RotateToAngleCommand(0));
			AddSequential(new DriveDistanceCommand(.5, .5, 2000));	
			AddSequential(new Rotate180Command());
			if (driveBack==1) {
				AddSequential(new DriveDistanceCommand(.5, .5, 2000));
				AddSequential(traverseCommand);
			}
		}
	}
};
Ok so your rebuilding the command in the
Code:
void AutonomousInit()
That makes since because with more testing now I found the command always use the status of the Sendable chooser when the Roborio booted up. When rebuilding the Command before
Code:
autonomousCommand->Start()
you capture the current state of the sendable Choosers.
Reply With Quote
  #6   Spotlight this post!  
Unread 02-05-2016, 00:04
cpapplefamily cpapplefamily is offline
Registered User
FRC #3244 (Granite City Gearheads)
Team Role: Mentor
 
Join Date: May 2015
Rookie Year: 2015
Location: Minnesota
Posts: 242
cpapplefamily has a spectacular aura aboutcpapplefamily has a spectacular aura about
Re: Run a command with conditions

In an effort to continue down this rabbit hole here is where I sit.

I have continued with one of the original ideas before I attempt to try the build the autonomousCommand just before running it. To better discusse the code here is a link to the Github repo
https://github.com/GraniteCiyGearhea...ntsABot_Talahi
If we drill to
Code:
FIRSTStronghold2016/Copy of SirAntsABot_Talahi/src/org/usfirst/frc3244/SirAntsABot/commands/Auto_22_Demo_03_Drive_N_Score
We can see we are driving the Bot with a few commands before we:
Code:
addSequential(new Auto_Score_Ball_In_Goal());
This Code is now executing as I desired by only shooting if the goalChooser is not zero. Thanks to kylelanman for pointing it out we need to start the commands.

Now the trouble I'm having is getting the next sequence to continue when
Code:
Auto_Score_Ball_In_Goal()
is done. I have inserted some prints to show me who's end() and interrupted() methods are being called. The time out was just a test in Auto_Score_Ball_In_Goal(). I have also tried to use !c.isRunning. If you look at what c is its a command group called "PinBall_Cycle". This group sets the claw and shoots the ball. I also put system.out.println in these end methods to see if they are completing. It seems to me that everything works as planed and completing, only I'm not returning to the Auto_22_Demo_03_Drive_N_Score to finish the last two commands in the group.

Maybe someone can point me to or explain to me the life cycle of a command and what is needed to move onto the next sequence in a command group.
Reply With Quote
  #7   Spotlight this post!  
Unread 07-05-2016, 22:53
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,559
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
Re: Run a command with conditions

Calling end() doesn't cause a command to end. Making isFinished() return true does.

I think the problem is that the commands you are starting are canceling Auto_22_Demo_03_Drive_N_Score because they require the same subsystems.
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:18.

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