Files
allwpilib/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/cpp/commands/ComplexAuto.cpp
Starlight220 10e04e2b13 [examples] FrisbeeBot: Fix reference capture (#4449)
The parameter should be passed by value.
2022-10-02 08:18:43 -05:00

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}));
}