mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
51 lines
2.0 KiB
C++
51 lines
2.0 KiB
C++
// Copyright (c) FIRST and other WPILib contributors.
|
|
// Open Source Software; you can modify and/or share it under the terms of
|
|
// the WPILib BSD license file in the root directory of this project.
|
|
|
|
#include "commands/ComplexAuto.h"
|
|
|
|
#include <frc2/command/FunctionalCommand.h>
|
|
#include <frc2/command/InstantCommand.h>
|
|
#include <frc2/command/ParallelRaceGroup.h>
|
|
|
|
using namespace AutoConstants;
|
|
|
|
ComplexAuto::ComplexAuto(DriveSubsystem* drive, HatchSubsystem* hatch) {
|
|
AddCommands(
|
|
// Drive forward the specified distance
|
|
frc2::FunctionalCommand(
|
|
// Reset encoders on command start
|
|
[drive] { drive->ResetEncoders(); },
|
|
// Drive forward while the command is executing
|
|
[drive] { drive->ArcadeDrive(kAutoDriveSpeed, 0); },
|
|
// Stop driving at the end of the command
|
|
[drive](bool interrupted) { drive->ArcadeDrive(0, 0); },
|
|
// End the command when the robot's driven distance exceeds the
|
|
// desired value
|
|
[drive] {
|
|
return drive->GetAverageEncoderDistance() >=
|
|
kAutoDriveDistanceInches;
|
|
},
|
|
// Requires the drive subsystem
|
|
{drive}),
|
|
// Release the hatch
|
|
frc2::InstantCommand([hatch] { hatch->ReleaseHatch(); }, {hatch}),
|
|
// Drive backward the specified distance
|
|
// Drive forward the specified distance
|
|
frc2::FunctionalCommand(
|
|
// Reset encoders on command start
|
|
[drive] { drive->ResetEncoders(); },
|
|
// Drive backward while the command is executing
|
|
[drive] { drive->ArcadeDrive(-kAutoDriveSpeed, 0); },
|
|
// Stop driving at the end of the command
|
|
[drive](bool interrupted) { drive->ArcadeDrive(0, 0); },
|
|
// End the command when the robot's driven distance exceeds the
|
|
// desired value
|
|
[drive] {
|
|
return drive->GetAverageEncoderDistance() <=
|
|
kAutoBackupDistanceInches;
|
|
},
|
|
// Requires the drive subsystem
|
|
{drive}));
|
|
}
|