Add XboxController examples for arcade and tank drive (#2058)

This commit is contained in:
CTT
2019-11-10 22:53:17 -08:00
committed by Peter Johnson
parent e3dd1c5d77
commit 486fa9c696
8 changed files with 247 additions and 0 deletions

View File

@@ -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 <frc/GenericHID.h>
#include <frc/PWMVictorSPX.h>
#include <frc/TimedRobot.h>
#include <frc/XboxController.h>
#include <frc/drive/DifferentialDrive.h>
/**
* 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<Robot>(); }
#endif