View Single Post
  #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