mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
Add XboxController examples for arcade and tank drive (#2058)
This commit is contained in:
@@ -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 <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 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<Robot>(); }
|
||||
#endif
|
||||
@@ -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
|
||||
@@ -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
|
||||
}
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user