Adds command examples to built examples (#1062)

This commit is contained in:
Thad House
2018-05-15 23:56:03 -07:00
committed by Peter Johnson
parent 7cd15aa049
commit 938d5379e6
26 changed files with 771 additions and 1 deletions

View File

@@ -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() {}

View File

@@ -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 <Commands/Command.h>
class ReplaceMeCommand : public frc::Command {
public:
ReplaceMeCommand();
void Initialize() override;
void Execute() override;
bool IsFinished() override;
void End() override;
void Interrupted() override;
};

View File

@@ -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.
}

View File

@@ -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 <Commands/CommandGroup.h>
class ReplaceMeCommandGroup : public frc::CommandGroup {
public:
ReplaceMeCommandGroup();
};

View File

@@ -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"
}
]

View File

@@ -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() {}

View File

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

View File

@@ -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 <LiveWindow/LiveWindow.h>
#include <SmartDashboard/SmartDashboard.h>
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());
}

View File

@@ -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 <Commands/PIDSubsystem.h>
class ReplaceMePIDSubsystem : public frc::PIDSubsystem {
public:
ReplaceMePIDSubsystem();
double ReturnPIDInput() override;
void UsePIDOutput(double output) override;
void InitDefaultCommand() override;
};

View File

@@ -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.

View File

@@ -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 <Commands/Subsystem.h>
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;
};

View File

@@ -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() {}

View File

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

View File

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

View File

@@ -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 <Buttons/Trigger.h>
class ReplaceMeTrigger : public frc::Trigger {
public:
ReplaceMeTrigger();
bool Get() override;
};