diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/arcadedrive/Main.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/arcadedrive/Main.java new file mode 100644 index 0000000000..438697e777 --- /dev/null +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/arcadedrive/Main.java @@ -0,0 +1,29 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2018-2019 FIRST. All Rights Reserved. */ +/* Open Source Software - may be modified and shared by FRC teams. The code */ +/* must be accompanied by the FIRST BSD license file in the root directory of */ +/* the project. */ +/*----------------------------------------------------------------------------*/ + +package edu.wpi.first.wpilibj.examples.arcadedrive; + +import edu.wpi.first.wpilibj.RobotBase; + +/** + * Do NOT add any static variables to this class, or any initialization at all. + * Unless you know what you are doing, do not modify this file except to + * change the parameter class to the startRobot call. + */ +public final class Main { + private Main() { + } + + /** + * Main initialization function. Do not perform any initialization here. + * + *
If you change your main robot class, change the parameter type. + */ + public static void main(String... args) { + RobotBase.startRobot(Robot::new); + } +} diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/arcadedrive/Robot.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/arcadedrive/Robot.java new file mode 100644 index 0000000000..f0026187b3 --- /dev/null +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/arcadedrive/Robot.java @@ -0,0 +1,32 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */ +/* Open Source Software - may be modified and shared by FRC teams. The code */ +/* must be accompanied by the FIRST BSD license file in the root directory of */ +/* the project. */ +/*----------------------------------------------------------------------------*/ + +package edu.wpi.first.wpilibj.examples.arcadedrive; + +import edu.wpi.first.wpilibj.Joystick; +import edu.wpi.first.wpilibj.PWMVictorSPX; +import edu.wpi.first.wpilibj.TimedRobot; +import edu.wpi.first.wpilibj.drive.DifferentialDrive; + +/** + * This is a demo program showing the use of the DifferentialDrive class. + * Runs the motors with arcade steering. + */ +public class Robot extends TimedRobot { + private final PWMVictorSPX m_leftMotor = new PWMVictorSPX(0); + private final PWMVictorSPX m_rightMotor = new PWMVictorSPX(1); + private final DifferentialDrive m_robotDrive = new DifferentialDrive(m_leftMotor, m_rightMotor); + private final Joystick m_stick = new Joystick(0); + + @Override + public void teleopPeriodic() { + // Drive with arcade drive. + // That means that the Y axis drives forward + // and backward, and the X turns left and right. + m_robotDrive.arcadeDrive(m_stick.getY(), m_stick.getX()); + } +} diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/examples.json b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/examples.json index 81cbcb37a1..90dac6c058 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/examples.json +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/examples.json @@ -22,6 +22,16 @@ "gradlebase": "java", "mainclass": "Main" }, + { + "name": "Arcade Drive", + "description": "Demonstrates the use of the DifferentialDrive class to drive a robot with Arcade Drive.", + "tags": [ + "Getting Started with Java" + ], + "foldername": "arcadedrive", + "gradlebase": "java", + "mainclass": "Main" + }, { "name": "Mecanum Drive", "description": "Demonstrate the use of the RobotDrive class doing teleop driving with Mecanum steering",