Smart Dashboard
<< Simple Kenect Driver | FRC | Spike Coding >>
- Make a new project
- Select FRC-New CommandBasedRobot Template - call project name BroBot, other something you like--Package Name: org.usfirst.frc4101, Class name: Brobot
- In the first package. Use the OI to bind the operator input, and RoboMap to make physical connections to logical names
public class RobotMap{
public static final int
leftMotor=1,
rightMotor=2;
}
- The second package has the CommandBase and all the Commands you write. When you make a new command, be sure to add it to the CommandBase
- The third package has our subsystems-- the hardware that is controlled by your Commands
Adding a subsystem
- rightclick on the third package which has our subsystems, and select New Subsystem (if that is not a choice, select Other, then find Subsystem
- Name it and press next. here is example Claw subsystem.
public class Claw extends Subsystem {
// The claws motor
Victor motor;
// Initialize your subsystem here
/**
* Initialize the claw with the motor declared in {@link RobotMap}
*/
public Claw() {
super("Claw");
motor = new Victor(RobotMap.clawMotor);
}
/**
* Initialize the default command to be {@link ClawDoNothing}.
*/
public void initDefaultCommand() {
setDefaultCommand(new ClawDoNothing());
}
/**
* Implements the claw's open capability. Simply tells the motor to move full
* speed in one direction, it is the commands responsibility to tell it when
* to stop opening. If the command doesn't, it will keep opening until the
* command ends and the default command {@link ClawDoNothing} takes over.
*/
public void open() {
motor.set(1);
}
/**
* Implements the claw's close capability. Simply tells the motor to move
* full speed in one direction, it is the commands responsibility to tell it
* when to stop closing. If the command doesn't, it will keep opening until
* the command ends and the default command {@link ClawDoNothing} takes over.
*/
public void close() {
motor.set(-1);
}
/**
* Implements the claw's do nothing capability. Simply tells the motor to
* stop moving. After this is called the claw is neither opening or closing.
*/
public void doNothing() {
motor.set(0);
}
}
To Make a new Command
- In CoomandBase add an import so it can find your new subsystem
import edu.<your third package name>.brobot.subsystem.Claw public static Claw claw = new Claw();
- Go to the second package where the Commands are, right-clcik and select "New Command" like ClawDoNothing
public class ClawDoNothing extends CommandBase {
/**
* Initialize the command so that it requires the claw. This means it will
* be interrupted if another command requiring the claw is run.
*/
public ClawDoNothing() {
requires(claw);
}
// Called just before this Command runs the first time
protected void initialize() {
}
// Called repeatedly when this Command is scheduled to run
/**
* Tells the claw to do nothing, stopping any previous movement.
*/
protected void execute() {
claw.doNothing();
}
// Make this return true when this Command no longer needs to run execute()
/**
* @return false, so that it executes forever or until another command
* interrupts it.
*/
protected boolean isFinished() {
return false;
}
// Called once after isFinished returns true
protected void end() {
}
// Called when another command which requires one or more of the same
// subsystems is scheduled to run
protected void interrupted() {
}
}
To bind the Command to a button
- Go to the first package and edit the OI class
Here is and example from the Gears Robot
public class OI {
// Create the joystick and of the 8 buttons on it
Joystick leftJoy = new Joystick(1);
Button button1 = new JoystickButton(leftJoy, 1),
button2 = new JoystickButton(leftJoy, 2),
button3 = new JoystickButton(leftJoy, 3),
button4 = new JoystickButton(leftJoy, 4),
button5 = new JoystickButton(leftJoy, 5),
button6 = new JoystickButton(leftJoy, 6),
button7 = new JoystickButton(leftJoy, 7),
button8 = new JoystickButton(leftJoy, 8);
/**
* Bind the press of each button to a specific command or command group.
*/
public OI() {
button1.whenPressed(new PrepareToGrab());
button2.whenPressed(new Grab());
button7.whenPressed(new SodaDelivery());
}
/**
* @return The value of the left joystick.
*/
public double getLeftSpeed() {
return leftJoy.getY();
}
/**
* @return The value of the right joystick. Note: this uses raw axis because
* we have a logitech joystick that resembles a PS controller.
*/
public double getRightSpeed() {
return leftJoy.getRawAxis(4);
}
}
