Add format script which invokes clang-format on the C++ source code (#41)

On Windows machines, clang-format.exe must be in the PATH environment variable.
This commit is contained in:
Tyler Veness
2016-05-20 17:30:37 -07:00
committed by Peter Johnson
parent 68690643d2
commit e14e45da76
383 changed files with 13787 additions and 13198 deletions

View File

@@ -6,12 +6,12 @@
/*----------------------------------------------------------------------------*/
#include "Commands/Command.h"
#include <typeinfo>
#include "Commands/CommandGroup.h"
#include "Commands/Scheduler.h"
#include "RobotState.h"
#include "Timer.h"
#include "WPIErrors.h"
#include <typeinfo>
static const std::string kName = "name";
static const std::string kRunning = "running";
@@ -27,12 +27,14 @@ Command::Command() : Command("", -1.0) {}
/**
* Creates a new command with the given name and no timeout.
*
* @param name the name for this command
*/
Command::Command(const std::string &name) : Command(name, -1.0) {}
Command::Command(const std::string& name) : Command(name, -1.0) {}
/**
* Creates a new command with the given timeout and a default name.
*
* @param timeout the time (in seconds) before this command "times out"
* @see Command#isTimedOut() isTimedOut()
*/
@@ -40,11 +42,12 @@ Command::Command(double timeout) : Command("", timeout) {}
/**
* Creates a new command with the given name and timeout.
* @param name the name of the command
*
* @param name the name of the command
* @param timeout the time (in seconds) before this command "times out"
* @see Command#isTimedOut() isTimedOut()
*/
Command::Command(const std::string &name, double timeout) {
Command::Command(const std::string& name, double timeout) {
// We use -1.0 to indicate no timeout.
if (timeout < 0.0 && timeout != -1.0)
wpi_setWPIErrorWithContext(ParameterOutOfRange, "timeout < 0.0");
@@ -54,8 +57,7 @@ Command::Command(const std::string &name, double timeout) {
// If name contains an empty string
if (name.length() == 0) {
m_name = std::string("Command_") + std::string(typeid(*this).name());
}
else {
} else {
m_name = name;
}
}
@@ -65,14 +67,17 @@ Command::~Command() {
}
/**
* Get the ID (sequence number) for this command
* Get the ID (sequence number) for this command.
*
* The ID is a unique sequence number that is incremented for each command.
*
* @return the ID of this command
*/
int Command::GetID() const { return m_commandID; }
/**
* Sets the timeout of this command.
*
* @param timeout the timeout (in seconds)
* @see Command#isTimedOut() isTimedOut()
*/
@@ -85,7 +90,9 @@ void Command::SetTimeout(double timeout) {
/**
* Returns the time since this command was initialized (in seconds).
*
* This function will work even if there is no specified timeout.
*
* @return the time since this command was initialized (in seconds).
*/
double Command::TimeSinceInitialized() const {
@@ -98,6 +105,7 @@ double Command::TimeSinceInitialized() const {
/**
* This method specifies that the given {@link Subsystem} is used by this
* command.
*
* This method is crucial to the functioning of the Command System in general.
*
* <p>Note that the recommended way to call this method is in the
@@ -106,7 +114,7 @@ double Command::TimeSinceInitialized() const {
* @param subsystem the {@link Subsystem} required
* @see Subsystem
*/
void Command::Requires(Subsystem *subsystem) {
void Command::Requires(Subsystem* subsystem) {
if (!AssertUnlocked("Can not add new requirement to command")) return;
if (subsystem != nullptr)
@@ -117,8 +125,9 @@ void Command::Requires(Subsystem *subsystem) {
/**
* Called when the command has been removed.
* This will call {@link Command#interrupted() interrupted()} or {@link
* Command#end() end()}.
*
* This will call {@link Command#interrupted() interrupted()} or
* {@link Command#end() end()}.
*/
void Command::Removed() {
if (m_initialized) {
@@ -138,10 +147,10 @@ void Command::Removed() {
/**
* Starts up the command. Gets the command ready to start.
*
* <p>Note that the command will eventually start, however it will not
* necessarily
* do so immediately, and may in fact be canceled before initialize is even
* called.</p>
* necessarily do so immediately, and may in fact be canceled before initialize
* is even called.</p>
*/
void Command::Start() {
LockChanges();
@@ -155,6 +164,7 @@ void Command::Start() {
/**
* The run method is used internally to actually run the commands.
*
* @return whether or not the command should stay within the {@link Scheduler}.
*/
bool Command::Run() {
@@ -184,18 +194,19 @@ void Command::_End() {}
/**
* Called to indicate that the timer should start.
*
* This is called right before {@link Command#initialize() initialize()} is,
* inside the
* {@link Command#run() run()} method.
* inside the {@link Command#run() run()} method.
*/
void Command::StartTiming() { m_startTime = Timer::GetFPGATimestamp(); }
/**
* Returns whether or not the {@link Command#timeSinceInitialized()
* timeSinceInitialized()}
* method returns a number which is greater than or equal to the timeout for the
* command.
* Returns whether or not the
* {@link Command#timeSinceInitialized() timeSinceInitialized()} method returns
* a number which is greater than or equal to the timeout for the command.
*
* If there is no timeout, this will always return false.
*
* @return whether the time has expired
*/
bool Command::IsTimedOut() const {
@@ -204,28 +215,31 @@ bool Command::IsTimedOut() const {
/**
* Returns the requirements (as an std::set of {@link Subsystem Subsystems}
* pointers) of this command
* pointers) of this command.
*
* @return the requirements (as an std::set of {@link Subsystem Subsystems}
* pointers) of this command
* pointers) of this command
*/
Command::SubsystemSet Command::GetRequirements() const {
return m_requirements;
}
/**
* Prevents further changes from being made
* Prevents further changes from being made.
*/
void Command::LockChanges() { m_locked = true; }
/**
* If changes are locked, then this will generate a CommandIllegalUse error.
*
* @param message the message to report on error (it is appended by a default
* message)
* message)
* @return true if assert passed, false if assert failed
*/
bool Command::AssertUnlocked(const std::string &message) {
bool Command::AssertUnlocked(const std::string& message) {
if (m_locked) {
std::string buf = message + " after being started or being added to a command group";
std::string buf =
message + " after being started or being added to a command group";
wpi_setWPIErrorWithContext(CommandIllegalUse, buf);
return false;
}
@@ -234,9 +248,10 @@ bool Command::AssertUnlocked(const std::string &message) {
/**
* Sets the parent of this command. No actual change is made to the group.
*
* @param parent the parent
*/
void Command::SetParent(CommandGroup *parent) {
void Command::SetParent(CommandGroup* parent) {
if (parent == nullptr) {
wpi_setWPIErrorWithContext(NullParameter, "parent");
} else if (m_parent != nullptr) {
@@ -254,6 +269,7 @@ void Command::SetParent(CommandGroup *parent) {
/**
* This is used internally to mark that the command has been started.
*
* The lifecycle of a command is:
*
* startRunning() is called.
@@ -261,8 +277,7 @@ void Command::SetParent(CommandGroup *parent) {
* removed() is called
*
* It is very important that startRunning and removed be called in order or some
* assumptions
* of the code will be broken.
* assumptions of the code will be broken.
*/
void Command::StartRunning() {
m_running = true;
@@ -272,22 +287,24 @@ void Command::StartRunning() {
/**
* Returns whether or not the command is running.
*
* This may return true even if the command has just been canceled, as it may
* not have yet called {@link Command#interrupted()}.
*
* @return whether or not the command is running
*/
bool Command::IsRunning() const { return m_running; }
/**
* This will cancel the current command.
*
* <p>This will cancel the current command eventually. It can be called
* multiple times.
* And it can be called when the command is not running. If the command is
* running though,
* then the command will be marked as canceled and eventually removed.</p>
* <p>A command can not be canceled
* if it is a part of a command group, you must cancel the command group
* instead.</p>
* multiple times. And it can be called when the command is not running. If
* the command is running though, then the command will be marked as canceled
* and eventually removed.</p>
*
* <p>A command can not be canceled if it is a part of a command group, you
* must cancel the command group instead.</p>
*/
void Command::Cancel() {
if (m_parent != nullptr)
@@ -300,8 +317,9 @@ void Command::Cancel() {
/**
* This works like cancel(), except that it doesn't throw an exception if it is
* a part
* of a command group. Should only be called by the parent command group.
* a part of a command group.
*
* Should only be called by the parent command group.
*/
void Command::_Cancel() {
if (IsRunning()) m_canceled = true;
@@ -309,18 +327,21 @@ void Command::_Cancel() {
/**
* Returns whether or not this has been canceled.
*
* @return whether or not this has been canceled
*/
bool Command::IsCanceled() const { return m_canceled; }
/**
* Returns whether or not this command can be interrupted.
*
* @return whether or not this command can be interrupted
*/
bool Command::IsInterruptible() const { return m_interruptible; }
/**
* Sets whether or not this command can be interrupted.
*
* @param interruptible whether or not this command can be interrupted
*/
void Command::SetInterruptible(bool interruptible) {
@@ -329,20 +350,23 @@ void Command::SetInterruptible(bool interruptible) {
/**
* Checks if the command requires the given {@link Subsystem}.
*
* @param system the system
* @return whether or not the subsystem is required (false if given nullptr)
*/
bool Command::DoesRequire(Subsystem *system) const {
bool Command::DoesRequire(Subsystem* system) const {
return m_requirements.count(system) > 0;
}
/**
* Returns the {@link CommandGroup} that this command is a part of.
*
* Will return null if this {@link Command} is not in a group.
*
* @return the {@link CommandGroup} that this command is a part of (or null if
* not in group)
* not in group)
*/
CommandGroup *Command::GetGroup() const { return m_parent; }
CommandGroup* Command::GetGroup() const { return m_parent; }
/**
* Sets whether or not this {@link Command} should run when the robot is
@@ -350,6 +374,7 @@ CommandGroup *Command::GetGroup() const { return m_parent; }
*
* <p>By default a command will not run when the robot is disabled, and will in
* fact be canceled.</p>
*
* @param run whether or not this command should run when the robot is disabled
*/
void Command::SetRunWhenDisabled(bool run) { m_runWhenDisabled = run; }
@@ -357,14 +382,13 @@ void Command::SetRunWhenDisabled(bool run) { m_runWhenDisabled = run; }
/**
* Returns whether or not this {@link Command} will run when the robot is
* disabled, or if it will cancel itself.
*
* @return whether or not this {@link Command} will run when the robot is
* disabled, or if it will cancel itself
* disabled, or if it will cancel itself
*/
bool Command::WillRunWhenDisabled() const { return m_runWhenDisabled; }
std::string Command::GetName() const {
return m_name;
}
std::string Command::GetName() const { return m_name; }
std::string Command::GetSmartDashboardType() const { return "Command"; }

View File

@@ -12,24 +12,21 @@
* Creates a new {@link CommandGroup CommandGroup} with the given name.
* @param name the name for this command group
*/
CommandGroup::CommandGroup(const std::string &name) : Command(name) {}
CommandGroup::CommandGroup(const std::string& name) : Command(name) {}
/**
* Adds a new {@link Command Command} to the group. The {@link Command Command}
* will be started after
* all the previously added {@link Command Commands}.
* will be started after all the previously added {@link Command Commands}.
*
* <p>Note that any requirements the given {@link Command Command} has will be
* added to the
* group. For this reason, a {@link Command Command's} requirements can not be
* changed after
* being added to a group.</p>
* added to the group. For this reason, a {@link Command Command's}
* requirements can not be changed after being added to a group.</p>
*
* <p>It is recommended that this method be called in the constructor.</p>
*
* @param command The {@link Command Command} to be added
*/
void CommandGroup::AddSequential(Command *command) {
void CommandGroup::AddSequential(Command* command) {
if (command == nullptr) {
wpi_setWPIErrorWithContext(NullParameter, "command");
return;
@@ -53,23 +50,19 @@ void CommandGroup::AddSequential(Command *command) {
* commands.
*
* <p>Once the {@link Command Command} is started, it will be run until it
* finishes or the time
* expires, whichever is sooner. Note that the given {@link Command Command}
* will have no
* knowledge that it is on a timer.</p>
* finishes or the time expires, whichever is sooner. Note that the given
* {@link Command Command} will have no knowledge that it is on a timer.</p>
*
* <p>Note that any requirements the given {@link Command Command} has will be
* added to the
* group. For this reason, a {@link Command Command's} requirements can not be
* changed after
* being added to a group.</p>
* added to the group. For this reason, a {@link Command Command's}
* requirements can not be changed after being added to a group.</p>
*
* <p>It is recommended that this method be called in the constructor.</p>
*
* @param command The {@link Command Command} to be added
* @param timeout The timeout (in seconds)
*/
void CommandGroup::AddSequential(Command *command, double timeout) {
void CommandGroup::AddSequential(Command* command, double timeout) {
if (command == nullptr) {
wpi_setWPIErrorWithContext(NullParameter, "command");
return;
@@ -93,30 +86,24 @@ void CommandGroup::AddSequential(Command *command, double timeout) {
/**
* Adds a new child {@link Command} to the group. The {@link Command} will be
* started after
* all the previously added {@link Command Commands}.
* started after all the previously added {@link Command Commands}.
*
* <p>Instead of waiting for the child to finish, a {@link CommandGroup} will
* have it
* run at the same time as the subsequent {@link Command Commands}. The child
* will run until either
* it finishes, a new child with conflicting requirements is started, or
* the main sequence runs a {@link Command} with conflicting requirements. In
* the latter
* two cases, the child will be canceled even if it says it can't be
* interrupted.</p>
* have it run at the same time as the subsequent {@link Command Commands}.
* The child will run until either it finishes, a new child with conflicting
* requirements is started, or the main sequence runs a {@link Command} with
* conflicting requirements. In the latter two cases, the child will be
* canceled even if it says it can't be interrupted.</p>
*
* <p>Note that any requirements the given {@link Command Command} has will be
* added to the
* group. For this reason, a {@link Command Command's} requirements can not be
* changed after
* being added to a group.</p>
* added to the group. For this reason, a {@link Command Command's}
* requirements can not be changed after being added to a group.</p>
*
* <p>It is recommended that this method be called in the constructor.</p>
*
* @param command The command to be added
*/
void CommandGroup::AddParallel(Command *command) {
void CommandGroup::AddParallel(Command* command) {
if (command == nullptr) {
wpi_setWPIErrorWithContext(NullParameter, "command");
return;
@@ -136,38 +123,31 @@ void CommandGroup::AddParallel(Command *command) {
/**
* Adds a new child {@link Command} to the group with the given timeout. The
* {@link Command} will be started after
* all the previously added {@link Command Commands}.
* {@link Command} will be started after all the previously added
* {@link Command Commands}.
*
* <p>Once the {@link Command Command} is started, it will run until it
* finishes, is interrupted,
* or the time expires, whichever is sooner. Note that the given {@link Command
* Command} will have no
* knowledge that it is on a timer.</p>
* finishes, is interrupted, or the time expires, whichever is sooner. Note
* that the given {@link Command Command} will have no knowledge that it is on
* a timer.</p>
*
* <p>Instead of waiting for the child to finish, a {@link CommandGroup} will
* have it
* run at the same time as the subsequent {@link Command Commands}. The child
* will run until either
* it finishes, the timeout expires, a new child with conflicting requirements
* is started, or
* the main sequence runs a {@link Command} with conflicting requirements. In
* the latter
* two cases, the child will be canceled even if it says it can't be
* interrupted.</p>
* have it run at the same time as the subsequent {@link Command Commands}.
* The child will run until either it finishes, the timeout expires, a new
* child with conflicting requirements is started, or the main sequence runs a
* {@link Command} with conflicting requirements. In the latter two cases, the
* child will be canceled even if it says it can't be interrupted.</p>
*
* <p>Note that any requirements the given {@link Command Command} has will be
* added to the
* group. For this reason, a {@link Command Command's} requirements can not be
* changed after
* being added to a group.</p>
* added to the group. For this reason, a {@link Command Command's}
* requirements can not be changed after being added to a group.</p>
*
* <p>It is recommended that this method be called in the constructor.</p>
*
* @param command The command to be added
* @param timeout The timeout (in seconds)
*/
void CommandGroup::AddParallel(Command *command, double timeout) {
void CommandGroup::AddParallel(Command* command, double timeout) {
if (command == nullptr) {
wpi_setWPIErrorWithContext(NullParameter, "command");
return;
@@ -193,7 +173,7 @@ void CommandGroup::_Initialize() { m_currentCommandIndex = -1; }
void CommandGroup::_Execute() {
CommandGroupEntry entry;
Command *cmd = nullptr;
Command* cmd = nullptr;
bool firstRun = false;
if (m_currentCommandIndex == -1) {
@@ -247,7 +227,7 @@ void CommandGroup::_Execute() {
auto iter = m_children.begin();
for (; iter != m_children.end();) {
entry = *iter;
Command *child = entry.m_command;
Command* child = entry.m_command;
if (entry.IsTimedOut()) child->_Cancel();
if (!child->Run()) {
@@ -264,14 +244,14 @@ void CommandGroup::_End() {
// IsFinished method
if (m_currentCommandIndex != -1 &&
(unsigned)m_currentCommandIndex < m_commands.size()) {
Command *cmd = m_commands[m_currentCommandIndex].m_command;
Command* cmd = m_commands[m_currentCommandIndex].m_command;
cmd->_Cancel();
cmd->Removed();
}
auto iter = m_children.begin();
for (; iter != m_children.end(); iter++) {
Command *cmd = iter->m_command;
Command* cmd = iter->m_command;
cmd->_Cancel();
cmd->Removed();
}
@@ -302,7 +282,7 @@ bool CommandGroup::IsInterruptible() const {
if (m_currentCommandIndex != -1 &&
(unsigned)m_currentCommandIndex < m_commands.size()) {
Command *cmd = m_commands[m_currentCommandIndex].m_command;
Command* cmd = m_commands[m_currentCommandIndex].m_command;
if (!cmd->IsInterruptible()) return false;
}
@@ -314,10 +294,10 @@ bool CommandGroup::IsInterruptible() const {
return true;
}
void CommandGroup::CancelConflicts(Command *command) {
void CommandGroup::CancelConflicts(Command* command) {
auto childIter = m_children.begin();
for (; childIter != m_children.end();) {
Command *child = childIter->m_command;
Command* child = childIter->m_command;
bool erased = false;
Command::SubsystemSet requirements = command->GetRequirements();

View File

@@ -9,7 +9,7 @@
#include "Commands/Command.h"
CommandGroupEntry::CommandGroupEntry(Command *command, Sequence state,
CommandGroupEntry::CommandGroupEntry(Command* command, Sequence state,
double timeout)
: m_timeout(timeout), m_command(command), m_state(state) {}

View File

@@ -9,22 +9,23 @@
#include "float.h"
PIDCommand::PIDCommand(const std::string &name, double p, double i, double d, double f,
double period)
PIDCommand::PIDCommand(const std::string& name, double p, double i, double d,
double f, double period)
: Command(name) {
m_controller = std::make_shared<PIDController>(p, i, d, this, this, period);
}
PIDCommand::PIDCommand(double p, double i, double d, double f, double period) {
m_controller = std::make_shared<PIDController>(p, i, d, f, this, this, period);
m_controller =
std::make_shared<PIDController>(p, i, d, f, this, this, period);
}
PIDCommand::PIDCommand(const std::string &name, double p, double i, double d)
PIDCommand::PIDCommand(const std::string& name, double p, double i, double d)
: Command(name) {
m_controller = std::make_shared<PIDController>(p, i, d, this, this);
}
PIDCommand::PIDCommand(const std::string &name, double p, double i, double d,
PIDCommand::PIDCommand(const std::string& name, double p, double i, double d,
double period)
: Command(name) {
m_controller = std::make_shared<PIDController>(p, i, d, this, this, period);

View File

@@ -12,12 +12,14 @@
/**
* Instantiates a {@link PIDSubsystem} that will use the given p, i and d
* values.
*
* @param name the name
* @param p the proportional value
* @param i the integral value
* @param d the derivative value
* @param p the proportional value
* @param i the integral value
* @param d the derivative value
*/
PIDSubsystem::PIDSubsystem(const std::string &name, double p, double i, double d)
PIDSubsystem::PIDSubsystem(const std::string& name, double p, double i,
double d)
: Subsystem(name) {
m_controller = std::make_shared<PIDController>(p, i, d, this, this);
}
@@ -25,39 +27,46 @@ PIDSubsystem::PIDSubsystem(const std::string &name, double p, double i, double d
/**
* Instantiates a {@link PIDSubsystem} that will use the given p, i and d
* values.
*
* @param name the name
* @param p the proportional value
* @param i the integral value
* @param d the derivative value
* @param f the feedforward value
* @param p the proportional value
* @param i the integral value
* @param d the derivative value
* @param f the feedforward value
*/
PIDSubsystem::PIDSubsystem(const std::string &name, double p, double i, double d,
double f)
PIDSubsystem::PIDSubsystem(const std::string& name, double p, double i,
double d, double f)
: Subsystem(name) {
m_controller = std::make_shared<PIDController>(p, i, d, f, this, this);
}
/**
* Instantiates a {@link PIDSubsystem} that will use the given p, i and d
* values. It will also space the time
* between PID loop calculations to be equal to the given period.
* @param name the name
* @param p the proportional value
* @param i the integral value
* @param d the derivative value
* @param f the feedfoward value
* values.
*
* It will also space the time between PID loop calculations to be equal to the
* given period.
*
* @param name the name
* @param p the proportional value
* @param i the integral value
* @param d the derivative value
* @param f the feedfoward value
* @param period the time (in seconds) between calculations
*/
PIDSubsystem::PIDSubsystem(const std::string &name, double p, double i, double d,
double f, double period)
PIDSubsystem::PIDSubsystem(const std::string& name, double p, double i,
double d, double f, double period)
: Subsystem(name) {
m_controller = std::make_shared<PIDController>(p, i, d, f, this, this, period);
m_controller =
std::make_shared<PIDController>(p, i, d, f, this, this, period);
}
/**
* Instantiates a {@link PIDSubsystem} that will use the given p, i and d
* values.
*
* It will use the class name as its name.
*
* @param p the proportional value
* @param i the integral value
* @param d the derivative value
@@ -70,7 +79,9 @@ PIDSubsystem::PIDSubsystem(double p, double i, double d)
/**
* Instantiates a {@link PIDSubsystem} that will use the given p, i and d
* values.
*
* It will use the class name as its name.
*
* @param p the proportional value
* @param i the integral value
* @param d the derivative value
@@ -84,33 +95,36 @@ PIDSubsystem::PIDSubsystem(double p, double i, double d, double f)
/**
* Instantiates a {@link PIDSubsystem} that will use the given p, i and d
* values.
* It will use the class name as its name.
* It will also space the time
*
* It will use the class name as its name. It will also space the time
* between PID loop calculations to be equal to the given period.
* @param p the proportional value
* @param i the integral value
* @param d the derivative value
* @param f the feedforward value
*
* @param p the proportional value
* @param i the integral value
* @param d the derivative value
* @param f the feedforward value
* @param period the time (in seconds) between calculations
*/
PIDSubsystem::PIDSubsystem(double p, double i, double d, double f,
double period)
: Subsystem("PIDSubsystem") {
m_controller = std::make_shared<PIDController>(p, i, d, f, this, this, period);
m_controller =
std::make_shared<PIDController>(p, i, d, f, this, this, period);
}
/**
* Enables the internal {@link PIDController}
* Enables the internal {@link PIDController}.
*/
void PIDSubsystem::Enable() { m_controller->Enable(); }
/**
* Disables the internal {@link PIDController}
* Disables the internal {@link PIDController}.
*/
void PIDSubsystem::Disable() { m_controller->Disable(); }
/**
* Returns the {@link PIDController} used by this {@link PIDSubsystem}.
*
* Use this if you would like to fine tune the pid loop.
*
* @return the {@link PIDController} used by this {@link PIDSubsystem}
@@ -120,11 +134,11 @@ std::shared_ptr<PIDController> PIDSubsystem::GetPIDController() {
}
/**
* Sets the setpoint to the given value. If {@link PIDCommand#SetRange(double,
* double) SetRange(...)}
* was called,
* then the given setpoint
* will be trimmed to fit within the range.
* Sets the setpoint to the given value.
*
* If {@link PIDCommand#SetRange(double, double) SetRange(...)} was called,
* then the given setpoint will be trimmed to fit within the range.
*
* @param setpoint the new setpoint
*/
void PIDSubsystem::SetSetpoint(double setpoint) {
@@ -133,8 +147,10 @@ void PIDSubsystem::SetSetpoint(double setpoint) {
/**
* Adds the given value to the setpoint.
*
* If {@link PIDCommand#SetRange(double, double) SetRange(...)} was used,
* then the bounds will still be honored by this method.
*
* @param deltaSetpoint the change in the setpoint
*/
void PIDSubsystem::SetSetpointRelative(double deltaSetpoint) {
@@ -142,7 +158,8 @@ void PIDSubsystem::SetSetpointRelative(double deltaSetpoint) {
}
/**
* Return the current setpoint
* Return the current setpoint.
*
* @return The current setpoint
*/
double PIDSubsystem::GetSetpoint() { return m_controller->GetSetpoint(); }
@@ -167,49 +184,52 @@ void PIDSubsystem::SetOutputRange(float minimumOutput, float maximumOutput) {
m_controller->SetOutputRange(minimumOutput, maximumOutput);
}
/*
/**
* Set the absolute error which is considered tolerable for use with
* OnTarget.
* @param percentage error which is tolerable
*
* @param absValue absolute error which is tolerable
*/
void PIDSubsystem::SetAbsoluteTolerance(float absValue) {
m_controller->SetAbsoluteTolerance(absValue);
}
/*
* Set the percentage error which is considered tolerable for use with
* OnTarget.
* @param percentage error which is tolerable
/**
* Set the percentage error which is considered tolerable for use with OnTarget.
*
* @param percent percentage error which is tolerable
*/
void PIDSubsystem::SetPercentTolerance(float percent) {
m_controller->SetPercentTolerance(percent);
}
/*
/**
* Return true if the error is within the percentage of the total input range,
* determined by SetTolerance. This asssumes that the maximum and minimum input
* were set using SetInput. Use OnTarget() in the IsFinished() method of
* commands
* that use this subsystem.
* determined by SetTolerance.
*
* This asssumes that the maximum and minimum input were set using SetInput.
* Use OnTarget() in the IsFinished() method of commands that use this
* subsystem.
*
* Currently this just reports on target as the actual value passes through the
* setpoint.
* Ideally it should be based on being within the tolerance for some period of
* time.
* setpoint. Ideally it should be based on being within the tolerance for some
* period of time.
*
* @return true if the error is within the percentage tolerance of the input
* range
* range
*/
bool PIDSubsystem::OnTarget() const { return m_controller->OnTarget(); }
/**
* Returns the current position
* Returns the current position.
*
* @return the current position
*/
double PIDSubsystem::GetPosition() { return ReturnPIDInput(); }
/**
* Returns the current rate
* Returns the current rate.
*
* @return the current rate
*/
double PIDSubsystem::GetRate() { return ReturnPIDInput(); }

View File

@@ -6,12 +6,12 @@
/*----------------------------------------------------------------------------*/
#include "Commands/PrintCommand.h"
#include "stdio.h"
#include <sstream>
#include "stdio.h"
PrintCommand::PrintCommand(const std::string &message)
: Command(((std::stringstream &)(std::stringstream("Print \"") << message
<< "\""))
PrintCommand::PrintCommand(const std::string& message)
: Command(((std::stringstream&)(std::stringstream("Print \"") << message
<< "\""))
.str()
.c_str()) {
m_message = message;

View File

@@ -7,23 +7,22 @@
#include "Commands/Scheduler.h"
#include <algorithm>
#include <iostream>
#include <set>
#include "Buttons/ButtonScheduler.h"
#include "Commands/Subsystem.h"
#include "HLUsageReporting.h"
#include "WPIErrors.h"
#include <iostream>
#include <set>
#include <algorithm>
Scheduler::Scheduler() {
HLUsageReporting::ReportScheduler();
}
Scheduler::Scheduler() { HLUsageReporting::ReportScheduler(); }
/**
* Returns the {@link Scheduler}, creating it if one does not exist.
*
* @return the {@link Scheduler}
*/
Scheduler *Scheduler::GetInstance() {
Scheduler* Scheduler::GetInstance() {
static Scheduler instance;
return &instance;
}
@@ -32,12 +31,13 @@ void Scheduler::SetEnabled(bool enabled) { m_enabled = enabled; }
/**
* Add a command to be scheduled later.
*
* In any pass through the scheduler, all commands are added to the additions
* list, then
* at the end of the pass, they are all scheduled.
* list, then at the end of the pass, they are all scheduled.
*
* @param command The command to be scheduled
*/
void Scheduler::AddCommand(Command *command) {
void Scheduler::AddCommand(Command* command) {
std::lock_guard<priority_mutex> sync(m_additionsLock);
if (std::find(m_additions.begin(), m_additions.end(), command) !=
m_additions.end())
@@ -45,12 +45,12 @@ void Scheduler::AddCommand(Command *command) {
m_additions.push_back(command);
}
void Scheduler::AddButton(ButtonScheduler *button) {
void Scheduler::AddButton(ButtonScheduler* button) {
std::lock_guard<priority_mutex> sync(m_buttonsLock);
m_buttons.push_back(button);
}
void Scheduler::ProcessCommandAddition(Command *command) {
void Scheduler::ProcessCommandAddition(Command* command) {
if (command == nullptr) return;
// Check to make sure no adding during adding
@@ -67,7 +67,7 @@ void Scheduler::ProcessCommandAddition(Command *command) {
Command::SubsystemSet requirements = command->GetRequirements();
Command::SubsystemSet::iterator iter;
for (iter = requirements.begin(); iter != requirements.end(); iter++) {
Subsystem *lock = *iter;
Subsystem* lock = *iter;
if (lock->GetCurrentCommand() != nullptr &&
!lock->GetCurrentCommand()->IsInterruptible())
return;
@@ -76,7 +76,7 @@ void Scheduler::ProcessCommandAddition(Command *command) {
// Give it the requirements
m_adding = true;
for (iter = requirements.begin(); iter != requirements.end(); iter++) {
Subsystem *lock = *iter;
Subsystem* lock = *iter;
if (lock->GetCurrentCommand() != nullptr) {
lock->GetCurrentCommand()->Cancel();
Remove(lock->GetCurrentCommand());
@@ -93,8 +93,9 @@ void Scheduler::ProcessCommandAddition(Command *command) {
}
/**
* Runs a single iteration of the loop. This method should be called often in
* order to have a functioning
* Runs a single iteration of the loop.
*
* This method should be called often in order to have a functioning
* {@link Command} system. The loop has five stages:
*
* <ol>
@@ -122,7 +123,7 @@ void Scheduler::Run() {
// Loop through the commands
auto commandIter = m_commands.begin();
for (; commandIter != m_commands.end();) {
Command *command = *commandIter;
Command* command = *commandIter;
// Increment before potentially removing to keep the iterator valid
commandIter++;
if (!command->Run()) {
@@ -144,7 +145,7 @@ void Scheduler::Run() {
// Add in the defaults
auto subsystemIter = m_subsystems.begin();
for (; subsystemIter != m_subsystems.end(); subsystemIter++) {
Subsystem *lock = *subsystemIter;
Subsystem* lock = *subsystemIter;
if (lock->GetCurrentCommand() == nullptr) {
ProcessCommandAddition(lock->GetDefaultCommand());
}
@@ -156,12 +157,13 @@ void Scheduler::Run() {
/**
* Registers a {@link Subsystem} to this {@link Scheduler}, so that the {@link
* Scheduler} might know
* if a default {@link Command} needs to be run. All {@link Subsystem
* Subsystems} should call this.
* Scheduler} might know if a default {@link Command} needs to be run.
*
* All {@link Subsystem Subsystems} should call this.
*
* @param system the system
*/
void Scheduler::RegisterSubsystem(Subsystem *subsystem) {
void Scheduler::RegisterSubsystem(Subsystem* subsystem) {
if (subsystem == nullptr) {
wpi_setWPIErrorWithContext(NullParameter, "subsystem");
return;
@@ -171,9 +173,10 @@ void Scheduler::RegisterSubsystem(Subsystem *subsystem) {
/**
* Removes the {@link Command} from the {@link Scheduler}.
*
* @param command the command to remove
*/
void Scheduler::Remove(Command *command) {
void Scheduler::Remove(Command* command) {
if (command == nullptr) {
wpi_setWPIErrorWithContext(NullParameter, "command");
return;
@@ -184,7 +187,7 @@ void Scheduler::Remove(Command *command) {
Command::SubsystemSet requirements = command->GetRequirements();
auto iter = requirements.begin();
for (; iter != requirements.end(); iter++) {
Subsystem *lock = *iter;
Subsystem* lock = *iter;
lock->SetCurrentCommand(nullptr);
}
@@ -211,7 +214,7 @@ void Scheduler::ResetAll() {
/**
* Update the network tables associated with the Scheduler object on the
* SmartDashboard
* SmartDashboard.
*/
void Scheduler::UpdateTable() {
CommandSet::iterator commandIter;
@@ -230,7 +233,7 @@ void Scheduler::UpdateTable() {
for (commandIter = m_commands.begin(); commandIter != m_commands.end();
++commandIter) {
for (unsigned i = 0; i < toCancel.size(); i++) {
Command *c = *commandIter;
Command* c = *commandIter;
if (c->GetID() == toCancel[i]) {
c->Cancel();
}
@@ -246,7 +249,7 @@ void Scheduler::UpdateTable() {
ids.resize(0);
for (commandIter = m_commands.begin(); commandIter != m_commands.end();
++commandIter) {
Command *c = *commandIter;
Command* c = *commandIter;
commands.push_back(c->GetName());
ids.push_back(c->GetID());
}

View File

@@ -7,7 +7,7 @@
#include "Commands/StartCommand.h"
StartCommand::StartCommand(Command *commandToStart) : Command("StartCommand") {
StartCommand::StartCommand(Command* commandToStart) : Command("StartCommand") {
m_commandToFork = commandToStart;
}

View File

@@ -12,20 +12,21 @@
#include "WPIErrors.h"
/**
* Creates a subsystem with the given name
* Creates a subsystem with the given name.
*
* @param name the name of the subsystem
*/
Subsystem::Subsystem(const std::string &name) {
Subsystem::Subsystem(const std::string& name) {
m_name = name;
Scheduler::GetInstance()->RegisterSubsystem(this);
}
/**
* Initialize the default command for this subsystem
* Initialize the default command for this subsystem.
*
* This is meant to be the place to call SetDefaultCommand in a subsystem and
* will be called
* on all the subsystems by the CommandBase method before the program starts
* running by using
* the list of all registered Subsystems inside the Scheduler.
* will be called on all the subsystems by the CommandBase method before the
* program starts running by using the list of all registered Subsystems inside
* the Scheduler.
*
* This should be overridden by a Subsystem that has a default Command
*/
@@ -36,12 +37,11 @@ void Subsystem::InitDefaultCommand() {}
* then there will be no default command for the subsystem.
*
* <p><b>WARNING:</b> This should <b>NOT</b> be called in a constructor if the
* subsystem is a
* singleton.</p>
* subsystem is a singleton.</p>
*
* @param command the default command (or null if there should be none)
*/
void Subsystem::SetDefaultCommand(Command *command) {
void Subsystem::SetDefaultCommand(Command* command) {
if (command == nullptr) {
m_defaultCommand = nullptr;
} else {
@@ -75,9 +75,10 @@ void Subsystem::SetDefaultCommand(Command *command) {
/**
* Returns the default command (or null if there is none).
*
* @return the default command
*/
Command *Subsystem::GetDefaultCommand() {
Command* Subsystem::GetDefaultCommand() {
if (!m_initializedDefaultCommand) {
m_initializedDefaultCommand = true;
InitDefaultCommand();
@@ -86,27 +87,29 @@ Command *Subsystem::GetDefaultCommand() {
}
/**
* Sets the current command
* Sets the current command.
*
* @param command the new current command
*/
void Subsystem::SetCurrentCommand(Command *command) {
void Subsystem::SetCurrentCommand(Command* command) {
m_currentCommand = command;
m_currentCommandChanged = true;
}
/**
* Returns the command which currently claims this subsystem.
*
* @return the command which currently claims this subsystem
*/
Command *Subsystem::GetCurrentCommand() const { return m_currentCommand; }
Command* Subsystem::GetCurrentCommand() const { return m_currentCommand; }
/**
* Call this to alert Subsystem that the current command is actually the
* command.
*
* Sometimes, the {@link Subsystem} is told that it has no command while the
* {@link Scheduler}
* is going through the loop, only to be soon after given a new one. This will
* avoid that situation.
* {@link Scheduler} is going through the loop, only to be soon after given a
* new one. This will avoid that situation.
*/
void Subsystem::ConfirmCommand() {
if (m_currentCommandChanged) {

View File

@@ -10,12 +10,12 @@
WaitCommand::WaitCommand(double timeout)
: Command(
((std::stringstream &)(std::stringstream("Wait(") << timeout << ")"))
((std::stringstream&)(std::stringstream("Wait(") << timeout << ")"))
.str()
.c_str(),
timeout) {}
WaitCommand::WaitCommand(const std::string &name, double timeout)
WaitCommand::WaitCommand(const std::string& name, double timeout)
: Command(name, timeout) {}
void WaitCommand::Initialize() {}

View File

@@ -11,7 +11,7 @@
WaitForChildren::WaitForChildren(double timeout)
: Command("WaitForChildren", timeout) {}
WaitForChildren::WaitForChildren(const std::string &name, double timeout)
WaitForChildren::WaitForChildren(const std::string& name, double timeout)
: Command(name, timeout) {}
void WaitForChildren::Initialize() {}

View File

@@ -10,6 +10,7 @@
/**
* A {@link WaitCommand} will wait until a certain match time before finishing.
*
* This will wait until the game clock reaches some value, then continue to the
* next command.
* @see CommandGroup
@@ -19,7 +20,7 @@ WaitUntilCommand::WaitUntilCommand(double time)
m_time = time;
}
WaitUntilCommand::WaitUntilCommand(const std::string &name, double time)
WaitUntilCommand::WaitUntilCommand(const std::string& name, double time)
: Command(name, time) {
m_time = time;
}