Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public MyAuto(Robot robot) {

@Override
public void start() {
/* Called once when the robot is enabled. */
autoTimer.restart(); // Reset the timer to zero at the start of auto
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@
import org.wpilib.hardware.imu.OnboardIMU;
import org.wpilib.hardware.imu.OnboardIMU.MountOrientation;

/**
* The methods in this class are called automatically as described in the OpModeRobot documentation.
* OpMode classes anywhere in the package (or sub-packages) where this class is located are
* automatically registered to display in the Driver Station. If you change the name of this class
* or the package after creating this project, you must also update the Main.java file in the
* project.
*/
public class Robot extends OpModeRobot {

private SparkMax leftLeader = new SparkMax(0, 0, MotorType.kBrushless);
Expand All @@ -37,8 +44,11 @@ public class Robot extends OpModeRobot {
public final DifferentialDrive drivetrain =
new DifferentialDrive(leftLeader::setThrottle, rightLeader::setThrottle);

/**
* This function is run when the robot is first started up and should be used for any
* initialization code.
*/
public Robot() {

var leftConfig = new SparkMaxConfig().inverted(true);
leftLeader.configure(
leftConfig, ResetMode.kResetSafeParameters, PersistMode.kPersistParameters);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,26 @@ public class MyAuto extends PeriodicOpMode {
private final Robot robot;
private Timer timer = new Timer();

/** The Robot instance is passed into the opmode via the constructor. */
public MyAuto(Robot robot) {
this.robot = robot;
}

@Override
public void start() {
timer.restart();
/* Called once when the robot is enabled. */
timer.restart(); // Reset the timer to zero at the start of auto
}

/*
* This method runs periodically, using the same period as the Robot instance.
*
* Additional periodic methods may be configured with addPeriodic(),
* which can have periods that differ from the main Robot instance.
*/
@Override
public void periodic() {
if (timer.hasElapsed(4)) {
if (timer.hasElapsed(4)) { // Drive for 4 seconds after the start of auto
robot.drivetrain.arcadeDrive(0.0, 0.0); // Stop the robot after 4 seconds
} else {
robot.drivetrain.arcadeDrive(0.5, 0.0); // Drive forward at half speed with no rotation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ public class MyTeleop extends PeriodicOpMode {
private final Robot robot;
private final NiDsXboxController xboxController = new NiDsXboxController(0);

/** The Robot instance is passed into the opmode via the constructor. */
public MyTeleop(Robot robot) {
this.robot = robot;
}

@Override
public void periodic() {
/* Called periodically (set time interval) while the robot is enabled. */
robot.drivetrain.arcadeDrive(-xboxController.getLeftY(), xboxController.getRightX());

if (xboxController.getRightBumperButton()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ public MyAuto(Robot robot) {
}

@Override
public void start() {}
public void start() {
/* Called once when the robot is enabled. */
}

/*
* This method runs periodically, using the same period as the Robot instance.
Expand Down
11 changes: 11 additions & 0 deletions examples/stage1/templates/rev/src/main/java/first/robot/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,19 @@

import org.wpilib.framework.OpModeRobot;

/**
* The methods in this class are called automatically as described in the OpModeRobot documentation.
* OpMode classes anywhere in the package (or sub-packages) where this class is located are
* automatically registered to display in the Driver Station. If you change the name of this class
* or the package after creating this project, you must also update the Main.java file in the
* project.
*/
public class Robot extends OpModeRobot {

/**
* This function is run when the robot is first started up and should be used for any
* initialization code.
*/
public Robot() {}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,22 @@
public class MyAuto extends PeriodicOpMode {
private final Robot robot;

/** The Robot instance is passed into the opmode via the constructor. */
public MyAuto(Robot robot) {
this.robot = robot;
}

@Override
public void start() {}
public void start() {
/* Called once when the robot is enabled. */
}

/*
* This method runs periodically, using the same period as the Robot instance.
*
* Additional periodic methods may be configured with addPeriodic(),
* which can have periods that differ from the main Robot instance.
*/
@Override
public void periodic() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@
public class MyTeleop extends PeriodicOpMode {
private final Robot robot;

/** The Robot instance is passed into the opmode via the constructor. */
public MyTeleop(Robot robot) {
this.robot = robot;
}

@Override
public void periodic() {}
public void periodic() {
/* Called periodically (set time interval) while the robot is enabled. */
}
}
Loading