mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
Add java arcade drive example (#1810)
This commit is contained in:
@@ -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.
|
||||
*
|
||||
* <p>If you change your main robot class, change the parameter type.
|
||||
*/
|
||||
public static void main(String... args) {
|
||||
RobotBase.startRobot(Robot::new);
|
||||
}
|
||||
}
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user