Version 10 (modified by 10 years ago) (diff) | ,
---|
Command Based Robots
Structure Documentation:
Subsystem
- Default Commands
- Continuously executing until Interrupt
setDefaultCommand(new ExampleGroup());
- Relation To Robot
- Subsystems can be compared to mechanisms that use the same overall resources
- Realize that two actions that require the same subsystem cannot occur at the same time
- Dependencies
- These prevent two different commands from utilizing the same resources on the robot
- Dependencies are created by
requires(Robot.exampleSubsystem);
Commands
- Initialization
- Initialization occurs when a command is run for the first time
- This means that if a command is stopped and then run again the init() method will run twice
- Execution
- The execute method inside of a command is must be concise and must not bog down the system or the entire robot may stop
- This means that large loops and wait methods should not be inside of an execute command
- Interrupts
- Called to stop a command from running
- Specifically when robot is disabled or a dependency overlaps
- Connection With Buttons
- Commands can be easily mapped to buttons through the OI class
- Manually Starting Commands
- In order to manually start commands, create a new command object and run the start() method on the new command object
- This may be very important when programming the autonomous robot
ExampleCommand cmd = new ExampleCommand()
cmd.start();
Input Class
- Input Devices
- Input devices are mapped through joystick and button objects
Joystick js0 = new Joystick(0);
Button btn00 = new JoystickButton(js0, 0);
- Button Actions
- Commands can be mapped to buttons or triggers in the OI class
btn00.whileHeld(new Command());
Robot Map
- Ports
- This class centralizes port numbers and connection numbers for robot-wide use
public static int defaultMotor = 2;
Command Groups
- About
- Command Groups are used for command sequencing and parallelization
- Basically running things in a specific order or at the same time
- Think about automated actions
- Commands will add in order of methods to add them
- Parallel
- Runs one command in the command group after the other without the need for an end command.
addParallel(new Command1());
- Ending Parallel
- When an end() method is run in a parallel command group, the ended command is removed from the group until the next instance of the command is run.
- Sequential
- Runs one command in the command group after the other with the need for an end() command before moving to the next command.
addSequential(new Command1());