mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-01 02:41:48 +00:00
Update to 2018_v4 image and new build system. (#598)
* Revert "Force OpenCV to 3.1.0 (#602)"
This reverts commit 50ed55e8e2.
* Removes Simulation
* Removes old build system
* Removes old gtest
* Adds new gmock and gtest
* Updates to new ni-libraries
* removes MyRobot (to be replaced)
* moves files to new location
* Adds new sim backend and new test executables
* updates .styleguide and .gitignore
* Changes cpp WPILibVersion to a function
MSVC throws an AV with the old version.
* Disables USBCamera on all systems except for linux
* 2018 NI Libraries
* New build system
This commit is contained in:
committed by
Peter Johnson
parent
50ed55e8e2
commit
e1195e8b9d
173
wpilibc/src/main/native/include/Commands/Command.h
Normal file
173
wpilibc/src/main/native/include/Commands/Command.h
Normal file
@@ -0,0 +1,173 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2011-2017. 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 <memory>
|
||||
#include <set>
|
||||
#include <string>
|
||||
|
||||
#include "ErrorBase.h"
|
||||
#include "SmartDashboard/NamedSendable.h"
|
||||
#include "tables/ITableListener.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
class CommandGroup;
|
||||
class Subsystem;
|
||||
|
||||
/**
|
||||
* The Command class is at the very core of the entire command framework.
|
||||
* Every command can be started with a call to {@link Command#Start() Start()}.
|
||||
* Once a command is started it will call {@link Command#Initialize()
|
||||
* Initialize()}, and then will repeatedly call
|
||||
* {@link Command#Execute() Execute()} until the
|
||||
* {@link Command#IsFinished() IsFinished()} returns true. Once it does,
|
||||
* {@link Command#End() End()} will be called.
|
||||
*
|
||||
* <p>However, if at any point while it is running {@link Command#Cancel()
|
||||
* Cancel()} is called, then the command will be stopped and
|
||||
* {@link Command#Interrupted() Interrupted()} will be called.</p>
|
||||
*
|
||||
* <p>If a command uses a {@link Subsystem}, then it should specify that it does
|
||||
* so by calling the {@link Command#Requires(Subsystem) Requires(...)} method
|
||||
* in its constructor. Note that a Command may have multiple requirements, and
|
||||
* {@link Command#Requires(Subsystem) Requires(...)} should be called for each
|
||||
* one.</p>
|
||||
*
|
||||
* <p>If a command is running and a new command with shared requirements is
|
||||
* started, then one of two things will happen. If the active command is
|
||||
* interruptible, then {@link Command#Cancel() Cancel()} will be called and the
|
||||
* command will be removed to make way for the new one. If the active command
|
||||
* is not interruptible, the other one will not even be started, and the active
|
||||
* one will continue functioning.</p>
|
||||
*
|
||||
* @see CommandGroup
|
||||
* @see Subsystem
|
||||
*/
|
||||
class Command : public ErrorBase, public NamedSendable, public ITableListener {
|
||||
friend class CommandGroup;
|
||||
friend class Scheduler;
|
||||
|
||||
public:
|
||||
Command();
|
||||
explicit Command(const std::string& name);
|
||||
explicit Command(double timeout);
|
||||
Command(const std::string& name, double timeout);
|
||||
virtual ~Command();
|
||||
double TimeSinceInitialized() const;
|
||||
void Requires(Subsystem* s);
|
||||
bool IsCanceled() const;
|
||||
void Start();
|
||||
bool Run();
|
||||
void Cancel();
|
||||
bool IsRunning() const;
|
||||
bool IsInterruptible() const;
|
||||
void SetInterruptible(bool interruptible);
|
||||
bool DoesRequire(Subsystem* subsystem) const;
|
||||
typedef std::set<Subsystem*> SubsystemSet;
|
||||
SubsystemSet GetRequirements() const;
|
||||
CommandGroup* GetGroup() const;
|
||||
void SetRunWhenDisabled(bool run);
|
||||
bool WillRunWhenDisabled() const;
|
||||
int GetID() const;
|
||||
|
||||
protected:
|
||||
void SetTimeout(double timeout);
|
||||
bool IsTimedOut() const;
|
||||
bool AssertUnlocked(const std::string& message);
|
||||
void SetParent(CommandGroup* parent);
|
||||
void ClearRequirements();
|
||||
|
||||
virtual void Initialize();
|
||||
virtual void Execute();
|
||||
|
||||
/**
|
||||
* Returns whether this command is finished.
|
||||
* If it is, then the command will be removed and {@link Command#end() end()}
|
||||
* will be called.
|
||||
*
|
||||
* <p>It may be useful for a team to reference the {@link Command#isTimedOut()
|
||||
* isTimedOut()} method for time-sensitive commands.</p>
|
||||
*
|
||||
* <p>Returning false will result in the command never ending automatically.
|
||||
* It may still be cancelled manually or interrupted by another command.
|
||||
* Returning true will result in the command executing once and finishing
|
||||
* immediately. We recommend using {@link InstantCommand} for this.</p>
|
||||
*
|
||||
* @return whether this command is finished.
|
||||
* @see Command#isTimedOut() isTimedOut()
|
||||
*/
|
||||
virtual bool IsFinished() = 0;
|
||||
|
||||
virtual void End();
|
||||
virtual void Interrupted();
|
||||
|
||||
virtual void _Initialize();
|
||||
virtual void _Interrupted();
|
||||
virtual void _Execute();
|
||||
virtual void _End();
|
||||
virtual void _Cancel();
|
||||
|
||||
friend class ConditionalCommand;
|
||||
|
||||
private:
|
||||
void LockChanges();
|
||||
/*synchronized*/ void Removed();
|
||||
void StartRunning();
|
||||
void StartTiming();
|
||||
|
||||
/** The name of this command */
|
||||
std::string m_name;
|
||||
|
||||
/** The time since this command was initialized */
|
||||
double m_startTime = -1;
|
||||
|
||||
/** The time (in seconds) before this command "times out" (or -1 if no
|
||||
* timeout) */
|
||||
double m_timeout;
|
||||
|
||||
/** Whether or not this command has been initialized */
|
||||
bool m_initialized = false;
|
||||
|
||||
/** The requirements (or null if no requirements) */
|
||||
SubsystemSet m_requirements;
|
||||
|
||||
/** Whether or not it is running */
|
||||
bool m_running = false;
|
||||
|
||||
/** Whether or not it is interruptible*/
|
||||
bool m_interruptible = true;
|
||||
|
||||
/** Whether or not it has been canceled */
|
||||
bool m_canceled = false;
|
||||
|
||||
/** Whether or not it has been locked */
|
||||
bool m_locked = false;
|
||||
|
||||
/** Whether this command should run when the robot is disabled */
|
||||
bool m_runWhenDisabled = false;
|
||||
|
||||
/** The {@link CommandGroup} this is in */
|
||||
CommandGroup* m_parent = nullptr;
|
||||
|
||||
int m_commandID = m_commandCounter++;
|
||||
static int m_commandCounter;
|
||||
|
||||
public:
|
||||
std::string GetName() const override;
|
||||
void InitTable(std::shared_ptr<ITable> subtable) override;
|
||||
std::shared_ptr<ITable> GetTable() const override;
|
||||
std::string GetSmartDashboardType() const override;
|
||||
void ValueChanged(ITable* source, llvm::StringRef key,
|
||||
std::shared_ptr<nt::Value> value, bool isNew) override;
|
||||
|
||||
protected:
|
||||
std::shared_ptr<ITable> m_table;
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
76
wpilibc/src/main/native/include/Commands/CommandGroup.h
Normal file
76
wpilibc/src/main/native/include/Commands/CommandGroup.h
Normal file
@@ -0,0 +1,76 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2011-2017. 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 <list>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "Commands/Command.h"
|
||||
#include "Commands/CommandGroupEntry.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
/**
|
||||
* A {@link CommandGroup} is a list of commands which are executed in sequence.
|
||||
*
|
||||
* <p>Commands in a {@link CommandGroup} are added using the {@link
|
||||
* CommandGroup#AddSequential(Command) AddSequential(...)} method and are
|
||||
* called sequentially. {@link CommandGroup CommandGroups} are themselves
|
||||
* {@link Command Commands} and can be given to other
|
||||
* {@link CommandGroup CommandGroups}.</p>
|
||||
*
|
||||
* <p>{@link CommandGroup CommandGroups} will carry all of the requirements of
|
||||
* their {@link Command subcommands}. Additional requirements can be specified
|
||||
* by calling {@link CommandGroup#Requires(Subsystem) Requires(...)} normally
|
||||
* in the constructor.</P>
|
||||
*
|
||||
* <p>CommandGroups can also execute commands in parallel, simply by adding them
|
||||
* using {@link CommandGroup#AddParallel(Command) AddParallel(...)}.</p>
|
||||
*
|
||||
* @see Command
|
||||
* @see Subsystem
|
||||
*/
|
||||
class CommandGroup : public Command {
|
||||
public:
|
||||
CommandGroup() = default;
|
||||
explicit CommandGroup(const std::string& name);
|
||||
virtual ~CommandGroup() = default;
|
||||
|
||||
void AddSequential(Command* command);
|
||||
void AddSequential(Command* command, double timeout);
|
||||
void AddParallel(Command* command);
|
||||
void AddParallel(Command* command, double timeout);
|
||||
bool IsInterruptible() const;
|
||||
int GetSize() const;
|
||||
|
||||
protected:
|
||||
virtual void Initialize();
|
||||
virtual void Execute();
|
||||
virtual bool IsFinished();
|
||||
virtual void End();
|
||||
virtual void Interrupted();
|
||||
virtual void _Initialize();
|
||||
virtual void _Interrupted();
|
||||
virtual void _Execute();
|
||||
virtual void _End();
|
||||
|
||||
private:
|
||||
void CancelConflicts(Command* command);
|
||||
|
||||
/** The commands in this group (stored in entries) */
|
||||
std::vector<CommandGroupEntry> m_commands;
|
||||
|
||||
/** The active children in this group (stored in entries) */
|
||||
std::list<CommandGroupEntry> m_children;
|
||||
|
||||
/** The current command, -1 signifies that none have been run */
|
||||
int m_currentCommandIndex = -1;
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
31
wpilibc/src/main/native/include/Commands/CommandGroupEntry.h
Normal file
31
wpilibc/src/main/native/include/Commands/CommandGroupEntry.h
Normal file
@@ -0,0 +1,31 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2011-2017. 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
|
||||
|
||||
namespace frc {
|
||||
|
||||
class Command;
|
||||
|
||||
class CommandGroupEntry {
|
||||
public:
|
||||
typedef enum {
|
||||
kSequence_InSequence,
|
||||
kSequence_BranchPeer,
|
||||
kSequence_BranchChild
|
||||
} Sequence;
|
||||
|
||||
CommandGroupEntry() = default;
|
||||
CommandGroupEntry(Command* command, Sequence state, double timeout = -1.0);
|
||||
bool IsTimedOut() const;
|
||||
|
||||
double m_timeout = -1.0;
|
||||
Command* m_command = nullptr;
|
||||
Sequence m_state = kSequence_InSequence;
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
@@ -0,0 +1,80 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2017. 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 <string>
|
||||
|
||||
#include "Commands/Command.h"
|
||||
#include "Commands/InstantCommand.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
/**
|
||||
* A {@link ConditionalCommand} is a {@link Command} that starts one of two
|
||||
* commands.
|
||||
*
|
||||
* <p>
|
||||
* A {@link ConditionalCommand} uses m_condition to determine whether it should
|
||||
* run m_onTrue or m_onFalse.
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* A {@link ConditionalCommand} adds the proper {@link Command} to the {@link
|
||||
* Scheduler} during {@link ConditionalCommand#initialize()} and then {@link
|
||||
* ConditionalCommand#isFinished()} will return true once that {@link Command}
|
||||
* has finished executing.
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* If no {@link Command} is specified for m_onFalse, the occurrence of that
|
||||
* condition will be a no-op.
|
||||
* </p>
|
||||
*
|
||||
* @see Command
|
||||
* @see Scheduler
|
||||
*/
|
||||
class ConditionalCommand : public Command {
|
||||
public:
|
||||
explicit ConditionalCommand(Command* onTrue, Command* onFalse = nullptr);
|
||||
ConditionalCommand(const std::string& name, Command* onTrue,
|
||||
Command* onFalse = nullptr);
|
||||
virtual ~ConditionalCommand() = default;
|
||||
|
||||
protected:
|
||||
/**
|
||||
* The Condition to test to determine which Command to run.
|
||||
*
|
||||
* @return true if m_onTrue should be run or false if m_onFalse should be run.
|
||||
*/
|
||||
virtual bool Condition() = 0;
|
||||
|
||||
void _Initialize() override;
|
||||
void _Cancel() override;
|
||||
bool IsFinished() override;
|
||||
void Interrupted() override;
|
||||
|
||||
private:
|
||||
/**
|
||||
* The Command to execute if {@link ConditionalCommand#Condition()} returns
|
||||
* true
|
||||
*/
|
||||
Command* m_onTrue;
|
||||
|
||||
/**
|
||||
* The Command to execute if {@link ConditionalCommand#Condition()} returns
|
||||
* false
|
||||
*/
|
||||
Command* m_onFalse;
|
||||
|
||||
/**
|
||||
* Stores command chosen by condition
|
||||
*/
|
||||
Command* m_chosenCommand = nullptr;
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
32
wpilibc/src/main/native/include/Commands/InstantCommand.h
Normal file
32
wpilibc/src/main/native/include/Commands/InstantCommand.h
Normal file
@@ -0,0 +1,32 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2016-2017. 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 <string>
|
||||
|
||||
#include "Commands/Command.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
/**
|
||||
* This command will execute once, then finish immediately afterward.
|
||||
*
|
||||
* <p>Subclassing {@link InstantCommand} is shorthand for returning true from
|
||||
* {@link Command isFinished}.
|
||||
*/
|
||||
class InstantCommand : public Command {
|
||||
public:
|
||||
explicit InstantCommand(const std::string& name);
|
||||
InstantCommand() = default;
|
||||
virtual ~InstantCommand() = default;
|
||||
|
||||
protected:
|
||||
bool IsFinished() override;
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
61
wpilibc/src/main/native/include/Commands/PIDCommand.h
Normal file
61
wpilibc/src/main/native/include/Commands/PIDCommand.h
Normal file
@@ -0,0 +1,61 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2011-2017. 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 <memory>
|
||||
#include <string>
|
||||
|
||||
#include "Commands/Command.h"
|
||||
#include "PIDController.h"
|
||||
#include "PIDOutput.h"
|
||||
#include "PIDSource.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
class PIDCommand : public Command, public PIDOutput, public PIDSource {
|
||||
public:
|
||||
PIDCommand(const std::string& name, double p, double i, double d);
|
||||
PIDCommand(const std::string& name, double p, double i, double d,
|
||||
double period);
|
||||
PIDCommand(const std::string& name, double p, double i, double d, double f,
|
||||
double period);
|
||||
PIDCommand(double p, double i, double d);
|
||||
PIDCommand(double p, double i, double d, double period);
|
||||
PIDCommand(double p, double i, double d, double f, double period);
|
||||
virtual ~PIDCommand() = default;
|
||||
|
||||
void SetSetpointRelative(double deltaSetpoint);
|
||||
|
||||
// PIDOutput interface
|
||||
virtual void PIDWrite(double output);
|
||||
|
||||
// PIDSource interface
|
||||
virtual double PIDGet();
|
||||
|
||||
protected:
|
||||
std::shared_ptr<PIDController> GetPIDController() const;
|
||||
virtual void _Initialize();
|
||||
virtual void _Interrupted();
|
||||
virtual void _End();
|
||||
void SetSetpoint(double setpoint);
|
||||
double GetSetpoint() const;
|
||||
double GetPosition();
|
||||
|
||||
virtual double ReturnPIDInput() = 0;
|
||||
virtual void UsePIDOutput(double output) = 0;
|
||||
|
||||
private:
|
||||
/** The internal {@link PIDController} */
|
||||
std::shared_ptr<PIDController> m_controller;
|
||||
|
||||
public:
|
||||
void InitTable(std::shared_ptr<ITable> subtable) override;
|
||||
std::string GetSmartDashboardType() const override;
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
76
wpilibc/src/main/native/include/Commands/PIDSubsystem.h
Normal file
76
wpilibc/src/main/native/include/Commands/PIDSubsystem.h
Normal file
@@ -0,0 +1,76 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2011-2017. 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 <memory>
|
||||
#include <string>
|
||||
|
||||
#include "Commands/Subsystem.h"
|
||||
#include "PIDController.h"
|
||||
#include "PIDOutput.h"
|
||||
#include "PIDSource.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
/**
|
||||
* This class is designed to handle the case where there is a {@link Subsystem}
|
||||
* which uses a single {@link PIDController} almost constantly (for instance,
|
||||
* an elevator which attempts to stay at a constant height).
|
||||
*
|
||||
* <p>It provides some convenience methods to run an internal {@link
|
||||
* PIDController}. It also allows access to the internal {@link PIDController}
|
||||
* in order to give total control to the programmer.</p>
|
||||
*
|
||||
*/
|
||||
class PIDSubsystem : public Subsystem, public PIDOutput, public PIDSource {
|
||||
public:
|
||||
PIDSubsystem(const std::string& name, double p, double i, double d);
|
||||
PIDSubsystem(const std::string& name, double p, double i, double d, double f);
|
||||
PIDSubsystem(const std::string& name, double p, double i, double d, double f,
|
||||
double period);
|
||||
PIDSubsystem(double p, double i, double d);
|
||||
PIDSubsystem(double p, double i, double d, double f);
|
||||
PIDSubsystem(double p, double i, double d, double f, double period);
|
||||
virtual ~PIDSubsystem() = default;
|
||||
|
||||
void Enable();
|
||||
void Disable();
|
||||
|
||||
// PIDOutput interface
|
||||
virtual void PIDWrite(double output);
|
||||
|
||||
// PIDSource interface
|
||||
virtual double PIDGet();
|
||||
void SetSetpoint(double setpoint);
|
||||
void SetSetpointRelative(double deltaSetpoint);
|
||||
void SetInputRange(double minimumInput, double maximumInput);
|
||||
void SetOutputRange(double minimumOutput, double maximumOutput);
|
||||
double GetSetpoint();
|
||||
double GetPosition();
|
||||
double GetRate();
|
||||
|
||||
virtual void SetAbsoluteTolerance(double absValue);
|
||||
virtual void SetPercentTolerance(double percent);
|
||||
virtual bool OnTarget() const;
|
||||
|
||||
protected:
|
||||
std::shared_ptr<PIDController> GetPIDController();
|
||||
|
||||
virtual double ReturnPIDInput() = 0;
|
||||
virtual void UsePIDOutput(double output) = 0;
|
||||
|
||||
private:
|
||||
/** The internal {@link PIDController} */
|
||||
std::shared_ptr<PIDController> m_controller;
|
||||
|
||||
public:
|
||||
void InitTable(std::shared_ptr<ITable> subtable) override;
|
||||
std::string GetSmartDashboardType() const override;
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
28
wpilibc/src/main/native/include/Commands/PrintCommand.h
Normal file
28
wpilibc/src/main/native/include/Commands/PrintCommand.h
Normal file
@@ -0,0 +1,28 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2011-2017. 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 <string>
|
||||
|
||||
#include "Commands/InstantCommand.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
class PrintCommand : public InstantCommand {
|
||||
public:
|
||||
explicit PrintCommand(const std::string& message);
|
||||
virtual ~PrintCommand() = default;
|
||||
|
||||
protected:
|
||||
virtual void Initialize();
|
||||
|
||||
private:
|
||||
std::string m_message;
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
73
wpilibc/src/main/native/include/Commands/Scheduler.h
Normal file
73
wpilibc/src/main/native/include/Commands/Scheduler.h
Normal file
@@ -0,0 +1,73 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2011-2017. 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 <list>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "Commands/Command.h"
|
||||
#include "ErrorBase.h"
|
||||
#include "HAL/cpp/priority_mutex.h"
|
||||
#include "SmartDashboard/NamedSendable.h"
|
||||
#include "SmartDashboard/SmartDashboard.h"
|
||||
#include "networktables/NetworkTable.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
class ButtonScheduler;
|
||||
class Subsystem;
|
||||
|
||||
class Scheduler : public ErrorBase, public NamedSendable {
|
||||
public:
|
||||
static Scheduler* GetInstance();
|
||||
|
||||
void AddCommand(Command* command);
|
||||
void AddButton(ButtonScheduler* button);
|
||||
void RegisterSubsystem(Subsystem* subsystem);
|
||||
void Run();
|
||||
void Remove(Command* command);
|
||||
void RemoveAll();
|
||||
void ResetAll();
|
||||
void SetEnabled(bool enabled);
|
||||
|
||||
void UpdateTable();
|
||||
std::string GetSmartDashboardType() const;
|
||||
void InitTable(std::shared_ptr<ITable> subTable);
|
||||
std::shared_ptr<ITable> GetTable() const;
|
||||
std::string GetName() const;
|
||||
std::string GetType() const;
|
||||
|
||||
private:
|
||||
Scheduler();
|
||||
virtual ~Scheduler() = default;
|
||||
|
||||
void ProcessCommandAddition(Command* command);
|
||||
|
||||
Command::SubsystemSet m_subsystems;
|
||||
hal::priority_mutex m_buttonsLock;
|
||||
typedef std::vector<ButtonScheduler*> ButtonVector;
|
||||
ButtonVector m_buttons;
|
||||
typedef std::vector<Command*> CommandVector;
|
||||
hal::priority_mutex m_additionsLock;
|
||||
CommandVector m_additions;
|
||||
typedef std::set<Command*> CommandSet;
|
||||
CommandSet m_commands;
|
||||
bool m_adding = false;
|
||||
bool m_enabled = true;
|
||||
std::vector<std::string> commands;
|
||||
std::vector<double> ids;
|
||||
std::vector<double> toCancel;
|
||||
std::shared_ptr<ITable> m_table;
|
||||
bool m_runningCommandsChanged = false;
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
26
wpilibc/src/main/native/include/Commands/StartCommand.h
Normal file
26
wpilibc/src/main/native/include/Commands/StartCommand.h
Normal file
@@ -0,0 +1,26 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2011-2017. 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"
|
||||
|
||||
namespace frc {
|
||||
|
||||
class StartCommand : public InstantCommand {
|
||||
public:
|
||||
explicit StartCommand(Command* commandToStart);
|
||||
virtual ~StartCommand() = default;
|
||||
|
||||
protected:
|
||||
virtual void Initialize();
|
||||
|
||||
private:
|
||||
Command* m_commandToFork;
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
53
wpilibc/src/main/native/include/Commands/Subsystem.h
Normal file
53
wpilibc/src/main/native/include/Commands/Subsystem.h
Normal file
@@ -0,0 +1,53 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2011-2017. 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 <memory>
|
||||
#include <string>
|
||||
|
||||
#include "ErrorBase.h"
|
||||
#include "SmartDashboard/NamedSendable.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
class Command;
|
||||
|
||||
class Subsystem : public ErrorBase, public NamedSendable {
|
||||
friend class Scheduler;
|
||||
|
||||
public:
|
||||
explicit Subsystem(const std::string& name);
|
||||
virtual ~Subsystem() = default;
|
||||
|
||||
void SetDefaultCommand(Command* command);
|
||||
Command* GetDefaultCommand();
|
||||
void SetCurrentCommand(Command* command);
|
||||
Command* GetCurrentCommand() const;
|
||||
virtual void Periodic();
|
||||
virtual void InitDefaultCommand();
|
||||
|
||||
private:
|
||||
void ConfirmCommand();
|
||||
|
||||
Command* m_currentCommand = nullptr;
|
||||
bool m_currentCommandChanged = true;
|
||||
Command* m_defaultCommand = nullptr;
|
||||
std::string m_name;
|
||||
bool m_initializedDefaultCommand = false;
|
||||
|
||||
public:
|
||||
std::string GetName() const override;
|
||||
void InitTable(std::shared_ptr<ITable> subtable) override;
|
||||
std::shared_ptr<ITable> GetTable() const override;
|
||||
std::string GetSmartDashboardType() const override;
|
||||
|
||||
protected:
|
||||
std::shared_ptr<ITable> m_table;
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
30
wpilibc/src/main/native/include/Commands/TimedCommand.h
Normal file
30
wpilibc/src/main/native/include/Commands/TimedCommand.h
Normal file
@@ -0,0 +1,30 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2016-2017. 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 <string>
|
||||
|
||||
#include "Commands/Command.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
/**
|
||||
* A {@link TimedCommand} will wait for a timeout before finishing.
|
||||
* {@link TimedCommand} is used to execute a command for a given amount of time.
|
||||
*/
|
||||
class TimedCommand : public Command {
|
||||
public:
|
||||
TimedCommand(const std::string& name, double timeout);
|
||||
explicit TimedCommand(double timeout);
|
||||
virtual ~TimedCommand() = default;
|
||||
|
||||
protected:
|
||||
bool IsFinished() override;
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
23
wpilibc/src/main/native/include/Commands/WaitCommand.h
Normal file
23
wpilibc/src/main/native/include/Commands/WaitCommand.h
Normal file
@@ -0,0 +1,23 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2011-2017. 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 <string>
|
||||
|
||||
#include "Commands/TimedCommand.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
class WaitCommand : public TimedCommand {
|
||||
public:
|
||||
explicit WaitCommand(double timeout);
|
||||
WaitCommand(const std::string& name, double timeout);
|
||||
virtual ~WaitCommand() = default;
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
26
wpilibc/src/main/native/include/Commands/WaitForChildren.h
Normal file
26
wpilibc/src/main/native/include/Commands/WaitForChildren.h
Normal file
@@ -0,0 +1,26 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2011-2017. 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 <string>
|
||||
|
||||
#include "Commands/Command.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
class WaitForChildren : public Command {
|
||||
public:
|
||||
explicit WaitForChildren(double timeout);
|
||||
WaitForChildren(const std::string& name, double timeout);
|
||||
virtual ~WaitForChildren() = default;
|
||||
|
||||
protected:
|
||||
virtual bool IsFinished();
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
29
wpilibc/src/main/native/include/Commands/WaitUntilCommand.h
Normal file
29
wpilibc/src/main/native/include/Commands/WaitUntilCommand.h
Normal file
@@ -0,0 +1,29 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2011-2017. 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 <string>
|
||||
|
||||
#include "Commands/Command.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
class WaitUntilCommand : public Command {
|
||||
public:
|
||||
explicit WaitUntilCommand(double time);
|
||||
WaitUntilCommand(const std::string& name, double time);
|
||||
virtual ~WaitUntilCommand() = default;
|
||||
|
||||
protected:
|
||||
virtual bool IsFinished();
|
||||
|
||||
private:
|
||||
double m_time;
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
Reference in New Issue
Block a user