Run wpiformat on merged repo (#1021)

This commit is contained in:
Tyler Veness
2018-05-13 17:09:56 -07:00
committed by Peter Johnson
parent 0babbf317c
commit 6729a7d6b1
481 changed files with 9581 additions and 6828 deletions

View File

@@ -24,46 +24,46 @@ import org.opencv.imgproc.Imgproc;
* processing.
*/
public class Robot extends IterativeRobot {
Thread m_visionThread;
Thread m_visionThread;
@Override
public void robotInit() {
m_visionThread = new Thread(() -> {
// Get the Axis camera from CameraServer
AxisCamera camera
= CameraServer.getInstance().addAxisCamera("axis-camera.local");
// Set the resolution
camera.setResolution(640, 480);
@Override
public void robotInit() {
m_visionThread = new Thread(() -> {
// Get the Axis camera from CameraServer
AxisCamera camera
= CameraServer.getInstance().addAxisCamera("axis-camera.local");
// Set the resolution
camera.setResolution(640, 480);
// Get a CvSink. This will capture Mats from the camera
CvSink cvSink = CameraServer.getInstance().getVideo();
// Setup a CvSource. This will send images back to the Dashboard
CvSource outputStream
= CameraServer.getInstance().putVideo("Rectangle", 640, 480);
// Get a CvSink. This will capture Mats from the camera
CvSink cvSink = CameraServer.getInstance().getVideo();
// Setup a CvSource. This will send images back to the Dashboard
CvSource outputStream
= CameraServer.getInstance().putVideo("Rectangle", 640, 480);
// Mats are very memory expensive. Lets reuse this Mat.
Mat mat = new Mat();
// Mats are very memory expensive. Lets reuse this Mat.
Mat mat = new Mat();
// This cannot be 'true'. The program will never exit if it is. This
// lets the robot stop this thread when restarting robot code or
// deploying.
while (!Thread.interrupted()) {
// Tell the CvSink to grab a frame from the camera and put it
// in the source mat. If there is an error notify the output.
if (cvSink.grabFrame(mat) == 0) {
// Send the output the error.
outputStream.notifyError(cvSink.getError());
// skip the rest of the current iteration
continue;
}
// Put a rectangle on the image
Imgproc.rectangle(mat, new Point(100, 100), new Point(400, 400),
new Scalar(255, 255, 255), 5);
// Give the output stream a new image to display
outputStream.putFrame(mat);
}
});
m_visionThread.setDaemon(true);
m_visionThread.start();
}
// This cannot be 'true'. The program will never exit if it is. This
// lets the robot stop this thread when restarting robot code or
// deploying.
while (!Thread.interrupted()) {
// Tell the CvSink to grab a frame from the camera and put it
// in the source mat. If there is an error notify the output.
if (cvSink.grabFrame(mat) == 0) {
// Send the output the error.
outputStream.notifyError(cvSink.getError());
// skip the rest of the current iteration
continue;
}
// Put a rectangle on the image
Imgproc.rectangle(mat, new Point(100, 100), new Point(400, 400),
new Scalar(255, 255, 255), 5);
// Give the output stream a new image to display
outputStream.putFrame(mat);
}
});
m_visionThread.setDaemon(true);
m_visionThread.start();
}
}

View File

@@ -24,45 +24,45 @@ import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
* interface to the commands and command groups that allow control of the robot.
*/
public class OI {
private Joystick m_joystick = new Joystick(0);
private Joystick m_joystick = new Joystick(0);
public OI() {
// Put Some buttons on the SmartDashboard
SmartDashboard.putData("Elevator Bottom", new SetElevatorSetpoint(0));
SmartDashboard.putData("Elevator Platform", new SetElevatorSetpoint(0.2));
SmartDashboard.putData("Elevator Top", new SetElevatorSetpoint(0.3));
public OI() {
// Put Some buttons on the SmartDashboard
SmartDashboard.putData("Elevator Bottom", new SetElevatorSetpoint(0));
SmartDashboard.putData("Elevator Platform", new SetElevatorSetpoint(0.2));
SmartDashboard.putData("Elevator Top", new SetElevatorSetpoint(0.3));
SmartDashboard.putData("Wrist Horizontal", new SetWristSetpoint(0));
SmartDashboard.putData("Raise Wrist", new SetWristSetpoint(-45));
SmartDashboard.putData("Wrist Horizontal", new SetWristSetpoint(0));
SmartDashboard.putData("Raise Wrist", new SetWristSetpoint(-45));
SmartDashboard.putData("Open Claw", new OpenClaw());
SmartDashboard.putData("Close Claw", new CloseClaw());
SmartDashboard.putData("Open Claw", new OpenClaw());
SmartDashboard.putData("Close Claw", new CloseClaw());
SmartDashboard.putData("Deliver Soda", new Autonomous());
SmartDashboard.putData("Deliver Soda", new Autonomous());
// Create some buttons
JoystickButton dpadUp = new JoystickButton(m_joystick, 5);
JoystickButton dpadRight = new JoystickButton(m_joystick, 6);
JoystickButton dpadDown = new JoystickButton(m_joystick, 7);
JoystickButton dpadLeft = new JoystickButton(m_joystick, 8);
JoystickButton l2 = new JoystickButton(m_joystick, 9);
JoystickButton r2 = new JoystickButton(m_joystick, 10);
JoystickButton l1 = new JoystickButton(m_joystick, 11);
JoystickButton r1 = new JoystickButton(m_joystick, 12);
// Create some buttons
JoystickButton dpadUp = new JoystickButton(m_joystick, 5);
JoystickButton dpadRight = new JoystickButton(m_joystick, 6);
JoystickButton dpadDown = new JoystickButton(m_joystick, 7);
JoystickButton dpadLeft = new JoystickButton(m_joystick, 8);
JoystickButton l2 = new JoystickButton(m_joystick, 9);
JoystickButton r2 = new JoystickButton(m_joystick, 10);
JoystickButton l1 = new JoystickButton(m_joystick, 11);
JoystickButton r1 = new JoystickButton(m_joystick, 12);
// Connect the buttons to commands
dpadUp.whenPressed(new SetElevatorSetpoint(0.2));
dpadDown.whenPressed(new SetElevatorSetpoint(-0.2));
dpadRight.whenPressed(new CloseClaw());
dpadLeft.whenPressed(new OpenClaw());
// Connect the buttons to commands
dpadUp.whenPressed(new SetElevatorSetpoint(0.2));
dpadDown.whenPressed(new SetElevatorSetpoint(-0.2));
dpadRight.whenPressed(new CloseClaw());
dpadLeft.whenPressed(new OpenClaw());
r1.whenPressed(new PrepareToPickup());
r2.whenPressed(new Pickup());
l1.whenPressed(new Place());
l2.whenPressed(new Autonomous());
}
r1.whenPressed(new PrepareToPickup());
r2.whenPressed(new Pickup());
l1.whenPressed(new Place());
l2.whenPressed(new Autonomous());
}
public Joystick getJoystick() {
return m_joystick;
}
public Joystick getJoystick() {
return m_joystick;
}
}

View File

@@ -26,83 +26,83 @@ import edu.wpi.first.wpilibj.examples.gearsbot.subsystems.Wrist;
* directory.
*/
public class Robot extends IterativeRobot {
Command m_autonomousCommand;
Command m_autonomousCommand;
public static DriveTrain m_drivetrain;
public static Elevator m_elevator;
public static Wrist m_wrist;
public static Claw m_claw;
public static OI m_oi;
public static DriveTrain m_drivetrain;
public static Elevator m_elevator;
public static Wrist m_wrist;
public static Claw m_claw;
public static OI m_oi;
/**
* This function is run when the robot is first started up and should be
* used for any initialization code.
*/
@Override
public void robotInit() {
// Initialize all subsystems
m_drivetrain = new DriveTrain();
m_elevator = new Elevator();
m_wrist = new Wrist();
m_claw = new Claw();
m_oi = new OI();
/**
* This function is run when the robot is first started up and should be
* used for any initialization code.
*/
@Override
public void robotInit() {
// Initialize all subsystems
m_drivetrain = new DriveTrain();
m_elevator = new Elevator();
m_wrist = new Wrist();
m_claw = new Claw();
m_oi = new OI();
// instantiate the command used for the autonomous period
m_autonomousCommand = new Autonomous();
// instantiate the command used for the autonomous period
m_autonomousCommand = new Autonomous();
// Show what command your subsystem is running on the SmartDashboard
SmartDashboard.putData(m_drivetrain);
SmartDashboard.putData(m_elevator);
SmartDashboard.putData(m_wrist);
SmartDashboard.putData(m_claw);
}
// Show what command your subsystem is running on the SmartDashboard
SmartDashboard.putData(m_drivetrain);
SmartDashboard.putData(m_elevator);
SmartDashboard.putData(m_wrist);
SmartDashboard.putData(m_claw);
}
@Override
public void autonomousInit() {
m_autonomousCommand.start(); // schedule the autonomous command (example)
}
@Override
public void autonomousInit() {
m_autonomousCommand.start(); // schedule the autonomous command (example)
}
/**
* This function is called periodically during autonomous.
*/
@Override
public void autonomousPeriodic() {
Scheduler.getInstance().run();
log();
}
/**
* This function is called periodically during autonomous.
*/
@Override
public void autonomousPeriodic() {
Scheduler.getInstance().run();
log();
}
@Override
public void teleopInit() {
// This makes sure that the autonomous stops running when
// teleop starts running. If you want the autonomous to
// continue until interrupted by another command, remove
// this line or comment it out.
m_autonomousCommand.cancel();
}
@Override
public void teleopInit() {
// This makes sure that the autonomous stops running when
// teleop starts running. If you want the autonomous to
// continue until interrupted by another command, remove
// this line or comment it out.
m_autonomousCommand.cancel();
}
/**
* This function is called periodically during teleoperated mode.
*/
@Override
public void teleopPeriodic() {
Scheduler.getInstance().run();
log();
}
/**
* This function is called periodically during teleoperated mode.
*/
@Override
public void teleopPeriodic() {
Scheduler.getInstance().run();
log();
}
/**
* This function is called periodically during test mode.
*/
@Override
public void testPeriodic() {
}
/**
* This function is called periodically during test mode.
*/
@Override
public void testPeriodic() {
}
/**
* The log method puts interesting information to the SmartDashboard.
*/
private void log() {
m_wrist.log();
m_elevator.log();
m_drivetrain.log();
m_claw.log();
}
/**
* The log method puts interesting information to the SmartDashboard.
*/
private void log() {
m_wrist.log();
m_elevator.log();
m_drivetrain.log();
m_claw.log();
}
}

View File

@@ -13,17 +13,17 @@ import edu.wpi.first.wpilibj.command.CommandGroup;
* The main autonomous command to pickup and deliver the soda to the box.
*/
public class Autonomous extends CommandGroup {
public Autonomous() {
addSequential(new PrepareToPickup());
addSequential(new Pickup());
addSequential(new SetDistanceToBox(0.10));
// addSequential(new DriveStraight(4)); // Use Encoders if ultrasonic is
// broken
addSequential(new Place());
addSequential(new SetDistanceToBox(0.60));
// addSequential(new DriveStraight(-2)); // Use Encoders if ultrasonic
// is broken
addParallel(new SetWristSetpoint(-45));
addSequential(new CloseClaw());
}
public Autonomous() {
addSequential(new PrepareToPickup());
addSequential(new Pickup());
addSequential(new SetDistanceToBox(0.10));
// addSequential(new DriveStraight(4)); // Use Encoders if ultrasonic is
// broken
addSequential(new Place());
addSequential(new SetDistanceToBox(0.60));
// addSequential(new DriveStraight(-2)); // Use Encoders if ultrasonic
// is broken
addParallel(new SetWristSetpoint(-45));
addSequential(new CloseClaw());
}
}

View File

@@ -15,31 +15,31 @@ import edu.wpi.first.wpilibj.examples.gearsbot.Robot;
* motors is BAD!
*/
public class CloseClaw extends Command {
public CloseClaw() {
requires(Robot.m_claw);
}
public CloseClaw() {
requires(Robot.m_claw);
}
// Called just before this Command runs the first time
@Override
protected void initialize() {
Robot.m_claw.close();
}
// Called just before this Command runs the first time
@Override
protected void initialize() {
Robot.m_claw.close();
}
// Make this return true when this Command no longer needs to run execute()
@Override
protected boolean isFinished() {
return Robot.m_claw.isGrabbing();
}
// Make this return true when this Command no longer needs to run execute()
@Override
protected boolean isFinished() {
return Robot.m_claw.isGrabbing();
}
// Called once after isFinished returns true
@Override
protected void end() {
// NOTE: Doesn't stop in simulation due to lower friction causing the
// can to fall out
// + there is no need to worry about stalling the motor or crushing the
// can.
if (!Robot.isSimulation()) {
Robot.m_claw.stop();
}
}
// Called once after isFinished returns true
@Override
protected void end() {
// NOTE: Doesn't stop in simulation due to lower friction causing the
// can to fall out
// + there is no need to worry about stalling the motor or crushing the
// can.
if (!Robot.isSimulation()) {
Robot.m_claw.stop();
}
}
}

View File

@@ -20,53 +20,53 @@ import edu.wpi.first.wpilibj.examples.gearsbot.Robot;
* encoders.
*/
public class DriveStraight extends Command {
private PIDController m_pid;
private PIDController m_pid;
public DriveStraight(double distance) {
requires(Robot.m_drivetrain);
m_pid = new PIDController(4, 0, 0, new PIDSource() {
PIDSourceType m_sourceType = PIDSourceType.kDisplacement;
public DriveStraight(double distance) {
requires(Robot.m_drivetrain);
m_pid = new PIDController(4, 0, 0, new PIDSource() {
PIDSourceType m_sourceType = PIDSourceType.kDisplacement;
@Override
public double pidGet() {
return Robot.m_drivetrain.getDistance();
}
@Override
public double pidGet() {
return Robot.m_drivetrain.getDistance();
}
@Override
public void setPIDSourceType(PIDSourceType pidSource) {
m_sourceType = pidSource;
}
@Override
public void setPIDSourceType(PIDSourceType pidSource) {
m_sourceType = pidSource;
}
@Override
public PIDSourceType getPIDSourceType() {
return m_sourceType;
}
}, d -> Robot.m_drivetrain.drive(d, d));
@Override
public PIDSourceType getPIDSourceType() {
return m_sourceType;
}
}, d -> Robot.m_drivetrain.drive(d, d));
m_pid.setAbsoluteTolerance(0.01);
m_pid.setSetpoint(distance);
}
m_pid.setAbsoluteTolerance(0.01);
m_pid.setSetpoint(distance);
}
// Called just before this Command runs the first time
@Override
protected void initialize() {
// Get everything in a safe starting state.
Robot.m_drivetrain.reset();
m_pid.reset();
m_pid.enable();
}
// Called just before this Command runs the first time
@Override
protected void initialize() {
// Get everything in a safe starting state.
Robot.m_drivetrain.reset();
m_pid.reset();
m_pid.enable();
}
// Make this return true when this Command no longer needs to run execute()
@Override
protected boolean isFinished() {
return m_pid.onTarget();
}
// Make this return true when this Command no longer needs to run execute()
@Override
protected boolean isFinished() {
return m_pid.onTarget();
}
// Called once after isFinished returns true
@Override
protected void end() {
// Stop PID and the wheels
m_pid.disable();
Robot.m_drivetrain.drive(0, 0);
}
// Called once after isFinished returns true
@Override
protected void end() {
// Stop PID and the wheels
m_pid.disable();
Robot.m_drivetrain.drive(0, 0);
}
}

View File

@@ -15,20 +15,20 @@ import edu.wpi.first.wpilibj.examples.gearsbot.Robot;
* motors is BAD!
*/
public class OpenClaw extends TimedCommand {
public OpenClaw() {
super(1);
requires(Robot.m_claw);
}
public OpenClaw() {
super(1);
requires(Robot.m_claw);
}
// Called just before this Command runs the first time
@Override
protected void initialize() {
Robot.m_claw.open();
}
// Called just before this Command runs the first time
@Override
protected void initialize() {
Robot.m_claw.open();
}
// Called once after isFinished returns true
@Override
protected void end() {
Robot.m_claw.stop();
}
// Called once after isFinished returns true
@Override
protected void end() {
Robot.m_claw.stop();
}
}

View File

@@ -14,9 +14,9 @@ import edu.wpi.first.wpilibj.command.CommandGroup;
* state to drive around.
*/
public class Pickup extends CommandGroup {
public Pickup() {
addSequential(new CloseClaw());
addParallel(new SetWristSetpoint(-45));
addSequential(new SetElevatorSetpoint(0.25));
}
public Pickup() {
addSequential(new CloseClaw());
addParallel(new SetWristSetpoint(-45));
addSequential(new SetElevatorSetpoint(0.25));
}
}

View File

@@ -13,9 +13,9 @@ import edu.wpi.first.wpilibj.command.CommandGroup;
* Place a held soda can onto the platform.
*/
public class Place extends CommandGroup {
public Place() {
addSequential(new SetElevatorSetpoint(0.25));
addSequential(new SetWristSetpoint(0));
addSequential(new OpenClaw());
}
public Place() {
addSequential(new SetElevatorSetpoint(0.25));
addSequential(new SetWristSetpoint(0));
addSequential(new OpenClaw());
}
}

View File

@@ -13,9 +13,9 @@ import edu.wpi.first.wpilibj.command.CommandGroup;
* Make sure the robot is in a state to pickup soda cans.
*/
public class PrepareToPickup extends CommandGroup {
public PrepareToPickup() {
addParallel(new OpenClaw());
addParallel(new SetWristSetpoint(0));
addSequential(new SetElevatorSetpoint(0));
}
public PrepareToPickup() {
addParallel(new OpenClaw());
addParallel(new SetWristSetpoint(0));
addSequential(new SetElevatorSetpoint(0));
}
}

View File

@@ -20,53 +20,53 @@ import edu.wpi.first.wpilibj.examples.gearsbot.Robot;
* encoders.
*/
public class SetDistanceToBox extends Command {
private PIDController m_pid;
private PIDController m_pid;
public SetDistanceToBox(double distance) {
requires(Robot.m_drivetrain);
m_pid = new PIDController(-2, 0, 0, new PIDSource() {
PIDSourceType m_sourceType = PIDSourceType.kDisplacement;
public SetDistanceToBox(double distance) {
requires(Robot.m_drivetrain);
m_pid = new PIDController(-2, 0, 0, new PIDSource() {
PIDSourceType m_sourceType = PIDSourceType.kDisplacement;
@Override
public double pidGet() {
return Robot.m_drivetrain.getDistanceToObstacle();
}
@Override
public double pidGet() {
return Robot.m_drivetrain.getDistanceToObstacle();
}
@Override
public void setPIDSourceType(PIDSourceType pidSource) {
m_sourceType = pidSource;
}
@Override
public void setPIDSourceType(PIDSourceType pidSource) {
m_sourceType = pidSource;
}
@Override
public PIDSourceType getPIDSourceType() {
return m_sourceType;
}
}, d -> Robot.m_drivetrain.drive(d, d));
@Override
public PIDSourceType getPIDSourceType() {
return m_sourceType;
}
}, d -> Robot.m_drivetrain.drive(d, d));
m_pid.setAbsoluteTolerance(0.01);
m_pid.setSetpoint(distance);
}
m_pid.setAbsoluteTolerance(0.01);
m_pid.setSetpoint(distance);
}
// Called just before this Command runs the first time
@Override
protected void initialize() {
// Get everything in a safe starting state.
Robot.m_drivetrain.reset();
m_pid.reset();
m_pid.enable();
}
// Called just before this Command runs the first time
@Override
protected void initialize() {
// Get everything in a safe starting state.
Robot.m_drivetrain.reset();
m_pid.reset();
m_pid.enable();
}
// Make this return true when this Command no longer needs to run execute()
@Override
protected boolean isFinished() {
return m_pid.onTarget();
}
// Make this return true when this Command no longer needs to run execute()
@Override
protected boolean isFinished() {
return m_pid.onTarget();
}
// Called once after isFinished returns true
@Override
protected void end() {
// Stop PID and the wheels
m_pid.disable();
Robot.m_drivetrain.drive(0, 0);
}
// Called once after isFinished returns true
@Override
protected void end() {
// Stop PID and the wheels
m_pid.disable();
Robot.m_drivetrain.drive(0, 0);
}
}

View File

@@ -17,23 +17,23 @@ import edu.wpi.first.wpilibj.examples.gearsbot.Robot;
* PID!
*/
public class SetElevatorSetpoint extends Command {
private double m_setpoint;
private double m_setpoint;
public SetElevatorSetpoint(double setpoint) {
m_setpoint = setpoint;
requires(Robot.m_elevator);
}
public SetElevatorSetpoint(double setpoint) {
m_setpoint = setpoint;
requires(Robot.m_elevator);
}
// Called just before this Command runs the first time
@Override
protected void initialize() {
Robot.m_elevator.enable();
Robot.m_elevator.setSetpoint(m_setpoint);
}
// Called just before this Command runs the first time
@Override
protected void initialize() {
Robot.m_elevator.enable();
Robot.m_elevator.setSetpoint(m_setpoint);
}
// Make this return true when this Command no longer needs to run execute()
@Override
protected boolean isFinished() {
return Robot.m_elevator.onTarget();
}
// Make this return true when this Command no longer needs to run execute()
@Override
protected boolean isFinished() {
return Robot.m_elevator.onTarget();
}
}

View File

@@ -16,23 +16,23 @@ import edu.wpi.first.wpilibj.examples.gearsbot.Robot;
* commands using the wrist should make sure they disable PID!
*/
public class SetWristSetpoint extends Command {
private double m_setpoint;
private double m_setpoint;
public SetWristSetpoint(double setpoint) {
m_setpoint = setpoint;
requires(Robot.m_wrist);
}
public SetWristSetpoint(double setpoint) {
m_setpoint = setpoint;
requires(Robot.m_wrist);
}
// Called just before this Command runs the first time
@Override
protected void initialize() {
Robot.m_wrist.enable();
Robot.m_wrist.setSetpoint(m_setpoint);
}
// Called just before this Command runs the first time
@Override
protected void initialize() {
Robot.m_wrist.enable();
Robot.m_wrist.setSetpoint(m_setpoint);
}
// Make this return true when this Command no longer needs to run execute()
@Override
protected boolean isFinished() {
return Robot.m_wrist.onTarget();
}
// Make this return true when this Command no longer needs to run execute()
@Override
protected boolean isFinished() {
return Robot.m_wrist.onTarget();
}
}

View File

@@ -14,25 +14,25 @@ import edu.wpi.first.wpilibj.examples.gearsbot.Robot;
* Have the robot drive tank style using the PS3 Joystick until interrupted.
*/
public class TankDriveWithJoystick extends Command {
public TankDriveWithJoystick() {
requires(Robot.m_drivetrain);
}
public TankDriveWithJoystick() {
requires(Robot.m_drivetrain);
}
// Called repeatedly when this Command is scheduled to run
@Override
protected void execute() {
Robot.m_drivetrain.drive(Robot.m_oi.getJoystick());
}
// Called repeatedly when this Command is scheduled to run
@Override
protected void execute() {
Robot.m_drivetrain.drive(Robot.m_oi.getJoystick());
}
// Make this return true when this Command no longer needs to run execute()
@Override
protected boolean isFinished() {
return false; // Runs until interrupted
}
// Make this return true when this Command no longer needs to run execute()
@Override
protected boolean isFinished() {
return false; // Runs until interrupted
}
// Called once after isFinished returns true
@Override
protected void end() {
Robot.m_drivetrain.drive(0, 0);
}
// Called once after isFinished returns true
@Override
protected void end() {
Robot.m_drivetrain.drive(0, 0);
}
}

View File

@@ -17,50 +17,50 @@ import edu.wpi.first.wpilibj.command.Subsystem;
* don't stall.
*/
public class Claw extends Subsystem {
private Victor m_motor = new Victor(7);
private DigitalInput m_contact = new DigitalInput(5);
private Victor m_motor = new Victor(7);
private DigitalInput m_contact = new DigitalInput(5);
public Claw() {
super();
public Claw() {
super();
// Let's name everything on the LiveWindow
addChild("Motor", m_motor);
addChild("Limit Switch", m_contact);
}
// Let's name everything on the LiveWindow
addChild("Motor", m_motor);
addChild("Limit Switch", m_contact);
}
@Override
public void initDefaultCommand() {
}
@Override
public void initDefaultCommand() {
}
public void log() {
}
public void log() {
}
/**
* Set the claw motor to move in the open direction.
*/
public void open() {
m_motor.set(-1);
}
/**
* Set the claw motor to move in the open direction.
*/
public void open() {
m_motor.set(-1);
}
/**
* Set the claw motor to move in the close direction.
*/
public void close() {
m_motor.set(1);
}
/**
* Set the claw motor to move in the close direction.
*/
public void close() {
m_motor.set(1);
}
/**
* Stops the claw motor from moving.
*/
public void stop() {
m_motor.set(0);
}
/**
* Stops the claw motor from moving.
*/
public void stop() {
m_motor.set(0);
}
/**
* Return true when the robot is grabbing an object hard enough to trigger
* the limit switch.
*/
public boolean isGrabbing() {
return m_contact.get();
}
/**
* Return true when the robot is grabbing an object hard enough to trigger
* the limit switch.
*/
public boolean isGrabbing() {
return m_contact.get();
}
}

View File

@@ -26,119 +26,119 @@ import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
* and a gyro.
*/
public class DriveTrain extends Subsystem {
private SpeedController m_leftMotor
= new SpeedControllerGroup(new Spark(0), new Spark(1));
private SpeedController m_rightMotor
= new SpeedControllerGroup(new Spark(2), new Spark(3));
private SpeedController m_leftMotor
= new SpeedControllerGroup(new Spark(0), new Spark(1));
private SpeedController m_rightMotor
= new SpeedControllerGroup(new Spark(2), new Spark(3));
private DifferentialDrive m_drive
= new DifferentialDrive(m_leftMotor, m_rightMotor);
private DifferentialDrive m_drive
= new DifferentialDrive(m_leftMotor, m_rightMotor);
private Encoder m_leftEncoder = new Encoder(1, 2);
private Encoder m_rightEncoder = new Encoder(3, 4);
private AnalogInput m_rangefinder = new AnalogInput(6);
private AnalogGyro m_gyro = new AnalogGyro(1);
private Encoder m_leftEncoder = new Encoder(1, 2);
private Encoder m_rightEncoder = new Encoder(3, 4);
private AnalogInput m_rangefinder = new AnalogInput(6);
private AnalogGyro m_gyro = new AnalogGyro(1);
public DriveTrain() {
super();
public DriveTrain() {
super();
// Encoders may measure differently in the real world and in
// simulation. In this example the robot moves 0.042 barleycorns
// per tick in the real world, but the simulated encoders
// simulate 360 tick encoders. This if statement allows for the
// real robot to handle this difference in devices.
if (Robot.isReal()) {
m_leftEncoder.setDistancePerPulse(0.042);
m_rightEncoder.setDistancePerPulse(0.042);
} else {
// Circumference in ft = 4in/12(in/ft)*PI
m_leftEncoder.setDistancePerPulse((4.0 / 12.0 * Math.PI) / 360.0);
m_rightEncoder.setDistancePerPulse((4.0 / 12.0 * Math.PI) / 360.0);
}
// Encoders may measure differently in the real world and in
// simulation. In this example the robot moves 0.042 barleycorns
// per tick in the real world, but the simulated encoders
// simulate 360 tick encoders. This if statement allows for the
// real robot to handle this difference in devices.
if (Robot.isReal()) {
m_leftEncoder.setDistancePerPulse(0.042);
m_rightEncoder.setDistancePerPulse(0.042);
} else {
// Circumference in ft = 4in/12(in/ft)*PI
m_leftEncoder.setDistancePerPulse((4.0 / 12.0 * Math.PI) / 360.0);
m_rightEncoder.setDistancePerPulse((4.0 / 12.0 * Math.PI) / 360.0);
}
// Let's name the sensors on the LiveWindow
addChild("Drive", m_drive);
addChild("Left Encoder", m_leftEncoder);
addChild("Right Encoder", m_rightEncoder);
addChild("Rangefinder", m_rangefinder);
addChild("Gyro", m_gyro);
}
// Let's name the sensors on the LiveWindow
addChild("Drive", m_drive);
addChild("Left Encoder", m_leftEncoder);
addChild("Right Encoder", m_rightEncoder);
addChild("Rangefinder", m_rangefinder);
addChild("Gyro", m_gyro);
}
/**
* When no other command is running let the operator drive around using the
* PS3 joystick.
*/
@Override
public void initDefaultCommand() {
setDefaultCommand(new TankDriveWithJoystick());
}
/**
* When no other command is running let the operator drive around using the
* PS3 joystick.
*/
@Override
public void initDefaultCommand() {
setDefaultCommand(new TankDriveWithJoystick());
}
/**
* The log method puts interesting information to the SmartDashboard.
*/
public void log() {
SmartDashboard.putNumber("Left Distance", m_leftEncoder.getDistance());
SmartDashboard.putNumber("Right Distance", m_rightEncoder.getDistance());
SmartDashboard.putNumber("Left Speed", m_leftEncoder.getRate());
SmartDashboard.putNumber("Right Speed", m_rightEncoder.getRate());
SmartDashboard.putNumber("Gyro", m_gyro.getAngle());
}
/**
* The log method puts interesting information to the SmartDashboard.
*/
public void log() {
SmartDashboard.putNumber("Left Distance", m_leftEncoder.getDistance());
SmartDashboard.putNumber("Right Distance", m_rightEncoder.getDistance());
SmartDashboard.putNumber("Left Speed", m_leftEncoder.getRate());
SmartDashboard.putNumber("Right Speed", m_rightEncoder.getRate());
SmartDashboard.putNumber("Gyro", m_gyro.getAngle());
}
/**
* Tank style driving for the DriveTrain.
*
* @param left
* Speed in range [-1,1]
* @param right
* Speed in range [-1,1]
*/
public void drive(double left, double right) {
m_drive.tankDrive(left, right);
}
/**
* Tank style driving for the DriveTrain.
*
* @param left
* Speed in range [-1,1]
* @param right
* Speed in range [-1,1]
*/
public void drive(double left, double right) {
m_drive.tankDrive(left, right);
}
/**
* Tank style driving for the DriveTrain.
*
* @param joy The ps3 style joystick to use to drive tank style.
*/
public void drive(Joystick joy) {
drive(-joy.getY(), -joy.getThrottle());
}
/**
* Tank style driving for the DriveTrain.
*
* @param joy The ps3 style joystick to use to drive tank style.
*/
public void drive(Joystick joy) {
drive(-joy.getY(), -joy.getThrottle());
}
/**
* Get the robot's heading.
*
* @return The robots heading in degrees.
*/
public double getHeading() {
return m_gyro.getAngle();
}
/**
* Get the robot's heading.
*
* @return The robots heading in degrees.
*/
public double getHeading() {
return m_gyro.getAngle();
}
/**
* Reset the robots sensors to the zero states.
*/
public void reset() {
m_gyro.reset();
m_leftEncoder.reset();
m_rightEncoder.reset();
}
/**
* Reset the robots sensors to the zero states.
*/
public void reset() {
m_gyro.reset();
m_leftEncoder.reset();
m_rightEncoder.reset();
}
/**
* Get the average distance of the encoders since the last reset.
*
* @return The distance driven (average of left and right encoders).
*/
public double getDistance() {
return (m_leftEncoder.getDistance() + m_rightEncoder.getDistance()) / 2;
}
/**
* Get the average distance of the encoders since the last reset.
*
* @return The distance driven (average of left and right encoders).
*/
public double getDistance() {
return (m_leftEncoder.getDistance() + m_rightEncoder.getDistance()) / 2;
}
/**
* Get the distance to the obstacle.
*
* @return The distance to the obstacle detected by the rangefinder.
*/
public double getDistanceToObstacle() {
// Really meters in simulation since it's a rangefinder...
return m_rangefinder.getAverageVoltage();
}
/**
* Get the distance to the obstacle.
*
* @return The distance to the obstacle detected by the rangefinder.
*/
public double getDistanceToObstacle() {
// Really meters in simulation since it's a rangefinder...
return m_rangefinder.getAverageVoltage();
}
}

View File

@@ -19,62 +19,62 @@ import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
* world do to minor differences.
*/
public class Elevator extends PIDSubsystem {
private Victor m_motor;
private AnalogPotentiometer m_pot;
private Victor m_motor;
private AnalogPotentiometer m_pot;
private static final double kP_real = 4;
private static final double kI_real = 0.07;
private static final double kP_simulation = 18;
private static final double kI_simulation = 0.2;
private static final double kP_real = 4;
private static final double kI_real = 0.07;
private static final double kP_simulation = 18;
private static final double kI_simulation = 0.2;
public Elevator() {
super(kP_real, kI_real, 0);
if (Robot.isSimulation()) { // Check for simulation and update PID values
getPIDController().setPID(kP_simulation, kI_simulation, 0, 0);
}
setAbsoluteTolerance(0.005);
public Elevator() {
super(kP_real, kI_real, 0);
if (Robot.isSimulation()) { // Check for simulation and update PID values
getPIDController().setPID(kP_simulation, kI_simulation, 0, 0);
}
setAbsoluteTolerance(0.005);
m_motor = new Victor(5);
m_motor = new Victor(5);
// Conversion value of potentiometer varies between the real world and
// simulation
if (Robot.isReal()) {
m_pot = new AnalogPotentiometer(2, -2.0 / 5);
} else {
m_pot = new AnalogPotentiometer(2); // Defaults to meters
}
// Conversion value of potentiometer varies between the real world and
// simulation
if (Robot.isReal()) {
m_pot = new AnalogPotentiometer(2, -2.0 / 5);
} else {
m_pot = new AnalogPotentiometer(2); // Defaults to meters
}
// Let's name everything on the LiveWindow
addChild("Motor", m_motor);
addChild("Pot", m_pot);
}
// Let's name everything on the LiveWindow
addChild("Motor", m_motor);
addChild("Pot", m_pot);
}
@Override
public void initDefaultCommand() {
}
@Override
public void initDefaultCommand() {
}
/**
* The log method puts interesting information to the SmartDashboard.
*/
public void log() {
SmartDashboard.putData("Elevator Pot", (AnalogPotentiometer) m_pot);
}
/**
* The log method puts interesting information to the SmartDashboard.
*/
public void log() {
SmartDashboard.putData("Elevator Pot", (AnalogPotentiometer) m_pot);
}
/**
* Use the potentiometer as the PID sensor. This method is automatically
* called by the subsystem.
*/
@Override
protected double returnPIDInput() {
return m_pot.get();
}
/**
* Use the potentiometer as the PID sensor. This method is automatically
* called by the subsystem.
*/
@Override
protected double returnPIDInput() {
return m_pot.get();
}
/**
* Use the motor as the PID output. This method is automatically called by
* the subsystem.
*/
@Override
protected void usePIDOutput(double power) {
m_motor.set(power);
}
/**
* Use the motor as the PID output. This method is automatically called by
* the subsystem.
*/
@Override
protected void usePIDOutput(double power) {
m_motor.set(power);
}
}

View File

@@ -18,60 +18,60 @@ import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
* of a linear joint.
*/
public class Wrist extends PIDSubsystem {
private Victor m_motor;
private AnalogPotentiometer m_pot;
private Victor m_motor;
private AnalogPotentiometer m_pot;
private static final double kP_real = 1;
private static final double kP_simulation = 0.05;
private static final double kP_real = 1;
private static final double kP_simulation = 0.05;
public Wrist() {
super(kP_real, 0, 0);
if (Robot.isSimulation()) { // Check for simulation and update PID values
getPIDController().setPID(kP_simulation, 0, 0, 0);
}
setAbsoluteTolerance(2.5);
public Wrist() {
super(kP_real, 0, 0);
if (Robot.isSimulation()) { // Check for simulation and update PID values
getPIDController().setPID(kP_simulation, 0, 0, 0);
}
setAbsoluteTolerance(2.5);
m_motor = new Victor(6);
m_motor = new Victor(6);
// Conversion value of potentiometer varies between the real world and
// simulation
if (Robot.isReal()) {
m_pot = new AnalogPotentiometer(3, -270.0 / 5);
} else {
m_pot = new AnalogPotentiometer(3); // Defaults to degrees
}
// Conversion value of potentiometer varies between the real world and
// simulation
if (Robot.isReal()) {
m_pot = new AnalogPotentiometer(3, -270.0 / 5);
} else {
m_pot = new AnalogPotentiometer(3); // Defaults to degrees
}
// Let's name everything on the LiveWindow
addChild("Motor", m_motor);
addChild("Pot", m_pot);
}
// Let's name everything on the LiveWindow
addChild("Motor", m_motor);
addChild("Pot", m_pot);
}
@Override
public void initDefaultCommand() {
}
@Override
public void initDefaultCommand() {
}
/**
* The log method puts interesting information to the SmartDashboard.
*/
public void log() {
SmartDashboard.putData("Wrist Angle", (AnalogPotentiometer) m_pot);
}
/**
* The log method puts interesting information to the SmartDashboard.
*/
public void log() {
SmartDashboard.putData("Wrist Angle", (AnalogPotentiometer) m_pot);
}
/**
* Use the potentiometer as the PID sensor. This method is automatically
* called by the subsystem.
*/
@Override
protected double returnPIDInput() {
return m_pot.get();
}
/**
* Use the potentiometer as the PID sensor. This method is automatically
* called by the subsystem.
*/
@Override
protected double returnPIDInput() {
return m_pot.get();
}
/**
* Use the motor as the PID output. This method is automatically called by
* the subsystem.
*/
@Override
protected void usePIDOutput(double power) {
m_motor.set(power);
}
/**
* Use the motor as the PID output. This method is automatically called by
* the subsystem.
*/
@Override
protected void usePIDOutput(double power) {
m_motor.set(power);
}
}

View File

@@ -21,60 +21,60 @@ import edu.wpi.first.wpilibj.drive.DifferentialDrive;
* directory.
*/
public class Robot extends IterativeRobot {
private DifferentialDrive m_robotDrive
= new DifferentialDrive(new Spark(0), new Spark(1));
private Joystick m_stick = new Joystick(0);
private Timer m_timer = new Timer();
private DifferentialDrive m_robotDrive
= new DifferentialDrive(new Spark(0), new Spark(1));
private Joystick m_stick = new Joystick(0);
private Timer m_timer = new Timer();
/**
* This function is run when the robot is first started up and should be
* used for any initialization code.
*/
@Override
public void robotInit() {
}
/**
* This function is run when the robot is first started up and should be
* used for any initialization code.
*/
@Override
public void robotInit() {
}
/**
* This function is run once each time the robot enters autonomous mode.
*/
@Override
public void autonomousInit() {
m_timer.reset();
m_timer.start();
}
/**
* This function is run once each time the robot enters autonomous mode.
*/
@Override
public void autonomousInit() {
m_timer.reset();
m_timer.start();
}
/**
* This function is called periodically during autonomous.
*/
@Override
public void autonomousPeriodic() {
// Drive for 2 seconds
if (m_timer.get() < 2.0) {
m_robotDrive.arcadeDrive(0.5, 0.0); // drive forwards half speed
} else {
m_robotDrive.stopMotor(); // stop robot
}
}
/**
* This function is called periodically during autonomous.
*/
@Override
public void autonomousPeriodic() {
// Drive for 2 seconds
if (m_timer.get() < 2.0) {
m_robotDrive.arcadeDrive(0.5, 0.0); // drive forwards half speed
} else {
m_robotDrive.stopMotor(); // stop robot
}
}
/**
* This function is called once each time the robot enters teleoperated mode.
*/
@Override
public void teleopInit() {
}
/**
* This function is called once each time the robot enters teleoperated mode.
*/
@Override
public void teleopInit() {
}
/**
* This function is called periodically during teleoperated mode.
*/
@Override
public void teleopPeriodic() {
m_robotDrive.arcadeDrive(m_stick.getY(), m_stick.getX());
}
/**
* This function is called periodically during teleoperated mode.
*/
@Override
public void teleopPeriodic() {
m_robotDrive.arcadeDrive(m_stick.getY(), m_stick.getX());
}
/**
* This function is called periodically during test mode.
*/
@Override
public void testPeriodic() {
}
/**
* This function is called periodically during test mode.
*/
@Override
public void testPeriodic() {
}
}

View File

@@ -19,38 +19,38 @@ import edu.wpi.first.wpilibj.drive.DifferentialDrive;
* backwards while the gyro is used for direction keeping.
*/
public class Robot extends IterativeRobot {
private static final double kAngleSetpoint = 0.0;
private static final double kP = 0.005; // propotional turning constant
private static final double kAngleSetpoint = 0.0;
private static final double kP = 0.005; // propotional turning constant
// gyro calibration constant, may need to be adjusted;
// gyro value of 360 is set to correspond to one full revolution
private static final double kVoltsPerDegreePerSecond = 0.0128;
// gyro calibration constant, may need to be adjusted;
// gyro value of 360 is set to correspond to one full revolution
private static final double kVoltsPerDegreePerSecond = 0.0128;
private static final int kLeftMotorPort = 0;
private static final int kRightMotorPort = 1;
private static final int kGyroPort = 0;
private static final int kJoystickPort = 0;
private static final int kLeftMotorPort = 0;
private static final int kRightMotorPort = 1;
private static final int kGyroPort = 0;
private static final int kJoystickPort = 0;
private DifferentialDrive m_myRobot
= new DifferentialDrive(new Spark(kLeftMotorPort),
new Spark(kRightMotorPort));
private AnalogGyro m_gyro = new AnalogGyro(kGyroPort);
private Joystick m_joystick = new Joystick(kJoystickPort);
private DifferentialDrive m_myRobot
= new DifferentialDrive(new Spark(kLeftMotorPort),
new Spark(kRightMotorPort));
private AnalogGyro m_gyro = new AnalogGyro(kGyroPort);
private Joystick m_joystick = new Joystick(kJoystickPort);
@Override
public void robotInit() {
m_gyro.setSensitivity(kVoltsPerDegreePerSecond);
}
@Override
public void robotInit() {
m_gyro.setSensitivity(kVoltsPerDegreePerSecond);
}
/**
* The motor speed is set from the joystick while the RobotDrive turning
* value is assigned from the error between the setpoint and the gyro angle.
*/
@Override
public void teleopPeriodic() {
double turningValue = (kAngleSetpoint - m_gyro.getAngle()) * kP;
// Invert the direction of the turn if we are going backwards
turningValue = Math.copySign(turningValue, m_joystick.getY());
m_myRobot.arcadeDrive(m_joystick.getY(), turningValue);
}
/**
* The motor speed is set from the joystick while the RobotDrive turning
* value is assigned from the error between the setpoint and the gyro angle.
*/
@Override
public void teleopPeriodic() {
double turningValue = (kAngleSetpoint - m_gyro.getAngle()) * kP;
// Invert the direction of the turn if we are going backwards
turningValue = Math.copySign(turningValue, m_joystick.getY());
m_myRobot.arcadeDrive(m_joystick.getY(), turningValue);
}
}

View File

@@ -19,44 +19,44 @@ import edu.wpi.first.wpilibj.drive.MecanumDrive;
* (field-oriented controls).
*/
public class Robot extends IterativeRobot {
// gyro calibration constant, may need to be adjusted;
// gyro value of 360 is set to correspond to one full revolution
private static final double kVoltsPerDegreePerSecond = 0.0128;
// gyro calibration constant, may need to be adjusted;
// gyro value of 360 is set to correspond to one full revolution
private static final double kVoltsPerDegreePerSecond = 0.0128;
private static final int kFrontLeftChannel = 0;
private static final int kRearLeftChannel = 1;
private static final int kFrontRightChannel = 2;
private static final int kRearRightChannel = 3;
private static final int kGyroPort = 0;
private static final int kJoystickPort = 0;
private static final int kFrontLeftChannel = 0;
private static final int kRearLeftChannel = 1;
private static final int kFrontRightChannel = 2;
private static final int kRearRightChannel = 3;
private static final int kGyroPort = 0;
private static final int kJoystickPort = 0;
private MecanumDrive m_robotDrive;
private AnalogGyro m_gyro = new AnalogGyro(kGyroPort);
private Joystick m_joystick = new Joystick(kJoystickPort);
private MecanumDrive m_robotDrive;
private AnalogGyro m_gyro = new AnalogGyro(kGyroPort);
private Joystick m_joystick = new Joystick(kJoystickPort);
@Override
public void robotInit() {
Spark frontLeft = new Spark(kFrontLeftChannel);
Spark rearLeft = new Spark(kRearLeftChannel);
Spark frontRight = new Spark(kFrontRightChannel);
Spark rearRight = new Spark(kRearRightChannel);
@Override
public void robotInit() {
Spark frontLeft = new Spark(kFrontLeftChannel);
Spark rearLeft = new Spark(kRearLeftChannel);
Spark frontRight = new Spark(kFrontRightChannel);
Spark rearRight = new Spark(kRearRightChannel);
// Invert the left side motors.
// You may need to change or remove this to match your robot.
frontLeft.setInverted(true);
rearLeft.setInverted(true);
// Invert the left side motors.
// You may need to change or remove this to match your robot.
frontLeft.setInverted(true);
rearLeft.setInverted(true);
m_robotDrive = new MecanumDrive(frontLeft, rearLeft, frontRight, rearRight);
m_robotDrive = new MecanumDrive(frontLeft, rearLeft, frontRight, rearRight);
m_gyro.setSensitivity(kVoltsPerDegreePerSecond);
}
m_gyro.setSensitivity(kVoltsPerDegreePerSecond);
}
/**
* Mecanum drive is used with the gyro angle as an input.
*/
@Override
public void teleopPeriodic() {
m_robotDrive.driveCartesian(m_joystick.getX(), m_joystick.getY(),
m_joystick.getZ(), m_gyro.getAngle());
}
/**
* Mecanum drive is used with the gyro angle as an input.
*/
@Override
public void teleopPeriodic() {
m_robotDrive.driveCartesian(m_joystick.getX(), m_joystick.getY(),
m_joystick.getZ(), m_gyro.getAngle());
}
}

View File

@@ -24,45 +24,45 @@ import org.opencv.imgproc.Imgproc;
* processing.
*/
public class Robot extends IterativeRobot {
Thread m_visionThread;
Thread m_visionThread;
@Override
public void robotInit() {
m_visionThread = new Thread(() -> {
// Get the UsbCamera from CameraServer
UsbCamera camera = CameraServer.getInstance().startAutomaticCapture();
// Set the resolution
camera.setResolution(640, 480);
@Override
public void robotInit() {
m_visionThread = new Thread(() -> {
// Get the UsbCamera from CameraServer
UsbCamera camera = CameraServer.getInstance().startAutomaticCapture();
// Set the resolution
camera.setResolution(640, 480);
// Get a CvSink. This will capture Mats from the camera
CvSink cvSink = CameraServer.getInstance().getVideo();
// Setup a CvSource. This will send images back to the Dashboard
CvSource outputStream
= CameraServer.getInstance().putVideo("Rectangle", 640, 480);
// Get a CvSink. This will capture Mats from the camera
CvSink cvSink = CameraServer.getInstance().getVideo();
// Setup a CvSource. This will send images back to the Dashboard
CvSource outputStream
= CameraServer.getInstance().putVideo("Rectangle", 640, 480);
// Mats are very memory expensive. Lets reuse this Mat.
Mat mat = new Mat();
// Mats are very memory expensive. Lets reuse this Mat.
Mat mat = new Mat();
// This cannot be 'true'. The program will never exit if it is. This
// lets the robot stop this thread when restarting robot code or
// deploying.
while (!Thread.interrupted()) {
// Tell the CvSink to grab a frame from the camera and put it
// in the source mat. If there is an error notify the output.
if (cvSink.grabFrame(mat) == 0) {
// Send the output the error.
outputStream.notifyError(cvSink.getError());
// skip the rest of the current iteration
continue;
}
// Put a rectangle on the image
Imgproc.rectangle(mat, new Point(100, 100), new Point(400, 400),
new Scalar(255, 255, 255), 5);
// Give the output stream a new image to display
outputStream.putFrame(mat);
}
});
m_visionThread.setDaemon(true);
m_visionThread.start();
}
// This cannot be 'true'. The program will never exit if it is. This
// lets the robot stop this thread when restarting robot code or
// deploying.
while (!Thread.interrupted()) {
// Tell the CvSink to grab a frame from the camera and put it
// in the source mat. If there is an error notify the output.
if (cvSink.grabFrame(mat) == 0) {
// Send the output the error.
outputStream.notifyError(cvSink.getError());
// skip the rest of the current iteration
continue;
}
// Put a rectangle on the image
Imgproc.rectangle(mat, new Point(100, 100), new Point(400, 400),
new Scalar(255, 255, 255), 5);
// Give the output stream a new image to display
outputStream.putFrame(mat);
}
});
m_visionThread.setDaemon(true);
m_visionThread.start();
}
}

View File

@@ -17,38 +17,38 @@ import edu.wpi.first.wpilibj.drive.MecanumDrive;
* class.
*/
public class Robot extends IterativeRobot {
private static final int kFrontLeftChannel = 2;
private static final int kRearLeftChannel = 3;
private static final int kFrontRightChannel = 1;
private static final int kRearRightChannel = 0;
private static final int kFrontLeftChannel = 2;
private static final int kRearLeftChannel = 3;
private static final int kFrontRightChannel = 1;
private static final int kRearRightChannel = 0;
private static final int kJoystickChannel = 0;
private static final int kJoystickChannel = 0;
private MecanumDrive m_robotDrive;
private Joystick m_stick;
private MecanumDrive m_robotDrive;
private Joystick m_stick;
@Override
public void robotInit() {
Spark frontLeft = new Spark(kFrontLeftChannel);
Spark rearLeft = new Spark(kRearLeftChannel);
Spark frontRight = new Spark(kFrontRightChannel);
Spark rearRight = new Spark(kRearRightChannel);
@Override
public void robotInit() {
Spark frontLeft = new Spark(kFrontLeftChannel);
Spark rearLeft = new Spark(kRearLeftChannel);
Spark frontRight = new Spark(kFrontRightChannel);
Spark rearRight = new Spark(kRearRightChannel);
// Invert the left side motors.
// You may need to change or remove this to match your robot.
frontLeft.setInverted(true);
rearLeft.setInverted(true);
// Invert the left side motors.
// You may need to change or remove this to match your robot.
frontLeft.setInverted(true);
rearLeft.setInverted(true);
m_robotDrive = new MecanumDrive(frontLeft, rearLeft, frontRight, rearRight);
m_robotDrive = new MecanumDrive(frontLeft, rearLeft, frontRight, rearRight);
m_stick = new Joystick(kJoystickChannel);
}
m_stick = new Joystick(kJoystickChannel);
}
@Override
public void teleopPeriodic() {
// Use the joystick X axis for lateral movement, Y axis for forward
// movement, and Z axis for rotation.
m_robotDrive.driveCartesian(m_stick.getX(), m_stick.getY(),
m_stick.getZ(), 0.0);
}
@Override
public void teleopPeriodic() {
// Use the joystick X axis for lateral movement, Y axis for forward
// movement, and Z axis for rotation.
m_robotDrive.driveCartesian(m_stick.getX(), m_stick.getY(),
m_stick.getZ(), 0.0);
}
}

View File

@@ -21,20 +21,20 @@ import edu.wpi.first.wpilibj.Spark;
* range from -1 to 1 making it easy to work together.
*/
public class Robot extends IterativeRobot {
private static final int kMotorPort = 0;
private static final int kJoystickPort = 0;
private static final int kMotorPort = 0;
private static final int kJoystickPort = 0;
private SpeedController m_motor;
private Joystick m_joystick;
private SpeedController m_motor;
private Joystick m_joystick;
@Override
public void robotInit() {
m_motor = new Spark(kMotorPort);
m_joystick = new Joystick(kJoystickPort);
}
@Override
public void robotInit() {
m_motor = new Spark(kMotorPort);
m_joystick = new Joystick(kJoystickPort);
}
@Override
public void teleopPeriodic() {
m_motor.set(m_joystick.getY());
}
@Override
public void teleopPeriodic() {
m_motor.set(m_joystick.getY());
}
}

View File

@@ -27,31 +27,31 @@ import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
* functionality from the real robot is available.
*/
public class OI {
public Joystick m_joystick = new Joystick(0);
public Joystick m_joystick = new Joystick(0);
public OI() {
new JoystickButton(m_joystick, 12).whenPressed(new LowGoal());
new JoystickButton(m_joystick, 10).whenPressed(new Collect());
public OI() {
new JoystickButton(m_joystick, 12).whenPressed(new LowGoal());
new JoystickButton(m_joystick, 10).whenPressed(new Collect());
new JoystickButton(m_joystick, 11).whenPressed(
new SetPivotSetpoint(Pivot.kShoot));
new JoystickButton(m_joystick, 9).whenPressed(
new SetPivotSetpoint(Pivot.kShootNear));
new JoystickButton(m_joystick, 11).whenPressed(
new SetPivotSetpoint(Pivot.kShoot));
new JoystickButton(m_joystick, 9).whenPressed(
new SetPivotSetpoint(Pivot.kShootNear));
new DoubleButton(m_joystick, 2, 3).whenActive(new Shoot());
new DoubleButton(m_joystick, 2, 3).whenActive(new Shoot());
// SmartDashboard Buttons
SmartDashboard.putData("Drive Forward", new DriveForward(2.25));
SmartDashboard.putData("Drive Backward", new DriveForward(-2.25));
SmartDashboard.putData("Start Rollers",
new SetCollectionSpeed(Collector.kForward));
SmartDashboard.putData("Stop Rollers",
new SetCollectionSpeed(Collector.kStop));
SmartDashboard.putData("Reverse Rollers",
new SetCollectionSpeed(Collector.kReverse));
}
// SmartDashboard Buttons
SmartDashboard.putData("Drive Forward", new DriveForward(2.25));
SmartDashboard.putData("Drive Backward", new DriveForward(-2.25));
SmartDashboard.putData("Start Rollers",
new SetCollectionSpeed(Collector.kForward));
SmartDashboard.putData("Stop Rollers",
new SetCollectionSpeed(Collector.kStop));
SmartDashboard.putData("Reverse Rollers",
new SetCollectionSpeed(Collector.kReverse));
}
public Joystick getJoystick() {
return m_joystick;
}
public Joystick getJoystick() {
return m_joystick;
}
}

View File

@@ -31,98 +31,98 @@ import edu.wpi.first.wpilibj.examples.pacgoat.subsystems.Shooter;
* directory.
*/
public class Robot extends IterativeRobot {
Command m_autonomousCommand;
public static OI oi;
Command m_autonomousCommand;
public static OI oi;
// Initialize the subsystems
public static DriveTrain drivetrain = new DriveTrain();
public static Collector collector = new Collector();
public static Shooter shooter = new Shooter();
public static Pneumatics pneumatics = new Pneumatics();
public static Pivot pivot = new Pivot();
// Initialize the subsystems
public static DriveTrain drivetrain = new DriveTrain();
public static Collector collector = new Collector();
public static Shooter shooter = new Shooter();
public static Pneumatics pneumatics = new Pneumatics();
public static Pivot pivot = new Pivot();
public SendableChooser<Command> m_autoChooser;
public SendableChooser<Command> m_autoChooser;
// This function is run when the robot is first started up and should be
// used for any initialization code.
@Override
public void robotInit() {
SmartDashboard.putData(drivetrain);
SmartDashboard.putData(collector);
SmartDashboard.putData(shooter);
SmartDashboard.putData(pneumatics);
SmartDashboard.putData(pivot);
// This function is run when the robot is first started up and should be
// used for any initialization code.
@Override
public void robotInit() {
SmartDashboard.putData(drivetrain);
SmartDashboard.putData(collector);
SmartDashboard.putData(shooter);
SmartDashboard.putData(pneumatics);
SmartDashboard.putData(pivot);
// This MUST be here. If the OI creates Commands (which it very likely
// will), constructing it during the construction of CommandBase (from
// which commands extend), subsystems are not guaranteed to be
// yet. Thus, their requires() statements may grab null pointers. Bad
// news. Don't move it.
oi = new OI();
// This MUST be here. If the OI creates Commands (which it very likely
// will), constructing it during the construction of CommandBase (from
// which commands extend), subsystems are not guaranteed to be
// yet. Thus, their requires() statements may grab null pointers. Bad
// news. Don't move it.
oi = new OI();
// instantiate the command used for the autonomous period
m_autoChooser = new SendableChooser<Command>();
m_autoChooser.addDefault("Drive and Shoot", new DriveAndShootAutonomous());
m_autoChooser.addObject("Drive Forward", new DriveForward());
SmartDashboard.putData("Auto Mode", m_autoChooser);
}
// instantiate the command used for the autonomous period
m_autoChooser = new SendableChooser<Command>();
m_autoChooser.addDefault("Drive and Shoot", new DriveAndShootAutonomous());
m_autoChooser.addObject("Drive Forward", new DriveForward());
SmartDashboard.putData("Auto Mode", m_autoChooser);
}
@Override
public void autonomousInit() {
m_autonomousCommand = (Command) m_autoChooser.getSelected();
m_autonomousCommand.start();
}
@Override
public void autonomousInit() {
m_autonomousCommand = (Command) m_autoChooser.getSelected();
m_autonomousCommand.start();
}
// This function is called periodically during autonomous
@Override
public void autonomousPeriodic() {
Scheduler.getInstance().run();
log();
}
// This function is called periodically during autonomous
@Override
public void autonomousPeriodic() {
Scheduler.getInstance().run();
log();
}
@Override
public void teleopInit() {
// This makes sure that the autonomous stops running when
// teleop starts running. If you want the autonomous to
// continue until interrupted by another command, remove
// this line or comment it out.
if (m_autonomousCommand != null) {
m_autonomousCommand.cancel();
}
}
@Override
public void teleopInit() {
// This makes sure that the autonomous stops running when
// teleop starts running. If you want the autonomous to
// continue until interrupted by another command, remove
// this line or comment it out.
if (m_autonomousCommand != null) {
m_autonomousCommand.cancel();
}
}
// This function is called periodically during operator control
@Override
public void teleopPeriodic() {
Scheduler.getInstance().run();
log();
}
// This function is called periodically during operator control
@Override
public void teleopPeriodic() {
Scheduler.getInstance().run();
log();
}
// This function called periodically during test mode
@Override
public void testPeriodic() {
}
// This function called periodically during test mode
@Override
public void testPeriodic() {
}
@Override
public void disabledInit() {
Robot.shooter.unlatch();
}
@Override
public void disabledInit() {
Robot.shooter.unlatch();
}
// This function is called periodically while disabled
@Override
public void disabledPeriodic() {
log();
}
// This function is called periodically while disabled
@Override
public void disabledPeriodic() {
log();
}
/**
* Log interesting values to the SmartDashboard.
*/
private void log() {
Robot.pneumatics.writePressure();
SmartDashboard.putNumber("Pivot Pot Value", Robot.pivot.getAngle());
SmartDashboard.putNumber("Left Distance",
drivetrain.getLeftEncoder().getDistance());
SmartDashboard.putNumber("Right Distance",
drivetrain.getRightEncoder().getDistance());
}
/**
* Log interesting values to the SmartDashboard.
*/
private void log() {
Robot.pneumatics.writePressure();
SmartDashboard.putNumber("Pivot Pot Value", Robot.pivot.getAngle());
SmartDashboard.putNumber("Left Distance",
drivetrain.getLeftEncoder().getDistance());
SmartDashboard.putNumber("Right Distance",
drivetrain.getRightEncoder().getDistance());
}
}

View File

@@ -18,13 +18,13 @@ import edu.wpi.first.wpilibj.examples.pacgoat.Robot;
* the hot goal is detected or until it is timed out.
*/
public class CheckForHotGoal extends Command {
public CheckForHotGoal(double time) {
setTimeout(time);
}
public CheckForHotGoal(double time) {
setTimeout(time);
}
// Make this return true when this Command no longer needs to run execute()
@Override
protected boolean isFinished() {
return isTimedOut() || Robot.shooter.goalIsHot();
}
// Make this return true when this Command no longer needs to run execute()
@Override
protected boolean isFinished() {
return isTimedOut() || Robot.shooter.goalIsHot();
}
}

View File

@@ -18,13 +18,13 @@ import edu.wpi.first.wpilibj.examples.pacgoat.Robot;
* detect that.
*/
public class CloseClaw extends InstantCommand {
public CloseClaw() {
requires(Robot.collector);
}
public CloseClaw() {
requires(Robot.collector);
}
// Called just before this Command runs the first time
@Override
protected void initialize() {
Robot.collector.close();
}
// Called just before this Command runs the first time
@Override
protected void initialize() {
Robot.collector.close();
}
}

View File

@@ -16,10 +16,10 @@ import edu.wpi.first.wpilibj.examples.pacgoat.subsystems.Pivot;
* Get the robot set to collect balls.
*/
public class Collect extends CommandGroup {
public Collect() {
addSequential(new SetCollectionSpeed(Collector.kForward));
addParallel(new CloseClaw());
addSequential(new SetPivotSetpoint(Pivot.kCollect));
addSequential(new WaitForBall());
}
public Collect() {
addSequential(new SetCollectionSpeed(Collector.kForward));
addParallel(new CloseClaw());
addSequential(new SetPivotSetpoint(Pivot.kCollect));
addSequential(new WaitForBall());
}
}

View File

@@ -16,15 +16,15 @@ import edu.wpi.first.wpilibj.examples.pacgoat.Robot;
* it will wait briefly.
*/
public class DriveAndShootAutonomous extends CommandGroup {
public DriveAndShootAutonomous() {
addSequential(new CloseClaw());
addSequential(new WaitForPressure(), 2);
if (Robot.isReal()) {
// NOTE: Simulation doesn't currently have the concept of hot.
addSequential(new CheckForHotGoal(2));
}
addSequential(new SetPivotSetpoint(45));
addSequential(new DriveForward(8, 0.3));
addSequential(new Shoot());
}
public DriveAndShootAutonomous() {
addSequential(new CloseClaw());
addSequential(new WaitForPressure(), 2);
if (Robot.isReal()) {
// NOTE: Simulation doesn't currently have the concept of hot.
addSequential(new CheckForHotGoal(2));
}
addSequential(new SetPivotSetpoint(45));
addSequential(new DriveForward(8, 0.3));
addSequential(new Shoot());
}
}

View File

@@ -16,50 +16,50 @@ import edu.wpi.first.wpilibj.examples.pacgoat.Robot;
* control This command will drive a given distance limiting to a maximum speed.
*/
public class DriveForward extends Command {
private double m_driveForwardSpeed;
private double m_distance;
private double m_error;
private static final double kTolerance = 0.1;
private static final double kP = -1.0 / 5.0;
private double m_driveForwardSpeed;
private double m_distance;
private double m_error;
private static final double kTolerance = 0.1;
private static final double kP = -1.0 / 5.0;
public DriveForward() {
this(10, 0.5);
}
public DriveForward() {
this(10, 0.5);
}
public DriveForward(double dist) {
this(dist, 0.5);
}
public DriveForward(double dist) {
this(dist, 0.5);
}
public DriveForward(double dist, double maxSpeed) {
requires(Robot.drivetrain);
m_distance = dist;
m_driveForwardSpeed = maxSpeed;
}
public DriveForward(double dist, double maxSpeed) {
requires(Robot.drivetrain);
m_distance = dist;
m_driveForwardSpeed = maxSpeed;
}
@Override
protected void initialize() {
Robot.drivetrain.getRightEncoder().reset();
setTimeout(2);
}
@Override
protected void initialize() {
Robot.drivetrain.getRightEncoder().reset();
setTimeout(2);
}
@Override
protected void execute() {
m_error = m_distance - Robot.drivetrain.getRightEncoder().getDistance();
if (m_driveForwardSpeed * kP * m_error >= m_driveForwardSpeed) {
Robot.drivetrain.tankDrive(m_driveForwardSpeed, m_driveForwardSpeed);
} else {
Robot.drivetrain.tankDrive(m_driveForwardSpeed * kP * m_error,
m_driveForwardSpeed * kP * m_error);
}
}
@Override
protected void execute() {
m_error = m_distance - Robot.drivetrain.getRightEncoder().getDistance();
if (m_driveForwardSpeed * kP * m_error >= m_driveForwardSpeed) {
Robot.drivetrain.tankDrive(m_driveForwardSpeed, m_driveForwardSpeed);
} else {
Robot.drivetrain.tankDrive(m_driveForwardSpeed * kP * m_error,
m_driveForwardSpeed * kP * m_error);
}
}
@Override
protected boolean isFinished() {
return Math.abs(m_error) <= kTolerance || isTimedOut();
}
@Override
protected boolean isFinished() {
return Math.abs(m_error) <= kTolerance || isTimedOut();
}
@Override
protected void end() {
Robot.drivetrain.stop();
}
@Override
protected void end() {
Robot.drivetrain.stop();
}
}

View File

@@ -16,22 +16,22 @@ import edu.wpi.first.wpilibj.examples.pacgoat.Robot;
* except when interrupted by another command.
*/
public class DriveWithJoystick extends Command {
public DriveWithJoystick() {
requires(Robot.drivetrain);
}
public DriveWithJoystick() {
requires(Robot.drivetrain);
}
@Override
protected void execute() {
Robot.drivetrain.tankDrive(Robot.oi.getJoystick());
}
@Override
protected void execute() {
Robot.drivetrain.tankDrive(Robot.oi.getJoystick());
}
@Override
protected boolean isFinished() {
return false;
}
@Override
protected boolean isFinished() {
return false;
}
@Override
protected void end() {
Robot.drivetrain.stop();
}
@Override
protected void end() {
Robot.drivetrain.stop();
}
}

View File

@@ -15,20 +15,20 @@ import edu.wpi.first.wpilibj.examples.pacgoat.Robot;
* Extend the shooter and then retract it after a second.
*/
public class ExtendShooter extends TimedCommand {
public ExtendShooter() {
super(1);
requires(Robot.shooter);
}
public ExtendShooter() {
super(1);
requires(Robot.shooter);
}
// Called just before this Command runs the first time
@Override
protected void initialize() {
Robot.shooter.extendBoth();
}
// Called just before this Command runs the first time
@Override
protected void initialize() {
Robot.shooter.extendBoth();
}
// Called once after isFinished returns true
@Override
protected void end() {
Robot.shooter.retractBoth();
}
// Called once after isFinished returns true
@Override
protected void end() {
Robot.shooter.retractBoth();
}
}

View File

@@ -17,9 +17,9 @@ import edu.wpi.first.wpilibj.examples.pacgoat.subsystems.Pivot;
* it.
*/
public class LowGoal extends CommandGroup {
public LowGoal() {
addSequential(new SetPivotSetpoint(Pivot.kLowGoal));
addSequential(new SetCollectionSpeed(Collector.kReverse));
addSequential(new ExtendShooter());
}
public LowGoal() {
addSequential(new SetPivotSetpoint(Pivot.kLowGoal));
addSequential(new SetCollectionSpeed(Collector.kReverse));
addSequential(new ExtendShooter());
}
}

View File

@@ -15,19 +15,19 @@ import edu.wpi.first.wpilibj.examples.pacgoat.Robot;
* Opens the claw.
*/
public class OpenClaw extends Command {
public OpenClaw() {
requires(Robot.collector);
}
public OpenClaw() {
requires(Robot.collector);
}
// Called just before this Command runs the first time
@Override
protected void initialize() {
Robot.collector.open();
}
// Called just before this Command runs the first time
@Override
protected void initialize() {
Robot.collector.open();
}
// Make this return true when this Command no longer needs to run execute()
@Override
protected boolean isFinished() {
return Robot.collector.isOpen();
}
// Make this return true when this Command no longer needs to run execute()
@Override
protected boolean isFinished() {
return Robot.collector.isOpen();
}
}

View File

@@ -17,16 +17,16 @@ import edu.wpi.first.wpilibj.examples.pacgoat.Robot;
* the spinners may still be adjusting their speed.
*/
public class SetCollectionSpeed extends InstantCommand {
private double m_speed;
private double m_speed;
public SetCollectionSpeed(double speed) {
requires(Robot.collector);
this.m_speed = speed;
}
public SetCollectionSpeed(double speed) {
requires(Robot.collector);
this.m_speed = speed;
}
// Called just before this Command runs the first time
@Override
protected void initialize() {
Robot.collector.setSpeed(m_speed);
}
// Called just before this Command runs the first time
@Override
protected void initialize() {
Robot.collector.setSpeed(m_speed);
}
}

View File

@@ -17,23 +17,23 @@ import edu.wpi.first.wpilibj.examples.pacgoat.Robot;
* commands using the pivot should make sure they disable PID!
*/
public class SetPivotSetpoint extends Command {
private double m_setpoint;
private double m_setpoint;
public SetPivotSetpoint(double setpoint) {
this.m_setpoint = setpoint;
requires(Robot.pivot);
}
public SetPivotSetpoint(double setpoint) {
this.m_setpoint = setpoint;
requires(Robot.pivot);
}
// Called just before this Command runs the first time
@Override
protected void initialize() {
Robot.pivot.enable();
Robot.pivot.setSetpoint(m_setpoint);
}
// Called just before this Command runs the first time
@Override
protected void initialize() {
Robot.pivot.enable();
Robot.pivot.setSetpoint(m_setpoint);
}
// Make this return true when this Command no longer needs to run execute()
@Override
protected boolean isFinished() {
return Robot.pivot.onTarget();
}
// Make this return true when this Command no longer needs to run execute()
@Override
protected boolean isFinished() {
return Robot.pivot.onTarget();
}
}

View File

@@ -15,10 +15,10 @@ import edu.wpi.first.wpilibj.examples.pacgoat.subsystems.Collector;
* Shoot the ball at the current angle.
*/
public class Shoot extends CommandGroup {
public Shoot() {
addSequential(new WaitForPressure());
addSequential(new SetCollectionSpeed(Collector.kStop));
addSequential(new OpenClaw());
addSequential(new ExtendShooter());
}
public Shoot() {
addSequential(new WaitForPressure());
addSequential(new SetCollectionSpeed(Collector.kStop));
addSequential(new OpenClaw());
addSequential(new ExtendShooter());
}
}

View File

@@ -17,13 +17,13 @@ import edu.wpi.first.wpilibj.examples.pacgoat.Robot;
* condition.
*/
public class WaitForBall extends Command {
public WaitForBall() {
requires(Robot.collector);
}
public WaitForBall() {
requires(Robot.collector);
}
// Make this return true when this Command no longer needs to run execute()
@Override
protected boolean isFinished() {
return Robot.collector.hasBall();
}
// Make this return true when this Command no longer needs to run execute()
@Override
protected boolean isFinished() {
return Robot.collector.hasBall();
}
}

View File

@@ -16,13 +16,13 @@ import edu.wpi.first.wpilibj.examples.pacgoat.Robot;
* and is intended to be used in command groups to wait for this condition.
*/
public class WaitForPressure extends Command {
public WaitForPressure() {
requires(Robot.pneumatics);
}
public WaitForPressure() {
requires(Robot.pneumatics);
}
// Make this return true when this Command no longer needs to run execute()
@Override
protected boolean isFinished() {
return Robot.pneumatics.isPressurized();
}
// Make this return true when this Command no longer needs to run execute()
@Override
protected boolean isFinished() {
return Robot.pneumatics.isPressurized();
}
}

View File

@@ -19,81 +19,81 @@ import edu.wpi.first.wpilibj.command.Subsystem;
* to check if the piston is open.
*/
public class Collector extends Subsystem {
// Constants for some useful speeds
public static final double kForward = 1;
public static final double kStop = 0;
public static final double kReverse = -1;
// Constants for some useful speeds
public static final double kForward = 1;
public static final double kStop = 0;
public static final double kReverse = -1;
// Subsystem devices
private SpeedController m_rollerMotor = new Victor(6);
private DigitalInput m_ballDetector = new DigitalInput(10);
private DigitalInput m_openDetector = new DigitalInput(6);
private Solenoid m_piston = new Solenoid(1, 1);
// Subsystem devices
private SpeedController m_rollerMotor = new Victor(6);
private DigitalInput m_ballDetector = new DigitalInput(10);
private DigitalInput m_openDetector = new DigitalInput(6);
private Solenoid m_piston = new Solenoid(1, 1);
public Collector() {
// Put everything to the LiveWindow for testing.
addChild("Roller Motor", (Victor) m_rollerMotor);
addChild("Ball Detector", m_ballDetector);
addChild("Claw Open Detector", m_openDetector);
addChild("Piston", m_piston);
}
public Collector() {
// Put everything to the LiveWindow for testing.
addChild("Roller Motor", (Victor) m_rollerMotor);
addChild("Ball Detector", m_ballDetector);
addChild("Claw Open Detector", m_openDetector);
addChild("Piston", m_piston);
}
/**
* Whether or not the robot has the ball.
*
* <p>NOTE: The current simulation model uses the the lower part of the claw
* since the limit switch wasn't exported. At some point, this will be
* updated.
*
* @return Whether or not the robot has the ball.
*/
public boolean hasBall() {
return m_ballDetector.get(); // TODO: prepend ! to reflect real robot
}
/**
* Whether or not the robot has the ball.
*
* <p>NOTE: The current simulation model uses the the lower part of the claw
* since the limit switch wasn't exported. At some point, this will be
* updated.
*
* @return Whether or not the robot has the ball.
*/
public boolean hasBall() {
return m_ballDetector.get(); // TODO: prepend ! to reflect real robot
}
/**
* Set the speed to spin the collector rollers.
*
* @param speed The speed to spin the rollers.
*/
public void setSpeed(double speed) {
m_rollerMotor.set(-speed);
}
/**
* Set the speed to spin the collector rollers.
*
* @param speed The speed to spin the rollers.
*/
public void setSpeed(double speed) {
m_rollerMotor.set(-speed);
}
/**
* Stop the rollers from spinning.
*/
public void stop() {
m_rollerMotor.set(0);
}
/**
* Stop the rollers from spinning.
*/
public void stop() {
m_rollerMotor.set(0);
}
/**
* Wether or not the claw is open.
*
* @return Whether or not the claw is open.
*/
public boolean isOpen() {
return m_openDetector.get(); // TODO: prepend ! to reflect real robot
}
/**
* Wether or not the claw is open.
*
* @return Whether or not the claw is open.
*/
public boolean isOpen() {
return m_openDetector.get(); // TODO: prepend ! to reflect real robot
}
/**
* Open the claw up (For shooting).
*/
public void open() {
m_piston.set(true);
}
/**
* Open the claw up (For shooting).
*/
public void open() {
m_piston.set(true);
}
/**
* Close the claw (For collecting and driving).
*/
public void close() {
m_piston.set(false);
}
/**
* Close the claw (For collecting and driving).
*/
public void close() {
m_piston.set(false);
}
/**
* No default command.
*/
@Override
protected void initDefaultCommand() {
}
/**
* No default command.
*/
@Override
protected void initDefaultCommand() {
}
}

View File

@@ -26,115 +26,115 @@ import edu.wpi.first.wpilibj.examples.pacgoat.commands.DriveWithJoystick;
* information about it's speed and position.
*/
public class DriveTrain extends Subsystem {
// Subsystem devices
private SpeedController m_frontLeftCIM = new Victor(1);
private SpeedController m_frontRightCIM = new Victor(2);
private SpeedController m_rearLeftCIM = new Victor(3);
private SpeedController m_rearRightCIM = new Victor(4);
private SpeedControllerGroup m_leftCIMs = new SpeedControllerGroup(
m_frontLeftCIM, m_rearLeftCIM);
private SpeedControllerGroup m_rightCIMs = new SpeedControllerGroup(
m_frontRightCIM, m_rearRightCIM);
private DifferentialDrive m_drive;
private Encoder m_rightEncoder = new Encoder(1, 2, true, EncodingType.k4X);
private Encoder m_leftEncoder = new Encoder(3, 4, false, EncodingType.k4X);
private AnalogGyro m_gyro = new AnalogGyro(2);
// Subsystem devices
private SpeedController m_frontLeftCIM = new Victor(1);
private SpeedController m_frontRightCIM = new Victor(2);
private SpeedController m_rearLeftCIM = new Victor(3);
private SpeedController m_rearRightCIM = new Victor(4);
private SpeedControllerGroup m_leftCIMs = new SpeedControllerGroup(
m_frontLeftCIM, m_rearLeftCIM);
private SpeedControllerGroup m_rightCIMs = new SpeedControllerGroup(
m_frontRightCIM, m_rearRightCIM);
private DifferentialDrive m_drive;
private Encoder m_rightEncoder = new Encoder(1, 2, true, EncodingType.k4X);
private Encoder m_leftEncoder = new Encoder(3, 4, false, EncodingType.k4X);
private AnalogGyro m_gyro = new AnalogGyro(2);
public DriveTrain() {
// Configure drive motors
addChild("Front Left CIM", (Victor) m_frontLeftCIM);
addChild("Front Right CIM", (Victor) m_frontRightCIM);
addChild("Back Left CIM", (Victor) m_rearLeftCIM);
addChild("Back Right CIM", (Victor) m_rearRightCIM);
public DriveTrain() {
// Configure drive motors
addChild("Front Left CIM", (Victor) m_frontLeftCIM);
addChild("Front Right CIM", (Victor) m_frontRightCIM);
addChild("Back Left CIM", (Victor) m_rearLeftCIM);
addChild("Back Right CIM", (Victor) m_rearRightCIM);
// Configure the DifferentialDrive to reflect the fact that all motors
// are wired backwards (right is inverted in DifferentialDrive).
m_leftCIMs.setInverted(true);
m_drive = new DifferentialDrive(m_leftCIMs, m_rightCIMs);
m_drive.setSafetyEnabled(true);
m_drive.setExpiration(0.1);
m_drive.setMaxOutput(1.0);
// Configure the DifferentialDrive to reflect the fact that all motors
// are wired backwards (right is inverted in DifferentialDrive).
m_leftCIMs.setInverted(true);
m_drive = new DifferentialDrive(m_leftCIMs, m_rightCIMs);
m_drive.setSafetyEnabled(true);
m_drive.setExpiration(0.1);
m_drive.setMaxOutput(1.0);
// Configure encoders
m_rightEncoder.setPIDSourceType(PIDSourceType.kDisplacement);
m_leftEncoder.setPIDSourceType(PIDSourceType.kDisplacement);
// Configure encoders
m_rightEncoder.setPIDSourceType(PIDSourceType.kDisplacement);
m_leftEncoder.setPIDSourceType(PIDSourceType.kDisplacement);
if (Robot.isReal()) { // Converts to feet
m_rightEncoder.setDistancePerPulse(0.0785398);
m_leftEncoder.setDistancePerPulse(0.0785398);
} else {
// Convert to feet 4in diameter wheels with 360 tick sim encoders
m_rightEncoder.setDistancePerPulse(
(4.0/* in */ * Math.PI) / (360.0 * 12.0/* in/ft */));
m_leftEncoder.setDistancePerPulse(
(4.0/* in */ * Math.PI) / (360.0 * 12.0/* in/ft */));
}
if (Robot.isReal()) { // Converts to feet
m_rightEncoder.setDistancePerPulse(0.0785398);
m_leftEncoder.setDistancePerPulse(0.0785398);
} else {
// Convert to feet 4in diameter wheels with 360 tick sim encoders
m_rightEncoder.setDistancePerPulse(
(4.0/* in */ * Math.PI) / (360.0 * 12.0/* in/ft */));
m_leftEncoder.setDistancePerPulse(
(4.0/* in */ * Math.PI) / (360.0 * 12.0/* in/ft */));
}
addChild("Right Encoder", m_rightEncoder);
addChild("Left Encoder", m_leftEncoder);
addChild("Right Encoder", m_rightEncoder);
addChild("Left Encoder", m_leftEncoder);
// Configure gyro
if (Robot.isReal()) {
m_gyro.setSensitivity(0.007); // TODO: Handle more gracefully?
}
addChild("Gyro", m_gyro);
}
// Configure gyro
if (Robot.isReal()) {
m_gyro.setSensitivity(0.007); // TODO: Handle more gracefully?
}
addChild("Gyro", m_gyro);
}
/**
* When other commands aren't using the drivetrain, allow tank drive with
* the joystick.
*/
@Override
public void initDefaultCommand() {
setDefaultCommand(new DriveWithJoystick());
}
/**
* When other commands aren't using the drivetrain, allow tank drive with
* the joystick.
*/
@Override
public void initDefaultCommand() {
setDefaultCommand(new DriveWithJoystick());
}
/**
* Tank drive using a PS3 joystick.
*
* @param joy PS3 style joystick to use as the input for tank drive.
*/
public void tankDrive(Joystick joy) {
m_drive.tankDrive(joy.getY(), joy.getRawAxis(4));
}
/**
* Tank drive using a PS3 joystick.
*
* @param joy PS3 style joystick to use as the input for tank drive.
*/
public void tankDrive(Joystick joy) {
m_drive.tankDrive(joy.getY(), joy.getRawAxis(4));
}
/**
* Tank drive using individual joystick axes.
*
* @param leftAxis Left sides value
* @param rightAxis Right sides value
*/
public void tankDrive(double leftAxis, double rightAxis) {
m_drive.tankDrive(leftAxis, rightAxis);
}
/**
* Tank drive using individual joystick axes.
*
* @param leftAxis Left sides value
* @param rightAxis Right sides value
*/
public void tankDrive(double leftAxis, double rightAxis) {
m_drive.tankDrive(leftAxis, rightAxis);
}
/**
* Stop the drivetrain from moving.
*/
public void stop() {
m_drive.tankDrive(0, 0);
}
/**
* Stop the drivetrain from moving.
*/
public void stop() {
m_drive.tankDrive(0, 0);
}
/**
* The encoder getting the distance and speed of left side of the
* drivetrain.
*/
public Encoder getLeftEncoder() {
return m_leftEncoder;
}
/**
* The encoder getting the distance and speed of left side of the
* drivetrain.
*/
public Encoder getLeftEncoder() {
return m_leftEncoder;
}
/**
* The encoder getting the distance and speed of right side of the
* drivetrain.
*/
public Encoder getRightEncoder() {
return m_rightEncoder;
}
/**
* The encoder getting the distance and speed of right side of the
* drivetrain.
*/
public Encoder getRightEncoder() {
return m_rightEncoder;
}
/**
* The current angle of the drivetrain as measured by the Gyro.
*/
public double getAngle() {
return m_gyro.getAngle();
}
/**
* The current angle of the drivetrain as measured by the Gyro.
*/
public double getAngle() {
return m_gyro.getAngle();
}
}

View File

@@ -21,84 +21,84 @@ import edu.wpi.first.wpilibj.examples.pacgoat.Robot;
* of angle of the pivot and claw.
*/
public class Pivot extends PIDSubsystem {
// Constants for some useful angles
public static final double kCollect = 105;
public static final double kLowGoal = 90;
public static final double kShoot = 45;
public static final double kShootNear = 30;
// Constants for some useful angles
public static final double kCollect = 105;
public static final double kLowGoal = 90;
public static final double kShoot = 45;
public static final double kShootNear = 30;
// Sensors for measuring the position of the pivot.
private DigitalInput m_upperLimitSwitch = new DigitalInput(13);
private DigitalInput m_lowerLimitSwitch = new DigitalInput(12);
// Sensors for measuring the position of the pivot.
private DigitalInput m_upperLimitSwitch = new DigitalInput(13);
private DigitalInput m_lowerLimitSwitch = new DigitalInput(12);
// 0 degrees is vertical facing up.
// Angle increases the more forward the pivot goes.
private Potentiometer m_pot = new AnalogPotentiometer(1);
// 0 degrees is vertical facing up.
// Angle increases the more forward the pivot goes.
private Potentiometer m_pot = new AnalogPotentiometer(1);
// Motor to move the pivot.
private SpeedController m_motor = new Victor(5);
// Motor to move the pivot.
private SpeedController m_motor = new Victor(5);
public Pivot() {
super("Pivot", 7.0, 0.0, 8.0);
setAbsoluteTolerance(0.005);
getPIDController().setContinuous(false);
if (Robot.isSimulation()) { // PID is different in simulation.
getPIDController().setPID(0.5, 0.001, 2);
setAbsoluteTolerance(5);
}
public Pivot() {
super("Pivot", 7.0, 0.0, 8.0);
setAbsoluteTolerance(0.005);
getPIDController().setContinuous(false);
if (Robot.isSimulation()) { // PID is different in simulation.
getPIDController().setPID(0.5, 0.001, 2);
setAbsoluteTolerance(5);
}
// Put everything to the LiveWindow for testing.
addChild("Upper Limit Switch", m_upperLimitSwitch);
addChild("Lower Limit Switch", m_lowerLimitSwitch);
addChild("Pot", (AnalogPotentiometer) m_pot);
addChild("Motor", (Victor) m_motor);
addChild("PIDSubsystem Controller", getPIDController());
}
// Put everything to the LiveWindow for testing.
addChild("Upper Limit Switch", m_upperLimitSwitch);
addChild("Lower Limit Switch", m_lowerLimitSwitch);
addChild("Pot", (AnalogPotentiometer) m_pot);
addChild("Motor", (Victor) m_motor);
addChild("PIDSubsystem Controller", getPIDController());
}
/**
* No default command, if PID is enabled, the current setpoint will be
* maintained.
*/
@Override
public void initDefaultCommand() {
}
/**
* No default command, if PID is enabled, the current setpoint will be
* maintained.
*/
@Override
public void initDefaultCommand() {
}
/**
* The angle read in by the potentiometer.
*/
@Override
protected double returnPIDInput() {
return m_pot.get();
}
/**
* The angle read in by the potentiometer.
*/
@Override
protected double returnPIDInput() {
return m_pot.get();
}
/**
* Set the motor speed based off of the PID output.
*/
@Override
protected void usePIDOutput(double output) {
m_motor.pidWrite(output);
}
/**
* Set the motor speed based off of the PID output.
*/
@Override
protected void usePIDOutput(double output) {
m_motor.pidWrite(output);
}
/**
* If the pivot is at its upper limit.
*/
public boolean isAtUpperLimit() {
// TODO: inverted from real robot (prefix with !)
return m_upperLimitSwitch.get();
}
/**
* If the pivot is at its upper limit.
*/
public boolean isAtUpperLimit() {
// TODO: inverted from real robot (prefix with !)
return m_upperLimitSwitch.get();
}
/**
* If the pivot is at its lower limit.
*/
public boolean isAtLowerLimit() {
// TODO: inverted from real robot (prefix with !)
return m_lowerLimitSwitch.get();
}
/**
* If the pivot is at its lower limit.
*/
public boolean isAtLowerLimit() {
// TODO: inverted from real robot (prefix with !)
return m_lowerLimitSwitch.get();
}
/**
* The current angle of the pivot.
*/
public double getAngle() {
return m_pot.get();
}
/**
* The current angle of the pivot.
*/
public double getAngle() {
return m_pot.get();
}
}

View File

@@ -20,36 +20,36 @@ import edu.wpi.first.wpilibj.examples.pacgoat.Robot;
* sensors.
*/
public class Pneumatics extends Subsystem {
AnalogInput m_pressureSensor = new AnalogInput(3);
AnalogInput m_pressureSensor = new AnalogInput(3);
private static final double kMaxPressure = 2.55;
private static final double kMaxPressure = 2.55;
public Pneumatics() {
addChild("Pressure Sensor", m_pressureSensor);
}
public Pneumatics() {
addChild("Pressure Sensor", m_pressureSensor);
}
/**
* No default command.
*/
@Override
public void initDefaultCommand() {
}
/**
* No default command.
*/
@Override
public void initDefaultCommand() {
}
/**
* Whether or not the system is fully pressurized.
*/
public boolean isPressurized() {
if (Robot.isReal()) {
return kMaxPressure <= m_pressureSensor.getVoltage();
} else {
return true; // NOTE: Simulation always has full pressure
}
}
/**
* Whether or not the system is fully pressurized.
*/
public boolean isPressurized() {
if (Robot.isReal()) {
return kMaxPressure <= m_pressureSensor.getVoltage();
} else {
return true; // NOTE: Simulation always has full pressure
}
}
/**
* Puts the pressure on the SmartDashboard.
*/
public void writePressure() {
SmartDashboard.putNumber("Pressure", m_pressureSensor.getVoltage());
}
/**
* Puts the pressure on the SmartDashboard.
*/
public void writePressure() {
SmartDashboard.putNumber("Pressure", m_pressureSensor.getVoltage());
}
}

View File

@@ -23,151 +23,151 @@ import edu.wpi.first.wpilibj.command.Subsystem;
* cylinder and ignores the latch.
*/
public class Shooter extends Subsystem {
// Devices
DoubleSolenoid m_piston1 = new DoubleSolenoid(1, 3, 4);
DoubleSolenoid m_piston2 = new DoubleSolenoid(1, 5, 6);
Solenoid m_latchPiston = new Solenoid(1, 2);
DigitalInput m_piston1ReedSwitchFront = new DigitalInput(9);
DigitalInput m_piston1ReedSwitchBack = new DigitalInput(11);
//NOTE: currently ignored in simulation
DigitalInput m_hotGoalSensor = new DigitalInput(3);
// Devices
DoubleSolenoid m_piston1 = new DoubleSolenoid(1, 3, 4);
DoubleSolenoid m_piston2 = new DoubleSolenoid(1, 5, 6);
Solenoid m_latchPiston = new Solenoid(1, 2);
DigitalInput m_piston1ReedSwitchFront = new DigitalInput(9);
DigitalInput m_piston1ReedSwitchBack = new DigitalInput(11);
//NOTE: currently ignored in simulation
DigitalInput m_hotGoalSensor = new DigitalInput(3);
public Shooter() {
// Put everything to the LiveWindow for testing.
addChild("Hot Goal Sensor", m_hotGoalSensor);
addChild("Piston1 Reed Switch Front ", m_piston1ReedSwitchFront);
addChild("Piston1 Reed Switch Back ", m_piston1ReedSwitchBack);
addChild("Latch Piston", m_latchPiston);
}
public Shooter() {
// Put everything to the LiveWindow for testing.
addChild("Hot Goal Sensor", m_hotGoalSensor);
addChild("Piston1 Reed Switch Front ", m_piston1ReedSwitchFront);
addChild("Piston1 Reed Switch Back ", m_piston1ReedSwitchBack);
addChild("Latch Piston", m_latchPiston);
}
/**
* No default command.
*/
@Override
public void initDefaultCommand() {
}
/**
* No default command.
*/
@Override
public void initDefaultCommand() {
}
/**
* Extend both solenoids to shoot.
*/
public void extendBoth() {
m_piston1.set(DoubleSolenoid.Value.kForward);
m_piston2.set(DoubleSolenoid.Value.kForward);
}
/**
* Extend both solenoids to shoot.
*/
public void extendBoth() {
m_piston1.set(DoubleSolenoid.Value.kForward);
m_piston2.set(DoubleSolenoid.Value.kForward);
}
/**
* Retract both solenoids to prepare to shoot.
*/
public void retractBoth() {
m_piston1.set(DoubleSolenoid.Value.kReverse);
m_piston2.set(DoubleSolenoid.Value.kReverse);
}
/**
* Retract both solenoids to prepare to shoot.
*/
public void retractBoth() {
m_piston1.set(DoubleSolenoid.Value.kReverse);
m_piston2.set(DoubleSolenoid.Value.kReverse);
}
/**
* Extend solenoid 1 to shoot.
*/
public void extend1() {
m_piston1.set(DoubleSolenoid.Value.kForward);
}
/**
* Extend solenoid 1 to shoot.
*/
public void extend1() {
m_piston1.set(DoubleSolenoid.Value.kForward);
}
/**
* Retract solenoid 1 to prepare to shoot.
*/
public void retract1() {
m_piston1.set(DoubleSolenoid.Value.kReverse);
}
/**
* Retract solenoid 1 to prepare to shoot.
*/
public void retract1() {
m_piston1.set(DoubleSolenoid.Value.kReverse);
}
/**
* Extend solenoid 2 to shoot.
*/
public void extend2() {
m_piston2.set(DoubleSolenoid.Value.kReverse);
}
/**
* Extend solenoid 2 to shoot.
*/
public void extend2() {
m_piston2.set(DoubleSolenoid.Value.kReverse);
}
/**
* Retract solenoid 2 to prepare to shoot.
*/
public void retract2() {
m_piston2.set(DoubleSolenoid.Value.kForward);
}
/**
* Retract solenoid 2 to prepare to shoot.
*/
public void retract2() {
m_piston2.set(DoubleSolenoid.Value.kForward);
}
/**
* Turns off the piston1 double solenoid. This won't actuate anything
* because double solenoids preserve their state when turned off. This
* should be called in order to reduce the amount of time that the coils
* are powered.
*/
public void off1() {
m_piston1.set(DoubleSolenoid.Value.kOff);
}
/**
* Turns off the piston1 double solenoid. This won't actuate anything
* because double solenoids preserve their state when turned off. This
* should be called in order to reduce the amount of time that the coils
* are powered.
*/
public void off1() {
m_piston1.set(DoubleSolenoid.Value.kOff);
}
/**
* Turns off the piston2 double solenoid. This won't actuate anything
* because double solenoids preserve their state when turned off. This
* should be called in order to reduce the amount of time that the coils
* are powered.
*/
public void off2() {
m_piston2.set(DoubleSolenoid.Value.kOff);
}
/**
* Turns off the piston2 double solenoid. This won't actuate anything
* because double solenoids preserve their state when turned off. This
* should be called in order to reduce the amount of time that the coils
* are powered.
*/
public void off2() {
m_piston2.set(DoubleSolenoid.Value.kOff);
}
/**
* Release the latch so that we can shoot.
*/
public void unlatch() {
m_latchPiston.set(true);
}
/**
* Release the latch so that we can shoot.
*/
public void unlatch() {
m_latchPiston.set(true);
}
/**
* Latch so that pressure can build up and we aren't limited by air flow.
*/
public void latch() {
m_latchPiston.set(false);
}
/**
* Latch so that pressure can build up and we aren't limited by air flow.
*/
public void latch() {
m_latchPiston.set(false);
}
/**
* Toggles the latch postions.
*/
public void toggleLatchPosition() {
m_latchPiston.set(!m_latchPiston.get());
}
/**
* Toggles the latch postions.
*/
public void toggleLatchPosition() {
m_latchPiston.set(!m_latchPiston.get());
}
/**
* Is Piston 1 extended (after shooting).
*
* @return Whether or not piston 1 is fully extended.
*/
public boolean piston1IsExtended() {
return !m_piston1ReedSwitchFront.get();
}
/**
* Is Piston 1 extended (after shooting).
*
* @return Whether or not piston 1 is fully extended.
*/
public boolean piston1IsExtended() {
return !m_piston1ReedSwitchFront.get();
}
/**
* Is Piston 1 retracted (before shooting).
*
* @return Whether or not piston 1 is fully retracted.
*/
public boolean piston1IsRetracted() {
return !m_piston1ReedSwitchBack.get();
}
/**
* Is Piston 1 retracted (before shooting).
*
* @return Whether or not piston 1 is fully retracted.
*/
public boolean piston1IsRetracted() {
return !m_piston1ReedSwitchBack.get();
}
/**
* Turns off all double solenoids. Double solenoids hold their position when
* they are turned off. We should turn them off whenever possible to extend
* the life of the coils.
*/
public void offBoth() {
m_piston1.set(DoubleSolenoid.Value.kOff);
m_piston2.set(DoubleSolenoid.Value.kOff);
}
/**
* Turns off all double solenoids. Double solenoids hold their position when
* they are turned off. We should turn them off whenever possible to extend
* the life of the coils.
*/
public void offBoth() {
m_piston1.set(DoubleSolenoid.Value.kOff);
m_piston2.set(DoubleSolenoid.Value.kOff);
}
/**
* Return whether the goal is hot as read by the banner sensor.
*
* <p>NOTE: doesn't work in simulation.
*
* @return Whether or not the goal is hot
*/
public boolean goalIsHot() {
return m_hotGoalSensor.get();
}
/**
* Return whether the goal is hot as read by the banner sensor.
*
* <p>NOTE: doesn't work in simulation.
*
* @return Whether or not the goal is hot
*/
public boolean goalIsHot() {
return m_hotGoalSensor.get();
}
}

View File

@@ -15,18 +15,18 @@ import edu.wpi.first.wpilibj.buttons.Trigger;
* simultaneously pressed.
*/
public class DoubleButton extends Trigger {
private Joystick m_joy;
private int m_button1;
private int m_button2;
private Joystick m_joy;
private int m_button1;
private int m_button2;
public DoubleButton(Joystick joy, int button1, int button2) {
this.m_joy = joy;
this.m_button1 = button1;
this.m_button2 = button2;
}
public DoubleButton(Joystick joy, int button1, int button2) {
this.m_joy = joy;
this.m_button1 = button1;
this.m_button2 = button2;
}
@Override
public boolean get() {
return m_joy.getRawButton(m_button1) && m_joy.getRawButton(m_button2);
}
@Override
public boolean get() {
return m_joy.getRawButton(m_button1) && m_joy.getRawButton(m_button2);
}
}

View File

@@ -20,56 +20,56 @@ import edu.wpi.first.wpilibj.Joystick;
* mechanism.
*/
public class Robot extends IterativeRobot {
private static final int kPotChannel = 1;
private static final int kMotorChannel = 7;
private static final int kJoystickChannel = 0;
private static final int kPotChannel = 1;
private static final int kMotorChannel = 7;
private static final int kJoystickChannel = 0;
// bottom, middle, and top elevator setpoints
private static final double[] kSetPoints = {1.0, 2.6, 4.3};
// bottom, middle, and top elevator setpoints
private static final double[] kSetPoints = {1.0, 2.6, 4.3};
// proportional, integral, and derivative speed constants; motor inverted
// DANGER: when tuning PID constants, high/inappropriate values for kP, kI,
// and kD may cause dangerous, uncontrollable, or undesired behavior!
// these may need to be positive for a non-inverted motor
private static final double kP = -5.0;
private static final double kI = -0.02;
private static final double kD = -2.0;
// proportional, integral, and derivative speed constants; motor inverted
// DANGER: when tuning PID constants, high/inappropriate values for kP, kI,
// and kD may cause dangerous, uncontrollable, or undesired behavior!
// these may need to be positive for a non-inverted motor
private static final double kP = -5.0;
private static final double kI = -0.02;
private static final double kD = -2.0;
private PIDController m_pidController;
private AnalogInput m_potentiometer;
private SpeedController m_elevatorMotor;
private Joystick m_joystick;
private PIDController m_pidController;
private AnalogInput m_potentiometer;
private SpeedController m_elevatorMotor;
private Joystick m_joystick;
private int m_index = 0;
private boolean m_previousButtonValue = false;
private int m_index = 0;
private boolean m_previousButtonValue = false;
@Override
public void robotInit() {
m_potentiometer = new AnalogInput(kPotChannel);
m_elevatorMotor = new Spark(kMotorChannel);
m_joystick = new Joystick(kJoystickChannel);
@Override
public void robotInit() {
m_potentiometer = new AnalogInput(kPotChannel);
m_elevatorMotor = new Spark(kMotorChannel);
m_joystick = new Joystick(kJoystickChannel);
m_pidController
= new PIDController(kP, kI, kD, m_potentiometer, m_elevatorMotor);
m_pidController.setInputRange(0, 5);
}
m_pidController
= new PIDController(kP, kI, kD, m_potentiometer, m_elevatorMotor);
m_pidController.setInputRange(0, 5);
}
@Override
public void teleopInit() {
m_pidController.enable();
}
@Override
public void teleopInit() {
m_pidController.enable();
}
@Override
public void teleopPeriodic() {
// when the button is pressed once, the selected elevator setpoint
// is incremented
boolean currentButtonValue = m_joystick.getTrigger();
if (currentButtonValue && !m_previousButtonValue) {
// index of the elevator setpoint wraps around.
m_index = (m_index + 1) % kSetPoints.length;
}
m_previousButtonValue = currentButtonValue;
@Override
public void teleopPeriodic() {
// when the button is pressed once, the selected elevator setpoint
// is incremented
boolean currentButtonValue = m_joystick.getTrigger();
if (currentButtonValue && !m_previousButtonValue) {
// index of the elevator setpoint wraps around.
m_index = (m_index + 1) % kSetPoints.length;
}
m_previousButtonValue = currentButtonValue;
m_pidController.setSetpoint(kSetPoints[m_index]);
}
m_pidController.setSetpoint(kSetPoints[m_index]);
}
}

View File

@@ -17,9 +17,9 @@ import edu.wpi.first.wpilibj.IterativeRobot;
* the robotInit() method in your program.
*/
public class Robot extends IterativeRobot {
@Override
public void robotInit() {
CameraServer.getInstance().startAutomaticCapture();
}
@Override
public void robotInit() {
CameraServer.getInstance().startAutomaticCapture();
}
}

View File

@@ -17,19 +17,19 @@ import edu.wpi.first.wpilibj.drive.DifferentialDrive;
* it contains the code necessary to operate a robot with tank drive.
*/
public class Robot extends IterativeRobot {
private DifferentialDrive m_myRobot;
private Joystick m_leftStick;
private Joystick m_rightStick;
private DifferentialDrive m_myRobot;
private Joystick m_leftStick;
private Joystick m_rightStick;
@Override
public void robotInit() {
m_myRobot = new DifferentialDrive(new Spark(0), new Spark(1));
m_leftStick = new Joystick(0);
m_rightStick = new Joystick(1);
}
@Override
public void robotInit() {
m_myRobot = new DifferentialDrive(new Spark(0), new Spark(1));
m_leftStick = new Joystick(0);
m_rightStick = new Joystick(1);
}
@Override
public void teleopPeriodic() {
m_myRobot.tankDrive(m_leftStick.getY(), m_rightStick.getY());
}
@Override
public void teleopPeriodic() {
m_myRobot.tankDrive(m_leftStick.getY(), m_rightStick.getY());
}
}

View File

@@ -18,36 +18,36 @@ import edu.wpi.first.wpilibj.drive.DifferentialDrive;
*/
public class Robot extends IterativeRobot {
// distance in inches the robot wants to stay from an object
private static final double kHoldDistance = 12.0;
// distance in inches the robot wants to stay from an object
private static final double kHoldDistance = 12.0;
// factor to convert sensor values to a distance in inches
private static final double kValueToInches = 0.125;
// factor to convert sensor values to a distance in inches
private static final double kValueToInches = 0.125;
// proportional speed constant
private static final double kP = 0.05;
// proportional speed constant
private static final double kP = 0.05;
private static final int kLeftMotorPort = 0;
private static final int kRightMotorPort = 1;
private static final int kUltrasonicPort = 0;
private static final int kLeftMotorPort = 0;
private static final int kRightMotorPort = 1;
private static final int kUltrasonicPort = 0;
private AnalogInput m_ultrasonic = new AnalogInput(kUltrasonicPort);
private DifferentialDrive m_robotDrive
= new DifferentialDrive(new Spark(kLeftMotorPort),
new Spark(kRightMotorPort));
private AnalogInput m_ultrasonic = new AnalogInput(kUltrasonicPort);
private DifferentialDrive m_robotDrive
= new DifferentialDrive(new Spark(kLeftMotorPort),
new Spark(kRightMotorPort));
/**
* Tells the robot to drive to a set distance (in inches) from an object
* using proportional control.
*/
public void teleopPeriodic() {
// sensor returns a value from 0-4095 that is scaled to inches
double currentDistance = m_ultrasonic.getValue() * kValueToInches;
/**
* Tells the robot to drive to a set distance (in inches) from an object
* using proportional control.
*/
public void teleopPeriodic() {
// sensor returns a value from 0-4095 that is scaled to inches
double currentDistance = m_ultrasonic.getValue() * kValueToInches;
// convert distance error to a motor speed
double currentSpeed = (kHoldDistance - currentDistance) * kP;
// convert distance error to a motor speed
double currentSpeed = (kHoldDistance - currentDistance) * kP;
// drive robot
m_robotDrive.arcadeDrive(currentSpeed, 0);
}
// drive robot
m_robotDrive.arcadeDrive(currentSpeed, 0);
}
}

View File

@@ -19,53 +19,53 @@ import edu.wpi.first.wpilibj.drive.DifferentialDrive;
* ultrasonic sensor to reach and maintain a set distance from an object.
*/
public class Robot extends IterativeRobot {
// distance in inches the robot wants to stay from an object
private static final double kHoldDistance = 12.0;
// distance in inches the robot wants to stay from an object
private static final double kHoldDistance = 12.0;
// maximum distance in inches we expect the robot to see
private static final double kMaxDistance = 24.0;
// maximum distance in inches we expect the robot to see
private static final double kMaxDistance = 24.0;
// factor to convert sensor values to a distance in inches
private static final double kValueToInches = 0.125;
// factor to convert sensor values to a distance in inches
private static final double kValueToInches = 0.125;
// proportional speed constant
private static final double kP = 7.0;
// proportional speed constant
private static final double kP = 7.0;
// integral speed constant
private static final double kI = 0.018;
// integral speed constant
private static final double kI = 0.018;
// derivative speed constant
private static final double kD = 1.5;
// derivative speed constant
private static final double kD = 1.5;
private static final int kLeftMotorPort = 0;
private static final int kRightMotorPort = 1;
private static final int kUltrasonicPort = 0;
private static final int kLeftMotorPort = 0;
private static final int kRightMotorPort = 1;
private static final int kUltrasonicPort = 0;
private AnalogInput m_ultrasonic = new AnalogInput(kUltrasonicPort);
private DifferentialDrive m_robotDrive
= new DifferentialDrive(new Spark(kLeftMotorPort),
new Spark(kRightMotorPort));
private PIDController m_pidController
= new PIDController(kP, kI, kD, m_ultrasonic, new MyPidOutput());
private AnalogInput m_ultrasonic = new AnalogInput(kUltrasonicPort);
private DifferentialDrive m_robotDrive
= new DifferentialDrive(new Spark(kLeftMotorPort),
new Spark(kRightMotorPort));
private PIDController m_pidController
= new PIDController(kP, kI, kD, m_ultrasonic, new MyPidOutput());
/**
* Drives the robot a set distance from an object using PID control and the
* ultrasonic sensor.
*/
@Override
public void teleopInit() {
// Set expected range to 0-24 inches; e.g. at 24 inches from object go
// full forward, at 0 inches from object go full backward.
m_pidController.setInputRange(0, kMaxDistance * kValueToInches);
// Set setpoint of the pid controller
m_pidController.setSetpoint(kHoldDistance * kValueToInches);
m_pidController.enable(); // begin PID control
}
/**
* Drives the robot a set distance from an object using PID control and the
* ultrasonic sensor.
*/
@Override
public void teleopInit() {
// Set expected range to 0-24 inches; e.g. at 24 inches from object go
// full forward, at 0 inches from object go full backward.
m_pidController.setInputRange(0, kMaxDistance * kValueToInches);
// Set setpoint of the pid controller
m_pidController.setSetpoint(kHoldDistance * kValueToInches);
m_pidController.enable(); // begin PID control
}
private class MyPidOutput implements PIDOutput {
@Override
public void pidWrite(double output) {
m_robotDrive.arcadeDrive(output, 0);
}
}
private class MyPidOutput implements PIDOutput {
@Override
public void pidWrite(double output) {
m_robotDrive.arcadeDrive(output, 0);
}
}
}

View File

@@ -12,31 +12,31 @@ package edu.wpi.first.wpilibj.templates.commandbased;
* interface to the commands and command groups that allow control of the robot.
*/
public class OI {
//// CREATING BUTTONS
// One type of button is a joystick button which is any button on a
//// joystick.
// You create one by telling it which joystick it's on and which button
// number it is.
// Joystick stick = new Joystick(port);
// Button button = new JoystickButton(stick, buttonNumber);
//// CREATING BUTTONS
// One type of button is a joystick button which is any button on a
//// joystick.
// You create one by telling it which joystick it's on and which button
// number it is.
// Joystick stick = new Joystick(port);
// Button button = new JoystickButton(stick, buttonNumber);
// There are a few additional built in buttons you can use. Additionally,
// by subclassing Button you can create custom triggers and bind those to
// commands the same as any other Button.
// There are a few additional built in buttons you can use. Additionally,
// by subclassing Button you can create custom triggers and bind those to
// commands the same as any other Button.
//// TRIGGERING COMMANDS WITH BUTTONS
// Once you have a button, it's trivial to bind it to a button in one of
// three ways:
//// TRIGGERING COMMANDS WITH BUTTONS
// Once you have a button, it's trivial to bind it to a button in one of
// three ways:
// Start the command when the button is pressed and let it run the command
// until it is finished as determined by it's isFinished method.
// button.whenPressed(new ExampleCommand());
// Start the command when the button is pressed and let it run the command
// until it is finished as determined by it's isFinished method.
// button.whenPressed(new ExampleCommand());
// Run the command while the button is being held down and interrupt it once
// the button is released.
// button.whileHeld(new ExampleCommand());
// Run the command while the button is being held down and interrupt it once
// the button is released.
// button.whileHeld(new ExampleCommand());
// Start the command when the button is released and let it run the command
// until it is finished as determined by it's isFinished method.
// button.whenReleased(new ExampleCommand());
// Start the command when the button is released and let it run the command
// until it is finished as determined by it's isFinished method.
// button.whenReleased(new ExampleCommand());
}

View File

@@ -23,98 +23,98 @@ import edu.wpi.first.wpilibj.templates.commandbased.subsystems.ExampleSubsystem;
* project.
*/
public class Robot extends TimedRobot {
public static ExampleSubsystem m_subsystem = new ExampleSubsystem();
public static OI m_oi;
public static ExampleSubsystem m_subsystem = new ExampleSubsystem();
public static OI m_oi;
Command m_autonomousCommand;
SendableChooser<Command> m_chooser = new SendableChooser<>();
Command m_autonomousCommand;
SendableChooser<Command> m_chooser = new SendableChooser<>();
/**
* This function is run when the robot is first started up and should be
* used for any initialization code.
*/
@Override
public void robotInit() {
m_oi = new OI();
m_chooser.addDefault("Default Auto", new ExampleCommand());
// chooser.addObject("My Auto", new MyAutoCommand());
SmartDashboard.putData("Auto mode", m_chooser);
}
/**
* This function is run when the robot is first started up and should be
* used for any initialization code.
*/
@Override
public void robotInit() {
m_oi = new OI();
m_chooser.addDefault("Default Auto", new ExampleCommand());
// chooser.addObject("My Auto", new MyAutoCommand());
SmartDashboard.putData("Auto mode", m_chooser);
}
/**
* This function is called once each time the robot enters Disabled mode.
* You can use it to reset any subsystem information you want to clear when
* the robot is disabled.
*/
@Override
public void disabledInit() {
/**
* This function is called once each time the robot enters Disabled mode.
* You can use it to reset any subsystem information you want to clear when
* the robot is disabled.
*/
@Override
public void disabledInit() {
}
}
@Override
public void disabledPeriodic() {
Scheduler.getInstance().run();
}
@Override
public void disabledPeriodic() {
Scheduler.getInstance().run();
}
/**
* This autonomous (along with the chooser code above) shows how to select
* between different autonomous modes using the dashboard. The sendable
* chooser code works with the Java SmartDashboard. If you prefer the
* LabVIEW Dashboard, remove all of the chooser code and uncomment the
* getString code to get the auto name from the text box below the Gyro
*
* <p>You can add additional auto modes by adding additional commands to the
* chooser code above (like the commented example) or additional comparisons
* to the switch structure below with additional strings & commands.
*/
@Override
public void autonomousInit() {
m_autonomousCommand = m_chooser.getSelected();
/**
* This autonomous (along with the chooser code above) shows how to select
* between different autonomous modes using the dashboard. The sendable
* chooser code works with the Java SmartDashboard. If you prefer the
* LabVIEW Dashboard, remove all of the chooser code and uncomment the
* getString code to get the auto name from the text box below the Gyro
*
* <p>You can add additional auto modes by adding additional commands to the
* chooser code above (like the commented example) or additional comparisons
* to the switch structure below with additional strings & commands.
*/
@Override
public void autonomousInit() {
m_autonomousCommand = m_chooser.getSelected();
/*
* String autoSelected = SmartDashboard.getString("Auto Selector",
* "Default"); switch(autoSelected) { case "My Auto": autonomousCommand
* = new MyAutoCommand(); break; case "Default Auto": default:
* autonomousCommand = new ExampleCommand(); break; }
*/
/*
* String autoSelected = SmartDashboard.getString("Auto Selector",
* "Default"); switch(autoSelected) { case "My Auto": autonomousCommand
* = new MyAutoCommand(); break; case "Default Auto": default:
* autonomousCommand = new ExampleCommand(); break; }
*/
// schedule the autonomous command (example)
if (m_autonomousCommand != null) {
m_autonomousCommand.start();
}
}
// schedule the autonomous command (example)
if (m_autonomousCommand != null) {
m_autonomousCommand.start();
}
}
/**
* This function is called periodically during autonomous.
*/
@Override
public void autonomousPeriodic() {
Scheduler.getInstance().run();
}
/**
* This function is called periodically during autonomous.
*/
@Override
public void autonomousPeriodic() {
Scheduler.getInstance().run();
}
@Override
public void teleopInit() {
// This makes sure that the autonomous stops running when
// teleop starts running. If you want the autonomous to
// continue until interrupted by another command, remove
// this line or comment it out.
if (m_autonomousCommand != null) {
m_autonomousCommand.cancel();
}
}
@Override
public void teleopInit() {
// This makes sure that the autonomous stops running when
// teleop starts running. If you want the autonomous to
// continue until interrupted by another command, remove
// this line or comment it out.
if (m_autonomousCommand != null) {
m_autonomousCommand.cancel();
}
}
/**
* This function is called periodically during operator control.
*/
@Override
public void teleopPeriodic() {
Scheduler.getInstance().run();
}
/**
* This function is called periodically during operator control.
*/
@Override
public void teleopPeriodic() {
Scheduler.getInstance().run();
}
/**
* This function is called periodically during test mode.
*/
@Override
public void testPeriodic() {
}
/**
* This function is called periodically during test mode.
*/
@Override
public void testPeriodic() {
}
}

View File

@@ -14,13 +14,13 @@ package edu.wpi.first.wpilibj.templates.commandbased;
* floating around.
*/
public class RobotMap {
// For example to map the left and right motors, you could define the
// following variables to use with your drivetrain subsystem.
// public static int leftMotor = 1;
// public static int rightMotor = 2;
// For example to map the left and right motors, you could define the
// following variables to use with your drivetrain subsystem.
// public static int leftMotor = 1;
// public static int rightMotor = 2;
// If you are using multiple modules, make sure to define both the port
// number and the module. For example you with a rangefinder:
// public static int rangefinderPort = 1;
// public static int rangefinderModule = 1;
// If you are using multiple modules, make sure to define both the port
// number and the module. For example you with a rangefinder:
// public static int rangefinderPort = 1;
// public static int rangefinderModule = 1;
}

View File

@@ -14,35 +14,35 @@ import edu.wpi.first.wpilibj.templates.commandbased.Robot;
* An example command. You can replace me with your own command.
*/
public class ExampleCommand extends Command {
public ExampleCommand() {
// Use requires() here to declare subsystem dependencies
requires(Robot.m_subsystem);
}
public ExampleCommand() {
// Use requires() here to declare subsystem dependencies
requires(Robot.m_subsystem);
}
// Called just before this Command runs the first time
@Override
protected void initialize() {
}
// Called just before this Command runs the first time
@Override
protected void initialize() {
}
// Called repeatedly when this Command is scheduled to run
@Override
protected void execute() {
}
// Called repeatedly when this Command is scheduled to run
@Override
protected void execute() {
}
// Make this return true when this Command no longer needs to run execute()
@Override
protected boolean isFinished() {
return false;
}
// Make this return true when this Command no longer needs to run execute()
@Override
protected boolean isFinished() {
return false;
}
// Called once after isFinished returns true
@Override
protected void end() {
}
// Called once after isFinished returns true
@Override
protected void end() {
}
// Called when another command which requires one or more of the same
// subsystems is scheduled to run
@Override
protected void interrupted() {
}
// Called when another command which requires one or more of the same
// subsystems is scheduled to run
@Override
protected void interrupted() {
}
}

View File

@@ -13,11 +13,11 @@ import edu.wpi.first.wpilibj.command.Subsystem;
* An example subsystem. You can replace me with your own Subsystem.
*/
public class ExampleSubsystem extends Subsystem {
// Put methods for controlling this subsystem
// here. Call these from Commands.
// Put methods for controlling this subsystem
// here. Call these from Commands.
public void initDefaultCommand() {
// Set the default command for a subsystem here.
// setDefaultCommand(new MySpecialCommand());
}
public void initDefaultCommand() {
// Set the default command for a subsystem here.
// setDefaultCommand(new MySpecialCommand());
}
}

View File

@@ -19,68 +19,68 @@ import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
* project.
*/
public class Robot extends IterativeRobot {
private static final String kDefaultAuto = "Default";
private static final String kCustomAuto = "My Auto";
private String m_autoSelected;
private SendableChooser<String> m_chooser = new SendableChooser<>();
private static final String kDefaultAuto = "Default";
private static final String kCustomAuto = "My Auto";
private String m_autoSelected;
private SendableChooser<String> m_chooser = new SendableChooser<>();
/**
* This function is run when the robot is first started up and should be
* used for any initialization code.
*/
@Override
public void robotInit() {
m_chooser.addDefault("Default Auto", kDefaultAuto);
m_chooser.addObject("My Auto", kCustomAuto);
SmartDashboard.putData("Auto choices", m_chooser);
}
/**
* This function is run when the robot is first started up and should be
* used for any initialization code.
*/
@Override
public void robotInit() {
m_chooser.addDefault("Default Auto", kDefaultAuto);
m_chooser.addObject("My Auto", kCustomAuto);
SmartDashboard.putData("Auto choices", m_chooser);
}
/**
* This autonomous (along with the chooser code above) shows how to select
* between different autonomous modes using the dashboard. The sendable
* chooser code works with the Java SmartDashboard. If you prefer the
* LabVIEW Dashboard, remove all of the chooser code and uncomment the
* getString line to get the auto name from the text box below the Gyro
*
* <p>You can add additional auto modes by adding additional comparisons to
* the switch structure below with additional strings. If using the
* SendableChooser make sure to add them to the chooser code above as well.
*/
@Override
public void autonomousInit() {
m_autoSelected = m_chooser.getSelected();
// autoSelected = SmartDashboard.getString("Auto Selector",
// defaultAuto);
System.out.println("Auto selected: " + m_autoSelected);
}
/**
* This autonomous (along with the chooser code above) shows how to select
* between different autonomous modes using the dashboard. The sendable
* chooser code works with the Java SmartDashboard. If you prefer the
* LabVIEW Dashboard, remove all of the chooser code and uncomment the
* getString line to get the auto name from the text box below the Gyro
*
* <p>You can add additional auto modes by adding additional comparisons to
* the switch structure below with additional strings. If using the
* SendableChooser make sure to add them to the chooser code above as well.
*/
@Override
public void autonomousInit() {
m_autoSelected = m_chooser.getSelected();
// autoSelected = SmartDashboard.getString("Auto Selector",
// defaultAuto);
System.out.println("Auto selected: " + m_autoSelected);
}
/**
* This function is called periodically during autonomous.
*/
@Override
public void autonomousPeriodic() {
switch (m_autoSelected) {
case kCustomAuto:
// Put custom auto code here
break;
case kDefaultAuto:
default:
// Put default auto code here
break;
}
}
/**
* This function is called periodically during autonomous.
*/
@Override
public void autonomousPeriodic() {
switch (m_autoSelected) {
case kCustomAuto:
// Put custom auto code here
break;
case kDefaultAuto:
default:
// Put default auto code here
break;
}
}
/**
* This function is called periodically during operator control.
*/
@Override
public void teleopPeriodic() {
}
/**
* This function is called periodically during operator control.
*/
@Override
public void teleopPeriodic() {
}
/**
* This function is called periodically during test mode.
*/
@Override
public void testPeriodic() {
}
/**
* This function is called periodically during test mode.
*/
@Override
public void testPeriodic() {
}
}

View File

@@ -33,123 +33,123 @@ import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
* Command-Based instead if you're new.
*/
public class Robot extends SampleRobot {
private static final String kDefaultAuto = "Default";
private static final String kCustomAuto = "My Auto";
private static final String kDefaultAuto = "Default";
private static final String kCustomAuto = "My Auto";
private DifferentialDrive m_robotDrive
= new DifferentialDrive(new Spark(0), new Spark(1));
private Joystick m_stick = new Joystick(0);
private SendableChooser<String> m_chooser = new SendableChooser<>();
private DifferentialDrive m_robotDrive
= new DifferentialDrive(new Spark(0), new Spark(1));
private Joystick m_stick = new Joystick(0);
private SendableChooser<String> m_chooser = new SendableChooser<>();
public Robot() {
m_robotDrive.setExpiration(0.1);
}
public Robot() {
m_robotDrive.setExpiration(0.1);
}
@Override
public void robotInit() {
m_chooser.addDefault("Default Auto", kDefaultAuto);
m_chooser.addObject("My Auto", kCustomAuto);
SmartDashboard.putData("Auto modes", m_chooser);
}
@Override
public void robotInit() {
m_chooser.addDefault("Default Auto", kDefaultAuto);
m_chooser.addObject("My Auto", kCustomAuto);
SmartDashboard.putData("Auto modes", m_chooser);
}
/**
* This autonomous (along with the chooser code above) shows how to select
* between different autonomous modes using the dashboard. The sendable
* chooser code works with the Java SmartDashboard. If you prefer the
* LabVIEW Dashboard, remove all of the chooser code and uncomment the
* getString line to get the auto name from the text box below the Gyro
*
* <p>You can add additional auto modes by adding additional comparisons to
* the if-else structure below with additional strings. If using the
* SendableChooser make sure to add them to the chooser code above as well.
*
* <p>If you wanted to run a similar autonomous mode with an IterativeRobot
* you would write:
*
* <blockquote><pre>{@code
* Timer timer = new Timer();
*
* // This function is run once each time the robot enters autonomous mode
* public void autonomousInit() {
* timer.reset();
* timer.start();
* }
*
* // This function is called periodically during autonomous
* public void autonomousPeriodic() {
* // Drive for 2 seconds
* if (timer.get() < 2.0) {
* myRobot.drive(-0.5, 0.0); // drive forwards half speed
* } else if (timer.get() < 5.0) {
* myRobot.drive(-1.0, 0.0); // drive forwards full speed
* } else {
* myRobot.drive(0.0, 0.0); // stop robot
* }
* }
* }</pre></blockquote>
*/
@Override
public void autonomous() {
String autoSelected = m_chooser.getSelected();
// String autoSelected = SmartDashboard.getString("Auto Selector",
// defaultAuto);
System.out.println("Auto selected: " + autoSelected);
/**
* This autonomous (along with the chooser code above) shows how to select
* between different autonomous modes using the dashboard. The sendable
* chooser code works with the Java SmartDashboard. If you prefer the
* LabVIEW Dashboard, remove all of the chooser code and uncomment the
* getString line to get the auto name from the text box below the Gyro
*
* <p>You can add additional auto modes by adding additional comparisons to
* the if-else structure below with additional strings. If using the
* SendableChooser make sure to add them to the chooser code above as well.
*
* <p>If you wanted to run a similar autonomous mode with an IterativeRobot
* you would write:
*
* <blockquote><pre>{@code
* Timer timer = new Timer();
*
* // This function is run once each time the robot enters autonomous mode
* public void autonomousInit() {
* timer.reset();
* timer.start();
* }
*
* // This function is called periodically during autonomous
* public void autonomousPeriodic() {
* // Drive for 2 seconds
* if (timer.get() < 2.0) {
* myRobot.drive(-0.5, 0.0); // drive forwards half speed
* } else if (timer.get() < 5.0) {
* myRobot.drive(-1.0, 0.0); // drive forwards full speed
* } else {
* myRobot.drive(0.0, 0.0); // stop robot
* }
* }
* }</pre></blockquote>
*/
@Override
public void autonomous() {
String autoSelected = m_chooser.getSelected();
// String autoSelected = SmartDashboard.getString("Auto Selector",
// defaultAuto);
System.out.println("Auto selected: " + autoSelected);
// MotorSafety improves safety when motors are updated in loops
// but is disabled here because motor updates are not looped in
// this autonomous mode.
m_robotDrive.setSafetyEnabled(false);
// MotorSafety improves safety when motors are updated in loops
// but is disabled here because motor updates are not looped in
// this autonomous mode.
m_robotDrive.setSafetyEnabled(false);
switch (autoSelected) {
case kCustomAuto:
// Spin at half speed for two seconds
m_robotDrive.arcadeDrive(0.0, 0.5);
Timer.delay(2.0);
switch (autoSelected) {
case kCustomAuto:
// Spin at half speed for two seconds
m_robotDrive.arcadeDrive(0.0, 0.5);
Timer.delay(2.0);
// Stop robot
m_robotDrive.arcadeDrive(0.0, 0.0);
break;
case kDefaultAuto:
default:
// Drive forwards for two seconds
m_robotDrive.arcadeDrive(-0.5, 0.0);
Timer.delay(2.0);
// Stop robot
m_robotDrive.arcadeDrive(0.0, 0.0);
break;
case kDefaultAuto:
default:
// Drive forwards for two seconds
m_robotDrive.arcadeDrive(-0.5, 0.0);
Timer.delay(2.0);
// Stop robot
m_robotDrive.arcadeDrive(0.0, 0.0);
break;
}
}
// Stop robot
m_robotDrive.arcadeDrive(0.0, 0.0);
break;
}
}
/**
* Runs the motors with arcade steering.
*
* <p>If you wanted to run a similar teleoperated mode with an IterativeRobot
* you would write:
*
* <blockquote><pre>{@code
* // This function is called periodically during operator control
* public void teleopPeriodic() {
* myRobot.arcadeDrive(stick);
* }
* }</pre></blockquote>
*/
@Override
public void operatorControl() {
m_robotDrive.setSafetyEnabled(true);
while (isOperatorControl() && isEnabled()) {
// Drive arcade style
m_robotDrive.arcadeDrive(-m_stick.getY(), m_stick.getX());
/**
* Runs the motors with arcade steering.
*
* <p>If you wanted to run a similar teleoperated mode with an IterativeRobot
* you would write:
*
* <blockquote><pre>{@code
* // This function is called periodically during operator control
* public void teleopPeriodic() {
* myRobot.arcadeDrive(stick);
* }
* }</pre></blockquote>
*/
@Override
public void operatorControl() {
m_robotDrive.setSafetyEnabled(true);
while (isOperatorControl() && isEnabled()) {
// Drive arcade style
m_robotDrive.arcadeDrive(-m_stick.getY(), m_stick.getX());
// The motors will be updated every 5ms
Timer.delay(0.005);
}
}
// The motors will be updated every 5ms
Timer.delay(0.005);
}
}
/**
* Runs during test mode.
*/
@Override
public void test() {
}
/**
* Runs during test mode.
*/
@Override
public void test() {
}
}

View File

@@ -19,68 +19,68 @@ import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
* project.
*/
public class Robot extends TimedRobot {
private static final String kDefaultAuto = "Default";
private static final String kCustomAuto = "My Auto";
private String m_autoSelected;
private SendableChooser<String> m_chooser = new SendableChooser<>();
private static final String kDefaultAuto = "Default";
private static final String kCustomAuto = "My Auto";
private String m_autoSelected;
private SendableChooser<String> m_chooser = new SendableChooser<>();
/**
* This function is run when the robot is first started up and should be
* used for any initialization code.
*/
@Override
public void robotInit() {
m_chooser.addDefault("Default Auto", kDefaultAuto);
m_chooser.addObject("My Auto", kCustomAuto);
SmartDashboard.putData("Auto choices", m_chooser);
}
/**
* This function is run when the robot is first started up and should be
* used for any initialization code.
*/
@Override
public void robotInit() {
m_chooser.addDefault("Default Auto", kDefaultAuto);
m_chooser.addObject("My Auto", kCustomAuto);
SmartDashboard.putData("Auto choices", m_chooser);
}
/**
* This autonomous (along with the chooser code above) shows how to select
* between different autonomous modes using the dashboard. The sendable
* chooser code works with the Java SmartDashboard. If you prefer the
* LabVIEW Dashboard, remove all of the chooser code and uncomment the
* getString line to get the auto name from the text box below the Gyro
*
* <p>You can add additional auto modes by adding additional comparisons to
* the switch structure below with additional strings. If using the
* SendableChooser make sure to add them to the chooser code above as well.
*/
@Override
public void autonomousInit() {
m_autoSelected = m_chooser.getSelected();
// m_autoSelected = SmartDashboard.getString("Auto Selector",
// kDefaultAuto);
System.out.println("Auto selected: " + m_autoSelected);
}
/**
* This autonomous (along with the chooser code above) shows how to select
* between different autonomous modes using the dashboard. The sendable
* chooser code works with the Java SmartDashboard. If you prefer the
* LabVIEW Dashboard, remove all of the chooser code and uncomment the
* getString line to get the auto name from the text box below the Gyro
*
* <p>You can add additional auto modes by adding additional comparisons to
* the switch structure below with additional strings. If using the
* SendableChooser make sure to add them to the chooser code above as well.
*/
@Override
public void autonomousInit() {
m_autoSelected = m_chooser.getSelected();
// m_autoSelected = SmartDashboard.getString("Auto Selector",
// kDefaultAuto);
System.out.println("Auto selected: " + m_autoSelected);
}
/**
* This function is called periodically during autonomous.
*/
@Override
public void autonomousPeriodic() {
switch (m_autoSelected) {
case kCustomAuto:
// Put custom auto code here
break;
case kDefaultAuto:
default:
// Put default auto code here
break;
}
}
/**
* This function is called periodically during autonomous.
*/
@Override
public void autonomousPeriodic() {
switch (m_autoSelected) {
case kCustomAuto:
// Put custom auto code here
break;
case kDefaultAuto:
default:
// Put default auto code here
break;
}
}
/**
* This function is called periodically during operator control.
*/
@Override
public void teleopPeriodic() {
}
/**
* This function is called periodically during operator control.
*/
@Override
public void teleopPeriodic() {
}
/**
* This function is called periodically during test mode.
*/
@Override
public void testPeriodic() {
}
/**
* This function is called periodically during test mode.
*/
@Override
public void testPeriodic() {
}
}