mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-06 03:31:43 +00:00
committed by
Peter Johnson
parent
b115c75226
commit
b78f580d47
@@ -81,45 +81,13 @@ class Command : public ErrorBase, public NamedSendable, public ITableListener {
|
||||
bool IsTimedOut() const;
|
||||
bool AssertUnlocked(const std::string& message);
|
||||
void SetParent(CommandGroup* parent);
|
||||
/**
|
||||
* The initialize method is called the first time this Command is run after
|
||||
* being started.
|
||||
*/
|
||||
virtual void Initialize() = 0;
|
||||
/**
|
||||
* The execute method is called repeatedly until this Command either finishes
|
||||
* or is canceled.
|
||||
*/
|
||||
virtual void Execute() = 0;
|
||||
/**
|
||||
* 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>
|
||||
* @return whether this command is finished.
|
||||
* @see Command#isTimedOut() isTimedOut()
|
||||
*/
|
||||
virtual bool IsFinished() = 0;
|
||||
/**
|
||||
* Called when the command ended peacefully. This is where you may want
|
||||
* to wrap up loose ends, like shutting off a motor that was being used
|
||||
* in the command.
|
||||
*/
|
||||
virtual void End() = 0;
|
||||
/**
|
||||
* Called when the command ends because somebody called
|
||||
* {@link Command#cancel() cancel()} or another command shared the same
|
||||
* requirements as this one, and booted it out.
|
||||
*
|
||||
* <p>This is where you may want to wrap up loose ends, like shutting off a
|
||||
* motor that was being used in the command.</p>
|
||||
*
|
||||
* <p>Generally, it is useful to simply call the {@link Command#end() end()}
|
||||
* method within this method</p>
|
||||
*/
|
||||
virtual void Interrupted() = 0;
|
||||
|
||||
virtual void Initialize();
|
||||
virtual void Execute();
|
||||
virtual bool IsFinished();
|
||||
virtual void End();
|
||||
virtual void Interrupted();
|
||||
|
||||
virtual void _Initialize();
|
||||
virtual void _Interrupted();
|
||||
virtual void _Execute();
|
||||
|
||||
26
wpilibc/shared/include/Commands/InstantCommand.h
Normal file
26
wpilibc/shared/include/Commands/InstantCommand.h
Normal file
@@ -0,0 +1,26 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2016. 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 InstantCommand : public Command {
|
||||
public:
|
||||
explicit InstantCommand(const std::string& name);
|
||||
InstantCommand() = default;
|
||||
virtual ~InstantCommand() = default;
|
||||
|
||||
protected:
|
||||
virtual bool IsFinished();
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
@@ -9,21 +9,17 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "Commands/Command.h"
|
||||
#include "Commands/InstantCommand.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
class PrintCommand : public Command {
|
||||
class PrintCommand : public InstantCommand {
|
||||
public:
|
||||
explicit PrintCommand(const std::string& message);
|
||||
virtual ~PrintCommand() = default;
|
||||
|
||||
protected:
|
||||
virtual void Initialize();
|
||||
virtual void Execute();
|
||||
virtual bool IsFinished();
|
||||
virtual void End();
|
||||
virtual void Interrupted();
|
||||
|
||||
private:
|
||||
std::string m_message;
|
||||
|
||||
@@ -7,21 +7,17 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Commands/Command.h"
|
||||
#include "Commands/InstantCommand.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
class StartCommand : public Command {
|
||||
class StartCommand : public InstantCommand {
|
||||
public:
|
||||
explicit StartCommand(Command* commandToStart);
|
||||
virtual ~StartCommand() = default;
|
||||
|
||||
protected:
|
||||
virtual void Initialize();
|
||||
virtual void Execute();
|
||||
virtual bool IsFinished();
|
||||
virtual void End();
|
||||
virtual void Interrupted();
|
||||
|
||||
private:
|
||||
Command* m_commandToFork;
|
||||
|
||||
26
wpilibc/shared/include/Commands/TimedCommand.h
Normal file
26
wpilibc/shared/include/Commands/TimedCommand.h
Normal file
@@ -0,0 +1,26 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2016. 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 TimedCommand : public Command {
|
||||
public:
|
||||
TimedCommand(const std::string& name, double timeout);
|
||||
explicit TimedCommand(double timeout);
|
||||
virtual ~TimedCommand() = default;
|
||||
|
||||
protected:
|
||||
virtual bool IsFinished();
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
@@ -9,22 +9,15 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "Commands/Command.h"
|
||||
#include "Commands/TimedCommand.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
class WaitCommand : public Command {
|
||||
class WaitCommand : public TimedCommand {
|
||||
public:
|
||||
explicit WaitCommand(double timeout);
|
||||
WaitCommand(const std::string& name, double timeout);
|
||||
virtual ~WaitCommand() = default;
|
||||
|
||||
protected:
|
||||
virtual void Initialize();
|
||||
virtual void Execute();
|
||||
virtual bool IsFinished();
|
||||
virtual void End();
|
||||
virtual void Interrupted();
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
|
||||
@@ -20,11 +20,7 @@ class WaitForChildren : public Command {
|
||||
virtual ~WaitForChildren() = default;
|
||||
|
||||
protected:
|
||||
virtual void Initialize();
|
||||
virtual void Execute();
|
||||
virtual bool IsFinished();
|
||||
virtual void End();
|
||||
virtual void Interrupted();
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
|
||||
@@ -20,11 +20,7 @@ class WaitUntilCommand : public Command {
|
||||
virtual ~WaitUntilCommand() = default;
|
||||
|
||||
protected:
|
||||
virtual void Initialize();
|
||||
virtual void Execute();
|
||||
virtual bool IsFinished();
|
||||
virtual void End();
|
||||
virtual void Interrupted();
|
||||
|
||||
private:
|
||||
double m_time;
|
||||
|
||||
Reference in New Issue
Block a user