diff --git a/shared/examplecheck.gradle b/shared/examplecheck.gradle index 4e7bdc2be5..3d05c67292 100644 --- a/shared/examplecheck.gradle +++ b/shared/examplecheck.gradle @@ -70,6 +70,7 @@ task checkCommands(type: Task) { assert it.tags != null assert it.foldername != null assert it.replacename != null + assert it.commandversion != null if (project.isCppCommands) { assert it.headers != null assert !it.headers.isEmpty() diff --git a/wpilibcExamples/src/main/cpp/commands/command2/ReplaceMeCommand2.cpp b/wpilibcExamples/src/main/cpp/commands/command2/ReplaceMeCommand2.cpp new file mode 100644 index 0000000000..e8085a1b17 --- /dev/null +++ b/wpilibcExamples/src/main/cpp/commands/command2/ReplaceMeCommand2.cpp @@ -0,0 +1,24 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 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 "ReplaceMeCommand2.h" + +ReplaceMeCommand2::ReplaceMeCommand2() { + // Use addRequirements() here to declare subsystem dependencies. +} + +// Called when the command is initially scheduled. +void ReplaceMeCommand2::Initialize() {} + +// Called repeatedly when this Command is scheduled to run +void ReplaceMeCommand2::Execute() {} + +// Called once the command ends or is interrupted. +void ReplaceMeCommand2::End(bool interrupted) {} + +// Returns true when the command should end. +bool ReplaceMeCommand2::IsFinished() { return false; } diff --git a/wpilibcExamples/src/main/cpp/commands/command2/ReplaceMeCommand2.h b/wpilibcExamples/src/main/cpp/commands/command2/ReplaceMeCommand2.h new file mode 100644 index 0000000000..fd041fad28 --- /dev/null +++ b/wpilibcExamples/src/main/cpp/commands/command2/ReplaceMeCommand2.h @@ -0,0 +1,32 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 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. */ +/*----------------------------------------------------------------------------*/ + +#pragma once + +#include +#include + +/** + * An example command. + * + *

Note that this extends CommandHelper, rather extending CommandBase + * directly; this is crucially important, or else the decorator functions in + * Command will *not* work! + */ +class ReplaceMeCommand2 + : public frc2::CommandHelper { + public: + ReplaceMeCommand2(); + + void Initialize() override; + + void Execute() override; + + void End(bool interrupted) override; + + bool IsFinished() override; +}; diff --git a/wpilibcExamples/src/main/cpp/commands/commands.json b/wpilibcExamples/src/main/cpp/commands/commands.json index bb8cbb6950..d039a73364 100644 --- a/wpilibcExamples/src/main/cpp/commands/commands.json +++ b/wpilibcExamples/src/main/cpp/commands/commands.json @@ -12,10 +12,11 @@ "source": [ "ReplaceMeEmptyClass.cpp" ], - "replacename": "ReplaceMeEmptyClass" + "replacename": "ReplaceMeEmptyClass", + "commandversion": 0 }, { - "name": "Command", + "name": "Command (Old)", "description": "Create a base command", "tags": [ "command" @@ -27,10 +28,11 @@ "source": [ "ReplaceMeCommand.cpp" ], - "replacename": "ReplaceMeCommand" + "replacename": "ReplaceMeCommand", + "commandversion": 1 }, { - "name": "Command Group", + "name": "Command Group (Old)", "description": "Create a command group", "tags": [ "commandgroup" @@ -42,10 +44,11 @@ "source": [ "ReplaceMeCommandGroup.cpp" ], - "replacename": "ReplaceMeCommandGroup" + "replacename": "ReplaceMeCommandGroup", + "commandversion": 1 }, { - "name": "Instant Command", + "name": "Instant Command (Old)", "description": "A command that runs immediately", "tags": [ "instantcommand" @@ -57,10 +60,11 @@ "source": [ "ReplaceMeInstantCommand.cpp" ], - "replacename": "ReplaceMeInstantCommand" + "replacename": "ReplaceMeInstantCommand", + "commandversion": 1 }, { - "name": "Subsystem", + "name": "Subsystem (Old)", "description": "A subsystem", "tags": [ "subsystem" @@ -72,10 +76,11 @@ "source": [ "ReplaceMeSubsystem.cpp" ], - "replacename": "ReplaceMeSubsystem" + "replacename": "ReplaceMeSubsystem", + "commandversion": 1 }, { - "name": "PID Subsystem", + "name": "PID Subsystem (Old)", "description": "A subsystem that runs a PID loop", "tags": [ "pidsubsystem", @@ -88,10 +93,11 @@ "source": [ "ReplaceMePIDSubsystem.cpp" ], - "replacename": "ReplaceMePIDSubsystem" + "replacename": "ReplaceMePIDSubsystem", + "commandversion": 1 }, { - "name": "Timed Command", + "name": "Timed Command (Old)", "description": "A command that runs for a specified time", "tags": [ "timedcommand" @@ -103,10 +109,11 @@ "source": [ "ReplaceMeTimedCommand.cpp" ], - "replacename": "ReplaceMeTimedCommand" + "replacename": "ReplaceMeTimedCommand", + "commandversion": 1 }, { - "name": "Trigger", + "name": "Trigger (Old)", "description": "A command that runs off of a trigger", "tags": [ "trigger" @@ -118,6 +125,215 @@ "source": [ "ReplaceMeTrigger.cpp" ], - "replacename": "ReplaceMeTrigger" + "replacename": "ReplaceMeTrigger", + "commandversion": 1 + }, + { + "name": "Command (New)", + "description": "A command.", + "tags": [ + "command" + ], + "foldername": "command2", + "headers": [ + "ReplaceMeCommand2.h" + ], + "source": [ + "ReplaceMeCommand2.cpp" + ], + "replacename": "ReplaceMeCommand2", + "commandversion": 2 + }, + { + "name": "InstantCommand (New)", + "description": "A command that finishes instantly.", + "tags": [ + "instantcommand" + ], + "foldername": "instantcommand", + "headers": [ + "ReplaceMeInstantCommand2.h" + ], + "source": [ + "ReplaceMeInstantCommand2.cpp" + ], + "replacename": "ReplaceMeInstantCommand2", + "commandversion": 2 + }, + { + "name": "ParallelCommandGroup (New)", + "description": "A command group that runs commands in parallel, ending when all commands have finished.", + "tags": [ + "parallelcommandgroup" + ], + "foldername": "parallelcommandgroup", + "headers": [ + "ReplaceMeParallelCommandGroup.h" + ], + "source": [ + "ReplaceMeParallelCommandGroup.cpp" + ], + "replacename": "ReplaceMeParallelCommandGroup", + "commandversion": 2 + }, + { + "name": "ParallelDeadlineGroup (New)", + "description": "A command group that runs commands in parallel, ending when a specific command has finished.", + "tags": [ + "paralleldeadlinegroup" + ], + "foldername": "paralleldeadlinegroup", + "headers": [ + "ReplaceMeParallelDeadlineGroup.h" + ], + "source": [ + "ReplaceMeParallelDeadlineGroup.cpp" + ], + "replacename": "ReplaceMeParallelDeadlineGroup", + "commandversion": 2 + }, + { + "name": "ParallelRaceGroup (New)", + "description": "A command that runs commands in parallel, ending as soon as any command has finished.", + "tags": [ + "parallelracegroup" + ], + "foldername": "parallelracegroup", + "headers": [ + "ReplaceMeParallelRaceGroup.h" + ], + "source": [ + "ReplaceMeParallelRaceGroup.cpp" + ], + "replacename": "ReplaceMeParallelRaceGroup", + "commandversion": 2 + }, + { + "name": "PIDCommand (New)", + "description": "A command that runs a PIDController.", + "tags": [ + "pidcommand" + ], + "foldername": "pidcommand", + "headers": [ + "ReplaceMePIDCommand.h" + ], + "source": [ + "ReplaceMePIDCommand.cpp" + ], + "replacename": "ReplaceMePIDCommand", + "commandversion": 2 + }, + { + "name": "PIDSubsystem (New)", + "description": "A subsystem that runs a PIDController.", + "tags": [ + "pidsubsystem" + ], + "foldername": "pidsubsystem2", + "headers": [ + "ReplaceMePIDSubsystem2.h" + ], + "source": [ + "ReplaceMePIDSubsystem2.cpp" + ], + "replacename": "ReplaceMePIDSubsystem2", + "commandversion": 2 + }, + { + "name": "ProfiledPIDCommand (New)", + "description": "A command that runs a ProfiledPIDController.", + "tags": [ + "profiledpidcommand" + ], + "foldername": "profiledpidcommand", + "headers": [ + "ReplaceMeProfiledPIDCommand.h" + ], + "source": [ + "ReplaceMeProfiledPIDCommand.cpp" + ], + "replacename": "ReplaceMeProfiledPIDCommand", + "commandversion": 2 + }, + { + "name": "ProfiledPIDSubsystem (New)", + "description": "A subsystem that runs a ProfiledPIDController.", + "tags": [ + "profiledpidsubsystem" + ], + "foldername": "profiledpidsubsystem", + "headers": [ + "ReplaceMeProfiledPIDSubsystem.h" + ], + "source": [ + "ReplaceMeProfiledPIDSubsystem.cpp" + ], + "replacename": "ReplaceMeProfiledPIDSubsystem", + "commandversion": 2 + }, + { + "name": "SequentialCommandGroup (New)", + "description": "A command group that runs commands in sequence.", + "tags": [ + "sequentialcommandgroup" + ], + "foldername": "sequentialcommandgroup", + "headers": [ + "ReplaceMeSequentialCommandGroup.h" + ], + "source": [ + "ReplaceMeSequentialCommandGroup.cpp" + ], + "replacename": "ReplaceMeSequentialCommandGroup", + "commandversion": 2 + }, + { + "name": "Subsystem (New)", + "description": "A robot subsystem.", + "tags": [ + "subsystem" + ], + "foldername": "subsystem2", + "headers": [ + "ReplaceMeSubsystem2.h" + ], + "source": [ + "ReplaceMeSubsystem2.cpp" + ], + "replacename": "ReplaceMeSubsystem2", + "commandversion": 2 + }, + { + "name": "TrapezoidProfileCommand (New)", + "description": "A command that executes a trapezoidal motion profile.", + "tags": [ + "trapezoidprofilecommand" + ], + "foldername": "trapezoidprofilecommand", + "headers": [ + "ReplaceMeTrapezoidProfileCommand.h" + ], + "source": [ + "ReplaceMeTrapezoidProfileCommand.cpp" + ], + "replacename": "ReplaceMeTrapezoidProfileCommand", + "commandversion": 2 + }, + { + "name": "TrapezoidProfileSubsystem (New)", + "description": "A command that executes a trapezoidal motion profile.", + "tags": [ + "trapezoidprofilesubsystem" + ], + "foldername": "trapezoidprofilesubsystem", + "headers": [ + "ReplaceMeTrapezoidProfileSubsystem.h" + ], + "source": [ + "ReplaceMeTrapezoidProfileSubsystem.cpp" + ], + "replacename": "ReplaceMeTrapezoidProfileSubsystem", + "commandversion": 2 } ] diff --git a/wpilibcExamples/src/main/cpp/commands/instantcommand/ReplaceMeInstantCommand2.cpp b/wpilibcExamples/src/main/cpp/commands/instantcommand/ReplaceMeInstantCommand2.cpp new file mode 100644 index 0000000000..bf54a0a5cc --- /dev/null +++ b/wpilibcExamples/src/main/cpp/commands/instantcommand/ReplaceMeInstantCommand2.cpp @@ -0,0 +1,18 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 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 "ReplaceMeInstantCommand2.h" + +// NOTE: Consider using this command inline, rather than writing a subclass. +// For more information, see: +// https://docs.wpilib.org/en/latest/docs/software/commandbased/convenience-features.html +ReplaceMeInstantCommand2::ReplaceMeInstantCommand2() { + // Use addRequirements() here to declare subsystem dependencies. +} + +// Called when the command is initially scheduled. +void ReplaceMeInstantCommand2::Initialize() {} diff --git a/wpilibcExamples/src/main/cpp/commands/instantcommand/ReplaceMeInstantCommand2.h b/wpilibcExamples/src/main/cpp/commands/instantcommand/ReplaceMeInstantCommand2.h new file mode 100644 index 0000000000..dec11c25a5 --- /dev/null +++ b/wpilibcExamples/src/main/cpp/commands/instantcommand/ReplaceMeInstantCommand2.h @@ -0,0 +1,20 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 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. */ +/*----------------------------------------------------------------------------*/ + +#pragma once + +#include +#include + +class ReplaceMeInstantCommand2 + : public frc2::CommandHelper { + public: + ReplaceMeInstantCommand2(); + + void Initialize() override; +}; diff --git a/wpilibcExamples/src/main/cpp/commands/parallelcommandgroup/ReplaceMeParallelCommandGroup.cpp b/wpilibcExamples/src/main/cpp/commands/parallelcommandgroup/ReplaceMeParallelCommandGroup.cpp new file mode 100644 index 0000000000..aa99a3c123 --- /dev/null +++ b/wpilibcExamples/src/main/cpp/commands/parallelcommandgroup/ReplaceMeParallelCommandGroup.cpp @@ -0,0 +1,16 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 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 "ReplaceMeParallelCommandGroup.h" + +// NOTE: Consider using this command inline, rather than writing a subclass. +// For more information, see: +// https://docs.wpilib.org/en/latest/docs/software/commandbased/convenience-features.html +ReplaceMeParallelCommandGroup::ReplaceMeParallelCommandGroup() { + // Add your commands here, e.g. + // AddCommands(FooCommand(), BarCommand()); +} diff --git a/wpilibcExamples/src/main/cpp/commands/parallelcommandgroup/ReplaceMeParallelCommandGroup.h b/wpilibcExamples/src/main/cpp/commands/parallelcommandgroup/ReplaceMeParallelCommandGroup.h new file mode 100644 index 0000000000..a4f9519216 --- /dev/null +++ b/wpilibcExamples/src/main/cpp/commands/parallelcommandgroup/ReplaceMeParallelCommandGroup.h @@ -0,0 +1,18 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 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. */ +/*----------------------------------------------------------------------------*/ + +#pragma once + +#include +#include + +class ReplaceMeParallelCommandGroup + : public frc2::CommandHelper { + public: + ReplaceMeParallelCommandGroup(); +}; diff --git a/wpilibcExamples/src/main/cpp/commands/paralleldeadlinegroup/ReplaceMeParallelDeadlineGroup.cpp b/wpilibcExamples/src/main/cpp/commands/paralleldeadlinegroup/ReplaceMeParallelDeadlineGroup.cpp new file mode 100644 index 0000000000..1cfcfa000b --- /dev/null +++ b/wpilibcExamples/src/main/cpp/commands/paralleldeadlinegroup/ReplaceMeParallelDeadlineGroup.cpp @@ -0,0 +1,21 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 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 "ReplaceMeParallelDeadlineGroup.h" + +#include + +// NOTE: Consider using this command inline, rather than writing a subclass. +// For more information, see: +// https://docs.wpilib.org/en/latest/docs/software/commandbased/convenience-features.html +ReplaceMeParallelDeadlineGroup::ReplaceMeParallelDeadlineGroup() + : CommandHelper( + // The deadline command + frc2::InstantCommand([] {})) { + // Add your commands here, e.g. + // AddCommands(FooCommand(), BarCommand()); +} diff --git a/wpilibcExamples/src/main/cpp/commands/paralleldeadlinegroup/ReplaceMeParallelDeadlineGroup.h b/wpilibcExamples/src/main/cpp/commands/paralleldeadlinegroup/ReplaceMeParallelDeadlineGroup.h new file mode 100644 index 0000000000..7ecebb4f7e --- /dev/null +++ b/wpilibcExamples/src/main/cpp/commands/paralleldeadlinegroup/ReplaceMeParallelDeadlineGroup.h @@ -0,0 +1,18 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 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. */ +/*----------------------------------------------------------------------------*/ + +#pragma once + +#include +#include + +class ReplaceMeParallelDeadlineGroup + : public frc2::CommandHelper { + public: + ReplaceMeParallelDeadlineGroup(); +}; diff --git a/wpilibcExamples/src/main/cpp/commands/parallelracegroup/ReplaceMeParallelRaceGroup.cpp b/wpilibcExamples/src/main/cpp/commands/parallelracegroup/ReplaceMeParallelRaceGroup.cpp new file mode 100644 index 0000000000..f3f1d86942 --- /dev/null +++ b/wpilibcExamples/src/main/cpp/commands/parallelracegroup/ReplaceMeParallelRaceGroup.cpp @@ -0,0 +1,16 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 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 "ReplaceMeParallelRaceGroup.h" + +// NOTE: Consider using this command inline, rather than writing a subclass. +// For more information, see: +// https://docs.wpilib.org/en/latest/docs/software/commandbased/convenience-features.html +ReplaceMeParallelRaceGroup::ReplaceMeParallelRaceGroup() { + // Add your commands here, e.g. + // AddCommands(FooCommand(), BarCommand()); +} diff --git a/wpilibcExamples/src/main/cpp/commands/parallelracegroup/ReplaceMeParallelRaceGroup.h b/wpilibcExamples/src/main/cpp/commands/parallelracegroup/ReplaceMeParallelRaceGroup.h new file mode 100644 index 0000000000..0b13b18774 --- /dev/null +++ b/wpilibcExamples/src/main/cpp/commands/parallelracegroup/ReplaceMeParallelRaceGroup.h @@ -0,0 +1,18 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 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. */ +/*----------------------------------------------------------------------------*/ + +#pragma once + +#include +#include + +class ReplaceMeParallelRaceGroup + : public frc2::CommandHelper { + public: + ReplaceMeParallelRaceGroup(); +}; diff --git a/wpilibcExamples/src/main/cpp/commands/pidcommand/ReplaceMePIDCommand.cpp b/wpilibcExamples/src/main/cpp/commands/pidcommand/ReplaceMePIDCommand.cpp new file mode 100644 index 0000000000..b465b1eea0 --- /dev/null +++ b/wpilibcExamples/src/main/cpp/commands/pidcommand/ReplaceMePIDCommand.cpp @@ -0,0 +1,25 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 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 "ReplaceMePIDCommand.h" + +// NOTE: Consider using this command inline, rather than writing a subclass. +// For more information, see: +// https://docs.wpilib.org/en/latest/docs/software/commandbased/convenience-features.html +ReplaceMePIDCommand::ReplaceMePIDCommand() + : CommandHelper(frc2::PIDController(0, 0, 0), + // This should return the measurement + [] { return 0; }, + // This should return the setpoint (can also be a constant) + [] { return 0; }, + // This uses the output + [](double output) { + // Use the output here + }) {} + +// Returns true when the command should end. +bool ReplaceMePIDCommand::IsFinished() { return false; } diff --git a/wpilibcExamples/src/main/cpp/commands/pidcommand/ReplaceMePIDCommand.h b/wpilibcExamples/src/main/cpp/commands/pidcommand/ReplaceMePIDCommand.h new file mode 100644 index 0000000000..03c874c676 --- /dev/null +++ b/wpilibcExamples/src/main/cpp/commands/pidcommand/ReplaceMePIDCommand.h @@ -0,0 +1,19 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 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. */ +/*----------------------------------------------------------------------------*/ + +#pragma once + +#include +#include + +class ReplaceMePIDCommand + : public frc2::CommandHelper { + public: + ReplaceMePIDCommand(); + + bool IsFinished() override; +}; diff --git a/wpilibcExamples/src/main/cpp/commands/pidsubsystem2/ReplaceMePIDSubsystem2.cpp b/wpilibcExamples/src/main/cpp/commands/pidsubsystem2/ReplaceMePIDSubsystem2.cpp new file mode 100644 index 0000000000..0fa81a2ae2 --- /dev/null +++ b/wpilibcExamples/src/main/cpp/commands/pidsubsystem2/ReplaceMePIDSubsystem2.cpp @@ -0,0 +1,22 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 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 "ReplaceMePIDSubsystem2.h" + +ReplaceMePIDSubsystem2::ReplaceMePIDSubsystem2() + : PIDSubsystem( + // The PIDController used by the subsystem + frc2::PIDController(0, 0, 0)) {} + +void ReplaceMePIDSubsystem2::UseOutput(double output, double setpoint) { + // Use the output here +} + +double ReplaceMePIDSubsystem2::GetMeasurement() { + // Return the process variable measurement here + return 0; +} diff --git a/wpilibcExamples/src/main/cpp/commands/pidsubsystem2/ReplaceMePIDSubsystem2.h b/wpilibcExamples/src/main/cpp/commands/pidsubsystem2/ReplaceMePIDSubsystem2.h new file mode 100644 index 0000000000..6c8e344ed3 --- /dev/null +++ b/wpilibcExamples/src/main/cpp/commands/pidsubsystem2/ReplaceMePIDSubsystem2.h @@ -0,0 +1,20 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 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. */ +/*----------------------------------------------------------------------------*/ + +#pragma once + +#include + +class ReplaceMePIDSubsystem2 : public frc2::PIDSubsystem { + public: + ReplaceMePIDSubsystem2(); + + protected: + void UseOutput(double output, double setpoint) override; + + double GetMeasurement() override; +}; diff --git a/wpilibcExamples/src/main/cpp/commands/profiledpidcommand/ReplaceMeProfiledPIDCommand.cpp b/wpilibcExamples/src/main/cpp/commands/profiledpidcommand/ReplaceMeProfiledPIDCommand.cpp new file mode 100644 index 0000000000..392e643514 --- /dev/null +++ b/wpilibcExamples/src/main/cpp/commands/profiledpidcommand/ReplaceMeProfiledPIDCommand.cpp @@ -0,0 +1,34 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 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 "ReplaceMeProfiledPIDCommand.h" + +// NOTE: Consider using this command inline, rather than writing a subclass. +// For more information, see: +// https://docs.wpilib.org/en/latest/docs/software/commandbased/convenience-features.html +ReplaceMeProfiledPIDCommand::ReplaceMeProfiledPIDCommand() + : CommandHelper( + // The ProfiledPIDController that the command will use + frc::ProfiledPIDController( + // The PID gains + 0, 0, 0, + // The motion profile constraints + {0_mps, 0_mps_sq}), + // This should return the measurement + [] { return 0_m; }, + // This should return the goal state (can also be a constant) + [] { + return frc::TrapezoidProfile::State{0_m, 0_mps}; + }, + // This uses the output and current trajectory setpoint + [](double output, + frc::TrapezoidProfile::State setpoint) { + // Use the output and setpoint here + }) {} + +// Returns true when the command should end. +bool ReplaceMeProfiledPIDCommand::IsFinished() { return false; } diff --git a/wpilibcExamples/src/main/cpp/commands/profiledpidcommand/ReplaceMeProfiledPIDCommand.h b/wpilibcExamples/src/main/cpp/commands/profiledpidcommand/ReplaceMeProfiledPIDCommand.h new file mode 100644 index 0000000000..d3407e8880 --- /dev/null +++ b/wpilibcExamples/src/main/cpp/commands/profiledpidcommand/ReplaceMeProfiledPIDCommand.h @@ -0,0 +1,20 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 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. */ +/*----------------------------------------------------------------------------*/ + +#pragma once + +#include +#include + +class ReplaceMeProfiledPIDCommand + : public frc2::CommandHelper, + ReplaceMeProfiledPIDCommand> { + public: + ReplaceMeProfiledPIDCommand(); + + bool IsFinished() override; +}; diff --git a/wpilibcExamples/src/main/cpp/commands/profiledpidsubsystem/ReplaceMeProfiledPIDSubsystem.cpp b/wpilibcExamples/src/main/cpp/commands/profiledpidsubsystem/ReplaceMeProfiledPIDSubsystem.cpp new file mode 100644 index 0000000000..dc27b4357f --- /dev/null +++ b/wpilibcExamples/src/main/cpp/commands/profiledpidsubsystem/ReplaceMeProfiledPIDSubsystem.cpp @@ -0,0 +1,27 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 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 "ReplaceMeProfiledPIDSubsystem.h" + +ReplaceMeProfiledPIDSubsystem::ReplaceMeProfiledPIDSubsystem() + : ProfiledPIDSubsystem( + // The ProfiledPIDController used by the subsystem + frc::ProfiledPIDController( + // The PID gains + 0, 0, 0, + // The constraints for the motion profiles + {0_mps, 0_mps_sq})) {} + +void ReplaceMeProfiledPIDSubsystem::UseOutput( + double output, frc::TrapezoidProfile::State setpoint) { + // Use the output and current trajectory setpoint here +} + +units::meter_t ReplaceMeProfiledPIDSubsystem::GetMeasurement() { + // Return the process variable measurement here + return 0_m; +} diff --git a/wpilibcExamples/src/main/cpp/commands/profiledpidsubsystem/ReplaceMeProfiledPIDSubsystem.h b/wpilibcExamples/src/main/cpp/commands/profiledpidsubsystem/ReplaceMeProfiledPIDSubsystem.h new file mode 100644 index 0000000000..b382b1df54 --- /dev/null +++ b/wpilibcExamples/src/main/cpp/commands/profiledpidsubsystem/ReplaceMeProfiledPIDSubsystem.h @@ -0,0 +1,22 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 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. */ +/*----------------------------------------------------------------------------*/ + +#pragma once + +#include + +class ReplaceMeProfiledPIDSubsystem + : public frc2::ProfiledPIDSubsystem { + public: + ReplaceMeProfiledPIDSubsystem(); + + protected: + void UseOutput(double output, + frc::TrapezoidProfile::State setpoint) override; + + units::meter_t GetMeasurement() override; +}; diff --git a/wpilibcExamples/src/main/cpp/commands/sequentialcommandgroup/ReplaceMeSequentialCommandGroup.cpp b/wpilibcExamples/src/main/cpp/commands/sequentialcommandgroup/ReplaceMeSequentialCommandGroup.cpp new file mode 100644 index 0000000000..3a5fadc4da --- /dev/null +++ b/wpilibcExamples/src/main/cpp/commands/sequentialcommandgroup/ReplaceMeSequentialCommandGroup.cpp @@ -0,0 +1,16 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 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 "ReplaceMeSequentialCommandGroup.h" + +// NOTE: Consider using this command inline, rather than writing a subclass. +// For more information, see: +// https://docs.wpilib.org/en/latest/docs/software/commandbased/convenience-features.html +ReplaceMeSequentialCommandGroup::ReplaceMeSequentialCommandGroup() { + // Add your commands here, e.g. + // AddCommands(FooCommand(), BarCommand()); +} diff --git a/wpilibcExamples/src/main/cpp/commands/sequentialcommandgroup/ReplaceMeSequentialCommandGroup.h b/wpilibcExamples/src/main/cpp/commands/sequentialcommandgroup/ReplaceMeSequentialCommandGroup.h new file mode 100644 index 0000000000..5e629b86d5 --- /dev/null +++ b/wpilibcExamples/src/main/cpp/commands/sequentialcommandgroup/ReplaceMeSequentialCommandGroup.h @@ -0,0 +1,18 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 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. */ +/*----------------------------------------------------------------------------*/ + +#pragma once + +#include +#include + +class ReplaceMeSequentialCommandGroup + : public frc2::CommandHelper { + public: + ReplaceMeSequentialCommandGroup(); +}; diff --git a/wpilibcExamples/src/main/cpp/commands/subsystem2/ReplaceMeSubsystem2.cpp b/wpilibcExamples/src/main/cpp/commands/subsystem2/ReplaceMeSubsystem2.cpp new file mode 100644 index 0000000000..5d6805ab5d --- /dev/null +++ b/wpilibcExamples/src/main/cpp/commands/subsystem2/ReplaceMeSubsystem2.cpp @@ -0,0 +1,13 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 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 "ReplaceMeSubsystem2.h" + +ReplaceMeSubsystem2::ReplaceMeSubsystem2() {} + +// This method will be called once per scheduler run +void ReplaceMeSubsystem2::Periodic() {} diff --git a/wpilibcExamples/src/main/cpp/commands/subsystem2/ReplaceMeSubsystem2.h b/wpilibcExamples/src/main/cpp/commands/subsystem2/ReplaceMeSubsystem2.h new file mode 100644 index 0000000000..6f15f467e2 --- /dev/null +++ b/wpilibcExamples/src/main/cpp/commands/subsystem2/ReplaceMeSubsystem2.h @@ -0,0 +1,24 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 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. */ +/*----------------------------------------------------------------------------*/ + +#pragma once + +#include + +class ReplaceMeSubsystem2 : public frc2::SubsystemBase { + public: + ReplaceMeSubsystem2(); + + /** + * Will be called periodically whenever the CommandScheduler runs. + */ + void Periodic(); + + private: + // Components (e.g. motor controllers and sensors) should generally be + // declared private and exposed only through public methods. +}; diff --git a/wpilibcExamples/src/main/cpp/commands/trapezoidprofilecommand/ReplaceMeTrapezoidProfileCommand.cpp b/wpilibcExamples/src/main/cpp/commands/trapezoidprofilecommand/ReplaceMeTrapezoidProfileCommand.cpp new file mode 100644 index 0000000000..b8cb678657 --- /dev/null +++ b/wpilibcExamples/src/main/cpp/commands/trapezoidprofilecommand/ReplaceMeTrapezoidProfileCommand.cpp @@ -0,0 +1,25 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 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 "ReplaceMeTrapezoidProfileCommand.h" + +// NOTE: Consider using this command inline, rather than writing a subclass. +// For more information, see: +// https://docs.wpilib.org/en/latest/docs/software/commandbased/convenience-features.html +ReplaceMeTrapezoidProfileCommand::ReplaceMeTrapezoidProfileCommand() + : CommandHelper + // The profile to execute + (frc::TrapezoidProfile( + // The maximum velocity and acceleration of the profile + {5_mps, 5_mps_sq}, + // The goal state of the profile + {10_m, 0_mps}, + // The initial state of the profile + {0_m, 0_mps}), + [](frc::TrapezoidProfile::State state) { + // Use the computed intermediate trajectory state here + }) {} diff --git a/wpilibcExamples/src/main/cpp/commands/trapezoidprofilecommand/ReplaceMeTrapezoidProfileCommand.h b/wpilibcExamples/src/main/cpp/commands/trapezoidprofilecommand/ReplaceMeTrapezoidProfileCommand.h new file mode 100644 index 0000000000..e9043be551 --- /dev/null +++ b/wpilibcExamples/src/main/cpp/commands/trapezoidprofilecommand/ReplaceMeTrapezoidProfileCommand.h @@ -0,0 +1,18 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 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. */ +/*----------------------------------------------------------------------------*/ + +#pragma once + +#include +#include + +class ReplaceMeTrapezoidProfileCommand + : public frc2::CommandHelper, + ReplaceMeTrapezoidProfileCommand> { + public: + ReplaceMeTrapezoidProfileCommand(); +}; diff --git a/wpilibcExamples/src/main/cpp/commands/trapezoidprofilesubsystem/ReplaceMeTrapezoidProfileSubsystem.cpp b/wpilibcExamples/src/main/cpp/commands/trapezoidprofilesubsystem/ReplaceMeTrapezoidProfileSubsystem.cpp new file mode 100644 index 0000000000..162c02f084 --- /dev/null +++ b/wpilibcExamples/src/main/cpp/commands/trapezoidprofilesubsystem/ReplaceMeTrapezoidProfileSubsystem.cpp @@ -0,0 +1,20 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 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 "ReplaceMeTrapezoidProfileSubsystem.h" + +ReplaceMeTrapezoidProfileSubsystem::ReplaceMeTrapezoidProfileSubsystem() + : TrapezoidProfileSubsystem( + // The motion profile constraints + {5_mps, 5_mps_sq}, + // The initial position of the mechanism + 0_m) {} + +void ReplaceMeTrapezoidProfileSubsystem::UseState( + frc::TrapezoidProfile::State state) { + // Use the current profile state here +} diff --git a/wpilibcExamples/src/main/cpp/commands/trapezoidprofilesubsystem/ReplaceMeTrapezoidProfileSubsystem.h b/wpilibcExamples/src/main/cpp/commands/trapezoidprofilesubsystem/ReplaceMeTrapezoidProfileSubsystem.h new file mode 100644 index 0000000000..e93f590300 --- /dev/null +++ b/wpilibcExamples/src/main/cpp/commands/trapezoidprofilesubsystem/ReplaceMeTrapezoidProfileSubsystem.h @@ -0,0 +1,19 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 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. */ +/*----------------------------------------------------------------------------*/ + +#pragma once + +#include + +class ReplaceMeTrapezoidProfileSubsystem + : frc2::TrapezoidProfileSubsystem { + public: + ReplaceMeTrapezoidProfileSubsystem(); + + protected: + void UseState(frc::TrapezoidProfile::State state) override; +}; diff --git a/wpilibcExamples/src/main/cpp/templates/commandbased/include/subsystems/ExampleSubsystem.h b/wpilibcExamples/src/main/cpp/templates/commandbased/include/subsystems/ExampleSubsystem.h index 763eafdac0..f6cd550514 100644 --- a/wpilibcExamples/src/main/cpp/templates/commandbased/include/subsystems/ExampleSubsystem.h +++ b/wpilibcExamples/src/main/cpp/templates/commandbased/include/subsystems/ExampleSubsystem.h @@ -18,8 +18,6 @@ class ExampleSubsystem : public frc2::SubsystemBase { */ void Periodic() override; - // Subsystem methods go here. - private: // Components (e.g. motor controllers and sensors) should generally be // declared private and exposed only through public methods. diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/command2/ReplaceMeCommand.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/command2/ReplaceMeCommand.java new file mode 100644 index 0000000000..5d3a501be4 --- /dev/null +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/command2/ReplaceMeCommand.java @@ -0,0 +1,40 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 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. */ +/*----------------------------------------------------------------------------*/ + +package edu.wpi.first.wpilibj.commands.command2; + +import edu.wpi.first.wpilibj2.command.CommandBase; + +public class ReplaceMeCommand extends CommandBase { + /** + * Creates a new ReplaceMeCommand. + */ + public ReplaceMeCommand() { + // Use addRequirements() here to declare subsystem dependencies. + } + + // Called when the command is initially scheduled. + @Override + public void initialize() { + } + + // Called every time the scheduler runs while the command is scheduled. + @Override + public void execute() { + } + + // Called once the command ends or is interrupted. + @Override + public void end(boolean interrupted) { + } + + // Returns true when the command should end. + @Override + public boolean isFinished() { + return false; + } +} diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/commands.json b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/commands.json index 289492658e..a0f3a61e3c 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/commands.json +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/commands.json @@ -6,34 +6,38 @@ "class" ], "foldername": "emptyclass", - "replacename": "ReplaceMeEmptyClass" + "replacename": "ReplaceMeEmptyClass", + "commandversion": 0 }, { - "name": "Command", + "name": "Command (Old)", "description": "Create a base command", "tags": [ "command" ], "foldername": "command", - "replacename": "ReplaceMeCommand" + "replacename": "ReplaceMeCommand", + "commandversion": 1 }, { - "name": "Command Group", + "name": "Command Group (Old)", "description": "Create a command group", "tags": [ "commandgroup" ], "foldername": "commandgroup", - "replacename": "ReplaceMeCommandGroup" + "replacename": "ReplaceMeCommandGroup", + "commandversion": 1 }, { - "name": "Instant Command", + "name": "Instant Command (Old)", "description": "A command that runs immediately", "tags": [ "instantcommand" ], "foldername": "instant", - "replacename": "ReplaceMeInstantCommand" + "replacename": "ReplaceMeInstantCommand", + "commandversion": 1 }, { "name": "Subsystem", @@ -42,34 +46,168 @@ "subsystem" ], "foldername": "subsystem", - "replacename": "ReplaceMeSubsystem" + "replacename": "ReplaceMeSubsystem", + "commandversion": 1 }, { - "name": "PID Subsystem", + "name": "PID Subsystem (Old)", "description": "A subsystem that runs a PID loop", "tags": [ "pidsubsystem", "pid" ], "foldername": "pidsubsystem", - "replacename": "ReplaceMePIDSubsystem" + "replacename": "ReplaceMePIDSubsystem", + "commandversion": 1 }, { - "name": "Timed Command", + "name": "Timed Command (Old)", "description": "A command that runs for a specified time", "tags": [ "timedcommand" ], "foldername": "timed", - "replacename": "ReplaceMeTimedCommand" + "replacename": "ReplaceMeTimedCommand", + "commandversion": 1 }, { - "name": "Trigger", + "name": "Trigger (Old)", "description": "A command that runs off of a trigger", "tags": [ "trigger" ], "foldername": "trigger", - "replacename": "ReplaceMeTrigger" + "replacename": "ReplaceMeTrigger", + "commandversion": 1 + }, + { + "name": "Command (New)", + "description": "A command.", + "tags": [ + "command" + ], + "foldername": "command2", + "replacename": "ReplaceMeCommand", + "commandversion": 2 + }, + { + "name": "InstantCommand (New)", + "description": "A command that finishes instantly.", + "tags": [ + "instantcommand" + ], + "foldername": "instantcommand", + "replacename": "ReplaceMeInstantCommand", + "commandversion": 2 + }, + { + "name": "ParallelCommandGroup (New)", + "description": "A command group that runs commands in parallel, ending when all commands have finished.", + "tags": [ + "parallelcommandgroup" + ], + "foldername": "parallelcommandgroup", + "replacename": "ReplaceMeParallelCommandGroup", + "commandversion": 2 + }, + { + "name": "ParallelDeadlineGroup (New)", + "description": "A command group that runs commands in parallel, ending when a specific command has finished.", + "tags": [ + "paralleldeadlinegroup" + ], + "foldername": "paralleldeadlinegroup", + "replacename": "ReplaceMeParallelDeadlineGroup", + "commandversion": 2 + }, + { + "name": "ParallelRaceGroup (New)", + "description": "A command that runs commands in parallel, ending as soon as any command has finished.", + "tags": [ + "parallelracegroup" + ], + "foldername": "parallelracegroup", + "replacename": "ReplaceMeParallelRaceGroup", + "commandversion": 2 + }, + { + "name": "PIDCommand (New)", + "description": "A command that runs a PIDController.", + "tags": [ + "pidcommand" + ], + "foldername": "pidcommand", + "replacename": "ReplaceMePIDCommand", + "commandversion": 2 + }, + { + "name": "PIDSubsystem (New)", + "description": "A subsystem that runs a PIDController.", + "tags": [ + "pidsubsystem" + ], + "foldername": "pidsubsystem2", + "replacename": "ReplaceMePIDSubsystem", + "commandversion": 2 + }, + { + "name": "ProfiledPIDCommand (New)", + "description": "A command that runs a ProfiledPIDController.", + "tags": [ + "profiledpidcommand" + ], + "foldername": "profiledpidcommand", + "replacename": "ReplaceMeProfiledPIDCommand", + "commandversion": 2 + }, + { + "name": "ProfiledPIDSubsystem (New)", + "description": "A subsystem that runs a ProfiledPIDController.", + "tags": [ + "profiledpidsubsystem" + ], + "foldername": "profiledpidsubsystem", + "replacename": "ReplaceMeProfiledPIDSubsystem", + "commandversion": 2 + }, + { + "name": "SequentialCommandGroup (New)", + "description": "A command group that runs commands in sequence.", + "tags": [ + "sequentialcommandgroup" + ], + "foldername": "sequentialcommandgroup", + "replacename": "ReplaceMeSequentialCommandGroup", + "commandversion": 2 + }, + { + "name": "Subsystem (New)", + "description": "A robot subsystem.", + "tags": [ + "subsystem" + ], + "foldername": "subsystem2", + "replacename": "ReplaceMeSubsystem", + "commandversion": 2 + }, + { + "name": "TrapezoidProfileCommand (New)", + "description": "A command that executes a trapezoidal motion profile.", + "tags": [ + "trapezoidprofilecommand" + ], + "foldername": "trapezoidprofilecommand", + "replacename": "ReplaceMeTrapezoidProfileCommand", + "commandversion": 2 + }, + { + "name": "TrapezoidProfileSubsystem (New)", + "description": "A command that executes a trapezoidal motion profile.", + "tags": [ + "trapezoidprofilesubsystem" + ], + "foldername": "trapezoidprofilesubsystem", + "replacename": "ReplaceMeTrapezoidProfileSubsystem", + "commandversion": 2 } ] diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/instantcommand/ReplaceMeInstantCommand.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/instantcommand/ReplaceMeInstantCommand.java new file mode 100644 index 0000000000..6764ed755e --- /dev/null +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/instantcommand/ReplaceMeInstantCommand.java @@ -0,0 +1,24 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 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. */ +/*----------------------------------------------------------------------------*/ + +package edu.wpi.first.wpilibj.commands.instantcommand; + +import edu.wpi.first.wpilibj2.command.InstantCommand; + +// NOTE: Consider using this command inline, rather than writing a subclass. For more +// information, see: +// https://docs.wpilib.org/en/latest/docs/software/commandbased/convenience-features.html +public class ReplaceMeInstantCommand extends InstantCommand { + public ReplaceMeInstantCommand() { + // Use addRequirements() here to declare subsystem dependencies. + } + + // Called when the command is initially scheduled. + @Override + public void initialize() { + } +} diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/parallelcommandgroup/ReplaceMeParallelCommandGroup.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/parallelcommandgroup/ReplaceMeParallelCommandGroup.java new file mode 100644 index 0000000000..f293c414cc --- /dev/null +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/parallelcommandgroup/ReplaceMeParallelCommandGroup.java @@ -0,0 +1,23 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 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. */ +/*----------------------------------------------------------------------------*/ + +package edu.wpi.first.wpilibj.commands.parallelcommandgroup; + +import edu.wpi.first.wpilibj2.command.ParallelCommandGroup; + +// NOTE: Consider using this command inline, rather than writing a subclass. For more +// information, see: +// https://docs.wpilib.org/en/latest/docs/software/commandbased/convenience-features.html +public class ReplaceMeParallelCommandGroup extends ParallelCommandGroup { + /** + * Creates a new ReplaceMeParallelCommandGroup. + */ + public ReplaceMeParallelCommandGroup() { + // Add your commands in the super() call, e.g. + // super(new FooCommand(), new BarCommand());super(); + } +} diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/paralleldeadlinegroup/ReplaceMeParallelDeadlineGroup.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/paralleldeadlinegroup/ReplaceMeParallelDeadlineGroup.java new file mode 100644 index 0000000000..9092834826 --- /dev/null +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/paralleldeadlinegroup/ReplaceMeParallelDeadlineGroup.java @@ -0,0 +1,26 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 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. */ +/*----------------------------------------------------------------------------*/ + +package edu.wpi.first.wpilibj.commands.paralleldeadlinegroup; + +import edu.wpi.first.wpilibj2.command.InstantCommand; +import edu.wpi.first.wpilibj2.command.ParallelDeadlineGroup; + +// NOTE: Consider using this command inline, rather than writing a subclass. For more +// information, see: +// https://docs.wpilib.org/en/latest/docs/software/commandbased/convenience-features.html +public class ReplaceMeParallelDeadlineGroup extends ParallelDeadlineGroup { + /** + * Creates a new ReplaceMeParallelDeadlineGroup. + */ + public ReplaceMeParallelDeadlineGroup() { + // Add your commands in the super() call. Add the deadline first. + super( + new InstantCommand() + ); + } +} diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/parallelracegroup/ReplaceMeParallelRaceGroup.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/parallelracegroup/ReplaceMeParallelRaceGroup.java new file mode 100644 index 0000000000..686f3395b8 --- /dev/null +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/parallelracegroup/ReplaceMeParallelRaceGroup.java @@ -0,0 +1,24 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 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. */ +/*----------------------------------------------------------------------------*/ + +package edu.wpi.first.wpilibj.commands.parallelracegroup; + +import edu.wpi.first.wpilibj2.command.ParallelRaceGroup; + +// NOTE: Consider using this command inline, rather than writing a subclass. For more +// information, see: +// https://docs.wpilib.org/en/latest/docs/software/commandbased/convenience-features.html +public class ReplaceMeParallelRaceGroup extends ParallelRaceGroup { + /** + * Creates a new ReplaceMeParallelRaceGroup. + */ + public ReplaceMeParallelRaceGroup() { + // Add your commands in the super() call, e.g. + // super(new FooCommand(), new BarCommand()); + super(); + } +} diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/pidcommand/ReplaceMePIDCommand.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/pidcommand/ReplaceMePIDCommand.java new file mode 100644 index 0000000000..2615b08ef7 --- /dev/null +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/pidcommand/ReplaceMePIDCommand.java @@ -0,0 +1,41 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 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. */ +/*----------------------------------------------------------------------------*/ + +package edu.wpi.first.wpilibj.commands.pidcommand; + +import edu.wpi.first.wpilibj.controller.PIDController; +import edu.wpi.first.wpilibj2.command.PIDCommand; + +// NOTE: Consider using this command inline, rather than writing a subclass. For more +// information, see: +// https://docs.wpilib.org/en/latest/docs/software/commandbased/convenience-features.html +public class ReplaceMePIDCommand extends PIDCommand { + /** + * Creates a new ReplaceMePIDCommand. + */ + public ReplaceMePIDCommand() { + super( + // The controller that the command will use + new PIDController(0, 0, 0), + // This should return the measurement + () -> 0, + // This should return the setpoint (can also be a constant) + () -> 0, + // This uses the output + output -> { + // Use the output here + }); + // Use addRequirements() here to declare subsystem dependencies. + // Configure additional PID options by calling `getController` here. + } + + // Returns true when the command should end. + @Override + public boolean isFinished() { + return false; + } +} diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/pidsubsystem2/ReplaceMePIDSubsystem.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/pidsubsystem2/ReplaceMePIDSubsystem.java new file mode 100644 index 0000000000..7d5e7b3465 --- /dev/null +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/pidsubsystem2/ReplaceMePIDSubsystem.java @@ -0,0 +1,33 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 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. */ +/*----------------------------------------------------------------------------*/ + +package edu.wpi.first.wpilibj.commands.pidsubsystem2; + +import edu.wpi.first.wpilibj.controller.PIDController; +import edu.wpi.first.wpilibj2.command.PIDSubsystem; + +public class ReplaceMePIDSubsystem extends PIDSubsystem { + /** + * Creates a new ReplaceMePIDSubsystem. + */ + public ReplaceMePIDSubsystem() { + super( + // The PIDController used by the subsystem + new PIDController(0, 0, 0)); + } + + @Override + public void useOutput(double output, double setpoint) { + // Use the output here + } + + @Override + public double getMeasurement() { + // Return the process variable measurement here + return 0; + } +} diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/profiledpidcommand/ReplaceMeProfiledPIDCommand.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/profiledpidcommand/ReplaceMeProfiledPIDCommand.java new file mode 100644 index 0000000000..91a6e828a4 --- /dev/null +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/profiledpidcommand/ReplaceMeProfiledPIDCommand.java @@ -0,0 +1,46 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 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. */ +/*----------------------------------------------------------------------------*/ + +package edu.wpi.first.wpilibj.commands.profiledpidcommand; + +import edu.wpi.first.wpilibj.controller.ProfiledPIDController; +import edu.wpi.first.wpilibj.trajectory.TrapezoidProfile; +import edu.wpi.first.wpilibj2.command.ProfiledPIDCommand; + +// NOTE: Consider using this command inline, rather than writing a subclass. For more +// information, see: +// https://docs.wpilib.org/en/latest/docs/software/commandbased/convenience-features.html +public class ReplaceMeProfiledPIDCommand extends ProfiledPIDCommand { + /** + * Creates a new ReplaceMeProfiledPIDCommand. + */ + public ReplaceMeProfiledPIDCommand() { + super( + // The ProfiledPIDController used by the command + new ProfiledPIDController( + // The PID gains + 0, 0, 0, + // The motion profile constraints + new TrapezoidProfile.Constraints(0, 0)), + // This should return the measurement + () -> 0, + // This should return the goal (can also be a constant) + () -> new TrapezoidProfile.State(), + // This uses the output + (output, setpoint) -> { + // Use the output (and setpoint, if desired) here + }); + // Use addRequirements() here to declare subsystem dependencies. + // Configure additional PID options by calling `getController` here. + } + + // Returns true when the command should end. + @Override + public boolean isFinished() { + return false; + } +} diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/profiledpidsubsystem/ReplaceMeProfiledPIDSubsystem.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/profiledpidsubsystem/ReplaceMeProfiledPIDSubsystem.java new file mode 100644 index 0000000000..b380d4ebba --- /dev/null +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/profiledpidsubsystem/ReplaceMeProfiledPIDSubsystem.java @@ -0,0 +1,36 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 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. */ +/*----------------------------------------------------------------------------*/ + +package edu.wpi.first.wpilibj.commands.profiledpidsubsystem; + +import edu.wpi.first.wpilibj.controller.ProfiledPIDController; +import edu.wpi.first.wpilibj.trajectory.TrapezoidProfile; +import edu.wpi.first.wpilibj2.command.ProfiledPIDSubsystem; + +public class ReplaceMeProfiledPIDSubsystem extends ProfiledPIDSubsystem { + /** + * Creates a new ReplaceMeProfiledPIDSubsystem. + */ + public ReplaceMeProfiledPIDSubsystem() { + super( + // The ProfiledPIDController used by the subsystem + new ProfiledPIDController(0, 0, 0, + // The motion profile constraints + new TrapezoidProfile.Constraints(0, 0))); + } + + @Override + public void useOutput(double output, TrapezoidProfile.State setpoint) { + // Use the output (and optionally the setpoint) here + } + + @Override + public double getMeasurement() { + // Return the process variable measurement here + return 0; + } +} diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/sequentialcommandgroup/ReplaceMeSequentialCommandGroup.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/sequentialcommandgroup/ReplaceMeSequentialCommandGroup.java new file mode 100644 index 0000000000..f08e2dd1b1 --- /dev/null +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/sequentialcommandgroup/ReplaceMeSequentialCommandGroup.java @@ -0,0 +1,24 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 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. */ +/*----------------------------------------------------------------------------*/ + +package edu.wpi.first.wpilibj.commands.sequentialcommandgroup; + +import edu.wpi.first.wpilibj2.command.SequentialCommandGroup; + +// NOTE: Consider using this command inline, rather than writing a subclass. For more +// information, see: +// https://docs.wpilib.org/en/latest/docs/software/commandbased/convenience-features.html +public class ReplaceMeSequentialCommandGroup extends SequentialCommandGroup { + /** + * Creates a new ReplaceMeSequentialCommandGroup. + */ + public ReplaceMeSequentialCommandGroup() { + // Add your commands in the super() call, e.g. + // super(new FooCommand(), new BarCommand()); + super(); + } +} diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/subsystem2/ReplaceMeSubsystem.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/subsystem2/ReplaceMeSubsystem.java new file mode 100644 index 0000000000..0fa5838229 --- /dev/null +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/subsystem2/ReplaceMeSubsystem.java @@ -0,0 +1,24 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 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. */ +/*----------------------------------------------------------------------------*/ + +package edu.wpi.first.wpilibj.commands.subsystem2; + +import edu.wpi.first.wpilibj2.command.SubsystemBase; + +public class ReplaceMeSubsystem extends SubsystemBase { + /** + * Creates a new ReplaceMeSubsystem. + */ + public ReplaceMeSubsystem() { + + } + + @Override + public void periodic() { + // This method will be called once per scheduler run + } +} diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/trapezoidprofilecommand/ReplaceMeTrapezoidProfileCommand.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/trapezoidprofilecommand/ReplaceMeTrapezoidProfileCommand.java new file mode 100644 index 0000000000..d779a22a18 --- /dev/null +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/trapezoidprofilecommand/ReplaceMeTrapezoidProfileCommand.java @@ -0,0 +1,34 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 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. */ +/*----------------------------------------------------------------------------*/ + +package edu.wpi.first.wpilibj.commands.trapezoidprofilecommand; + +import edu.wpi.first.wpilibj.trajectory.TrapezoidProfile; +import edu.wpi.first.wpilibj2.command.TrapezoidProfileCommand; + +// NOTE: Consider using this command inline, rather than writing a subclass. For more +// information, see: +// https://docs.wpilib.org/en/latest/docs/software/commandbased/convenience-features.html +public class ReplaceMeTrapezoidProfileCommand extends TrapezoidProfileCommand { + /** + * Creates a new ReplaceMeTrapezoidProfileCommand. + */ + public ReplaceMeTrapezoidProfileCommand() { + super( + // The motion profile to be executed + new TrapezoidProfile( + // The motion profile constraints + new TrapezoidProfile.Constraints(0, 0), + // Goal state + new TrapezoidProfile.State(), + // Initial state + new TrapezoidProfile.State()), + state -> { + // Use current trajectory state here + }); + } +} diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/trapezoidprofilesubsystem/ReplaceMeTrapezoidProfileSubsystem.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/trapezoidprofilesubsystem/ReplaceMeTrapezoidProfileSubsystem.java new file mode 100644 index 0000000000..46f1b447af --- /dev/null +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/trapezoidprofilesubsystem/ReplaceMeTrapezoidProfileSubsystem.java @@ -0,0 +1,29 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 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. */ +/*----------------------------------------------------------------------------*/ + +package edu.wpi.first.wpilibj.commands.trapezoidprofilesubsystem; + +import edu.wpi.first.wpilibj.trajectory.TrapezoidProfile; +import edu.wpi.first.wpilibj2.command.TrapezoidProfileSubsystem; + +public class ReplaceMeTrapezoidProfileSubsystem extends TrapezoidProfileSubsystem { + /** + * Creates a new ReplaceMeTrapezoidProfileSubsystem. + */ + public ReplaceMeTrapezoidProfileSubsystem() { + super( + // The constraints for the generated profiles + new TrapezoidProfile.Constraints(0, 0), + // The initial position of the mechanism + 0); + } + + @Override + protected void useState(TrapezoidProfile.State state) { + // Use the computed profile state here. + } +} diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/commandbased/commands/ExampleCommand.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/commandbased/commands/ExampleCommand.java index cc79077900..7cfe64285a 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/commandbased/commands/ExampleCommand.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/commandbased/commands/ExampleCommand.java @@ -24,6 +24,28 @@ public class ExampleCommand extends CommandBase { */ public ExampleCommand(ExampleSubsystem subsystem) { m_subsystem = subsystem; + // Use addRequirements() here to declare subsystem dependencies. addRequirements(subsystem); } + + // Called when the command is initially scheduled. + @Override + public void initialize() { + } + + // Called every time the scheduler runs while the command is scheduled. + @Override + public void execute() { + } + + // Called once the command ends or is interrupted. + @Override + public void end(boolean interrupted) { + } + + // Returns true when the command should end. + @Override + public boolean isFinished() { + return false; + } } diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/commandbased/subsystems/ExampleSubsystem.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/commandbased/subsystems/ExampleSubsystem.java index b260c7778a..8d56fcf45d 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/commandbased/subsystems/ExampleSubsystem.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/commandbased/subsystems/ExampleSubsystem.java @@ -17,11 +17,8 @@ public class ExampleSubsystem extends SubsystemBase { } - /** - * Will be called periodically whenever the CommandScheduler runs. - */ @Override public void periodic() { - + // This method will be called once per scheduler run } }