From 938d5379e62c7d4e03b7fa8f0c5d884e3b328bb4 Mon Sep 17 00:00:00 2001 From: Thad House Date: Tue, 15 May 2018 23:56:03 -0700 Subject: [PATCH] Adds command examples to built examples (#1062) --- wpilibcExamples/build.gradle | 31 ++++- wpilibcExamples/publish.gradle | 23 ++++ .../cpp/commands/command/ReplaceMeCommand.cpp | 29 +++++ .../cpp/commands/command/ReplaceMeCommand.h | 20 ++++ .../commandgroup/ReplaceMeCommandGroup.cpp | 27 +++++ .../commandgroup/ReplaceMeCommandGroup.h | 15 +++ .../src/main/cpp/commands/commands.json | 108 ++++++++++++++++++ .../instant/ReplaceMeInstantCommand.cpp | 16 +++ .../instant/ReplaceMeInstantCommand.h | 16 +++ .../pidsubsystem/ReplaceMePIDSubsystem.cpp | 36 ++++++ .../pidsubsystem/ReplaceMePIDSubsystem.h | 18 +++ .../commands/subsystem/ReplaceMeSubsystem.cpp | 18 +++ .../commands/subsystem/ReplaceMeSubsystem.h | 20 ++++ .../commands/timed/ReplaceMeTimedCommand.cpp | 27 +++++ .../commands/timed/ReplaceMeTimedCommand.h | 19 +++ .../cpp/commands/trigger/ReplaceMeTrigger.cpp | 12 ++ .../cpp/commands/trigger/ReplaceMeTrigger.h | 16 +++ wpilibjExamples/publish.gradle | 23 ++++ .../commands/command/ReplaceMeCommand.java | 43 +++++++ .../commandgroup/ReplaceMeCommandGroup.java | 31 +++++ .../wpi/first/wpilibj/commands/commands.json | 66 +++++++++++ .../instant/ReplaceMeInstantCommand.java | 27 +++++ .../pidsubsystem/ReplaceMePIDSubsystem.java | 45 ++++++++ .../subsystem/ReplaceMeSubsystem.java | 24 ++++ .../commands/timed/ReplaceMeTimedCommand.java | 42 +++++++ .../commands/trigger/ReplaceMeTrigger.java | 20 ++++ 26 files changed, 771 insertions(+), 1 deletion(-) create mode 100644 wpilibcExamples/src/main/cpp/commands/command/ReplaceMeCommand.cpp create mode 100644 wpilibcExamples/src/main/cpp/commands/command/ReplaceMeCommand.h create mode 100644 wpilibcExamples/src/main/cpp/commands/commandgroup/ReplaceMeCommandGroup.cpp create mode 100644 wpilibcExamples/src/main/cpp/commands/commandgroup/ReplaceMeCommandGroup.h create mode 100644 wpilibcExamples/src/main/cpp/commands/commands.json create mode 100644 wpilibcExamples/src/main/cpp/commands/instant/ReplaceMeInstantCommand.cpp create mode 100644 wpilibcExamples/src/main/cpp/commands/instant/ReplaceMeInstantCommand.h create mode 100644 wpilibcExamples/src/main/cpp/commands/pidsubsystem/ReplaceMePIDSubsystem.cpp create mode 100644 wpilibcExamples/src/main/cpp/commands/pidsubsystem/ReplaceMePIDSubsystem.h create mode 100644 wpilibcExamples/src/main/cpp/commands/subsystem/ReplaceMeSubsystem.cpp create mode 100644 wpilibcExamples/src/main/cpp/commands/subsystem/ReplaceMeSubsystem.h create mode 100644 wpilibcExamples/src/main/cpp/commands/timed/ReplaceMeTimedCommand.cpp create mode 100644 wpilibcExamples/src/main/cpp/commands/timed/ReplaceMeTimedCommand.h create mode 100644 wpilibcExamples/src/main/cpp/commands/trigger/ReplaceMeTrigger.cpp create mode 100644 wpilibcExamples/src/main/cpp/commands/trigger/ReplaceMeTrigger.h create mode 100644 wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/command/ReplaceMeCommand.java create mode 100644 wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/commandgroup/ReplaceMeCommandGroup.java create mode 100644 wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/commands.json create mode 100644 wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/instant/ReplaceMeInstantCommand.java create mode 100644 wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/pidsubsystem/ReplaceMePIDSubsystem.java create mode 100644 wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/subsystem/ReplaceMeSubsystem.java create mode 100644 wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/timed/ReplaceMeTimedCommand.java create mode 100644 wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/trigger/ReplaceMeTrigger.java diff --git a/wpilibcExamples/build.gradle b/wpilibcExamples/build.gradle index a9c9250058..421f3aa46b 100644 --- a/wpilibcExamples/build.gradle +++ b/wpilibcExamples/build.gradle @@ -29,8 +29,9 @@ templatesTree.list(new FilenameFilter() { templatesMap.put(it, []) } + ext { - sharedCvConfigs = examplesMap + templatesMap + sharedCvConfigs = examplesMap + templatesMap + [commands: []] staticCvConfigs = [:] useJava = false useCpp = true @@ -40,6 +41,34 @@ apply from: "${rootDir}/shared/opencv.gradle" model { components { + commands(NativeLibrarySpec) { + binaries.all { binary -> + if (binary in StaticLibraryBinarySpec) { + binary.buildable = false + return + } + lib project: ':wpilibc', library: 'wpilibc', linkage: 'shared' + lib project: ':ntcore', library: 'ntcore', linkage: 'shared' + lib project: ':cscore', library: 'cscore', linkage: 'shared' + lib project: ':hal', library: 'hal', linkage: 'shared' + lib project: ':cameraserver', library: 'cameraserver', linkage: 'shared' + lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared' + project(':ni-libraries').addNiLibrariesToLinker(binary) + } + sources { + cpp { + source { + srcDirs = ['src/main/cpp/commands'] + include '**/*.cpp' + } + exportedHeaders { + srcDirs 'src/main/cpp/commands' + include '**/*.h' + } + } + } + } + examplesMap.each { key, value -> "${key}"(NativeExecutableSpec) { binaries.all { binary -> diff --git a/wpilibcExamples/publish.gradle b/wpilibcExamples/publish.gradle index 1903ed1aa0..2ba4e65e63 100644 --- a/wpilibcExamples/publish.gradle +++ b/wpilibcExamples/publish.gradle @@ -16,6 +16,7 @@ if (project.hasProperty("publishVersion")) { def baseExamplesArtifactId = 'examples' def baseTemplatesArtifactId = 'templates' +def baseCommandsArtifactId = 'commands' def artifactGroupId = 'edu.wpi.first.wpilibc' def outputsFolder = file("$project.buildDir/outputs") @@ -46,8 +47,22 @@ task cppTemplatesZip(type: Zip) { } } +task cppCommandsZip(type: Zip) { + destinationDir = outputsFolder + baseName = 'wpilibc-commands' + + from(licenseFile) { + into '/' + } + + from('src/main/cpp/commands') { + into 'commands' + } +} + build.dependsOn cppTemplatesZip build.dependsOn cppExamplesZip +build.dependsOn cppCommandsZip publishing { publications { @@ -66,5 +81,13 @@ publishing { groupId artifactGroupId version pubVersion } + + commands(MavenPublication) { + artifact cppCommandsZip + + artifactId = baseCommandsArtifactId + groupId artifactGroupId + version pubVersion + } } } diff --git a/wpilibcExamples/src/main/cpp/commands/command/ReplaceMeCommand.cpp b/wpilibcExamples/src/main/cpp/commands/command/ReplaceMeCommand.cpp new file mode 100644 index 0000000000..07c233e807 --- /dev/null +++ b/wpilibcExamples/src/main/cpp/commands/command/ReplaceMeCommand.cpp @@ -0,0 +1,29 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2017-2018 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 "ReplaceMeCommand.h" + +ReplaceMeCommand::ReplaceMeCommand() { + // Use Requires() here to declare subsystem dependencies + // eg. Requires(Robot::chassis.get()); +} + +// Called just before this Command runs the first time +void ReplaceMeCommand::Initialize() {} + +// Called repeatedly when this Command is scheduled to run +void ReplaceMeCommand::Execute() {} + +// Make this return true when this Command no longer needs to run execute() +bool ReplaceMeCommand::IsFinished() { return false; } + +// Called once after isFinished returns true +void ReplaceMeCommand::End() {} + +// Called when another command which requires one or more of the same +// subsystems is scheduled to run +void ReplaceMeCommand::Interrupted() {} diff --git a/wpilibcExamples/src/main/cpp/commands/command/ReplaceMeCommand.h b/wpilibcExamples/src/main/cpp/commands/command/ReplaceMeCommand.h new file mode 100644 index 0000000000..9762deac18 --- /dev/null +++ b/wpilibcExamples/src/main/cpp/commands/command/ReplaceMeCommand.h @@ -0,0 +1,20 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2017-2018 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 ReplaceMeCommand : public frc::Command { + public: + ReplaceMeCommand(); + void Initialize() override; + void Execute() override; + bool IsFinished() override; + void End() override; + void Interrupted() override; +}; diff --git a/wpilibcExamples/src/main/cpp/commands/commandgroup/ReplaceMeCommandGroup.cpp b/wpilibcExamples/src/main/cpp/commands/commandgroup/ReplaceMeCommandGroup.cpp new file mode 100644 index 0000000000..1a431f42f4 --- /dev/null +++ b/wpilibcExamples/src/main/cpp/commands/commandgroup/ReplaceMeCommandGroup.cpp @@ -0,0 +1,27 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2017-2018 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 "ReplaceMeCommandGroup.h" + +ReplaceMeCommandGroup::ReplaceMeCommandGroup() { + // Add Commands here: + // e.g. AddSequential(new Command1()); + // AddSequential(new Command2()); + // these will run in order. + + // To run multiple commands at the same time, + // use AddParallel() + // e.g. AddParallel(new Command1()); + // AddSequential(new Command2()); + // Command1 and Command2 will run in parallel. + + // A command group will require all of the subsystems that each member + // would require. + // e.g. if Command1 requires chassis, and Command2 requires arm, + // a CommandGroup containing them would require both the chassis and the + // arm. +} diff --git a/wpilibcExamples/src/main/cpp/commands/commandgroup/ReplaceMeCommandGroup.h b/wpilibcExamples/src/main/cpp/commands/commandgroup/ReplaceMeCommandGroup.h new file mode 100644 index 0000000000..bafef5ddcc --- /dev/null +++ b/wpilibcExamples/src/main/cpp/commands/commandgroup/ReplaceMeCommandGroup.h @@ -0,0 +1,15 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2017-2018 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 ReplaceMeCommandGroup : public frc::CommandGroup { + public: + ReplaceMeCommandGroup(); +}; diff --git a/wpilibcExamples/src/main/cpp/commands/commands.json b/wpilibcExamples/src/main/cpp/commands/commands.json new file mode 100644 index 0000000000..8d9c1e588a --- /dev/null +++ b/wpilibcExamples/src/main/cpp/commands/commands.json @@ -0,0 +1,108 @@ +[ + { + "name": "Command", + "description": "Create a base command", + "tags": [ + "command" + ], + "foldername": "command", + "headers": [ + "ReplaceMeCommand.h" + ], + "source": [ + "ReplaceMeCommand.cpp" + ], + "replacename": "ReplaceMeCommand" + }, + { + "name": "Command Group", + "description": "Create a command group", + "tags": [ + "commandgroup" + ], + "foldername": "commandgroup", + "headers": [ + "ReplaceMeCommandGroup.h" + ], + "source": [ + "ReplaceMeCommandGroup.cpp" + ], + "replacename": "ReplaceMeCommandGroup" + }, + { + "name": "Instant Command", + "description": "A command that runs immediately", + "tags": [ + "instantcommand" + ], + "foldername": "instant", + "headers": [ + "ReplaceMeInstantCommand.h" + ], + "source": [ + "ReplaceMeInstantCommand.cpp" + ], + "replacename": "ReplaceMeInstantCommand" + }, + { + "name": "Subsystem", + "description": "A subsystem", + "tags": [ + "subsystem" + ], + "foldername": "subsystem", + "headers": [ + "ReplaceMeSubsystem.h" + ], + "source": [ + "ReplaceMeSubsystem.cpp" + ], + "replacename": "ReplaceMeSubsystem" + }, + { + "name": "PID Subsystem", + "description": "A subsystem that runs a PID loop", + "tags": [ + "pidsubsystem", + "pid" + ], + "foldername": "pidsubsystem", + "headers": [ + "ReplaceMePIDSubsystem.h" + ], + "source": [ + "ReplaceMePIDSubsystem.cpp" + ], + "replacename": "ReplaceMePIDSubsystem" + }, + { + "name": "Timed Command", + "description": "A command that runs for a specified time", + "tags": [ + "timedcommand" + ], + "foldername": "timed", + "headers": [ + "ReplaceMeTimedCommand.h" + ], + "source": [ + "ReplaceMeTimedCommand.cpp" + ], + "replacename": "ReplaceMeTimedCommand" + }, + { + "name": "Trigger", + "description": "A command that runs off of a trigger", + "tags": [ + "trigger" + ], + "foldername": "trigger", + "headers": [ + "ReplaceMeTrigger.h" + ], + "source": [ + "ReplaceMeTrigger.cpp" + ], + "replacename": "ReplaceMeTrigger" + } +] diff --git a/wpilibcExamples/src/main/cpp/commands/instant/ReplaceMeInstantCommand.cpp b/wpilibcExamples/src/main/cpp/commands/instant/ReplaceMeInstantCommand.cpp new file mode 100644 index 0000000000..c130e0982d --- /dev/null +++ b/wpilibcExamples/src/main/cpp/commands/instant/ReplaceMeInstantCommand.cpp @@ -0,0 +1,16 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2017-2018 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 "ReplaceMeInstantCommand.h" + +ReplaceMeInstantCommand::ReplaceMeInstantCommand() { + // Use Requires() here to declare subsystem dependencies + // eg. Requires(Robot::chassis.get()); +} + +// Called once when the command executes +void ReplaceMeInstantCommand::Initialize() {} diff --git a/wpilibcExamples/src/main/cpp/commands/instant/ReplaceMeInstantCommand.h b/wpilibcExamples/src/main/cpp/commands/instant/ReplaceMeInstantCommand.h new file mode 100644 index 0000000000..b1ff17210a --- /dev/null +++ b/wpilibcExamples/src/main/cpp/commands/instant/ReplaceMeInstantCommand.h @@ -0,0 +1,16 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2017-2018 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 "Commands/InstantCommand.h" + +class ReplaceMeInstantCommand : public frc::InstantCommand { + public: + ReplaceMeInstantCommand(); + void Initialize() override; +}; diff --git a/wpilibcExamples/src/main/cpp/commands/pidsubsystem/ReplaceMePIDSubsystem.cpp b/wpilibcExamples/src/main/cpp/commands/pidsubsystem/ReplaceMePIDSubsystem.cpp new file mode 100644 index 0000000000..8466110f74 --- /dev/null +++ b/wpilibcExamples/src/main/cpp/commands/pidsubsystem/ReplaceMePIDSubsystem.cpp @@ -0,0 +1,36 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2017-2018 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 "ReplaceMePIDSubsystem.h" + +#include +#include + +ReplaceMePIDSubsystem::ReplaceMePIDSubsystem() + : PIDSubsystem("ReplaceMePIDSubsystem", 1.0, 0.0, 0.0) { + // Use these to get going: + // SetSetpoint() - Sets where the PID controller should move the system + // to + // Enable() - Enables the PID controller. +} + +double ReplaceMePIDSubsystem::ReturnPIDInput() { + // Return your input value for the PID loop + // e.g. a sensor, like a potentiometer: + // yourPot->SetAverageVoltage() / kYourMaxVoltage; + return 0; +} + +void ReplaceMePIDSubsystem::UsePIDOutput(double output) { + // Use output to drive your system, like a motor + // e.g. yourMotor->Set(output); +} + +void ReplaceMePIDSubsystem::InitDefaultCommand() { + // Set the default command for a subsystem here. + // SetDefaultCommand(new MySpecialCommand()); +} diff --git a/wpilibcExamples/src/main/cpp/commands/pidsubsystem/ReplaceMePIDSubsystem.h b/wpilibcExamples/src/main/cpp/commands/pidsubsystem/ReplaceMePIDSubsystem.h new file mode 100644 index 0000000000..a7d51b6c1b --- /dev/null +++ b/wpilibcExamples/src/main/cpp/commands/pidsubsystem/ReplaceMePIDSubsystem.h @@ -0,0 +1,18 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2017-2018 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 ReplaceMePIDSubsystem : public frc::PIDSubsystem { + public: + ReplaceMePIDSubsystem(); + double ReturnPIDInput() override; + void UsePIDOutput(double output) override; + void InitDefaultCommand() override; +}; diff --git a/wpilibcExamples/src/main/cpp/commands/subsystem/ReplaceMeSubsystem.cpp b/wpilibcExamples/src/main/cpp/commands/subsystem/ReplaceMeSubsystem.cpp new file mode 100644 index 0000000000..8ca89d35f9 --- /dev/null +++ b/wpilibcExamples/src/main/cpp/commands/subsystem/ReplaceMeSubsystem.cpp @@ -0,0 +1,18 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2017-2018 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 "ReplaceMeSubsystem.h" + +ReplaceMeSubsystem::ReplaceMeSubsystem() : Subsystem("ExampleSubsystem") {} + +void ReplaceMeSubsystem::InitDefaultCommand() { + // Set the default command for a subsystem here. + // SetDefaultCommand(new MySpecialCommand()); +} + +// Put methods for controlling this subsystem +// here. Call these from Commands. diff --git a/wpilibcExamples/src/main/cpp/commands/subsystem/ReplaceMeSubsystem.h b/wpilibcExamples/src/main/cpp/commands/subsystem/ReplaceMeSubsystem.h new file mode 100644 index 0000000000..aacb8f8877 --- /dev/null +++ b/wpilibcExamples/src/main/cpp/commands/subsystem/ReplaceMeSubsystem.h @@ -0,0 +1,20 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2017-2018 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 ReplaceMeSubsystem : public frc::Subsystem { + private: + // It's desirable that everything possible under private except + // for methods that implement subsystem capabilities + + public: + ReplaceMeSubsystem(); + void InitDefaultCommand() override; +}; diff --git a/wpilibcExamples/src/main/cpp/commands/timed/ReplaceMeTimedCommand.cpp b/wpilibcExamples/src/main/cpp/commands/timed/ReplaceMeTimedCommand.cpp new file mode 100644 index 0000000000..2076e5bd1e --- /dev/null +++ b/wpilibcExamples/src/main/cpp/commands/timed/ReplaceMeTimedCommand.cpp @@ -0,0 +1,27 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2017-2018 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 "ReplaceMeTimedCommand.h" + +ReplaceMeTimedCommand::ReplaceMeTimedCommand(double timeout) + : TimedCommand(timeout) { + // Use Requires() here to declare subsystem dependencies + // eg. Requires(Robot::chassis.get()); +} + +// Called just before this Command runs the first time +void ReplaceMeTimedCommand::Initialize() {} + +// Called repeatedly when this Command is scheduled to run +void ReplaceMeTimedCommand::Execute() {} + +// Called once after command times out +void ReplaceMeTimedCommand::End() {} + +// Called when another command which requires one or more of the same +// subsystems is scheduled to run +void ReplaceMeTimedCommand::Interrupted() {} diff --git a/wpilibcExamples/src/main/cpp/commands/timed/ReplaceMeTimedCommand.h b/wpilibcExamples/src/main/cpp/commands/timed/ReplaceMeTimedCommand.h new file mode 100644 index 0000000000..1c31c71d2b --- /dev/null +++ b/wpilibcExamples/src/main/cpp/commands/timed/ReplaceMeTimedCommand.h @@ -0,0 +1,19 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2017-2018 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 "Commands/TimedCommand.h" + +class ReplaceMeTimedCommand : public frc::TimedCommand { + public: + explicit ReplaceMeTimedCommand(double timeout); + void Initialize() override; + void Execute() override; + void End() override; + void Interrupted() override; +}; diff --git a/wpilibcExamples/src/main/cpp/commands/trigger/ReplaceMeTrigger.cpp b/wpilibcExamples/src/main/cpp/commands/trigger/ReplaceMeTrigger.cpp new file mode 100644 index 0000000000..4759e0e7f8 --- /dev/null +++ b/wpilibcExamples/src/main/cpp/commands/trigger/ReplaceMeTrigger.cpp @@ -0,0 +1,12 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2017-2018 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 "ReplaceMeTrigger.h" + +ReplaceMeTrigger::ReplaceMeTrigger() {} + +bool ReplaceMeTrigger::Get() { return false; } diff --git a/wpilibcExamples/src/main/cpp/commands/trigger/ReplaceMeTrigger.h b/wpilibcExamples/src/main/cpp/commands/trigger/ReplaceMeTrigger.h new file mode 100644 index 0000000000..a369c6bb64 --- /dev/null +++ b/wpilibcExamples/src/main/cpp/commands/trigger/ReplaceMeTrigger.h @@ -0,0 +1,16 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2017-2018 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 ReplaceMeTrigger : public frc::Trigger { + public: + ReplaceMeTrigger(); + bool Get() override; +}; diff --git a/wpilibjExamples/publish.gradle b/wpilibjExamples/publish.gradle index b827926743..3457cd0c9b 100644 --- a/wpilibjExamples/publish.gradle +++ b/wpilibjExamples/publish.gradle @@ -16,6 +16,7 @@ if (project.hasProperty("publishVersion")) { def baseExamplesArtifactId = 'examples' def baseTemplatesArtifactId = 'templates' +def baseCommandsArtifactId = 'commands' def artifactGroupId = 'edu.wpi.first.wpilibj' def outputsFolder = file("$project.buildDir/outputs") @@ -46,8 +47,22 @@ task javaTemplatesZip(type: Zip) { } } +task javaCommandsZip(type: Zip) { + destinationDir = outputsFolder + baseName = 'wpilibj-commands' + + from(licenseFile) { + into '/' + } + + from('src/main/java/edu/wpi/first/wpilibj/commands') { + into 'commands' + } +} + build.dependsOn javaTemplatesZip build.dependsOn javaExamplesZip +build.dependsOn javaCommandsZip publishing { publications { @@ -66,5 +81,13 @@ publishing { groupId artifactGroupId version pubVersion } + + commands(MavenPublication) { + artifact javaCommandsZip + + artifactId = baseCommandsArtifactId + groupId artifactGroupId + version pubVersion + } } } diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/command/ReplaceMeCommand.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/command/ReplaceMeCommand.java new file mode 100644 index 0000000000..8b8229b334 --- /dev/null +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/command/ReplaceMeCommand.java @@ -0,0 +1,43 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2018 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.command; + +import edu.wpi.first.wpilibj.command.Command; + +public class ReplaceMeCommand extends Command { + public ReplaceMeCommand() { + // Use requires() here to declare subsystem dependencies + // eg. requires(chassis); + } + + // Called just before this Command runs the first time + @Override + protected void initialize() { + } + + // Called repeatedly when this Command is scheduled to run + @Override + protected void execute() { + } + + // Make this return true when this Command no longer needs to run execute() + @Override + protected boolean isFinished() { + return false; + } + + // Called once after isFinished returns true + @Override + protected void end() { + } + + // Called when another command which requires one or more of the same + // subsystems is scheduled to run + protected void interrupted() { + } +} diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/commandgroup/ReplaceMeCommandGroup.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/commandgroup/ReplaceMeCommandGroup.java new file mode 100644 index 0000000000..8a5304f890 --- /dev/null +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/commandgroup/ReplaceMeCommandGroup.java @@ -0,0 +1,31 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2018 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.commandgroup; + +import edu.wpi.first.wpilibj.command.CommandGroup; + +public class ReplaceMeCommandGroup extends CommandGroup { + public ReplaceMeCommandGroup() { + // Add Commands here: + // e.g. addSequential(new Command1()); + // addSequential(new Command2()); + // these will run in order. + + // To run multiple commands at the same time, + // use addParallel() + // e.g. addParallel(new Command1()); + // addSequential(new Command2()); + // Command1 and Command2 will run in parallel. + + // A command group will require all of the subsystems that each member + // would require. + // e.g. if Command1 requires chassis, and Command2 requires arm, + // a CommandGroup containing them would require both the chassis and the + // arm. + } +} 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 new file mode 100644 index 0000000000..dc50d97e56 --- /dev/null +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/commands.json @@ -0,0 +1,66 @@ +[ + { + "name": "Command", + "description": "Create a base command", + "tags": [ + "command" + ], + "foldername": "command", + "replacename": "ReplaceMeCommand" + }, + { + "name": "Command Group", + "description": "Create a command group", + "tags": [ + "commandgroup" + ], + "foldername": "commandgroup", + "replacename": "ReplaceMeCommandGroup" + }, + { + "name": "Instant Command", + "description": "A command that runs immediately", + "tags": [ + "instantcommand" + ], + "foldername": "instant", + "replacename": "ReplaceMeInstantCommand" + }, + { + "name": "Subsystem", + "description": "A subsystem", + "tags": [ + "subsystem" + ], + "foldername": "subsystem", + "replacename": "ReplaceMeSubsystem" + }, + { + "name": "PID Subsystem", + "description": "A subsystem that runs a PID loop", + "tags": [ + "pidsubsystem", + "pid" + ], + "foldername": "pidsubsystem", + "replacename": "ReplaceMePIDSubsystem" + }, + { + "name": "Timed Command", + "description": "A command that runs for a specified time", + "tags": [ + "timedcommand" + ], + "foldername": "timed", + "replacename": "ReplaceMeTimedCommand" + }, + { + "name": "Trigger", + "description": "A command that runs off of a trigger", + "tags": [ + "trigger" + ], + "foldername": "trigger", + "replacename": "ReplaceMeTrigger" + } +] diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/instant/ReplaceMeInstantCommand.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/instant/ReplaceMeInstantCommand.java new file mode 100644 index 0000000000..167a13b817 --- /dev/null +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/instant/ReplaceMeInstantCommand.java @@ -0,0 +1,27 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2018 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.instant; + +import edu.wpi.first.wpilibj.command.InstantCommand; + +/** + * Add your docs here. + */ +public class ReplaceMeInstantCommand extends InstantCommand { + public ReplaceMeInstantCommand() { + super(); + // Use requires() here to declare subsystem dependencies + // eg. requires(chassis); + } + + // Called once when the command executes + @Override + protected void initialize() { + } + +} diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/pidsubsystem/ReplaceMePIDSubsystem.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/pidsubsystem/ReplaceMePIDSubsystem.java new file mode 100644 index 0000000000..3eff99de53 --- /dev/null +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/pidsubsystem/ReplaceMePIDSubsystem.java @@ -0,0 +1,45 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2018 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.pidsubsystem; + +import edu.wpi.first.wpilibj.command.PIDSubsystem; + +/** + * Add your docs here. + */ +public class ReplaceMePIDSubsystem extends PIDSubsystem { + // Initialize your subsystem here + public ReplaceMePIDSubsystem() { + // Intert a subsystem name and PID values here + super("SubsystemName", 1, 2, 3); + // Use these to get going: + // setSetpoint() - Sets where the PID controller should move the system + // to + // enable() - Enables the PID controller. + } + + @Override + public void initDefaultCommand() { + // Set the default command for a subsystem here. + // setDefaultCommand(new MySpecialCommand()); + } + + @Override + protected double returnPIDInput() { + // Return your input value for the PID loop + // e.g. a sensor, like a potentiometer: + // yourPot.getAverageVoltage() / kYourMaxVoltage; + return 0.0; + } + + @Override + protected void usePIDOutput(double output) { + // Use output to drive your system, like a motor + // e.g. yourMotor.set(output); + } +} diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/subsystem/ReplaceMeSubsystem.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/subsystem/ReplaceMeSubsystem.java new file mode 100644 index 0000000000..1c7fe6da84 --- /dev/null +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/subsystem/ReplaceMeSubsystem.java @@ -0,0 +1,24 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2018 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.subsystem; + +import edu.wpi.first.wpilibj.command.Subsystem; + +/** + * Add your docs here. + */ +public class ReplaceMeSubsystem extends Subsystem { + // Put methods for controlling this subsystem + // here. Call these from Commands. + + @Override + public void initDefaultCommand() { + // Set the default command for a subsystem here. + // setDefaultCommand(new MySpecialCommand()); + } +} diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/timed/ReplaceMeTimedCommand.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/timed/ReplaceMeTimedCommand.java new file mode 100644 index 0000000000..ea92b2ec12 --- /dev/null +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/timed/ReplaceMeTimedCommand.java @@ -0,0 +1,42 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2018 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.timed; + +import edu.wpi.first.wpilibj.command.TimedCommand; + +/** + * Add your docs here. + */ +public class ReplaceMeTimedCommand extends TimedCommand { + public ReplaceMeTimedCommand(double timeout) { + super(timeout); + // Use requires() here to declare subsystem dependencies + // eg. requires(chassis); + } + + // Called just before this Command runs the first time + @Override + protected void initialize() { + } + + // Called repeatedly when this Command is scheduled to run + @Override + protected void execute() { + } + + // Called once after timeout + @Override + protected void end() { + } + + // Called when another command which requires one or more of the same + // subsystems is scheduled to run + @Override + protected void interrupted() { + } +} diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/trigger/ReplaceMeTrigger.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/trigger/ReplaceMeTrigger.java new file mode 100644 index 0000000000..713ac6d27d --- /dev/null +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/trigger/ReplaceMeTrigger.java @@ -0,0 +1,20 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2018 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.trigger; + +import edu.wpi.first.wpilibj.buttons.Trigger; + +/** + * Add your docs here. + */ +public class ReplaceMeTrigger extends Trigger { + @Override + public boolean get() { + return false; + } +}