|
| 1 | + |
| 2 | +package org.usfirst.frc.team5518.robot; |
| 3 | + |
| 4 | + |
| 5 | +import edu.wpi.first.wpilibj.SampleRobot; |
| 6 | +import edu.wpi.first.wpilibj.RobotDrive; |
| 7 | +import edu.wpi.first.wpilibj.Joystick; |
| 8 | +import edu.wpi.first.wpilibj.Timer; |
| 9 | + |
| 10 | +/** |
| 11 | + * This is a demo program showing the use of the RobotDrive class. |
| 12 | + * The SampleRobot class is the base of a robot application that will automatically call your |
| 13 | + * Autonomous and OperatorControl methods at the right time as controlled by the switches on |
| 14 | + * the driver station or the field controls. |
| 15 | + * |
| 16 | + * The VM is configured to automatically run this class, and to call the |
| 17 | + * functions corresponding to each mode, as described in the SampleRobot |
| 18 | + * documentation. If you change the name of this class or the package after |
| 19 | + * creating this project, you must also update the manifest file in the resource |
| 20 | + * directory. |
| 21 | + * |
| 22 | + * WARNING: While it may look like a good choice to use for your code if you're inexperienced, |
| 23 | + * don't. Unless you know what you are doing, complex code will be much more difficult under |
| 24 | + * this system. Use IterativeRobot or Command-Based instead if you're new. |
| 25 | + */ |
| 26 | +public class Robot extends SampleRobot { |
| 27 | + |
| 28 | + private static final int FRONT_LEFT_MOTOR = 2; |
| 29 | + private static final int REAR_LEFT_MOTOR = 1; |
| 30 | + private static final int FRONT_RIGHT_MOTOR = 3; |
| 31 | + private static final int REAR_RIGHT_MOTOR = 0; |
| 32 | + |
| 33 | + RobotDrive myRobot; |
| 34 | + Joystick stick; |
| 35 | + |
| 36 | + public Robot() { // initialize variables in constructor |
| 37 | + myRobot = new RobotDrive(FRONT_LEFT_MOTOR, REAR_LEFT_MOTOR, |
| 38 | + FRONT_RIGHT_MOTOR, REAR_RIGHT_MOTOR); |
| 39 | + myRobot.setExpiration(0.1); |
| 40 | + stick = new Joystick(0); |
| 41 | + } |
| 42 | + |
| 43 | + /** |
| 44 | + * Drive left & right motors for 2 seconds then stop |
| 45 | + */ |
| 46 | + public void autonomous() { // function for autonomous mode |
| 47 | + myRobot.setSafetyEnabled(false); |
| 48 | + myRobot.drive(-0.5, 0.0); // drive forwards half speed |
| 49 | + Timer.delay(2.0); // for 2 seconds |
| 50 | + myRobot.drive(0.0, 0.0); // stop robot |
| 51 | + } |
| 52 | + |
| 53 | + /** |
| 54 | + * Runs the motors with arcade steering. |
| 55 | + */ |
| 56 | + public void operatorControl() { // function for teleop mode |
| 57 | + myRobot.setSafetyEnabled(true); |
| 58 | + while (isOperatorControl() && isEnabled()) { |
| 59 | + myRobot.arcadeDrive(stick); // drive with arcade style (use right stick) |
| 60 | + Timer.delay(0.005); // wait for a motor update time |
| 61 | + } |
| 62 | + } |
| 63 | + |
| 64 | + /** |
| 65 | + * Runs during test mode |
| 66 | + */ |
| 67 | + public void test() { |
| 68 | + |
| 69 | + } |
| 70 | +} |
0 commit comments