mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-02 02:51:42 +00:00
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:
committed by
Peter Johnson
parent
68690643d2
commit
e14e45da76
@@ -8,34 +8,41 @@
|
||||
#include "Buttons/Button.h"
|
||||
|
||||
/**
|
||||
* Specifies the command to run when a button is first pressed
|
||||
* Specifies the command to run when a button is first pressed.
|
||||
*
|
||||
* @param command The pointer to the command to run
|
||||
*/
|
||||
void Button::WhenPressed(Command *command) { WhenActive(command); }
|
||||
void Button::WhenPressed(Command* command) { WhenActive(command); }
|
||||
|
||||
/**
|
||||
* Specifies the command to be scheduled while the button is pressed
|
||||
* Specifies the command to be scheduled while the button is pressed.
|
||||
*
|
||||
* The command will be scheduled repeatedly while the button is pressed and will
|
||||
* be canceled when the button is released.
|
||||
*
|
||||
* @param command The pointer to the command to run
|
||||
*/
|
||||
void Button::WhileHeld(Command *command) { WhileActive(command); }
|
||||
void Button::WhileHeld(Command* command) { WhileActive(command); }
|
||||
|
||||
/**
|
||||
* Specifies the command to run when the button is released
|
||||
* Specifies the command to run when the button is released.
|
||||
*
|
||||
* The command will be scheduled a single time.
|
||||
* @param The pointer to the command to run
|
||||
*
|
||||
* @param command The pointer to the command to run
|
||||
*/
|
||||
void Button::WhenReleased(Command *command) { WhenInactive(command); }
|
||||
void Button::WhenReleased(Command* command) { WhenInactive(command); }
|
||||
|
||||
/**
|
||||
* Cancels the specificed command when the button is pressed
|
||||
* @param The command to be canceled
|
||||
* Cancels the specificed command when the button is pressed.
|
||||
*
|
||||
* @param command The command to be canceled
|
||||
*/
|
||||
void Button::CancelWhenPressed(Command *command) { CancelWhenActive(command); }
|
||||
void Button::CancelWhenPressed(Command* command) { CancelWhenActive(command); }
|
||||
|
||||
/**
|
||||
* Toggle the specified command when the button is pressed
|
||||
* @param The command to be toggled
|
||||
* Toggle the specified command when the button is pressed.
|
||||
*
|
||||
* @param command The command to be toggled
|
||||
*/
|
||||
void Button::ToggleWhenPressed(Command *command) { ToggleWhenActive(command); }
|
||||
void Button::ToggleWhenPressed(Command* command) { ToggleWhenActive(command); }
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
#include "Commands/Scheduler.h"
|
||||
|
||||
ButtonScheduler::ButtonScheduler(bool last, Trigger *button, Command *orders)
|
||||
ButtonScheduler::ButtonScheduler(bool last, Trigger* button, Command* orders)
|
||||
: m_pressedLast(last), m_button(button), m_command(orders) {}
|
||||
|
||||
void ButtonScheduler::Start() { Scheduler::GetInstance()->AddButton(this); }
|
||||
|
||||
@@ -10,8 +10,8 @@
|
||||
#include "Buttons/Button.h"
|
||||
#include "Commands/Command.h"
|
||||
|
||||
CancelButtonScheduler::CancelButtonScheduler(bool last, Trigger *button,
|
||||
Command *orders)
|
||||
CancelButtonScheduler::CancelButtonScheduler(bool last, Trigger* button,
|
||||
Command* orders)
|
||||
: ButtonScheduler(last, button, orders) {
|
||||
pressedLast = m_button->Grab();
|
||||
}
|
||||
|
||||
@@ -10,8 +10,8 @@
|
||||
#include "Buttons/Button.h"
|
||||
#include "Commands/Command.h"
|
||||
|
||||
HeldButtonScheduler::HeldButtonScheduler(bool last, Trigger *button,
|
||||
Command *orders)
|
||||
HeldButtonScheduler::HeldButtonScheduler(bool last, Trigger* button,
|
||||
Command* orders)
|
||||
: ButtonScheduler(last, button, orders) {}
|
||||
|
||||
void HeldButtonScheduler::Execute() {
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
#include "Buttons/JoystickButton.h"
|
||||
|
||||
JoystickButton::JoystickButton(GenericHID *joystick, int buttonNumber)
|
||||
JoystickButton::JoystickButton(GenericHID* joystick, int buttonNumber)
|
||||
: m_joystick(joystick), m_buttonNumber(buttonNumber) {}
|
||||
|
||||
bool JoystickButton::Get() { return m_joystick->GetRawButton(m_buttonNumber); }
|
||||
|
||||
@@ -8,12 +8,14 @@
|
||||
#include "Buttons/NetworkButton.h"
|
||||
#include "networktables/NetworkTable.h"
|
||||
|
||||
NetworkButton::NetworkButton(const std::string &tableName, const std::string &field)
|
||||
NetworkButton::NetworkButton(const std::string& tableName,
|
||||
const std::string& field)
|
||||
: // TODO how is this supposed to work???
|
||||
m_netTable(NetworkTable::GetTable(tableName)),
|
||||
m_field(field) {}
|
||||
|
||||
NetworkButton::NetworkButton(std::shared_ptr<ITable> table, const std::string &field)
|
||||
NetworkButton::NetworkButton(std::shared_ptr<ITable> table,
|
||||
const std::string& field)
|
||||
: m_netTable(table), m_field(field) {}
|
||||
|
||||
bool NetworkButton::Get() {
|
||||
|
||||
@@ -10,8 +10,8 @@
|
||||
#include "Buttons/Button.h"
|
||||
#include "Commands/Command.h"
|
||||
|
||||
PressedButtonScheduler::PressedButtonScheduler(bool last, Trigger *button,
|
||||
Command *orders)
|
||||
PressedButtonScheduler::PressedButtonScheduler(bool last, Trigger* button,
|
||||
Command* orders)
|
||||
: ButtonScheduler(last, button, orders) {}
|
||||
|
||||
void PressedButtonScheduler::Execute() {
|
||||
|
||||
@@ -10,8 +10,8 @@
|
||||
#include "Buttons/Button.h"
|
||||
#include "Commands/Command.h"
|
||||
|
||||
ReleasedButtonScheduler::ReleasedButtonScheduler(bool last, Trigger *button,
|
||||
Command *orders)
|
||||
ReleasedButtonScheduler::ReleasedButtonScheduler(bool last, Trigger* button,
|
||||
Command* orders)
|
||||
: ButtonScheduler(last, button, orders) {}
|
||||
|
||||
void ReleasedButtonScheduler::Execute() {
|
||||
|
||||
@@ -10,8 +10,8 @@
|
||||
#include "Buttons/Button.h"
|
||||
#include "Commands/Command.h"
|
||||
|
||||
ToggleButtonScheduler::ToggleButtonScheduler(bool last, Trigger *button,
|
||||
Command *orders)
|
||||
ToggleButtonScheduler::ToggleButtonScheduler(bool last, Trigger* button,
|
||||
Command* orders)
|
||||
: ButtonScheduler(last, button, orders) {
|
||||
pressedLast = m_button->Grab();
|
||||
}
|
||||
|
||||
@@ -7,11 +7,11 @@
|
||||
|
||||
#include "Buttons/Button.h"
|
||||
|
||||
#include "Buttons/CancelButtonScheduler.h"
|
||||
#include "Buttons/HeldButtonScheduler.h"
|
||||
#include "Buttons/PressedButtonScheduler.h"
|
||||
#include "Buttons/ReleasedButtonScheduler.h"
|
||||
#include "Buttons/ToggleButtonScheduler.h"
|
||||
#include "Buttons/CancelButtonScheduler.h"
|
||||
|
||||
bool Trigger::Grab() {
|
||||
if (Get())
|
||||
@@ -25,27 +25,27 @@ bool Trigger::Grab() {
|
||||
return false;
|
||||
}
|
||||
|
||||
void Trigger::WhenActive(Command *command) {
|
||||
void Trigger::WhenActive(Command* command) {
|
||||
auto pbs = new PressedButtonScheduler(Grab(), this, command);
|
||||
pbs->Start();
|
||||
}
|
||||
|
||||
void Trigger::WhileActive(Command *command) {
|
||||
void Trigger::WhileActive(Command* command) {
|
||||
auto hbs = new HeldButtonScheduler(Grab(), this, command);
|
||||
hbs->Start();
|
||||
}
|
||||
|
||||
void Trigger::WhenInactive(Command *command) {
|
||||
void Trigger::WhenInactive(Command* command) {
|
||||
auto rbs = new ReleasedButtonScheduler(Grab(), this, command);
|
||||
rbs->Start();
|
||||
}
|
||||
|
||||
void Trigger::CancelWhenActive(Command *command) {
|
||||
void Trigger::CancelWhenActive(Command* command) {
|
||||
auto cbs = new CancelButtonScheduler(Grab(), this, command);
|
||||
cbs->Start();
|
||||
}
|
||||
|
||||
void Trigger::ToggleWhenActive(Command *command) {
|
||||
void Trigger::ToggleWhenActive(Command* command) {
|
||||
auto tbs = new ToggleButtonScheduler(Grab(), this, command);
|
||||
tbs->Start();
|
||||
}
|
||||
|
||||
@@ -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"; }
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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) {}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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(); }
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
#include "Commands/StartCommand.h"
|
||||
|
||||
StartCommand::StartCommand(Command *commandToStart) : Command("StartCommand") {
|
||||
StartCommand::StartCommand(Command* commandToStart) : Command("StartCommand") {
|
||||
m_commandToFork = commandToStart;
|
||||
}
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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() {}
|
||||
|
||||
@@ -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() {}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -7,11 +7,11 @@
|
||||
|
||||
#include "Error.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <cstring>
|
||||
#include <cstdlib>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "DriverStation.h"
|
||||
#include "Timer.h"
|
||||
@@ -70,12 +70,13 @@ void Error::Report() {
|
||||
locStream << m_function << " [";
|
||||
|
||||
#if defined(_WIN32)
|
||||
const int MAX_DIR = 100;
|
||||
char basename[MAX_DIR];
|
||||
_splitpath_s(m_filename.c_str(), NULL, 0, basename, MAX_DIR, NULL, 0, NULL, 0);
|
||||
locStream << basename;
|
||||
const int MAX_DIR = 100;
|
||||
char basename[MAX_DIR];
|
||||
_splitpath_s(m_filename.c_str(), NULL, 0, basename, MAX_DIR, NULL, 0, NULL,
|
||||
0);
|
||||
locStream << basename;
|
||||
#else
|
||||
locStream << basename(m_filename.c_str());
|
||||
locStream << basename(m_filename.c_str());
|
||||
#endif
|
||||
locStream << ":" << m_lineNumber << "]";
|
||||
|
||||
|
||||
@@ -10,8 +10,8 @@
|
||||
#include "WPIErrors.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <cstring>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <sstream>
|
||||
|
||||
priority_mutex ErrorBase::_globalErrorMutex;
|
||||
@@ -35,9 +35,9 @@ void ErrorBase::ClearError() const { m_error.Clear(); }
|
||||
* error to the "errno" global variable.
|
||||
*
|
||||
* @param contextMessage A custom message from the code that set the error.
|
||||
* @param filename Filename of the error source
|
||||
* @param function Function of the error source
|
||||
* @param lineNumber Line number of the error source
|
||||
* @param filename Filename of the error source
|
||||
* @param function Function of the error source
|
||||
* @param lineNumber Line number of the error source
|
||||
*/
|
||||
void ErrorBase::SetErrnoError(llvm::StringRef contextMessage,
|
||||
llvm::StringRef filename,
|
||||
@@ -55,7 +55,7 @@ void ErrorBase::SetErrnoError(llvm::StringRef contextMessage,
|
||||
err = buf;
|
||||
}
|
||||
|
||||
// Set the current error information for this object.
|
||||
// Set the current error information for this object.
|
||||
m_error.Set(-1, err, filename, function, lineNumber, this);
|
||||
|
||||
// Update the global error if there is not one already set.
|
||||
@@ -69,21 +69,21 @@ void ErrorBase::SetErrnoError(llvm::StringRef contextMessage,
|
||||
* @brief Set the current error information associated from the nivision Imaq
|
||||
* API.
|
||||
*
|
||||
* @param success The return from the function
|
||||
* @param success The return from the function
|
||||
* @param contextMessage A custom message from the code that set the error.
|
||||
* @param filename Filename of the error source
|
||||
* @param function Function of the error source
|
||||
* @param lineNumber Line number of the error source
|
||||
* @param filename Filename of the error source
|
||||
* @param function Function of the error source
|
||||
* @param lineNumber Line number of the error source
|
||||
*/
|
||||
void ErrorBase::SetImaqError(int success, llvm::StringRef contextMessage,
|
||||
llvm::StringRef filename, llvm::StringRef function,
|
||||
uint32_t lineNumber) const {
|
||||
// If there was an error
|
||||
// If there was an error
|
||||
if (success <= 0) {
|
||||
std::stringstream err;
|
||||
err << success << ": " << contextMessage;
|
||||
|
||||
// Set the current error information for this object.
|
||||
// Set the current error information for this object.
|
||||
m_error.Set(success, err.str(), filename, function, lineNumber, this);
|
||||
|
||||
// Update the global error if there is not one already set.
|
||||
@@ -97,11 +97,11 @@ void ErrorBase::SetImaqError(int success, llvm::StringRef contextMessage,
|
||||
/**
|
||||
* @brief Set the current error information associated with this sensor.
|
||||
*
|
||||
* @param code The error code
|
||||
* @param code The error code
|
||||
* @param contextMessage A custom message from the code that set the error.
|
||||
* @param filename Filename of the error source
|
||||
* @param function Function of the error source
|
||||
* @param lineNumber Line number of the error source
|
||||
* @param filename Filename of the error source
|
||||
* @param function Function of the error source
|
||||
* @param lineNumber Line number of the error source
|
||||
*/
|
||||
void ErrorBase::SetError(Error::Code code, llvm::StringRef contextMessage,
|
||||
llvm::StringRef filename, llvm::StringRef function,
|
||||
@@ -122,11 +122,11 @@ void ErrorBase::SetError(Error::Code code, llvm::StringRef contextMessage,
|
||||
/**
|
||||
* @brief Set the current error information associated with this sensor.
|
||||
*
|
||||
* @param errorMessage The error message from WPIErrors.h
|
||||
* @param errorMessage The error message from WPIErrors.h
|
||||
* @param contextMessage A custom message from the code that set the error.
|
||||
* @param filename Filename of the error source
|
||||
* @param function Function of the error source
|
||||
* @param lineNumber Line number of the error source
|
||||
* @param filename Filename of the error source
|
||||
* @param function Function of the error source
|
||||
* @param lineNumber Line number of the error source
|
||||
*/
|
||||
void ErrorBase::SetWPIError(llvm::StringRef errorMessage, Error::Code code,
|
||||
llvm::StringRef contextMessage,
|
||||
@@ -149,20 +149,20 @@ void ErrorBase::CloneError(const ErrorBase& rhs) const {
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Check if the current error code represents a fatal error.
|
||||
|
||||
@return true if the current error is fatal.
|
||||
*/
|
||||
* @brief Check if the current error code represents a fatal error.
|
||||
*
|
||||
* @return true if the current error is fatal.
|
||||
*/
|
||||
bool ErrorBase::StatusIsFatal() const { return m_error.GetCode() < 0; }
|
||||
|
||||
void ErrorBase::SetGlobalError(Error::Code code, llvm::StringRef contextMessage,
|
||||
llvm::StringRef filename,
|
||||
llvm::StringRef function, uint32_t lineNumber) {
|
||||
// If there was an error
|
||||
// If there was an error
|
||||
if (code != 0) {
|
||||
std::lock_guard<priority_mutex> mutex(_globalErrorMutex);
|
||||
|
||||
// Set the current error information for this object.
|
||||
// Set the current error information for this object.
|
||||
_globalError.Set(code, contextMessage, filename, function, lineNumber,
|
||||
nullptr);
|
||||
}
|
||||
@@ -183,8 +183,8 @@ void ErrorBase::SetGlobalWPIError(llvm::StringRef errorMessage,
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the current global error.
|
||||
*/
|
||||
* Retrieve the current global error.
|
||||
*/
|
||||
Error& ErrorBase::GetGlobalError() {
|
||||
std::lock_guard<priority_mutex> mutex(_globalErrorMutex);
|
||||
return _globalError;
|
||||
|
||||
@@ -7,9 +7,7 @@
|
||||
|
||||
#include "Filters/Filter.h"
|
||||
|
||||
Filter::Filter(std::shared_ptr<PIDSource> source) {
|
||||
m_source = source;
|
||||
}
|
||||
Filter::Filter(std::shared_ptr<PIDSource> source) { m_source = source; }
|
||||
|
||||
void Filter::SetPIDSourceType(PIDSourceType pidSource) {
|
||||
m_source->SetPIDSourceType(pidSource);
|
||||
@@ -19,6 +17,4 @@ PIDSourceType Filter::GetPIDSourceType() const {
|
||||
return m_source->GetPIDSourceType();
|
||||
}
|
||||
|
||||
double Filter::PIDGetSource() {
|
||||
return m_source->PIDGet();
|
||||
}
|
||||
double Filter::PIDGetSource() { return m_source->PIDGet(); }
|
||||
|
||||
@@ -10,56 +10,68 @@
|
||||
#include <cmath>
|
||||
|
||||
/**
|
||||
* Create a linear FIR or IIR filter
|
||||
* Create a linear FIR or IIR filter.
|
||||
*
|
||||
* @param source The PIDSource object that is used to get values
|
||||
* @param source The PIDSource object that is used to get values
|
||||
* @param ffGains The "feed forward" or FIR gains
|
||||
* @param fbGains The "feed back" or IIR gains
|
||||
*/
|
||||
LinearDigitalFilter::LinearDigitalFilter(std::shared_ptr<PIDSource> source,
|
||||
std::initializer_list<double> ffGains,
|
||||
std::initializer_list<double> fbGains) :
|
||||
Filter(source), m_inputs(ffGains.size()), m_outputs(fbGains.size()),
|
||||
m_inputGains(ffGains), m_outputGains(fbGains) {}
|
||||
std::initializer_list<double> fbGains)
|
||||
: Filter(source),
|
||||
m_inputs(ffGains.size()),
|
||||
m_outputs(fbGains.size()),
|
||||
m_inputGains(ffGains),
|
||||
m_outputGains(fbGains) {}
|
||||
|
||||
/**
|
||||
* Create a linear FIR or IIR filter
|
||||
* Create a linear FIR or IIR filter.
|
||||
*
|
||||
* @param source The PIDSource object that is used to get values
|
||||
* @param source The PIDSource object that is used to get values
|
||||
* @param ffGains The "feed forward" or FIR gains
|
||||
* @param fbGains The "feed back" or IIR gains
|
||||
*/
|
||||
LinearDigitalFilter::LinearDigitalFilter(std::shared_ptr<PIDSource> source,
|
||||
std::initializer_list<double> ffGains,
|
||||
const std::vector<double>& fbGains) :
|
||||
Filter(source), m_inputs(ffGains.size()), m_outputs(fbGains.size()),
|
||||
m_inputGains(ffGains), m_outputGains(fbGains) {}
|
||||
const std::vector<double>& fbGains)
|
||||
: Filter(source),
|
||||
m_inputs(ffGains.size()),
|
||||
m_outputs(fbGains.size()),
|
||||
m_inputGains(ffGains),
|
||||
m_outputGains(fbGains) {}
|
||||
|
||||
/**
|
||||
* Create a linear FIR or IIR filter
|
||||
* Create a linear FIR or IIR filter.
|
||||
*
|
||||
* @param source The PIDSource object that is used to get values
|
||||
* @param source The PIDSource object that is used to get values
|
||||
* @param ffGains The "feed forward" or FIR gains
|
||||
* @param fbGains The "feed back" or IIR gains
|
||||
*/
|
||||
LinearDigitalFilter::LinearDigitalFilter(std::shared_ptr<PIDSource> source,
|
||||
const std::vector<double>& ffGains,
|
||||
std::initializer_list<double> fbGains) :
|
||||
Filter(source), m_inputs(ffGains.size()), m_outputs(fbGains.size()),
|
||||
m_inputGains(ffGains), m_outputGains(fbGains) {}
|
||||
std::initializer_list<double> fbGains)
|
||||
: Filter(source),
|
||||
m_inputs(ffGains.size()),
|
||||
m_outputs(fbGains.size()),
|
||||
m_inputGains(ffGains),
|
||||
m_outputGains(fbGains) {}
|
||||
|
||||
/**
|
||||
* Create a linear FIR or IIR filter
|
||||
* Create a linear FIR or IIR filter.
|
||||
*
|
||||
* @param source The PIDSource object that is used to get values
|
||||
* @param source The PIDSource object that is used to get values
|
||||
* @param ffGains The "feed forward" or FIR gains
|
||||
* @param fbGains The "feed back" or IIR gains
|
||||
*/
|
||||
LinearDigitalFilter::LinearDigitalFilter(std::shared_ptr<PIDSource> source,
|
||||
const std::vector<double>& ffGains,
|
||||
const std::vector<double>& fbGains) :
|
||||
Filter(source), m_inputs(ffGains.size()), m_outputs(fbGains.size()),
|
||||
m_inputGains(ffGains), m_outputGains(fbGains) {}
|
||||
const std::vector<double>& fbGains)
|
||||
: Filter(source),
|
||||
m_inputs(ffGains.size()),
|
||||
m_outputs(fbGains.size()),
|
||||
m_inputGains(ffGains),
|
||||
m_outputGains(fbGains) {}
|
||||
|
||||
/**
|
||||
* Creates a one-pole IIR low-pass filter of the form:
|
||||
@@ -68,13 +80,12 @@ LinearDigitalFilter::LinearDigitalFilter(std::shared_ptr<PIDSource> source,
|
||||
*
|
||||
* This filter is stable for time constants greater than zero
|
||||
*
|
||||
* @param source The PIDSource object that is used to get values
|
||||
* @param source The PIDSource object that is used to get values
|
||||
* @param timeConstant The discrete-time time constant in seconds
|
||||
* @param period The period in seconds between samples taken by the user
|
||||
* @param period The period in seconds between samples taken by the user
|
||||
*/
|
||||
LinearDigitalFilter LinearDigitalFilter::SinglePoleIIR(std::shared_ptr<PIDSource> source,
|
||||
double timeConstant,
|
||||
double period) {
|
||||
LinearDigitalFilter LinearDigitalFilter::SinglePoleIIR(
|
||||
std::shared_ptr<PIDSource> source, double timeConstant, double period) {
|
||||
double gain = std::exp(-period / timeConstant);
|
||||
return LinearDigitalFilter(std::move(source), {1.0 - gain}, {-gain});
|
||||
}
|
||||
@@ -86,13 +97,12 @@ LinearDigitalFilter LinearDigitalFilter::SinglePoleIIR(std::shared_ptr<PIDSource
|
||||
*
|
||||
* This filter is stable for time constants greater than zero
|
||||
*
|
||||
* @param source The PIDSource object that is used to get values
|
||||
* @param source The PIDSource object that is used to get values
|
||||
* @param timeConstant The discrete-time time constant in seconds
|
||||
* @param period The period in seconds between samples taken by the user
|
||||
* @param period The period in seconds between samples taken by the user
|
||||
*/
|
||||
LinearDigitalFilter LinearDigitalFilter::HighPass(std::shared_ptr<PIDSource> source,
|
||||
double timeConstant,
|
||||
double period) {
|
||||
LinearDigitalFilter LinearDigitalFilter::HighPass(
|
||||
std::shared_ptr<PIDSource> source, double timeConstant, double period) {
|
||||
double gain = std::exp(-period / timeConstant);
|
||||
return LinearDigitalFilter(std::move(source), {gain, -gain}, {-gain});
|
||||
}
|
||||
@@ -104,11 +114,11 @@ LinearDigitalFilter LinearDigitalFilter::HighPass(std::shared_ptr<PIDSource> sou
|
||||
* This filter is always stable.
|
||||
*
|
||||
* @param source The PIDSource object that is used to get values
|
||||
* @param taps The number of samples to average over. Higher = smoother but
|
||||
* slower
|
||||
* @param taps The number of samples to average over. Higher = smoother but
|
||||
* slower
|
||||
*/
|
||||
LinearDigitalFilter LinearDigitalFilter::MovingAverage(std::shared_ptr<PIDSource> source,
|
||||
unsigned int taps) {
|
||||
LinearDigitalFilter LinearDigitalFilter::MovingAverage(
|
||||
std::shared_ptr<PIDSource> source, unsigned int taps) {
|
||||
assert(taps > 0);
|
||||
|
||||
std::vector<double> gains(taps, 1.0 / taps);
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#include "GyroBase.h"
|
||||
#include "WPIErrors.h"
|
||||
#include "LiveWindow/LiveWindow.h"
|
||||
#include "WPIErrors.h"
|
||||
|
||||
/**
|
||||
* Get the PIDOutput for the PIDSource base object. Can be set to return
|
||||
|
||||
@@ -6,23 +6,24 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#include "LiveWindow/LiveWindow.h"
|
||||
#include "networktables/NetworkTable.h"
|
||||
#include <algorithm>
|
||||
#include <sstream>
|
||||
#include "networktables/NetworkTable.h"
|
||||
|
||||
/**
|
||||
* Get an instance of the LiveWindow main class
|
||||
* Get an instance of the LiveWindow main class.
|
||||
*
|
||||
* This is a singleton to guarantee that there is only a single instance
|
||||
* regardless of
|
||||
* how many times GetInstance is called.
|
||||
* regardless of how many times GetInstance is called.
|
||||
*/
|
||||
LiveWindow *LiveWindow::GetInstance() {
|
||||
LiveWindow* LiveWindow::GetInstance() {
|
||||
static LiveWindow instance;
|
||||
return &instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* LiveWindow constructor.
|
||||
*
|
||||
* Allocate the necessary tables.
|
||||
*/
|
||||
LiveWindow::LiveWindow() : m_scheduler(Scheduler::GetInstance()) {
|
||||
@@ -31,7 +32,8 @@ LiveWindow::LiveWindow() : m_scheduler(Scheduler::GetInstance()) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the enabled status of LiveWindow
|
||||
* Change the enabled status of LiveWindow.
|
||||
*
|
||||
* If it changes to enabled, start livewindow running otherwise stop it
|
||||
*/
|
||||
void LiveWindow::SetEnabled(bool enabled) {
|
||||
@@ -58,16 +60,19 @@ void LiveWindow::SetEnabled(bool enabled) {
|
||||
|
||||
/**
|
||||
* @name AddSensor(subsystem, name, component)
|
||||
*
|
||||
* Add a Sensor associated with the subsystem and call it by the given name.
|
||||
*
|
||||
* @param subsystem The subsystem this component is part of.
|
||||
* @param name The name of this component.
|
||||
* @param name The name of this component.
|
||||
* @param component A LiveWindowSendable component that represents a sensor.
|
||||
*/
|
||||
//@{
|
||||
/**
|
||||
* @brief Use a STL smart pointer to share ownership of component.
|
||||
*/
|
||||
void LiveWindow::AddSensor(const std::string &subsystem, const std::string &name,
|
||||
void LiveWindow::AddSensor(const std::string& subsystem,
|
||||
const std::string& name,
|
||||
std::shared_ptr<LiveWindowSendable> component) {
|
||||
m_components[component].subsystem = subsystem;
|
||||
m_components[component].name = name;
|
||||
@@ -77,20 +82,20 @@ void LiveWindow::AddSensor(const std::string &subsystem, const std::string &name
|
||||
/**
|
||||
* @brief Pass a reference to LiveWindow and retain ownership of the component.
|
||||
*/
|
||||
void LiveWindow::AddSensor(const std::string &subsystem,
|
||||
const std::string &name,
|
||||
LiveWindowSendable &component) {
|
||||
void LiveWindow::AddSensor(const std::string& subsystem,
|
||||
const std::string& name,
|
||||
LiveWindowSendable& component) {
|
||||
AddSensor(subsystem, name, std::shared_ptr<LiveWindowSendable>(
|
||||
&component, [](LiveWindowSendable*){}));
|
||||
&component, [](LiveWindowSendable*) {}));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Use a raw pointer to the LiveWindow.
|
||||
* @deprecated Prefer smart pointers or references.
|
||||
*/
|
||||
void LiveWindow::AddSensor(const std::string &subsystem,
|
||||
const std::string &name,
|
||||
LiveWindowSendable *component) {
|
||||
void LiveWindow::AddSensor(const std::string& subsystem,
|
||||
const std::string& name,
|
||||
LiveWindowSendable* component) {
|
||||
AddSensor(subsystem, name, std::shared_ptr<LiveWindowSendable>(
|
||||
component, NullDeleter<LiveWindowSendable>()));
|
||||
}
|
||||
@@ -98,16 +103,19 @@ void LiveWindow::AddSensor(const std::string &subsystem,
|
||||
|
||||
/**
|
||||
* @name AddActuator(subsystem, name, component)
|
||||
*
|
||||
* Add an Actuator associated with the subsystem and call it by the given name.
|
||||
*
|
||||
* @param subsystem The subsystem this component is part of.
|
||||
* @param name The name of this component.
|
||||
* @param name The name of this component.
|
||||
* @param component A LiveWindowSendable component that represents a actuator.
|
||||
*/
|
||||
//@{
|
||||
/**
|
||||
* @brief Use a STL smart pointer to share ownership of component.
|
||||
*/
|
||||
void LiveWindow::AddActuator(const std::string &subsystem, const std::string &name,
|
||||
void LiveWindow::AddActuator(const std::string& subsystem,
|
||||
const std::string& name,
|
||||
std::shared_ptr<LiveWindowSendable> component) {
|
||||
m_components[component].subsystem = subsystem;
|
||||
m_components[component].name = name;
|
||||
@@ -117,19 +125,20 @@ void LiveWindow::AddActuator(const std::string &subsystem, const std::string &na
|
||||
/**
|
||||
* @brief Pass a reference to LiveWindow and retain ownership of the component.
|
||||
*/
|
||||
void LiveWindow::AddActuator(const std::string &subsystem,
|
||||
const std::string &name,
|
||||
LiveWindowSendable &component) {
|
||||
void LiveWindow::AddActuator(const std::string& subsystem,
|
||||
const std::string& name,
|
||||
LiveWindowSendable& component) {
|
||||
AddActuator(subsystem, name, std::shared_ptr<LiveWindowSendable>(
|
||||
&component, [](LiveWindowSendable*){}));
|
||||
&component, [](LiveWindowSendable*) {}));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Use a raw pointer to the LiveWindow.
|
||||
* @deprecated Prefer smart pointers or references.
|
||||
*/
|
||||
void LiveWindow::AddActuator(const std::string &subsystem, const std::string &name,
|
||||
LiveWindowSendable *component) {
|
||||
void LiveWindow::AddActuator(const std::string& subsystem,
|
||||
const std::string& name,
|
||||
LiveWindowSendable* component) {
|
||||
AddActuator(subsystem, name,
|
||||
std::shared_ptr<LiveWindowSendable>(
|
||||
component, NullDeleter<LiveWindowSendable>()));
|
||||
@@ -140,7 +149,7 @@ void LiveWindow::AddActuator(const std::string &subsystem, const std::string &na
|
||||
* Meant for internal use in other WPILib classes.
|
||||
*/
|
||||
void LiveWindow::AddSensor(std::string type, int channel,
|
||||
LiveWindowSendable *component) {
|
||||
LiveWindowSendable* component) {
|
||||
std::ostringstream oss;
|
||||
oss << type << "[" << channel << "]";
|
||||
AddSensor("Ungrouped", oss.str(), component);
|
||||
@@ -155,26 +164,29 @@ void LiveWindow::AddSensor(std::string type, int channel,
|
||||
* Meant for internal use in other WPILib classes.
|
||||
*/
|
||||
void LiveWindow::AddActuator(std::string type, int channel,
|
||||
LiveWindowSendable *component) {
|
||||
LiveWindowSendable* component) {
|
||||
std::ostringstream oss;
|
||||
oss << type << "[" << channel << "]";
|
||||
AddActuator("Ungrouped", oss.str(), std::shared_ptr<LiveWindowSendable>(
|
||||
component, [](LiveWindowSendable *) {}));
|
||||
AddActuator("Ungrouped", oss.str(),
|
||||
std::shared_ptr<LiveWindowSendable>(component,
|
||||
[](LiveWindowSendable*) {}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Meant for internal use in other WPILib classes.
|
||||
*/
|
||||
void LiveWindow::AddActuator(std::string type, int module, int channel,
|
||||
LiveWindowSendable *component) {
|
||||
LiveWindowSendable* component) {
|
||||
std::ostringstream oss;
|
||||
oss << type << "[" << module << "," << channel << "]";
|
||||
AddActuator("Ungrouped", oss.str(), std::shared_ptr<LiveWindowSendable>(
|
||||
component, [](LiveWindowSendable *) {}));
|
||||
AddActuator("Ungrouped", oss.str(),
|
||||
std::shared_ptr<LiveWindowSendable>(component,
|
||||
[](LiveWindowSendable*) {}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tell all the sensors to update (send) their values
|
||||
* Tell all the sensors to update (send) their values.
|
||||
*
|
||||
* Actuators are handled through callbacks on their value changing from the
|
||||
* SmartDashboard widgets.
|
||||
*/
|
||||
@@ -207,8 +219,8 @@ void LiveWindow::InitializeLiveWindowComponents() {
|
||||
LiveWindowComponent c = elem.second;
|
||||
std::string subsystem = c.subsystem;
|
||||
std::string name = c.name;
|
||||
m_liveWindowTable->GetSubTable(subsystem)
|
||||
->PutString("~TYPE~", "LW Subsystem");
|
||||
m_liveWindowTable->GetSubTable(subsystem)->PutString("~TYPE~",
|
||||
"LW Subsystem");
|
||||
std::shared_ptr<ITable> table(
|
||||
m_liveWindowTable->GetSubTable(subsystem)->GetSubTable(name));
|
||||
table->PutString("~TYPE~", component->GetSmartDashboardType());
|
||||
|
||||
@@ -8,6 +8,6 @@
|
||||
#include "LiveWindow/LiveWindowStatusListener.h"
|
||||
#include "Commands/Scheduler.h"
|
||||
|
||||
void LiveWindowStatusListener::ValueChanged(ITable *source, llvm::StringRef key,
|
||||
void LiveWindowStatusListener::ValueChanged(ITable* source, llvm::StringRef key,
|
||||
std::shared_ptr<nt::Value> value,
|
||||
bool isNew) {}
|
||||
|
||||
@@ -16,6 +16,4 @@ void PIDSource::SetPIDSourceType(PIDSourceType pidSource) {
|
||||
m_pidSource = pidSource;
|
||||
}
|
||||
|
||||
PIDSourceType PIDSource::GetPIDSourceType() const {
|
||||
return m_pidSource;
|
||||
}
|
||||
PIDSourceType PIDSource::GetPIDSourceType() const { return m_pidSource; }
|
||||
|
||||
@@ -6,17 +6,17 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#include "Resource.h"
|
||||
#include "WPIErrors.h"
|
||||
#include "ErrorBase.h"
|
||||
#include "WPIErrors.h"
|
||||
|
||||
priority_recursive_mutex Resource::m_createLock;
|
||||
|
||||
/**
|
||||
* Allocate storage for a new instance of Resource.
|
||||
*
|
||||
* Allocate a bool array of values that will get initialized to indicate that no
|
||||
* resources
|
||||
* have been allocated yet. The indicies of the resources are [0 .. elements -
|
||||
* 1].
|
||||
* resources have been allocated yet. The indicies of the resources are [0 ..
|
||||
* elements - 1].
|
||||
*/
|
||||
Resource::Resource(uint32_t elements) {
|
||||
std::lock_guard<priority_recursive_mutex> sync(m_createLock);
|
||||
@@ -26,12 +26,13 @@ Resource::Resource(uint32_t elements) {
|
||||
/**
|
||||
* Factory method to create a Resource allocation-tracker *if* needed.
|
||||
*
|
||||
* @param r -- address of the caller's Resource pointer. If *r == nullptr, this
|
||||
* will construct a Resource and make *r point to it. If *r != nullptr, i.e.
|
||||
* the caller already has a Resource instance, this won't do anything.
|
||||
* @param elements -- the number of elements for this Resource allocator to
|
||||
* track, that is, it will allocate resource numbers in the range
|
||||
* [0 .. elements - 1].
|
||||
* @param r address of the caller's Resource pointer. If *r == nullptr,
|
||||
* this will construct a Resource and make *r point to it. If
|
||||
* *r != nullptr, i.e. the caller already has a Resource
|
||||
* instance, this won't do anything.
|
||||
* @param elements the number of elements for this Resource allocator to
|
||||
* track, that is, it will allocate resource numbers in the
|
||||
* range [0 .. elements - 1].
|
||||
*/
|
||||
/*static*/ void Resource::CreateResourceObject(std::unique_ptr<Resource>& r,
|
||||
uint32_t elements) {
|
||||
@@ -43,11 +44,12 @@ Resource::Resource(uint32_t elements) {
|
||||
|
||||
/**
|
||||
* Allocate a resource.
|
||||
*
|
||||
* When a resource is requested, mark it allocated. In this case, a free
|
||||
* resource value
|
||||
* within the range is located and returned after it is marked allocated.
|
||||
* resource value within the range is located and returned after it is marked
|
||||
* allocated.
|
||||
*/
|
||||
uint32_t Resource::Allocate(const std::string &resourceDesc) {
|
||||
uint32_t Resource::Allocate(const std::string& resourceDesc) {
|
||||
std::lock_guard<priority_recursive_mutex> sync(m_allocateLock);
|
||||
for (uint32_t i = 0; i < m_isAllocated.size(); i++) {
|
||||
if (!m_isAllocated[i]) {
|
||||
@@ -61,11 +63,11 @@ uint32_t Resource::Allocate(const std::string &resourceDesc) {
|
||||
|
||||
/**
|
||||
* Allocate a specific resource value.
|
||||
*
|
||||
* The user requests a specific resource value, i.e. channel number and it is
|
||||
* verified
|
||||
* unallocated, then returned.
|
||||
* verified unallocated, then returned.
|
||||
*/
|
||||
uint32_t Resource::Allocate(uint32_t index, const std::string &resourceDesc) {
|
||||
uint32_t Resource::Allocate(uint32_t index, const std::string& resourceDesc) {
|
||||
std::lock_guard<priority_recursive_mutex> sync(m_allocateLock);
|
||||
if (index >= m_isAllocated.size()) {
|
||||
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, resourceDesc);
|
||||
@@ -81,10 +83,10 @@ uint32_t Resource::Allocate(uint32_t index, const std::string &resourceDesc) {
|
||||
|
||||
/**
|
||||
* Free an allocated resource.
|
||||
*
|
||||
* After a resource is no longer needed, for example a destructor is called for
|
||||
* a channel assignment
|
||||
* class, Free will release the resource value so it can be reused somewhere
|
||||
* else in the program.
|
||||
* a channel assignment class, Free will release the resource value so it can
|
||||
* be reused somewhere else in the program.
|
||||
*/
|
||||
void Resource::Free(uint32_t index) {
|
||||
std::unique_lock<priority_recursive_mutex> sync(m_allocateLock);
|
||||
|
||||
@@ -16,8 +16,7 @@ void RobotState::SetImplementation(RobotStateInterface& i) {
|
||||
&i, NullDeleter<RobotStateInterface>());
|
||||
}
|
||||
|
||||
void RobotState::SetImplementation(
|
||||
std::shared_ptr<RobotStateInterface> i) {
|
||||
void RobotState::SetImplementation(std::shared_ptr<RobotStateInterface> i) {
|
||||
impl = i;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,37 +14,42 @@ static const std::string kOptions = "options";
|
||||
static const std::string kSelected = "selected";
|
||||
|
||||
/**
|
||||
* Adds the given object to the list of options. On the {@link SmartDashboard}
|
||||
* on the desktop,
|
||||
* the object will appear as the given name.
|
||||
* @param name the name of the option
|
||||
* Adds the given object to the list of options.
|
||||
*
|
||||
* On the {@link SmartDashboard} on the desktop, the object will appear as the
|
||||
* given name.
|
||||
*
|
||||
* @param name the name of the option
|
||||
* @param object the option
|
||||
*/
|
||||
void SendableChooser::AddObject(const std::string &name, void *object) {
|
||||
void SendableChooser::AddObject(const std::string& name, void* object) {
|
||||
m_choices[name] = object;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the given object to the list of options and marks it as the default.
|
||||
*
|
||||
* Functionally, this is very close to {@link SendableChooser#AddObject(const
|
||||
* char *name, void *object) AddObject(...)}
|
||||
* except that it will use this as the default option if none other is
|
||||
* explicitly selected.
|
||||
* @param name the name of the option
|
||||
* char *name, void *object) AddObject(...)} except that it will use this as
|
||||
* the default option if none other is explicitly selected.
|
||||
*
|
||||
* @param name the name of the option
|
||||
* @param object the option
|
||||
*/
|
||||
void SendableChooser::AddDefault(const std::string &name, void *object) {
|
||||
void SendableChooser::AddDefault(const std::string& name, void* object) {
|
||||
m_defaultChoice = name;
|
||||
AddObject(name, object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the selected option. If there is none selected, it will return the
|
||||
* default. If there is none selected
|
||||
* and no default, then it will return {@code nullptr}.
|
||||
* Returns the selected option.
|
||||
*
|
||||
* If there is none selected, it will return the default. If there is none
|
||||
* selected and no default, then it will return {@code nullptr}.
|
||||
*
|
||||
* @return the option selected
|
||||
*/
|
||||
void *SendableChooser::GetSelected() {
|
||||
void* SendableChooser::GetSelected() {
|
||||
std::string selected = m_table->GetString(kSelected, m_defaultChoice);
|
||||
if (selected == "")
|
||||
return nullptr;
|
||||
@@ -56,7 +61,7 @@ void SendableChooser::InitTable(std::shared_ptr<ITable> subtable) {
|
||||
std::vector<std::string> keys;
|
||||
m_table = subtable;
|
||||
if (m_table != nullptr) {
|
||||
std::map<std::string, void *>::iterator iter;
|
||||
std::map<std::string, void*>::iterator iter;
|
||||
for (iter = m_choices.begin(); iter != m_choices.end(); iter++) {
|
||||
keys.push_back(iter->first);
|
||||
}
|
||||
|
||||
@@ -8,13 +8,13 @@
|
||||
#include "SmartDashboard/SmartDashboard.h"
|
||||
|
||||
//#include "NetworkCommunication/UsageReporting.h"
|
||||
#include "HLUsageReporting.h"
|
||||
#include "SmartDashboard/NamedSendable.h"
|
||||
#include "WPIErrors.h"
|
||||
#include "networktables/NetworkTable.h"
|
||||
#include "HLUsageReporting.h"
|
||||
|
||||
std::shared_ptr<ITable> SmartDashboard::m_table;
|
||||
std::map<std::shared_ptr<ITable> , Sendable *> SmartDashboard::m_tablesToData;
|
||||
std::map<std::shared_ptr<ITable>, Sendable*> SmartDashboard::m_tablesToData;
|
||||
|
||||
void SmartDashboard::init() {
|
||||
m_table = NetworkTable::GetTable("SmartDashboard");
|
||||
@@ -24,13 +24,14 @@ void SmartDashboard::init() {
|
||||
|
||||
/**
|
||||
* Maps the specified key to the specified value in this table.
|
||||
* The key can not be nullptr.
|
||||
*
|
||||
* The value can be retrieved by calling the get method with a key that is equal
|
||||
* to the original key.
|
||||
*
|
||||
* @param keyName the key
|
||||
* @param value the value
|
||||
* @param value the value
|
||||
*/
|
||||
void SmartDashboard::PutData(llvm::StringRef key, Sendable *data) {
|
||||
void SmartDashboard::PutData(llvm::StringRef key, Sendable* data) {
|
||||
if (data == nullptr) {
|
||||
wpi_setGlobalWPIErrorWithContext(NullParameter, "value");
|
||||
return;
|
||||
@@ -42,14 +43,15 @@ void SmartDashboard::PutData(llvm::StringRef key, Sendable *data) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps the specified key (where the key is the name of the {@link
|
||||
* SmartDashboardNamedData}
|
||||
* to the specified value in this table.
|
||||
* Maps the specified key (where the key is the name of the
|
||||
* {@link SmartDashboardNamedData} to the specified value in this table.
|
||||
*
|
||||
* The value can be retrieved by calling the get method with a key that is equal
|
||||
* to the original key.
|
||||
*
|
||||
* @param value the value
|
||||
*/
|
||||
void SmartDashboard::PutData(NamedSendable *value) {
|
||||
void SmartDashboard::PutData(NamedSendable* value) {
|
||||
if (value == nullptr) {
|
||||
wpi_setGlobalWPIErrorWithContext(NullParameter, "value");
|
||||
return;
|
||||
@@ -59,12 +61,13 @@ void SmartDashboard::PutData(NamedSendable *value) {
|
||||
|
||||
/**
|
||||
* Returns the value at the specified key.
|
||||
*
|
||||
* @param keyName the key
|
||||
* @return the value
|
||||
*/
|
||||
Sendable *SmartDashboard::GetData(llvm::StringRef key) {
|
||||
Sendable* SmartDashboard::GetData(llvm::StringRef key) {
|
||||
std::shared_ptr<ITable> subtable(m_table->GetSubTable(key));
|
||||
Sendable *data = m_tablesToData[subtable];
|
||||
Sendable* data = m_tablesToData[subtable];
|
||||
if (data == nullptr) {
|
||||
wpi_setGlobalWPIErrorWithContext(SmartDashboardMissingKey, key);
|
||||
return nullptr;
|
||||
@@ -75,11 +78,12 @@ Sendable *SmartDashboard::GetData(llvm::StringRef key) {
|
||||
/**
|
||||
* Maps the specified key to the specified complex value (such as an array) in
|
||||
* this table.
|
||||
* The key can not be nullptr.
|
||||
*
|
||||
* The value can be retrieved by calling the RetrieveValue method with a key
|
||||
* that is equal to the original key.
|
||||
*
|
||||
* @param keyName the key
|
||||
* @param value the value
|
||||
* @param value the value
|
||||
*/
|
||||
void SmartDashboard::PutValue(llvm::StringRef keyName,
|
||||
std::shared_ptr<nt::Value> value) {
|
||||
@@ -88,10 +92,10 @@ void SmartDashboard::PutValue(llvm::StringRef keyName,
|
||||
|
||||
/**
|
||||
* Retrieves the complex value (such as an array) in this table into the complex
|
||||
* data object
|
||||
* The key can not be nullptr.
|
||||
* data object.
|
||||
*
|
||||
* @param keyName the key
|
||||
* @param value the object to retrieve the value into
|
||||
* @param value the object to retrieve the value into
|
||||
*/
|
||||
std::shared_ptr<nt::Value> SmartDashboard::GetValue(llvm::StringRef keyName) {
|
||||
return m_table->GetValue(keyName);
|
||||
@@ -99,19 +103,22 @@ std::shared_ptr<nt::Value> SmartDashboard::GetValue(llvm::StringRef keyName) {
|
||||
|
||||
/**
|
||||
* Maps the specified key to the specified value in this table.
|
||||
* The key can not be nullptr.
|
||||
*
|
||||
* The value can be retrieved by calling the get method with a key that is equal
|
||||
* to the original key.
|
||||
*
|
||||
* @param keyName the key
|
||||
* @param value the value
|
||||
* @param value the value
|
||||
*/
|
||||
void SmartDashboard::PutBoolean(llvm::StringRef keyName, bool value) {
|
||||
m_table->PutBoolean(keyName, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value at the specified key. If the key is not found, returns the
|
||||
* default value.
|
||||
* Returns the value at the specified key.
|
||||
*
|
||||
* If the key is not found, returns the default value.
|
||||
*
|
||||
* @param keyName the key
|
||||
* @return the value
|
||||
*/
|
||||
@@ -121,19 +128,22 @@ bool SmartDashboard::GetBoolean(llvm::StringRef keyName, bool defaultValue) {
|
||||
|
||||
/**
|
||||
* Maps the specified key to the specified value in this table.
|
||||
* The key can not be nullptr.
|
||||
*
|
||||
* The value can be retrieved by calling the get method with a key that is equal
|
||||
* to the original key.
|
||||
*
|
||||
* @param keyName the key
|
||||
* @param value the value
|
||||
* @param value the value
|
||||
*/
|
||||
void SmartDashboard::PutNumber(llvm::StringRef keyName, double value) {
|
||||
m_table->PutNumber(keyName, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value at the specified key. If the key is not found, returns the
|
||||
* default value.
|
||||
* Returns the value at the specified key.
|
||||
*
|
||||
* If the key is not found, returns the default value.
|
||||
*
|
||||
* @param keyName the key
|
||||
* @return the value
|
||||
*/
|
||||
@@ -143,19 +153,22 @@ double SmartDashboard::GetNumber(llvm::StringRef keyName, double defaultValue) {
|
||||
|
||||
/**
|
||||
* Maps the specified key to the specified value in this table.
|
||||
* Neither the key nor the value can be nullptr.
|
||||
*
|
||||
* The value can be retrieved by calling the get method with a key that is equal
|
||||
* to the original key.
|
||||
*
|
||||
* @param keyName the key
|
||||
* @param value the value
|
||||
* @param value the value
|
||||
*/
|
||||
void SmartDashboard::PutString(llvm::StringRef keyName, llvm::StringRef value) {
|
||||
m_table->PutString(keyName, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value at the specified key. If the key is not found, returns the
|
||||
* default value.
|
||||
* Returns the value at the specified key.
|
||||
*
|
||||
* If the key is not found, returns the default value.
|
||||
*
|
||||
* @param keyName the key
|
||||
* @return the value
|
||||
*/
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#include <interfaces/Potentiometer.h>
|
||||
#include <Utility.h>
|
||||
#include <interfaces/Potentiometer.h>
|
||||
|
||||
void Potentiometer::SetPIDSourceType(PIDSourceType pidSource) {
|
||||
if (wpi_assert(pidSource == PIDSourceType::kDisplacement)) {
|
||||
|
||||
Reference in New Issue
Block a user