diff --git a/wpilibcExamples/src/main/cpp/examples/ArcadeDriveXboxController/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/ArcadeDriveXboxController/cpp/Robot.cpp new file mode 100644 index 0000000000..67f1e12043 --- /dev/null +++ b/wpilibcExamples/src/main/cpp/examples/ArcadeDriveXboxController/cpp/Robot.cpp @@ -0,0 +1,37 @@ +/*----------------------------------------------------------------------------*/ +/* 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. */ +/*----------------------------------------------------------------------------*/ + +#include +#include +#include +#include +#include + +/** + * This is a demo program showing the use of the DifferentialDrive class. + * Runs the motors with split arcade steering and an Xbox controller. + */ +class Robot : public frc::TimedRobot { + frc::PWMVictorSPX m_leftMotor{0}; + frc::PWMVictorSPX m_rightMotor{1}; + frc::DifferentialDrive m_robotDrive{m_leftMotor, m_rightMotor}; + frc::XboxController m_driverController{0}; + + public: + void TeleopPeriodic() { + // Drive with split arcade style + // That means that the Y axis of the left stick moves forward + // and backward, and the X of the right stick turns left and right. + m_robotDrive.ArcadeDrive( + m_driverController.GetY(frc::GenericHID::JoystickHand::kLeftHand), + m_driverController.GetX(frc::GenericHID::JoystickHand::kRightHand)); + } +}; + +#ifndef RUNNING_FRC_TESTS +int main() { return frc::StartRobot(); } +#endif diff --git a/wpilibcExamples/src/main/cpp/examples/TankDriveXboxController/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/TankDriveXboxController/cpp/Robot.cpp new file mode 100644 index 0000000000..3ca31ed7b1 --- /dev/null +++ b/wpilibcExamples/src/main/cpp/examples/TankDriveXboxController/cpp/Robot.cpp @@ -0,0 +1,35 @@ +/*----------------------------------------------------------------------------*/ +/* 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. */ +/*----------------------------------------------------------------------------*/ + +#include +#include +#include +#include +#include + +/** + * This is a demo program showing the use of the DifferentialDrive class. + * Runs the motors with tank steering and an Xbox controller. + */ +class Robot : public frc::TimedRobot { + frc::PWMVictorSPX m_leftMotor{0}; + frc::PWMVictorSPX m_rightMotor{1}; + frc::DifferentialDrive m_robotDrive{m_leftMotor, m_rightMotor}; + frc::XboxController m_driverController{0}; + + public: + void TeleopPeriodic() { + // Drive with tank style + m_robotDrive.TankDrive( + m_driverController.GetY(frc::GenericHID::JoystickHand::kLeftHand), + m_driverController.GetY(frc::GenericHID::JoystickHand::kRightHand)); + } +}; + +#ifndef RUNNING_FRC_TESTS +int main() { return frc::StartRobot(); } +#endif diff --git a/wpilibcExamples/src/main/cpp/examples/examples.json b/wpilibcExamples/src/main/cpp/examples/examples.json index 894080e3a2..edcf8ff4b2 100644 --- a/wpilibcExamples/src/main/cpp/examples/examples.json +++ b/wpilibcExamples/src/main/cpp/examples/examples.json @@ -402,5 +402,31 @@ "foldername": "RamseteCommand", "gradlebase": "cpp", "commandversion": 2 + }, + { + "name": "Arcade Drive Xbox Controller", + "description": "An example program which demonstrates the use of Arcade Drive with the DifferentialDrive class and an Xbox Controller.", + "tags": [ + "Getting Started with C++", + "Robot and Motor", + "XboxController", + "Complete List" + ], + "foldername": "ArcadeDriveXboxController", + "gradlebase": "cpp", + "commandversion": 1 + }, + { + "name": "Tank Drive Xbox Controller", + "description": "An example program which demonstrates the use of Tank Drive with the DifferentialDrive class and an Xbox Controller.", + "tags": [ + "Getting Started with C++", + "Robot and Motor", + "XboxController", + "Complete List" + ], + "foldername": "TankDriveXboxController", + "gradlebase": "cpp", + "commandversion": 1 } ] diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/arcadedrivexboxcontroller/Main.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/arcadedrivexboxcontroller/Main.java new file mode 100644 index 0000000000..fb5c2abac8 --- /dev/null +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/arcadedrivexboxcontroller/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.arcadedrivexboxcontroller; + +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/arcadedrivexboxcontroller/Robot.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/arcadedrivexboxcontroller/Robot.java new file mode 100644 index 0000000000..915d77e209 --- /dev/null +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/arcadedrivexboxcontroller/Robot.java @@ -0,0 +1,34 @@ +/*----------------------------------------------------------------------------*/ +/* 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.arcadedrivexboxcontroller; + +import edu.wpi.first.wpilibj.GenericHID.Hand; +import edu.wpi.first.wpilibj.PWMVictorSPX; +import edu.wpi.first.wpilibj.TimedRobot; +import edu.wpi.first.wpilibj.XboxController; +import edu.wpi.first.wpilibj.drive.DifferentialDrive; + +/** + * This is a demo program showing the use of the DifferentialDrive class. + * Runs the motors with split arcade steering and an Xbox controller. + */ +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 XboxController m_driverController = new XboxController(0); + + @Override + public void teleopPeriodic() { + // Drive with split arcade drive. + // That means that the Y axis of the left stick moves forward + // and backward, and the X of the right stick turns left and right. + m_robotDrive.arcadeDrive(m_driverController.getY(Hand.kLeft), + m_driverController.getX(Hand.kRight)); + } +} 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 54fa283dea..0d6a6e4c4b 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 @@ -427,5 +427,27 @@ "gradlebase": "java", "mainclass": "Main", "commandversion": 2 + }, + { + "name": "Arcade Drive Xbox Controller", + "description": "Demonstrates the use of the DifferentialDrive class to drive a robot with Arcade Drive and an Xbox Controller", + "tags": [ + "Getting Started with Java" + ], + "foldername": "arcadedrivexboxcontroller", + "gradlebase": "java", + "mainclass": "Main", + "commandversion": 1 + }, + { + "name": "Tank Drive Xbox Controller", + "description": "Demonstrates the use of the DifferentialDrive class to drive a robot with Tank Drive and an Xbox Controller", + "tags": [ + "Getting Started with Java" + ], + "foldername": "tankdrivexboxcontroller", + "gradlebase": "java", + "mainclass": "Main", + "commandversion": 1 } ] diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/tankdrivexboxcontroller/Main.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/tankdrivexboxcontroller/Main.java new file mode 100644 index 0000000000..3adcee9bb1 --- /dev/null +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/tankdrivexboxcontroller/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.tankdrivexboxcontroller; + +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/tankdrivexboxcontroller/Robot.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/tankdrivexboxcontroller/Robot.java new file mode 100644 index 0000000000..f0a9e76ea5 --- /dev/null +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/tankdrivexboxcontroller/Robot.java @@ -0,0 +1,35 @@ +/*----------------------------------------------------------------------------*/ +/* 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.tankdrivexboxcontroller; + +import edu.wpi.first.wpilibj.GenericHID.Hand; +import edu.wpi.first.wpilibj.PWMVictorSPX; +import edu.wpi.first.wpilibj.TimedRobot; +import edu.wpi.first.wpilibj.XboxController; +import edu.wpi.first.wpilibj.drive.DifferentialDrive; + +/** + * This is a demo program showing the use of the DifferentialDrive class. + * Runs the motors with tank steering and an Xbox controller. + */ +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 XboxController m_driverController = new XboxController(0); + + @Override + public void teleopPeriodic() { + // Drive with tank drive. + // That means that the Y axis of the left stick moves the left side + // of the robot forward and backward, and the Y axis of the right stick + // moves the right side of the robot forward and backward. + m_robotDrive.tankDrive(m_driverController.getY(Hand.kLeft), + m_driverController.getY(Hand.kRight)); + } +}