mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-23 01:21:42 +00:00
[examples] Update all examples to use NWU coordinate conventions (#4725)
This commit is contained in:
@@ -27,7 +27,7 @@ class Robot : public frc::TimedRobot {
|
||||
|
||||
void TeleopPeriodic() override {
|
||||
// Drive with arcade style
|
||||
m_robotDrive.ArcadeDrive(-m_stick.GetY(), m_stick.GetX());
|
||||
m_robotDrive.ArcadeDrive(-m_stick.GetY(), -m_stick.GetX());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ class Robot : public frc::TimedRobot {
|
||||
// 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.GetLeftY(),
|
||||
m_driverController.GetRightX());
|
||||
-m_driverController.GetRightX());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ RobotContainer::RobotContainer() {
|
||||
m_drive.SetDefaultCommand(frc2::cmd::Run(
|
||||
[this] {
|
||||
m_drive.ArcadeDrive(-m_driverController.GetLeftY(),
|
||||
m_driverController.GetRightX());
|
||||
-m_driverController.GetRightX());
|
||||
},
|
||||
{&m_drive}));
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ RobotContainer::RobotContainer() {
|
||||
// Set up default drive command
|
||||
m_drive.SetDefaultCommand(m_drive.ArcadeDriveCommand(
|
||||
[this] { return -m_driverController.GetLeftY(); },
|
||||
[this] { return m_driverController.GetRightX(); }));
|
||||
[this] { return -m_driverController.GetRightX(); }));
|
||||
}
|
||||
|
||||
void RobotContainer::ConfigureButtonBindings() {
|
||||
|
||||
@@ -16,7 +16,7 @@ RobotContainer::RobotContainer() {
|
||||
m_drive.SetDefaultCommand(frc2::cmd::Run(
|
||||
[this] {
|
||||
m_drive.ArcadeDrive(-m_driverController.GetLeftY(),
|
||||
m_driverController.GetRightX());
|
||||
-m_driverController.GetRightX());
|
||||
},
|
||||
{&m_drive}));
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ RobotContainer::RobotContainer() {
|
||||
m_drive.SetDefaultCommand(frc2::cmd::Run(
|
||||
[this] {
|
||||
m_drive.ArcadeDrive(-m_driverController.GetLeftY(),
|
||||
m_driverController.GetRightX());
|
||||
-m_driverController.GetRightX());
|
||||
},
|
||||
{&m_drive}));
|
||||
}
|
||||
|
||||
@@ -22,9 +22,9 @@ RobotContainer::RobotContainer()
|
||||
frc::SmartDashboard::PutData(&m_wrist);
|
||||
frc::SmartDashboard::PutData(&m_claw);
|
||||
|
||||
m_drivetrain.SetDefaultCommand(TankDrive([this] { return m_joy.GetLeftY(); },
|
||||
[this] { return m_joy.GetRightY(); },
|
||||
m_drivetrain));
|
||||
m_drivetrain.SetDefaultCommand(
|
||||
TankDrive([this] { return -m_joy.GetLeftY(); },
|
||||
[this] { return -m_joy.GetRightY(); }, m_drivetrain));
|
||||
|
||||
// Configure the button bindings
|
||||
ConfigureButtonBindings();
|
||||
|
||||
@@ -11,11 +11,11 @@
|
||||
class Robot : public frc::TimedRobot {
|
||||
public:
|
||||
Robot() {
|
||||
m_right.SetInverted(true);
|
||||
m_robotDrive.SetExpiration(100_ms);
|
||||
// We need to invert one side of the drivetrain so that positive voltages
|
||||
// result in both sides moving forward. Depending on how your robot's
|
||||
// gearbox is constructed, you might have to invert the left side instead.
|
||||
m_right.SetInverted(true);
|
||||
m_robotDrive.SetExpiration(100_ms);
|
||||
m_timer.Start();
|
||||
}
|
||||
|
||||
|
||||
@@ -32,9 +32,7 @@ class Robot : public frc::TimedRobot {
|
||||
*/
|
||||
void TeleopPeriodic() override {
|
||||
double turningValue = (kAngleSetpoint - m_gyro.GetAngle()) * kP;
|
||||
// Invert the direction of the turn if we are going backwards
|
||||
turningValue = std::copysign(turningValue, m_joystick.GetY());
|
||||
m_robotDrive.ArcadeDrive(-m_joystick.GetY(), turningValue);
|
||||
m_drive.ArcadeDrive(-m_joystick.GetY(), -turningValue);
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -52,7 +50,7 @@ class Robot : public frc::TimedRobot {
|
||||
|
||||
frc::PWMSparkMax m_left{kLeftMotorPort};
|
||||
frc::PWMSparkMax m_right{kRightMotorPort};
|
||||
frc::DifferentialDrive m_robotDrive{m_left, m_right};
|
||||
frc::DifferentialDrive m_drive{m_left, m_right};
|
||||
|
||||
frc::AnalogGyro m_gyro{kGyroPort};
|
||||
frc::Joystick m_joystick{kJoystickPort};
|
||||
|
||||
@@ -21,7 +21,7 @@ RobotContainer::RobotContainer() {
|
||||
m_drive.SetDefaultCommand(frc2::RunCommand(
|
||||
[this] {
|
||||
m_drive.ArcadeDrive(-m_driverController.GetLeftY(),
|
||||
m_driverController.GetRightX());
|
||||
-m_driverController.GetRightX());
|
||||
},
|
||||
{&m_drive}));
|
||||
}
|
||||
|
||||
@@ -28,8 +28,8 @@ class Robot : public frc::TimedRobot {
|
||||
* Mecanum drive is used with the gyro angle as an input.
|
||||
*/
|
||||
void TeleopPeriodic() override {
|
||||
m_robotDrive.DriveCartesian(-m_joystick.GetY(), m_joystick.GetX(),
|
||||
m_joystick.GetZ(), m_gyro.GetRotation2d());
|
||||
m_robotDrive.DriveCartesian(-m_joystick.GetY(), -m_joystick.GetX(),
|
||||
-m_joystick.GetZ(), m_gyro.GetRotation2d());
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
@@ -24,7 +24,7 @@ RobotContainer::RobotContainer() {
|
||||
m_drive.SetDefaultCommand(frc2::cmd::Run(
|
||||
[this] {
|
||||
m_drive.ArcadeDrive(-m_driverController.GetLeftY(),
|
||||
m_driverController.GetRightX());
|
||||
-m_driverController.GetRightX());
|
||||
},
|
||||
{&m_drive}));
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ RobotContainer::RobotContainer() {
|
||||
// Set up default drive command
|
||||
m_drive.SetDefaultCommand(DefaultDrive(
|
||||
&m_drive, [this] { return -m_driverController.GetLeftY(); },
|
||||
[this] { return m_driverController.GetRightX(); }));
|
||||
[this] { return -m_driverController.GetRightX(); }));
|
||||
}
|
||||
|
||||
void RobotContainer::ConfigureButtonBindings() {
|
||||
|
||||
@@ -30,9 +30,9 @@ RobotContainer::RobotContainer() {
|
||||
// Set up default drive command
|
||||
m_drive.SetDefaultCommand(frc2::RunCommand(
|
||||
[this] {
|
||||
m_drive.Drive(m_driverController.GetLeftY(),
|
||||
m_driverController.GetRightX(),
|
||||
m_driverController.GetLeftX(), false);
|
||||
m_drive.Drive(-m_driverController.GetLeftY(),
|
||||
-m_driverController.GetRightX(),
|
||||
-m_driverController.GetLeftX(), false);
|
||||
},
|
||||
{&m_drive}));
|
||||
}
|
||||
|
||||
@@ -24,8 +24,8 @@ class Robot : public frc::TimedRobot {
|
||||
/* Use the joystick X axis for forward movement, Y axis for lateral
|
||||
* movement, and Z axis for rotation.
|
||||
*/
|
||||
m_robotDrive.DriveCartesian(-m_stick.GetY(), m_stick.GetX(),
|
||||
m_stick.GetZ());
|
||||
m_robotDrive.DriveCartesian(-m_stick.GetY(), -m_stick.GetX(),
|
||||
-m_stick.GetZ());
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
@@ -28,8 +28,8 @@ RobotContainer::RobotContainer() {
|
||||
// Set up default drive command
|
||||
m_drive.SetDefaultCommand(frc2::RunCommand(
|
||||
[this] {
|
||||
m_drive.ArcadeDrive(m_driverController.GetLeftY(),
|
||||
m_driverController.GetRightX());
|
||||
m_drive.ArcadeDrive(-m_driverController.GetLeftY(),
|
||||
-m_driverController.GetRightX());
|
||||
},
|
||||
{&m_drive}));
|
||||
}
|
||||
|
||||
@@ -25,8 +25,8 @@ void RapidReactCommandBot::ConfigureBindings() {
|
||||
|
||||
// Control the drive with split-stick arcade controls
|
||||
m_drive.SetDefaultCommand(m_drive.ArcadeDriveCommand(
|
||||
[this] { return m_driverController.GetLeftY(); },
|
||||
[this] { return m_driverController.GetRightX(); }));
|
||||
[this] { return -m_driverController.GetLeftY(); },
|
||||
[this] { return -m_driverController.GetRightX(); }));
|
||||
|
||||
// Deploy the intake with the X button
|
||||
m_driverController.X().OnTrue(m_intake.IntakeCommand());
|
||||
|
||||
@@ -19,7 +19,7 @@ void RobotContainer::ConfigureButtonBindings() {
|
||||
// Also set default commands here
|
||||
m_drive.SetDefaultCommand(TeleopArcadeDrive(
|
||||
&m_drive, [this] { return -m_controller.GetRawAxis(1); },
|
||||
[this] { return m_controller.GetRawAxis(2); }));
|
||||
[this] { return -m_controller.GetRawAxis(2); }));
|
||||
|
||||
// Example of how to use the onboard IO
|
||||
m_onboardButtonA.OnTrue(frc2::cmd::Print("Button A Pressed"))
|
||||
|
||||
@@ -34,7 +34,7 @@ RobotContainer::RobotContainer() {
|
||||
m_drive.SetDefaultCommand(frc2::RunCommand(
|
||||
[this] {
|
||||
m_drive.ArcadeDrive(-m_driverController.GetLeftY(),
|
||||
m_driverController.GetRightX());
|
||||
-m_driverController.GetLeftX());
|
||||
},
|
||||
{&m_drive}));
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ class Robot : public frc::TimedRobot {
|
||||
|
||||
void TeleopPeriodic() override {
|
||||
// Drive with tank style
|
||||
m_robotDrive.TankDrive(m_leftStick.GetY(), m_rightStick.GetY());
|
||||
m_robotDrive.TankDrive(-m_leftStick.GetY(), -m_rightStick.GetY());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -32,6 +32,6 @@ public class Robot extends TimedRobot {
|
||||
// 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());
|
||||
m_robotDrive.arcadeDrive(-m_stick.getY(), -m_stick.getX());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,6 @@ public class Robot extends TimedRobot {
|
||||
// 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.getLeftY(), m_driverController.getRightX());
|
||||
m_robotDrive.arcadeDrive(-m_driverController.getLeftY(), -m_driverController.getRightX());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ public class RobotContainer {
|
||||
Commands.run(
|
||||
() ->
|
||||
m_robotDrive.arcadeDrive(
|
||||
-m_driverController.getLeftY(), m_driverController.getRightX()),
|
||||
-m_driverController.getLeftY(), -m_driverController.getRightX()),
|
||||
m_robotDrive));
|
||||
}
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ public class RobotContainer {
|
||||
// A split-stick arcade command, with forward/backward controlled by the left
|
||||
// hand, and turning controlled by the right.
|
||||
m_robotDrive.arcadeDriveCommand(
|
||||
() -> -m_driverController.getLeftY(), () -> m_driverController.getRightX()));
|
||||
() -> -m_driverController.getLeftY(), () -> -m_driverController.getRightX()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -46,7 +46,7 @@ public class RobotContainer {
|
||||
Commands.run(
|
||||
() ->
|
||||
m_robotDrive.arcadeDrive(
|
||||
-m_driverController.getLeftY(), m_driverController.getRightX()),
|
||||
-m_driverController.getLeftY(), -m_driverController.getRightX()),
|
||||
m_robotDrive));
|
||||
}
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ public class RobotContainer {
|
||||
Commands.run(
|
||||
() ->
|
||||
m_robotDrive.arcadeDrive(
|
||||
-m_driverController.getLeftY(), m_driverController.getRightX()),
|
||||
-m_driverController.getLeftY(), -m_driverController.getRightX()),
|
||||
m_robotDrive));
|
||||
}
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ public class RobotContainer {
|
||||
|
||||
// Assign default commands
|
||||
m_drivetrain.setDefaultCommand(
|
||||
new TankDrive(m_joystick::getLeftY, m_joystick::getRightY, m_drivetrain));
|
||||
new TankDrive(() -> -m_joystick.getLeftY(), () -> -m_joystick.getRightY(), m_drivetrain));
|
||||
|
||||
// Show what command your subsystem is running on the SmartDashboard
|
||||
SmartDashboard.putData(m_drivetrain);
|
||||
|
||||
@@ -61,7 +61,7 @@ public class Robot extends TimedRobot {
|
||||
/** This function is called periodically during teleoperated mode. */
|
||||
@Override
|
||||
public void teleopPeriodic() {
|
||||
m_robotDrive.arcadeDrive(-m_controller.getLeftY(), m_controller.getRightX());
|
||||
m_robotDrive.arcadeDrive(-m_controller.getLeftY(), -m_controller.getRightX());
|
||||
}
|
||||
|
||||
/** This function is called once each time the robot enters test mode. */
|
||||
|
||||
@@ -50,8 +50,6 @@ public class Robot extends TimedRobot {
|
||||
@Override
|
||||
public void teleopPeriodic() {
|
||||
double turningValue = (kAngleSetpoint - m_gyro.getAngle()) * kP;
|
||||
// Invert the direction of the turn if we are going backwards
|
||||
turningValue = Math.copySign(turningValue, m_joystick.getY());
|
||||
m_myRobot.arcadeDrive(-m_joystick.getY(), turningValue);
|
||||
m_myRobot.arcadeDrive(-m_joystick.getY(), -turningValue);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ public class RobotContainer {
|
||||
new RunCommand(
|
||||
() ->
|
||||
m_robotDrive.arcadeDrive(
|
||||
-m_driverController.getLeftY(), m_driverController.getRightX()),
|
||||
-m_driverController.getLeftY(), -m_driverController.getRightX()),
|
||||
m_robotDrive));
|
||||
}
|
||||
|
||||
|
||||
@@ -51,6 +51,6 @@ public class Robot extends TimedRobot {
|
||||
@Override
|
||||
public void teleopPeriodic() {
|
||||
m_robotDrive.driveCartesian(
|
||||
-m_joystick.getY(), m_joystick.getX(), m_joystick.getZ(), m_gyro.getRotation2d());
|
||||
-m_joystick.getY(), -m_joystick.getX(), -m_joystick.getZ(), m_gyro.getRotation2d());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ public class RobotContainer {
|
||||
Commands.run(
|
||||
() ->
|
||||
m_robotDrive.arcadeDrive(
|
||||
-m_driverController.getLeftY(), m_driverController.getRightX()),
|
||||
-m_driverController.getLeftY(), -m_driverController.getRightX()),
|
||||
m_robotDrive));
|
||||
|
||||
// Add commands to the autonomous command chooser
|
||||
|
||||
@@ -60,7 +60,9 @@ public class RobotContainer {
|
||||
// A split-stick arcade command, with forward/backward controlled by the left
|
||||
// hand, and turning controlled by the right.
|
||||
new DefaultDrive(
|
||||
m_robotDrive, m_driverController::getLeftY, m_driverController::getRightX));
|
||||
m_robotDrive,
|
||||
() -> -m_driverController.getLeftY(),
|
||||
() -> -m_driverController.getRightX()));
|
||||
|
||||
// Add commands to the autonomous command chooser
|
||||
m_chooser.setDefaultOption("Simple Auto", m_simpleAuto);
|
||||
|
||||
@@ -51,9 +51,9 @@ public class RobotContainer {
|
||||
new RunCommand(
|
||||
() ->
|
||||
m_robotDrive.drive(
|
||||
m_driverController.getLeftY(),
|
||||
m_driverController.getRightX(),
|
||||
m_driverController.getLeftX(),
|
||||
-m_driverController.getLeftY(),
|
||||
-m_driverController.getRightX(),
|
||||
-m_driverController.getLeftX(),
|
||||
false),
|
||||
m_robotDrive));
|
||||
}
|
||||
|
||||
@@ -42,6 +42,6 @@ public class Robot extends TimedRobot {
|
||||
public void teleopPeriodic() {
|
||||
// Use the joystick X axis for forward movement, Y axis for lateral
|
||||
// movement, and Z axis for rotation.
|
||||
m_robotDrive.driveCartesian(-m_stick.getY(), m_stick.getX(), m_stick.getZ());
|
||||
m_robotDrive.driveCartesian(-m_stick.getY(), -m_stick.getX(), -m_stick.getZ());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ public class RobotContainer {
|
||||
new RunCommand(
|
||||
() ->
|
||||
m_robotDrive.arcadeDrive(
|
||||
-m_driverController.getLeftY(), m_driverController.getRightX()),
|
||||
-m_driverController.getLeftY(), -m_driverController.getRightX()),
|
||||
m_robotDrive));
|
||||
}
|
||||
|
||||
|
||||
@@ -52,7 +52,8 @@ public class RapidReactCommandBot {
|
||||
|
||||
// Control the drive with split-stick arcade controls
|
||||
m_drive.setDefaultCommand(
|
||||
m_drive.arcadeDriveCommand(m_driverController::getLeftY, m_driverController::getRightX));
|
||||
m_drive.arcadeDriveCommand(
|
||||
() -> -m_driverController.getLeftY(), () -> -m_driverController.getRightX()));
|
||||
|
||||
// Deploy the intake with the X button
|
||||
m_driverController.x().onTrue(m_intake.intakeCommand());
|
||||
|
||||
@@ -92,6 +92,6 @@ public class RobotContainer {
|
||||
*/
|
||||
public Command getArcadeDriveCommand() {
|
||||
return new ArcadeDrive(
|
||||
m_drivetrain, () -> -m_controller.getRawAxis(1), () -> m_controller.getRawAxis(2));
|
||||
m_drivetrain, () -> -m_controller.getRawAxis(1), () -> -m_controller.getRawAxis(2));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ public class RobotContainer {
|
||||
new RunCommand(
|
||||
() ->
|
||||
m_robotDrive.arcadeDrive(
|
||||
-m_driverController.getLeftY(), m_driverController.getRightX()),
|
||||
-m_driverController.getLeftY(), -m_driverController.getRightX()),
|
||||
m_robotDrive));
|
||||
}
|
||||
|
||||
|
||||
@@ -36,6 +36,6 @@ public class Robot extends TimedRobot {
|
||||
|
||||
@Override
|
||||
public void teleopPeriodic() {
|
||||
m_myRobot.tankDrive(m_leftStick.getY(), m_rightStick.getY());
|
||||
m_myRobot.tankDrive(-m_leftStick.getY(), -m_rightStick.getY());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user