mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-23 01:21:42 +00:00
Reflowed comments and removed commented out code (#735)
This commit is contained in:
committed by
Peter Johnson
parent
1e8d18b328
commit
c663d7cd16
@@ -177,64 +177,7 @@ static std::string PixelFormatToString(int pixelFormat) {
|
||||
return "Unknown";
|
||||
}
|
||||
}
|
||||
#if 0
|
||||
static cs::VideoMode::PixelFormat PixelFormatFromString(llvm::StringRef str) {
|
||||
if (str == "MJPEG" || str == "mjpeg" || str == "JPEG" || str == "jpeg")
|
||||
return cs::VideoMode::PixelFormat::kMJPEG;
|
||||
if (str == "YUYV" || str == "yuyv") return cs::VideoMode::PixelFormat::kYUYV;
|
||||
if (str == "RGB565" || str == "rgb565")
|
||||
return cs::VideoMode::PixelFormat::kRGB565;
|
||||
if (str == "BGR" || str == "bgr") return cs::VideoMode::PixelFormat::kBGR;
|
||||
if (str == "GRAY" || str == "Gray" || str == "gray")
|
||||
return cs::VideoMode::PixelFormat::kGray;
|
||||
return cs::VideoMode::PixelFormat::kUnknown;
|
||||
}
|
||||
|
||||
static cs::VideoMode VideoModeFromString(llvm::StringRef modeStr) {
|
||||
cs::VideoMode mode;
|
||||
size_t pos;
|
||||
|
||||
// width: [0-9]+
|
||||
pos = modeStr.find_first_not_of("0123456789");
|
||||
llvm::StringRef widthStr = modeStr.slice(0, pos);
|
||||
modeStr = modeStr.drop_front(pos).ltrim(); // drop whitespace too
|
||||
|
||||
// 'x'
|
||||
if (modeStr.empty() || modeStr[0] != 'x') return mode;
|
||||
modeStr = modeStr.drop_front(1).ltrim(); // drop whitespace too
|
||||
|
||||
// height: [0-9]+
|
||||
pos = modeStr.find_first_not_of("0123456789");
|
||||
llvm::StringRef heightStr = modeStr.slice(0, pos);
|
||||
modeStr = modeStr.drop_front(pos).ltrim(); // drop whitespace too
|
||||
|
||||
// format: all characters until whitespace
|
||||
pos = modeStr.find_first_of(" \t\n\v\f\r");
|
||||
llvm::StringRef formatStr = modeStr.slice(0, pos);
|
||||
modeStr = modeStr.drop_front(pos).ltrim(); // drop whitespace too
|
||||
|
||||
// fps: [0-9.]+
|
||||
pos = modeStr.find_first_not_of("0123456789.");
|
||||
llvm::StringRef fpsStr = modeStr.slice(0, pos);
|
||||
modeStr = modeStr.drop_front(pos).ltrim(); // drop whitespace too
|
||||
|
||||
// "fps"
|
||||
if (!modeStr.startswith("fps")) return mode;
|
||||
|
||||
// make fps an integer string by dropping after the decimal
|
||||
fpsStr = fpsStr.slice(0, fpsStr.find('.'));
|
||||
|
||||
// convert width, height, and fps to integers
|
||||
if (widthStr.getAsInteger(10, mode.width)) return mode;
|
||||
if (heightStr.getAsInteger(10, mode.height)) return mode;
|
||||
if (fpsStr.getAsInteger(10, mode.fps)) return mode;
|
||||
|
||||
// convert format to enum value
|
||||
mode.pixelFormat = PixelFormatFromString(formatStr);
|
||||
|
||||
return mode;
|
||||
}
|
||||
#endif
|
||||
static std::string VideoModeToString(const cs::VideoMode& mode) {
|
||||
std::string rv;
|
||||
llvm::raw_string_ostream oss{rv};
|
||||
|
||||
@@ -25,6 +25,7 @@ int Command::m_commandCounter = 0;
|
||||
|
||||
/**
|
||||
* Creates a new command.
|
||||
*
|
||||
* The name of this command will be default.
|
||||
*/
|
||||
Command::Command() : Command("", -1.0) {}
|
||||
@@ -40,7 +41,7 @@ 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()
|
||||
* @see IsTimedOut()
|
||||
*/
|
||||
Command::Command(double timeout) : Command("", timeout) {}
|
||||
|
||||
@@ -49,7 +50,7 @@ Command::Command(double timeout) : Command("", timeout) {}
|
||||
*
|
||||
* @param name the name of the command
|
||||
* @param timeout the time (in seconds) before this command "times out"
|
||||
* @see Command#isTimedOut() isTimedOut()
|
||||
* @see IsTimedOut()
|
||||
*/
|
||||
Command::Command(const std::string& name, double timeout) {
|
||||
// We use -1.0 to indicate no timeout.
|
||||
@@ -75,7 +76,7 @@ Command::~Command() {
|
||||
*
|
||||
* The ID is a unique sequence number that is incremented for each command.
|
||||
*
|
||||
* @return the ID of this command
|
||||
* @return The ID of this command
|
||||
*/
|
||||
int Command::GetID() const { return m_commandID; }
|
||||
|
||||
@@ -83,7 +84,7 @@ int Command::GetID() const { return m_commandID; }
|
||||
* Sets the timeout of this command.
|
||||
*
|
||||
* @param timeout the timeout (in seconds)
|
||||
* @see Command#isTimedOut() isTimedOut()
|
||||
* @see IsTimedOut()
|
||||
*/
|
||||
void Command::SetTimeout(double timeout) {
|
||||
if (timeout < 0.0)
|
||||
@@ -107,15 +108,13 @@ double Command::TimeSinceInitialized() const {
|
||||
}
|
||||
|
||||
/**
|
||||
* This method specifies that the given {@link Subsystem} is used by this
|
||||
* command.
|
||||
* This method specifies that the given 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
|
||||
* constructor.</p>
|
||||
* Note that the recommended way to call this method is in the constructor.
|
||||
*
|
||||
* @param subsystem the {@link Subsystem} required
|
||||
* @param subsystem The Subsystem required
|
||||
* @see Subsystem
|
||||
*/
|
||||
void Command::Requires(Subsystem* subsystem) {
|
||||
@@ -130,8 +129,7 @@ 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 Interrupted() or End().
|
||||
*/
|
||||
void Command::Removed() {
|
||||
if (m_initialized) {
|
||||
@@ -150,11 +148,11 @@ void Command::Removed() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts up the command. Gets the command ready to start.
|
||||
* 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>
|
||||
* 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.
|
||||
*/
|
||||
void Command::Start() {
|
||||
LockChanges();
|
||||
@@ -169,7 +167,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}.
|
||||
* @return Whether or not the command should stay within the Scheduler.
|
||||
*/
|
||||
bool Command::Run() {
|
||||
if (!m_runWhenDisabled && m_parent == nullptr && RobotState::IsDisabled())
|
||||
@@ -201,22 +199,20 @@ void Command::Initialize() {}
|
||||
void Command::Execute() {}
|
||||
|
||||
/**
|
||||
* Called when the command ended peacefully. This is where you may want
|
||||
* to wrap up loose ends, like shutting off a motor that was being used
|
||||
* in the command.
|
||||
* Called when the command ended peacefully. This is where you may want to wrap
|
||||
* up loose ends, like shutting off a motor that was being used in the command.
|
||||
*/
|
||||
void Command::End() {}
|
||||
|
||||
/**
|
||||
* Called when the command ends because somebody called
|
||||
* {@link Command#cancel() cancel()} or another command shared the same
|
||||
* requirements as this one, and booted it out.
|
||||
* Called when the command ends because somebody called Cancel() or another
|
||||
* command shared the same requirements as this one, and booted it out.
|
||||
*
|
||||
* <p>This is where you may want to wrap up loose ends, like shutting off a
|
||||
* motor that was being used in the command.</p>
|
||||
* This is where you may want to wrap up loose ends, like shutting off a motor
|
||||
* that was being used in the command.
|
||||
*
|
||||
* <p>Generally, it is useful to simply call the {@link Command#end() end()}
|
||||
* method within this method, as done here.</p>
|
||||
* Generally, it is useful to simply call the End() method within this method,
|
||||
* as done here.
|
||||
*/
|
||||
void Command::Interrupted() { End(); }
|
||||
|
||||
@@ -231,15 +227,13 @@ 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.
|
||||
* This is called right before Initialize() is, inside the 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 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.
|
||||
*
|
||||
@@ -250,11 +244,11 @@ bool Command::IsTimedOut() const {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the requirements (as an std::set of {@link Subsystem Subsystems}
|
||||
* pointers) of this command.
|
||||
* Returns the requirements (as an std::set of Subsystem pointers) of this
|
||||
* command.
|
||||
*
|
||||
* @return the requirements (as an std::set of {@link Subsystem Subsystems}
|
||||
* pointers) of this command
|
||||
* @return The requirements (as an std::set of Subsystem pointers) of this
|
||||
* command
|
||||
*/
|
||||
Command::SubsystemSet Command::GetRequirements() const {
|
||||
return m_requirements;
|
||||
@@ -268,9 +262,9 @@ 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
|
||||
* @param message The message to report on error (it is appended by a default
|
||||
* message)
|
||||
* @return true if assert passed, false if assert failed
|
||||
* @return True if assert passed, false if assert failed.
|
||||
*/
|
||||
bool Command::AssertUnlocked(const std::string& message) {
|
||||
if (m_locked) {
|
||||
@@ -283,7 +277,7 @@ bool Command::AssertUnlocked(const std::string& message) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the parent of this command. No actual change is made to the group.
|
||||
* Sets the parent of this command. No actual change is made to the group.
|
||||
*
|
||||
* @param parent the parent
|
||||
*/
|
||||
@@ -302,9 +296,10 @@ void Command::SetParent(CommandGroup* parent) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears list of subsystem requirements. This is only used by
|
||||
* {@link ConditionalCommand} so cancelling the chosen command works properly in
|
||||
* {@link CommandGroup}.
|
||||
* Clears list of subsystem requirements.
|
||||
*
|
||||
* This is only used by ConditionalCommand so cancelling the chosen command
|
||||
* works properly in CommandGroup.
|
||||
*/
|
||||
void Command::ClearRequirements() { m_requirements.clear(); }
|
||||
|
||||
@@ -313,12 +308,11 @@ void Command::ClearRequirements() { m_requirements.clear(); }
|
||||
*
|
||||
* The lifecycle of a command is:
|
||||
*
|
||||
* startRunning() is called.
|
||||
* run() is called (multiple times potentially)
|
||||
* removed() is called
|
||||
* StartRunning() is called. Run() is called (multiple times potentially).
|
||||
* Removed() is called.
|
||||
*
|
||||
* It is very important that startRunning and removed be called in order or some
|
||||
* assumptions of the code will be broken.
|
||||
* It is very important that StartRunning() and Removed() be called in order or
|
||||
* some assumptions of the code will be broken.
|
||||
*/
|
||||
void Command::StartRunning() {
|
||||
m_running = true;
|
||||
@@ -330,7 +324,7 @@ 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()}.
|
||||
* not have yet called Interrupted().
|
||||
*
|
||||
* @return whether or not the command is running
|
||||
*/
|
||||
@@ -339,13 +333,13 @@ 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>
|
||||
* 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>A command can not be canceled if it is a part of a command group, you
|
||||
* must cancel the command group instead.</p>
|
||||
* A command can not be canceled if it is a part of a command group, you must
|
||||
* cancel the command group instead.
|
||||
*/
|
||||
void Command::Cancel() {
|
||||
if (m_parent != nullptr)
|
||||
@@ -357,7 +351,7 @@ void Command::Cancel() {
|
||||
}
|
||||
|
||||
/**
|
||||
* This works like cancel(), except that it doesn't throw an exception if it is
|
||||
* 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.
|
||||
@@ -390,7 +384,7 @@ void Command::SetInterruptible(bool interruptible) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the command requires the given {@link Subsystem}.
|
||||
* Checks if the command requires the given Subsystem.
|
||||
*
|
||||
* @param system the system
|
||||
* @return whether or not the subsystem is required (false if given nullptr)
|
||||
@@ -400,32 +394,31 @@ bool Command::DoesRequire(Subsystem* system) const {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the {@link CommandGroup} that this command is a part of.
|
||||
* Returns the CommandGroup that this command is a part of.
|
||||
*
|
||||
* Will return null if this {@link Command} is not in a group.
|
||||
* Will return null if this Command is not in a group.
|
||||
*
|
||||
* @return the {@link CommandGroup} that this command is a part of (or null if
|
||||
* not in group)
|
||||
* @return The CommandGroup that this command is a part of (or null if not in
|
||||
* group)
|
||||
*/
|
||||
CommandGroup* Command::GetGroup() const { return m_parent; }
|
||||
|
||||
/**
|
||||
* Sets whether or not this {@link Command} should run when the robot is
|
||||
* disabled.
|
||||
* Sets whether or not this Command should run when the robot is disabled.
|
||||
*
|
||||
* <p>By default a command will not run when the robot is disabled, and will in
|
||||
* fact be canceled.</p>
|
||||
* By default a command will not run when the robot is disabled, and will in
|
||||
* fact be canceled.
|
||||
*
|
||||
* @param run whether or not this command should run when the robot is disabled
|
||||
* @param run Whether this command should run when the robot is disabled.
|
||||
*/
|
||||
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.
|
||||
* Returns whether or not this 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
|
||||
* @return Whether this Command will run when the robot is disabled, or if it
|
||||
* will cancel itself.
|
||||
*/
|
||||
bool Command::WillRunWhenDisabled() const { return m_runWhenDisabled; }
|
||||
|
||||
|
||||
@@ -12,22 +12,23 @@
|
||||
using namespace frc;
|
||||
|
||||
/**
|
||||
* Creates a new {@link CommandGroup CommandGroup} with the given name.
|
||||
* @param name the name for this command group
|
||||
* Creates a new CommandGroup with the given name.
|
||||
*
|
||||
* @param name The name for this command group
|
||||
*/
|
||||
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}.
|
||||
* Adds a new Command to the group. The Command will be started after all the
|
||||
* previously added 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>
|
||||
* Note that any requirements the given Command has will be added to the group.
|
||||
* For this reason, a Command's requirements can not be changed after being
|
||||
* added to a group.
|
||||
*
|
||||
* <p>It is recommended that this method be called in the constructor.</p>
|
||||
* It is recommended that this method be called in the constructor.
|
||||
*
|
||||
* @param command The {@link Command Command} to be added
|
||||
* @param command The Command to be added
|
||||
*/
|
||||
void CommandGroup::AddSequential(Command* command) {
|
||||
if (command == nullptr) {
|
||||
@@ -48,21 +49,20 @@ void CommandGroup::AddSequential(Command* command) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new {@link Command Command} to the group with a given timeout.
|
||||
* The {@link Command Command} will be started after all the previously added
|
||||
* commands.
|
||||
* Adds a new Command to the group with a given timeout. The Command will be
|
||||
* started after all the previously added 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>
|
||||
* Once the Command is started, it will be run until it finishes or the time
|
||||
* expires, whichever is sooner. Note that the given Command will have no
|
||||
* knowledge that it is on a timer.
|
||||
*
|
||||
* <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>
|
||||
* Note that any requirements the given Command has will be added to the group.
|
||||
* For this reason, a Command's requirements can not be changed after being
|
||||
* added to a group.
|
||||
*
|
||||
* <p>It is recommended that this method be called in the constructor.</p>
|
||||
* It is recommended that this method be called in the constructor.
|
||||
*
|
||||
* @param command The {@link Command Command} to be added
|
||||
* @param command The Command to be added
|
||||
* @param timeout The timeout (in seconds)
|
||||
*/
|
||||
void CommandGroup::AddSequential(Command* command, double timeout) {
|
||||
@@ -88,21 +88,20 @@ 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}.
|
||||
* Adds a new child Command to the group. The Command will be started after all
|
||||
* the previously added 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>
|
||||
* Instead of waiting for the child to finish, a CommandGroup will have it run
|
||||
* at the same time as the subsequent Commands. The child will run until either
|
||||
* it finishes, a new child with conflicting requirements is started, or the
|
||||
* main sequence runs a Command with conflicting requirements. In the latter two
|
||||
* cases, the child will be canceled even if it says it can't be interrupted.
|
||||
*
|
||||
* <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>
|
||||
* Note that any requirements the given Command has will be added to the group.
|
||||
* For this reason, a Command's requirements can not be changed after being
|
||||
* added to a group.
|
||||
*
|
||||
* <p>It is recommended that this method be called in the constructor.</p>
|
||||
* It is recommended that this method be called in the constructor.
|
||||
*
|
||||
* @param command The command to be added
|
||||
*/
|
||||
@@ -125,27 +124,25 @@ 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}.
|
||||
* Adds a new child Command to the group with the given timeout. The Command
|
||||
* will be started after all the previously added 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>
|
||||
* Once the Command is started, it will run until it finishes, is interrupted,
|
||||
* or the time expires, whichever is sooner. Note that the given Command will
|
||||
* have no knowledge that it is on a timer.
|
||||
*
|
||||
* <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>
|
||||
* Instead of waiting for the child to finish, a CommandGroup will have it run
|
||||
* at the same time as the subsequent 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 Command with conflicting
|
||||
* requirements. In the latter two cases, the child will be canceled even if it
|
||||
* says it can't be interrupted.
|
||||
*
|
||||
* <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>
|
||||
* Note that any requirements the given Command has will be added to the group.
|
||||
* For this reason, a Command's requirements can not be changed after being
|
||||
* added to a group.
|
||||
*
|
||||
* <p>It is recommended that this method be called in the constructor.</p>
|
||||
* It is recommended that this method be called in the constructor.
|
||||
*
|
||||
* @param command The command to be added
|
||||
* @param timeout The timeout (in seconds)
|
||||
|
||||
@@ -25,10 +25,8 @@ static void RequireAll(Command& command, Command* onTrue, Command* onFalse) {
|
||||
/**
|
||||
* Creates a new ConditionalCommand with given onTrue and onFalse Commands.
|
||||
*
|
||||
* @param onTrue The Command to execute if {@link
|
||||
* ConditionalCommand#Condition()} returns true
|
||||
* @param onFalse The Command to execute if {@link
|
||||
* ConditionalCommand#Condition()} returns false
|
||||
* @param onTrue The Command to execute if Condition() returns true
|
||||
* @param onFalse The Command to execute if Condition() returns false
|
||||
*/
|
||||
ConditionalCommand::ConditionalCommand(Command* onTrue, Command* onFalse) {
|
||||
m_onTrue = onTrue;
|
||||
@@ -40,11 +38,9 @@ ConditionalCommand::ConditionalCommand(Command* onTrue, Command* onFalse) {
|
||||
/**
|
||||
* Creates a new ConditionalCommand with given onTrue and onFalse Commands.
|
||||
*
|
||||
* @param name the name for this command group
|
||||
* @param onTrue The Command to execute if {@link
|
||||
* ConditionalCommand#Condition()} returns true
|
||||
* @param onFalse The Command to execute if {@link
|
||||
* ConditionalCommand#Condition()} returns false
|
||||
* @param name The name for this command group
|
||||
* @param onTrue The Command to execute if Condition() returns true
|
||||
* @param onFalse The Command to execute if Condition() returns false
|
||||
*/
|
||||
ConditionalCommand::ConditionalCommand(const std::string& name, Command* onTrue,
|
||||
Command* onFalse)
|
||||
@@ -63,10 +59,8 @@ void ConditionalCommand::_Initialize() {
|
||||
}
|
||||
|
||||
if (m_chosenCommand != nullptr) {
|
||||
/*
|
||||
* This is a hack to make cancelling the chosen command inside a
|
||||
* CommandGroup work properly
|
||||
*/
|
||||
// This is a hack to make cancelling the chosen command inside a
|
||||
// CommandGroup work properly
|
||||
m_chosenCommand->ClearRequirements();
|
||||
|
||||
m_chosenCommand->Start();
|
||||
|
||||
@@ -10,8 +10,9 @@
|
||||
using namespace frc;
|
||||
|
||||
/**
|
||||
* Creates a new {@link InstantCommand} with the given name.
|
||||
* @param name the name for this command
|
||||
* Creates a new InstantCommand with the given name.
|
||||
*
|
||||
* @param name The name for this command
|
||||
*/
|
||||
InstantCommand::InstantCommand(const std::string& name) : Command(name) {}
|
||||
|
||||
|
||||
@@ -12,8 +12,7 @@
|
||||
using namespace frc;
|
||||
|
||||
/**
|
||||
* Instantiates a {@link PIDSubsystem} that will use the given p, i and d
|
||||
* values.
|
||||
* Instantiates a PIDSubsystem that will use the given P, I, and D values.
|
||||
*
|
||||
* @param name the name
|
||||
* @param p the proportional value
|
||||
@@ -27,8 +26,7 @@ PIDSubsystem::PIDSubsystem(const std::string& name, double p, double i,
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a {@link PIDSubsystem} that will use the given p, i and d
|
||||
* values.
|
||||
* Instantiates a PIDSubsystem that will use the given P, I, and D values.
|
||||
*
|
||||
* @param name the name
|
||||
* @param p the proportional value
|
||||
@@ -43,8 +41,7 @@ PIDSubsystem::PIDSubsystem(const std::string& name, double p, double i,
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a {@link PIDSubsystem} that will use the given p, i and d
|
||||
* values.
|
||||
* Instantiates a 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.
|
||||
@@ -64,8 +61,7 @@ PIDSubsystem::PIDSubsystem(const std::string& name, double p, double i,
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a {@link PIDSubsystem} that will use the given p, i and d
|
||||
* values.
|
||||
* Instantiates a PIDSubsystem that will use the given P, I, and D values.
|
||||
*
|
||||
* It will use the class name as its name.
|
||||
*
|
||||
@@ -79,8 +75,7 @@ PIDSubsystem::PIDSubsystem(double p, double i, double d)
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a {@link PIDSubsystem} that will use the given p, i and d
|
||||
* values.
|
||||
* Instantiates a PIDSubsystem that will use the given P, I, and D values.
|
||||
*
|
||||
* It will use the class name as its name.
|
||||
*
|
||||
@@ -95,8 +90,7 @@ PIDSubsystem::PIDSubsystem(double p, double i, double d, double f)
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a {@link PIDSubsystem} that will use the given p, i and d
|
||||
* values.
|
||||
* Instantiates a 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
|
||||
* between PID loop calculations to be equal to the given period.
|
||||
@@ -115,21 +109,21 @@ PIDSubsystem::PIDSubsystem(double p, double i, double d, double f,
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables the internal {@link PIDController}.
|
||||
* Enables the internal PIDController.
|
||||
*/
|
||||
void PIDSubsystem::Enable() { m_controller->Enable(); }
|
||||
|
||||
/**
|
||||
* Disables the internal {@link PIDController}.
|
||||
* Disables the internal PIDController.
|
||||
*/
|
||||
void PIDSubsystem::Disable() { m_controller->Disable(); }
|
||||
|
||||
/**
|
||||
* Returns the {@link PIDController} used by this {@link PIDSubsystem}.
|
||||
* Returns the PIDController used by this PIDSubsystem.
|
||||
*
|
||||
* Use this if you would like to fine tune the pid loop.
|
||||
* Use this if you would like to fine tune the PID loop.
|
||||
*
|
||||
* @return the {@link PIDController} used by this {@link PIDSubsystem}
|
||||
* @return The PIDController used by this PIDSubsystem
|
||||
*/
|
||||
std::shared_ptr<PIDController> PIDSubsystem::GetPIDController() {
|
||||
return m_controller;
|
||||
@@ -138,8 +132,8 @@ 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.
|
||||
* If SetRange() was called, then the given setpoint will be trimmed to fit
|
||||
* within the range.
|
||||
*
|
||||
* @param setpoint the new setpoint
|
||||
*/
|
||||
@@ -150,8 +144,7 @@ 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.
|
||||
* If SetRange() was used, then the bounds will still be honored by this method.
|
||||
*
|
||||
* @param deltaSetpoint the change in the setpoint
|
||||
*/
|
||||
@@ -197,7 +190,8 @@ void PIDSubsystem::SetAbsoluteTolerance(double absValue) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the percentage error which is considered tolerable for use with OnTarget.
|
||||
* Set the percentage error which is considered tolerable for use with
|
||||
* OnTarget().
|
||||
*
|
||||
* @param percent percentage error which is tolerable
|
||||
*/
|
||||
@@ -207,9 +201,9 @@ void PIDSubsystem::SetPercentTolerance(double percent) {
|
||||
|
||||
/**
|
||||
* Return true if the error is within the percentage of the total input range,
|
||||
* determined by SetTolerance.
|
||||
* determined by SetTolerance().
|
||||
*
|
||||
* This asssumes that the maximum and minimum input were set using SetInput.
|
||||
* This asssumes that the maximum and minimum input were set using SetInput().
|
||||
* Use OnTarget() in the IsFinished() method of commands that use this
|
||||
* subsystem.
|
||||
*
|
||||
@@ -217,7 +211,7 @@ void PIDSubsystem::SetPercentTolerance(double percent) {
|
||||
* 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
|
||||
* @return True if the error is within the percentage tolerance of the input
|
||||
* range
|
||||
*/
|
||||
bool PIDSubsystem::OnTarget() const { return m_controller->OnTarget(); }
|
||||
|
||||
@@ -20,9 +20,9 @@ using namespace frc;
|
||||
Scheduler::Scheduler() { HLUsageReporting::ReportScheduler(); }
|
||||
|
||||
/**
|
||||
* Returns the {@link Scheduler}, creating it if one does not exist.
|
||||
* Returns the Scheduler, creating it if one does not exist.
|
||||
*
|
||||
* @return the {@link Scheduler}
|
||||
* @return the Scheduler
|
||||
*/
|
||||
Scheduler* Scheduler::GetInstance() {
|
||||
static Scheduler instance;
|
||||
@@ -99,14 +99,14 @@ void Scheduler::ProcessCommandAddition(Command* command) {
|
||||
* 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:
|
||||
* Command system. The loop has five stages:
|
||||
*
|
||||
* <ol>
|
||||
* <li> Poll the Buttons </li>
|
||||
* <li> Execute/Remove the Commands </li>
|
||||
* <li> Send values to SmartDashboard </li>
|
||||
* <li> Add Commands </li>
|
||||
* <li> Add Defaults </li>
|
||||
* <li>Poll the Buttons</li>
|
||||
* <li>Execute/Remove the Commands</li>
|
||||
* <li>Send values to SmartDashboard</li>
|
||||
* <li>Add Commands</li>
|
||||
* <li>Add Defaults</li>
|
||||
* </ol>
|
||||
*/
|
||||
void Scheduler::Run() {
|
||||
@@ -166,10 +166,10 @@ 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.
|
||||
* Registers a Subsystem to this Scheduler, so that the Scheduler might know if
|
||||
* a default Command needs to be run.
|
||||
*
|
||||
* All {@link Subsystem Subsystems} should call this.
|
||||
* All Subsystems should call this.
|
||||
*
|
||||
* @param system the system
|
||||
*/
|
||||
@@ -182,7 +182,7 @@ void Scheduler::RegisterSubsystem(Subsystem* subsystem) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the {@link Command} from the {@link Scheduler}.
|
||||
* Removes the Command from the Scheduler.
|
||||
*
|
||||
* @param command the command to remove
|
||||
*/
|
||||
@@ -235,10 +235,8 @@ void Scheduler::UpdateTable() {
|
||||
toCancel = new_toCancel->GetDoubleArray();
|
||||
else
|
||||
toCancel.resize(0);
|
||||
// m_table->RetrieveValue("Ids", *ids);
|
||||
|
||||
// cancel commands that have had the cancel buttons pressed
|
||||
// on the SmartDashboad
|
||||
// Cancel commands whose cancel buttons were pressed on the SmartDashboard
|
||||
if (!toCancel.empty()) {
|
||||
for (auto commandIter = m_commands.begin();
|
||||
commandIter != m_commands.end(); ++commandIter) {
|
||||
|
||||
@@ -38,8 +38,8 @@ void Subsystem::InitDefaultCommand() {}
|
||||
* Sets the default command. If this is not called or is called with null,
|
||||
* 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>
|
||||
* <b>WARNING:</b> This should <b>NOT</b> be called in a constructor if the
|
||||
* subsystem is a singleton.
|
||||
*
|
||||
* @param command the default command (or null if there should be none)
|
||||
*/
|
||||
@@ -113,9 +113,9 @@ void Subsystem::Periodic() {}
|
||||
* 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.
|
||||
* Sometimes, the Subsystem is told that it has no command while the 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) {
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
using namespace frc;
|
||||
|
||||
/**
|
||||
* A {@link WaitCommand} will wait until a certain match time before finishing.
|
||||
* A 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.
|
||||
|
||||
@@ -54,10 +54,10 @@ void DigitalGlitchFilter::Add(DigitalSource* input) {
|
||||
}
|
||||
|
||||
void DigitalGlitchFilter::DoAdd(DigitalSource* input, int requested_index) {
|
||||
// Some sources from Counters and Encoders are null. By pushing the check
|
||||
// Some sources from Counters and Encoders are null. By pushing the check
|
||||
// here, we catch the issue more generally.
|
||||
if (input) {
|
||||
// we don't support GlitchFilters on AnalogTriggers.
|
||||
// We don't support GlitchFilters on AnalogTriggers.
|
||||
if (input->IsAnalogTrigger()) {
|
||||
wpi_setErrorWithContext(
|
||||
-1, "Analog Triggers not supported for DigitalGlitchFilters");
|
||||
|
||||
@@ -61,7 +61,7 @@ DigitalInput::~DigitalInput() {
|
||||
if (m_interrupt != HAL_kInvalidHandle) {
|
||||
int32_t status = 0;
|
||||
HAL_CleanInterrupts(m_interrupt, &status);
|
||||
// ignore status, as an invalid handle just needs to be ignored.
|
||||
// Ignore status, as an invalid handle just needs to be ignored.
|
||||
m_interrupt = HAL_kInvalidHandle;
|
||||
}
|
||||
|
||||
|
||||
@@ -174,8 +174,8 @@ bool DoubleSolenoid::IsFwdSolenoidBlackListed() const {
|
||||
*
|
||||
* If a solenoid is shorted, it is added to the blacklist and
|
||||
* disabled until power cycle, or until faults are cleared.
|
||||
* @see ClearAllPCMStickyFaults()
|
||||
*
|
||||
* @see ClearAllPCMStickyFaults()
|
||||
* @return If solenoid is disabled due to short.
|
||||
*/
|
||||
bool DoubleSolenoid::IsRevSolenoidBlackListed() const {
|
||||
|
||||
@@ -762,7 +762,7 @@ void DriverStation::Run() {
|
||||
* copied from the cache.
|
||||
*
|
||||
* @param force True to force an update to the cache, otherwise update if 50ms
|
||||
* have passed.
|
||||
* have passed.
|
||||
* @param controlWord Structure to put the return control word data into.
|
||||
*/
|
||||
void DriverStation::UpdateControlWord(bool force,
|
||||
|
||||
@@ -29,6 +29,7 @@ ErrorBase::ErrorBase() { HAL_Initialize(500, 0); }
|
||||
|
||||
/**
|
||||
* @brief Retrieve the current error.
|
||||
*
|
||||
* Get the current error information associated with this sensor.
|
||||
*/
|
||||
Error& ErrorBase::GetError() { return m_error; }
|
||||
@@ -42,7 +43,7 @@ void ErrorBase::ClearError() const { m_error.Clear(); }
|
||||
|
||||
/**
|
||||
* @brief Set error information associated with a C library call that set an
|
||||
* error to the "errno" global variable.
|
||||
* 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
|
||||
@@ -76,7 +77,7 @@ void ErrorBase::SetErrnoError(llvm::StringRef contextMessage,
|
||||
|
||||
/**
|
||||
* @brief Set the current error information associated from the nivision Imaq
|
||||
* API.
|
||||
* API.
|
||||
*
|
||||
* @param success The return from the function
|
||||
* @param contextMessage A custom message from the code that set the error.
|
||||
|
||||
@@ -150,17 +150,6 @@ bool I2C::ReadOnly(int count, uint8_t* buffer) {
|
||||
return HAL_ReadI2C(m_port, m_deviceAddress, buffer, count) < 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a broadcast write to all devices on the I2C bus.
|
||||
*
|
||||
* This is not currently implemented!
|
||||
*
|
||||
* @param registerAddress The register to write on all devices on the bus.
|
||||
* @param data The value to write to the devices.
|
||||
*/
|
||||
// [[gnu::warning("I2C::Broadcast() is not implemented.")]] void I2C::Broadcast(
|
||||
// int registerAddress, uint8_t data) {}
|
||||
|
||||
/**
|
||||
* Verify that a device's registers contain expected values.
|
||||
*
|
||||
|
||||
@@ -81,7 +81,7 @@ void InterruptableSensorBase::CancelInterrupts() {
|
||||
wpi_assert(m_interrupt != HAL_kInvalidHandle);
|
||||
int32_t status = 0;
|
||||
HAL_CleanInterrupts(m_interrupt, &status);
|
||||
// ignore status, as an invalid handle just needs to be ignored.
|
||||
// Ignore status, as an invalid handle just needs to be ignored.
|
||||
m_interrupt = HAL_kInvalidHandle;
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ void IterativeRobot::StartCompetition() {
|
||||
|
||||
// Loop forever, calling the appropriate mode-dependent function
|
||||
while (true) {
|
||||
// wait for driver station data so the loop doesn't hog the CPU
|
||||
// Wait for driver station data so the loop doesn't hog the CPU
|
||||
DriverStation::GetInstance().WaitForData();
|
||||
|
||||
LoopFunc();
|
||||
|
||||
@@ -149,8 +149,8 @@ void IterativeRobotBase::TestPeriodic() {
|
||||
void IterativeRobotBase::LoopFunc() {
|
||||
// Call the appropriate function depending upon the current robot mode
|
||||
if (IsDisabled()) {
|
||||
// call DisabledInit() if we are now just entering disabled mode from
|
||||
// either a different mode or from power-on
|
||||
// Call DisabledInit() if we are now just entering disabled mode from
|
||||
// either a different mode or from power-on.
|
||||
if (m_lastMode != Mode::kDisabled) {
|
||||
LiveWindow::GetInstance()->SetEnabled(false);
|
||||
DisabledInit();
|
||||
@@ -159,8 +159,8 @@ void IterativeRobotBase::LoopFunc() {
|
||||
HAL_ObserveUserProgramDisabled();
|
||||
DisabledPeriodic();
|
||||
} else if (IsAutonomous()) {
|
||||
// call AutonomousInit() if we are now just entering autonomous mode from
|
||||
// either a different mode or from power-on
|
||||
// Call AutonomousInit() if we are now just entering autonomous mode from
|
||||
// either a different mode or from power-on.
|
||||
if (m_lastMode != Mode::kAutonomous) {
|
||||
LiveWindow::GetInstance()->SetEnabled(false);
|
||||
AutonomousInit();
|
||||
@@ -169,8 +169,8 @@ void IterativeRobotBase::LoopFunc() {
|
||||
HAL_ObserveUserProgramAutonomous();
|
||||
AutonomousPeriodic();
|
||||
} else if (IsOperatorControl()) {
|
||||
// call TeleopInit() if we are now just entering teleop mode from
|
||||
// either a different mode or from power-on
|
||||
// Call TeleopInit() if we are now just entering teleop mode from
|
||||
// either a different mode or from power-on.
|
||||
if (m_lastMode != Mode::kTeleop) {
|
||||
LiveWindow::GetInstance()->SetEnabled(false);
|
||||
TeleopInit();
|
||||
@@ -180,8 +180,8 @@ void IterativeRobotBase::LoopFunc() {
|
||||
HAL_ObserveUserProgramTeleop();
|
||||
TeleopPeriodic();
|
||||
} else {
|
||||
// call TestInit() if we are now just entering test mode from
|
||||
// either a different mode or from power-on
|
||||
// Call TestInit() if we are now just entering test mode from
|
||||
// either a different mode or from power-on.
|
||||
if (m_lastMode != Mode::kTest) {
|
||||
LiveWindow::GetInstance()->SetEnabled(true);
|
||||
TestInit();
|
||||
|
||||
@@ -297,9 +297,6 @@ double Joystick::GetDirectionRadians() const {
|
||||
* Get the direction of the vector formed by the joystick and its origin
|
||||
* in degrees.
|
||||
*
|
||||
* uses std::acos(-1) to represent Pi due to absence of readily accessible Pi
|
||||
* constant in C++
|
||||
*
|
||||
* @return The direction of the vector in degrees
|
||||
*/
|
||||
double Joystick::GetDirectionDegrees() const {
|
||||
|
||||
@@ -49,6 +49,7 @@ MotorSafetyHelper::~MotorSafetyHelper() {
|
||||
|
||||
/**
|
||||
* Feed the motor safety object.
|
||||
*
|
||||
* Resets the timer on this object that is used to do the timeouts.
|
||||
*/
|
||||
void MotorSafetyHelper::Feed() {
|
||||
@@ -58,6 +59,7 @@ void MotorSafetyHelper::Feed() {
|
||||
|
||||
/**
|
||||
* Set the expiration time for the corresponding motor safety object.
|
||||
*
|
||||
* @param expirationTime The timeout value in seconds.
|
||||
*/
|
||||
void MotorSafetyHelper::SetExpiration(double expirationTime) {
|
||||
@@ -67,6 +69,7 @@ void MotorSafetyHelper::SetExpiration(double expirationTime) {
|
||||
|
||||
/**
|
||||
* Retrieve the timeout value for the corresponding motor safety object.
|
||||
*
|
||||
* @return the timeout value in seconds.
|
||||
*/
|
||||
double MotorSafetyHelper::GetExpiration() const {
|
||||
@@ -76,6 +79,7 @@ double MotorSafetyHelper::GetExpiration() const {
|
||||
|
||||
/**
|
||||
* Determine if the motor is still operating or has timed out.
|
||||
*
|
||||
* @return a true value if the motor is still operating normally and hasn't
|
||||
* timed out.
|
||||
*/
|
||||
@@ -86,6 +90,7 @@ bool MotorSafetyHelper::IsAlive() const {
|
||||
|
||||
/**
|
||||
* Check if this motor has exceeded its timeout.
|
||||
*
|
||||
* This method is called periodically to determine if this motor has exceeded
|
||||
* its timeout value. If it has, the stop method is called, and the motor is
|
||||
* shut down until its value is updated again.
|
||||
@@ -107,7 +112,9 @@ void MotorSafetyHelper::Check() {
|
||||
|
||||
/**
|
||||
* Enable/disable motor safety for this device
|
||||
*
|
||||
* Turn on and off the motor safety option for this PWM object.
|
||||
*
|
||||
* @param enabled True if motor safety is enforced for this object
|
||||
*/
|
||||
void MotorSafetyHelper::SetSafetyEnabled(bool enabled) {
|
||||
@@ -117,7 +124,9 @@ void MotorSafetyHelper::SetSafetyEnabled(bool enabled) {
|
||||
|
||||
/**
|
||||
* Return the state of the motor safety enabled flag
|
||||
*
|
||||
* Return if the motor safety is currently enabled for this devicce.
|
||||
*
|
||||
* @return True if motor safety is enforced for this device
|
||||
*/
|
||||
bool MotorSafetyHelper::IsSafetyEnabled() const {
|
||||
@@ -127,8 +136,9 @@ bool MotorSafetyHelper::IsSafetyEnabled() const {
|
||||
|
||||
/**
|
||||
* Check the motors to see if any have timed out.
|
||||
* This static method is called periodically to poll all the motors and stop
|
||||
* any that have timed out.
|
||||
*
|
||||
* This static method is called periodically to poll all the motors and stop any
|
||||
* that have timed out.
|
||||
*/
|
||||
void MotorSafetyHelper::CheckMotors() {
|
||||
std::lock_guard<wpi::mutex> sync(m_listMutex);
|
||||
|
||||
@@ -17,9 +17,9 @@ using namespace frc;
|
||||
* Constructor.
|
||||
*
|
||||
* @param pwmChannel The PWM channel that the Nidec Brushless controller is
|
||||
* attached to. 0-9 are on-board, 10-19 are on the MXP port
|
||||
* attached to. 0-9 are on-board, 10-19 are on the MXP port.
|
||||
* @param dioChannel The DIO channel that the Nidec Brushless controller is
|
||||
* attached to. 0-9 are on-board, 10-25 are on the MXP port
|
||||
* attached to. 0-9 are on-board, 10-25 are on the MXP port.
|
||||
*/
|
||||
NidecBrushless::NidecBrushless(int pwmChannel, int dioChannel)
|
||||
: m_safetyHelper(this), m_dio(dioChannel), m_pwm(pwmChannel) {
|
||||
@@ -40,8 +40,8 @@ NidecBrushless::NidecBrushless(int pwmChannel, int dioChannel)
|
||||
/**
|
||||
* Set the PWM value.
|
||||
*
|
||||
* <p>The PWM value is set using a range of -1.0 to 1.0, appropriately scaling
|
||||
* the value for the FPGA.
|
||||
* The PWM value is set using a range of -1.0 to 1.0, appropriately scaling the
|
||||
* value for the FPGA.
|
||||
*
|
||||
* @param speed The speed value between -1.0 and 1.0 to set.
|
||||
*/
|
||||
@@ -91,13 +91,13 @@ double NidecBrushless::GetExpiration() const {
|
||||
* Check if the motor is currently alive or stopped due to a timeout.
|
||||
*
|
||||
* @return a bool value that is true if the motor has NOT timed out and should
|
||||
* still be running.
|
||||
* still be running.
|
||||
*/
|
||||
bool NidecBrushless::IsAlive() const { return m_safetyHelper.IsAlive(); }
|
||||
|
||||
/**
|
||||
* Stop the motor. This is called by the MotorSafetyHelper object
|
||||
* when it has a timeout for this PWM and needs to stop it from running.
|
||||
* Stop the motor. This is called by the MotorSafetyHelper object when it has a
|
||||
* timeout for this PWM and needs to stop it from running.
|
||||
*/
|
||||
void NidecBrushless::StopMotor() { Disable(); }
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
using namespace frc;
|
||||
|
||||
/** The Preferences table name */
|
||||
// The Preferences table name
|
||||
static llvm::StringRef kTableName{"Preferences"};
|
||||
|
||||
Preferences::Preferences()
|
||||
@@ -124,8 +124,8 @@ int64_t Preferences::GetLong(llvm::StringRef key, int64_t defaultValue) {
|
||||
/**
|
||||
* Puts the given string into the preferences table.
|
||||
*
|
||||
* <p>The value may not have quotation marks, nor may the key
|
||||
* have any whitespace nor an equals sign</p>
|
||||
* The value may not have quotation marks, nor may the key have any whitespace
|
||||
* nor an equals sign.
|
||||
*
|
||||
* @param key the key
|
||||
* @param value the value
|
||||
@@ -139,7 +139,7 @@ void Preferences::PutString(llvm::StringRef key, llvm::StringRef value) {
|
||||
/**
|
||||
* Puts the given int into the preferences table.
|
||||
*
|
||||
* <p>The key may not have any whitespace nor an equals sign</p>
|
||||
* The key may not have any whitespace nor an equals sign.
|
||||
*
|
||||
* @param key the key
|
||||
* @param value the value
|
||||
@@ -153,7 +153,7 @@ void Preferences::PutInt(llvm::StringRef key, int value) {
|
||||
/**
|
||||
* Puts the given double into the preferences table.
|
||||
*
|
||||
* <p>The key may not have any whitespace nor an equals sign</p>
|
||||
* The key may not have any whitespace nor an equals sign.
|
||||
*
|
||||
* @param key the key
|
||||
* @param value the value
|
||||
@@ -167,7 +167,7 @@ void Preferences::PutDouble(llvm::StringRef key, double value) {
|
||||
/**
|
||||
* Puts the given float into the preferences table.
|
||||
*
|
||||
* <p>The key may not have any whitespace nor an equals sign</p>
|
||||
* The key may not have any whitespace nor an equals sign.
|
||||
*
|
||||
* @param key the key
|
||||
* @param value the value
|
||||
@@ -181,7 +181,7 @@ void Preferences::PutFloat(llvm::StringRef key, float value) {
|
||||
/**
|
||||
* Puts the given boolean into the preferences table.
|
||||
*
|
||||
* <p>The key may not have any whitespace nor an equals sign</p>
|
||||
* The key may not have any whitespace nor an equals sign.
|
||||
*
|
||||
* @param key the key
|
||||
* @param value the value
|
||||
@@ -195,7 +195,7 @@ void Preferences::PutBoolean(llvm::StringRef key, bool value) {
|
||||
/**
|
||||
* Puts the given long (int64_t) into the preferences table.
|
||||
*
|
||||
* <p>The key may not have any whitespace nor an equals sign</p>
|
||||
* The key may not have any whitespace nor an equals sign.
|
||||
*
|
||||
* @param key the key
|
||||
* @param value the value
|
||||
|
||||
@@ -179,7 +179,7 @@ void Relay::Set(Relay::Value value) {
|
||||
* Gets the current state of the relay.
|
||||
*
|
||||
* When set to kForwardOnly or kReverseOnly, value is returned as kOn/kOff not
|
||||
* kForward/kReverse (per the recommendation in Set)
|
||||
* kForward/kReverse (per the recommendation in Set).
|
||||
*
|
||||
* @return The current state of the relay as a Relay::Value
|
||||
*/
|
||||
@@ -220,7 +220,8 @@ Relay::Value Relay::Get() const {
|
||||
int Relay::GetChannel() const { return m_channel; }
|
||||
|
||||
/**
|
||||
* Set the expiration time for the Relay object
|
||||
* Set the expiration time for the Relay object.
|
||||
*
|
||||
* @param timeout The timeout (in seconds) for this relay object
|
||||
*/
|
||||
void Relay::SetExpiration(double timeout) {
|
||||
@@ -229,6 +230,7 @@ void Relay::SetExpiration(double timeout) {
|
||||
|
||||
/**
|
||||
* Return the expiration time for the relay object.
|
||||
*
|
||||
* @return The expiration time value.
|
||||
*/
|
||||
double Relay::GetExpiration() const { return m_safetyHelper->GetExpiration(); }
|
||||
|
||||
@@ -68,45 +68,51 @@ RobotBase::RobotBase() : m_ds(DriverStation::GetInstance()) {
|
||||
|
||||
/**
|
||||
* Determine if the Robot is currently enabled.
|
||||
*
|
||||
* @return True if the Robot is currently enabled by the field controls.
|
||||
*/
|
||||
bool RobotBase::IsEnabled() const { return m_ds.IsEnabled(); }
|
||||
|
||||
/**
|
||||
* Determine if the Robot is currently disabled.
|
||||
*
|
||||
* @return True if the Robot is currently disabled by the field controls.
|
||||
*/
|
||||
bool RobotBase::IsDisabled() const { return m_ds.IsDisabled(); }
|
||||
|
||||
/**
|
||||
* Determine if the robot is currently in Autonomous mode.
|
||||
*
|
||||
* @return True if the robot is currently operating Autonomously as determined
|
||||
* by the field controls.
|
||||
* by the field controls.
|
||||
*/
|
||||
bool RobotBase::IsAutonomous() const { return m_ds.IsAutonomous(); }
|
||||
|
||||
/**
|
||||
* Determine if the robot is currently in Operator Control mode.
|
||||
*
|
||||
* @return True if the robot is currently operating in Tele-Op mode as
|
||||
* determined by the field controls.
|
||||
* determined by the field controls.
|
||||
*/
|
||||
bool RobotBase::IsOperatorControl() const { return m_ds.IsOperatorControl(); }
|
||||
|
||||
/**
|
||||
* Determine if the robot is currently in Test mode.
|
||||
*
|
||||
* @return True if the robot is currently running tests as determined by the
|
||||
* field controls.
|
||||
* field controls.
|
||||
*/
|
||||
bool RobotBase::IsTest() const { return m_ds.IsTest(); }
|
||||
|
||||
/**
|
||||
* Indicates if new data is available from the driver station.
|
||||
*
|
||||
* @return Has new data arrived over the network since the last time this
|
||||
* function was called?
|
||||
* function was called?
|
||||
*/
|
||||
bool RobotBase::IsNewDataAvailable() const { return m_ds.IsNewControlData(); }
|
||||
|
||||
/**
|
||||
* Gets the ID of the main robot thread
|
||||
* Gets the ID of the main robot thread.
|
||||
*/
|
||||
std::thread::id RobotBase::GetThreadId() { return m_threadId; }
|
||||
|
||||
@@ -183,8 +183,9 @@ bool SmartDashboard::PutValue(llvm::StringRef keyName,
|
||||
|
||||
/**
|
||||
* Gets the current value in the table, setting it if it does not exist.
|
||||
*
|
||||
* @param key the key
|
||||
* @param defaultValue the default value to set if key doesn't exist.
|
||||
* @param defaultValue The default value to set if key doesn't exist.
|
||||
* @returns False if the table key exists with a different type
|
||||
*/
|
||||
bool SmartDashboard::SetDefaultValue(llvm::StringRef key,
|
||||
@@ -255,8 +256,9 @@ bool SmartDashboard::PutNumber(llvm::StringRef keyName, double value) {
|
||||
|
||||
/**
|
||||
* Gets the current value in the table, setting it if it does not exist.
|
||||
* @param key the key
|
||||
* @param defaultValue the default value to set if key doesn't exist.
|
||||
*
|
||||
* @param key The key.
|
||||
* @param defaultValue The default value to set if key doesn't exist.
|
||||
* @returns False if the table key exists with a different type
|
||||
*/
|
||||
bool SmartDashboard::SetDefaultNumber(llvm::StringRef key,
|
||||
@@ -315,13 +317,14 @@ std::string SmartDashboard::GetString(llvm::StringRef keyName,
|
||||
}
|
||||
|
||||
/**
|
||||
* Put a boolean array in the table
|
||||
* Put a boolean array in the table.
|
||||
*
|
||||
* @param key the key to be assigned to
|
||||
* @param value the value that will be assigned
|
||||
* @return False if the table key already exists with a different type
|
||||
*
|
||||
* @note The array must be of int's rather than of bool's because
|
||||
* std::vector<bool> is special-cased in C++. 0 is false, any
|
||||
* std::vector<bool> is special-cased in C++. 0 is false, any
|
||||
* non-zero value is true.
|
||||
*/
|
||||
bool SmartDashboard::PutBooleanArray(llvm::StringRef key,
|
||||
@@ -331,6 +334,7 @@ bool SmartDashboard::PutBooleanArray(llvm::StringRef key,
|
||||
|
||||
/**
|
||||
* Gets the current value in the table, setting it if it does not exist.
|
||||
*
|
||||
* @param key the key
|
||||
* @param defaultValue the default value to set if key doesn't exist.
|
||||
* @returns False if the table key exists with a different type
|
||||
@@ -341,18 +345,21 @@ bool SmartDashboard::SetDefaultBooleanArray(llvm::StringRef key,
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the boolean array the key maps to. If the key does not exist or is
|
||||
* of different type, it will return the default value.
|
||||
* @param key the key to look up
|
||||
* @param defaultValue the value to be returned if no value is found
|
||||
* @return the value associated with the given key or the given default value
|
||||
* if there is no value associated with the key
|
||||
* Returns the boolean array the key maps to.
|
||||
*
|
||||
* @note This makes a copy of the array. If the overhead of this is a
|
||||
* concern, use GetValue() instead.
|
||||
* If the key does not exist or is of different type, it will return the default
|
||||
* value.
|
||||
*
|
||||
* @param key The key to look up.
|
||||
* @param defaultValue The value to be returned if no value is found.
|
||||
* @return the value associated with the given key or the given default value
|
||||
* if there is no value associated with the key
|
||||
*
|
||||
* @note This makes a copy of the array. If the overhead of this is a concern,
|
||||
* use GetValue() instead.
|
||||
*
|
||||
* @note The returned array is std::vector<int> instead of std::vector<bool>
|
||||
* because std::vector<bool> is special-cased in C++. 0 is false, any
|
||||
* because std::vector<bool> is special-cased in C++. 0 is false, any
|
||||
* non-zero value is true.
|
||||
*/
|
||||
std::vector<int> SmartDashboard::GetBooleanArray(
|
||||
@@ -361,9 +368,10 @@ std::vector<int> SmartDashboard::GetBooleanArray(
|
||||
}
|
||||
|
||||
/**
|
||||
* Put a number array in the table
|
||||
* @param key the key to be assigned to
|
||||
* @param value the value that will be assigned
|
||||
* Put a number array in the table.
|
||||
*
|
||||
* @param key The key to be assigned to.
|
||||
* @param value The value that will be assigned.
|
||||
* @return False if the table key already exists with a different type
|
||||
*/
|
||||
bool SmartDashboard::PutNumberArray(llvm::StringRef key,
|
||||
@@ -373,8 +381,9 @@ bool SmartDashboard::PutNumberArray(llvm::StringRef key,
|
||||
|
||||
/**
|
||||
* Gets the current value in the table, setting it if it does not exist.
|
||||
* @param key the key
|
||||
* @param defaultValue the default value to set if key doesn't exist.
|
||||
*
|
||||
* @param key The key.
|
||||
* @param defaultValue The default value to set if key doesn't exist.
|
||||
* @returns False if the table key exists with a different type
|
||||
*/
|
||||
bool SmartDashboard::SetDefaultNumberArray(
|
||||
@@ -383,15 +392,18 @@ bool SmartDashboard::SetDefaultNumberArray(
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number array the key maps to. If the key does not exist or is
|
||||
* of different type, it will return the default value.
|
||||
* @param key the key to look up
|
||||
* @param defaultValue the value to be returned if no value is found
|
||||
* Returns the number array the key maps to.
|
||||
*
|
||||
* If the key does not exist or is of different type, it will return the default
|
||||
* value.
|
||||
*
|
||||
* @param key The key to look up.
|
||||
* @param defaultValue The value to be returned if no value is found.
|
||||
* @return the value associated with the given key or the given default value
|
||||
* if there is no value associated with the key
|
||||
*
|
||||
* @note This makes a copy of the array. If the overhead of this is a
|
||||
* concern, use GetValue() instead.
|
||||
* @note This makes a copy of the array. If the overhead of this is a concern,
|
||||
* use GetValue() instead.
|
||||
*/
|
||||
std::vector<double> SmartDashboard::GetNumberArray(
|
||||
llvm::StringRef key, llvm::ArrayRef<double> defaultValue) {
|
||||
@@ -399,9 +411,10 @@ std::vector<double> SmartDashboard::GetNumberArray(
|
||||
}
|
||||
|
||||
/**
|
||||
* Put a string array in the table
|
||||
* @param key the key to be assigned to
|
||||
* @param value the value that will be assigned
|
||||
* Put a string array in the table.
|
||||
*
|
||||
* @param key The key to be assigned to.
|
||||
* @param value The value that will be assigned.
|
||||
* @return False if the table key already exists with a different type
|
||||
*/
|
||||
bool SmartDashboard::PutStringArray(llvm::StringRef key,
|
||||
@@ -411,8 +424,9 @@ bool SmartDashboard::PutStringArray(llvm::StringRef key,
|
||||
|
||||
/**
|
||||
* Gets the current value in the table, setting it if it does not exist.
|
||||
* @param key the key
|
||||
* @param defaultValue the default value to set if key doesn't exist.
|
||||
*
|
||||
* @param key The key.
|
||||
* @param defaultValue The default value to set if key doesn't exist.
|
||||
* @returns False if the table key exists with a different type
|
||||
*/
|
||||
bool SmartDashboard::SetDefaultStringArray(
|
||||
@@ -421,15 +435,18 @@ bool SmartDashboard::SetDefaultStringArray(
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the string array the key maps to. If the key does not exist or is
|
||||
* of different type, it will return the default value.
|
||||
* @param key the key to look up
|
||||
* @param defaultValue the value to be returned if no value is found
|
||||
* Returns the string array the key maps to.
|
||||
*
|
||||
* If the key does not exist or is of different type, it will return the default
|
||||
* value.
|
||||
*
|
||||
* @param key The key to look up.
|
||||
* @param defaultValue The value to be returned if no value is found.
|
||||
* @return the value associated with the given key or the given default value
|
||||
* if there is no value associated with the key
|
||||
*
|
||||
* @note This makes a copy of the array. If the overhead of this is a
|
||||
* concern, use GetValue() instead.
|
||||
* @note This makes a copy of the array. If the overhead of this is a concern,
|
||||
* use GetValue() instead.
|
||||
*/
|
||||
std::vector<std::string> SmartDashboard::GetStringArray(
|
||||
llvm::StringRef key, llvm::ArrayRef<std::string> defaultValue) {
|
||||
@@ -437,9 +454,10 @@ std::vector<std::string> SmartDashboard::GetStringArray(
|
||||
}
|
||||
|
||||
/**
|
||||
* Put a raw value (byte array) in the table
|
||||
* @param key the key to be assigned to
|
||||
* @param value the value that will be assigned
|
||||
* Put a raw value (byte array) in the table.
|
||||
*
|
||||
* @param key The key to be assigned to.
|
||||
* @param value The value that will be assigned.
|
||||
* @return False if the table key already exists with a different type
|
||||
*/
|
||||
bool SmartDashboard::PutRaw(llvm::StringRef key, llvm::StringRef value) {
|
||||
@@ -448,8 +466,9 @@ bool SmartDashboard::PutRaw(llvm::StringRef key, llvm::StringRef value) {
|
||||
|
||||
/**
|
||||
* Gets the current value in the table, setting it if it does not exist.
|
||||
* @param key the key
|
||||
* @param defaultValue the default value to set if key doesn't exist.
|
||||
*
|
||||
* @param key The key.
|
||||
* @param defaultValue The default value to set if key doesn't exist.
|
||||
* @returns False if the table key exists with a different type
|
||||
*/
|
||||
bool SmartDashboard::SetDefaultRaw(llvm::StringRef key,
|
||||
@@ -458,14 +477,17 @@ bool SmartDashboard::SetDefaultRaw(llvm::StringRef key,
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the raw value (byte array) the key maps to. If the key does not
|
||||
* exist or is of different type, it will return the default value.
|
||||
* @param key the key to look up
|
||||
* @param defaultValue the value to be returned if no value is found
|
||||
* Returns the raw value (byte array) the key maps to.
|
||||
*
|
||||
* If the key does not exist or is of different type, it will return the default
|
||||
* value.
|
||||
*
|
||||
* @param key The key to look up.
|
||||
* @param defaultValue The value to be returned if no value is found.
|
||||
* @return the value associated with the given key or the given default value
|
||||
* if there is no value associated with the key
|
||||
*
|
||||
* @note This makes a copy of the raw contents. If the overhead of this is a
|
||||
* @note This makes a copy of the raw contents. If the overhead of this is a
|
||||
* concern, use GetValue() instead.
|
||||
*/
|
||||
std::string SmartDashboard::GetRaw(llvm::StringRef key,
|
||||
|
||||
@@ -16,8 +16,8 @@ namespace frc {
|
||||
/**
|
||||
* Get the thread priority for the specified thread.
|
||||
*
|
||||
* @param thread Reference to the thread to get the priority for
|
||||
* @param isRealTime Set to true if thread is realtime, otherwise false
|
||||
* @param thread Reference to the thread to get the priority for.
|
||||
* @param isRealTime Set to true if thread is realtime, otherwise false.
|
||||
* @return The current thread priority. Scaled 1-99, with 1 being highest.
|
||||
*/
|
||||
int GetThreadPriority(std::thread& thread, bool* isRealTime) {
|
||||
@@ -33,7 +33,7 @@ int GetThreadPriority(std::thread& thread, bool* isRealTime) {
|
||||
/**
|
||||
* Get the thread priority for the current thread
|
||||
*
|
||||
* @param isRealTime Set to true if thread is realtime, otherwise false
|
||||
* @param isRealTime Set to true if thread is realtime, otherwise false.
|
||||
* @return The current thread priority. Scaled 1-99.
|
||||
*/
|
||||
int GetCurrentThreadPriority(bool* isRealTime) {
|
||||
@@ -48,11 +48,12 @@ int GetCurrentThreadPriority(bool* isRealTime) {
|
||||
/**
|
||||
* Sets the thread priority for the specified thread
|
||||
*
|
||||
* @param thread Reference to the thread to set the priority of
|
||||
* @param thread Reference to the thread to set the priority of.
|
||||
* @param realTime Set to true to set a realtime priority, false for standard
|
||||
* priority
|
||||
* priority.
|
||||
* @param priority Priority to set the thread to. Scaled 1-99, with 1 being
|
||||
* highest. On RoboRIO, priority is ignored for non realtime setting
|
||||
* highest. On RoboRIO, priority is ignored for non realtime
|
||||
* setting.
|
||||
*
|
||||
* @return The success state of setting the priority
|
||||
*/
|
||||
@@ -68,9 +69,10 @@ bool SetThreadPriority(std::thread& thread, bool realTime, int priority) {
|
||||
* Sets the thread priority for the current thread
|
||||
*
|
||||
* @param realTime Set to true to set a realtime priority, false for standard
|
||||
* priority
|
||||
* priority.
|
||||
* @param priority Priority to set the thread to. Scaled 1-99, with 1 being
|
||||
* highest. On RoboRIO, priority is ignored for non realtime setting
|
||||
* highest. On RoboRIO, priority is ignored for non realtime
|
||||
* setting.
|
||||
*
|
||||
* @return The success state of setting the priority
|
||||
*/
|
||||
|
||||
@@ -22,8 +22,8 @@ namespace frc {
|
||||
*
|
||||
* Pause the execution of the program for a specified period of time given in
|
||||
* seconds. Motors will continue to run at their last assigned values, and
|
||||
* sensors will continue to update. Only the task containing the wait will
|
||||
* pause until the wait time is expired.
|
||||
* sensors will continue to update. Only the task containing the wait will pause
|
||||
* until the wait time is expired.
|
||||
*
|
||||
* @param seconds Length of time to pause, in seconds.
|
||||
*/
|
||||
@@ -34,13 +34,15 @@ void Wait(double seconds) {
|
||||
|
||||
/**
|
||||
* Return the FPGA system clock time in seconds.
|
||||
*
|
||||
* This is deprecated and just forwards to Timer::GetFPGATimestamp().
|
||||
*
|
||||
* @return Robot running time in seconds.
|
||||
*/
|
||||
double GetClock() { return Timer::GetFPGATimestamp(); }
|
||||
|
||||
/**
|
||||
* @brief Gives real-time clock system time with nanosecond resolution
|
||||
* @brief Gives real-time clock system time with nanosecond resolution
|
||||
* @return The time, just in case you want the robot to start autonomous at 8pm
|
||||
* on Saturday.
|
||||
*/
|
||||
@@ -63,14 +65,9 @@ const double Timer::kRolloverTime = (1ll << 32) / 1e6;
|
||||
* Create a new timer object.
|
||||
*
|
||||
* Create a new timer object and reset the time to zero. The timer is initially
|
||||
* not running and
|
||||
* must be started.
|
||||
* not running and must be started.
|
||||
*/
|
||||
Timer::Timer() {
|
||||
// Creates a semaphore to control access to critical regions.
|
||||
// Initially 'open'
|
||||
Reset();
|
||||
}
|
||||
Timer::Timer() { Reset(); }
|
||||
|
||||
/**
|
||||
* Get the current time from the timer. If the clock is running it is derived
|
||||
@@ -85,9 +82,9 @@ double Timer::Get() const {
|
||||
|
||||
std::lock_guard<wpi::mutex> sync(m_mutex);
|
||||
if (m_running) {
|
||||
// If the current time is before the start time, then the FPGA clock
|
||||
// rolled over. Compensate by adding the ~71 minutes that it takes
|
||||
// to roll over to the current time.
|
||||
// If the current time is before the start time, then the FPGA clock rolled
|
||||
// over. Compensate by adding the ~71 minutes that it takes to roll over to
|
||||
// the current time.
|
||||
if (currentTime < m_startTime) {
|
||||
currentTime += kRolloverTime;
|
||||
}
|
||||
@@ -149,7 +146,7 @@ void Timer::Stop() {
|
||||
* work without drifting later by the time it took to get around to checking.
|
||||
*
|
||||
* @param period The period to check for (in seconds).
|
||||
* @return True if the period has passed.
|
||||
* @return True if the period has passed.
|
||||
*/
|
||||
bool Timer::HasPeriodPassed(double period) {
|
||||
if (Get() > period) {
|
||||
@@ -178,14 +175,13 @@ double Timer::GetFPGATimestamp() {
|
||||
|
||||
/**
|
||||
* Return the approximate match time The FMS does not currently send the
|
||||
* official match time to
|
||||
* the robots This returns the time since the enable signal sent from the Driver
|
||||
* Station At the
|
||||
* beginning of autonomous, the time is reset to 0.0 seconds At the beginning of
|
||||
* teleop, the time
|
||||
* is reset to +15.0 seconds If the robot is disabled, this returns 0.0 seconds
|
||||
* Warning: This is
|
||||
* not an official time (so it cannot be used to argue with referees).
|
||||
* official match time to the robots This returns the time since the enable
|
||||
* signal sent from the Driver Station At the beginning of autonomous, the time
|
||||
* is reset to 0.0 seconds At the beginning of teleop, the time is reset to
|
||||
* +15.0 seconds If the robot is disabled, this returns 0.0 seconds.
|
||||
*
|
||||
* Warning: This is not an official time (so it cannot be used to argue with
|
||||
* referees).
|
||||
*
|
||||
* @return Match time in seconds since the beginning of autonomous
|
||||
*/
|
||||
|
||||
@@ -21,13 +21,17 @@ using namespace frc;
|
||||
|
||||
// Time (sec) for the ping trigger pulse.
|
||||
constexpr double Ultrasonic::kPingTime;
|
||||
|
||||
// Priority that the ultrasonic round robin task runs.
|
||||
const int Ultrasonic::kPriority;
|
||||
|
||||
// Max time (ms) between readings.
|
||||
constexpr double Ultrasonic::kMaxUltrasonicTime;
|
||||
constexpr double Ultrasonic::kSpeedOfSoundInchesPerSec;
|
||||
// automatic round robin mode
|
||||
|
||||
// Automatic round robin mode.
|
||||
std::atomic<bool> Ultrasonic::m_automaticEnabled{false};
|
||||
|
||||
std::set<Ultrasonic*> Ultrasonic::m_sensors;
|
||||
std::thread Ultrasonic::m_thread;
|
||||
|
||||
@@ -60,19 +64,19 @@ void Ultrasonic::UltrasonicChecker() {
|
||||
*
|
||||
* This is the common code that initializes the ultrasonic sensor given that
|
||||
* there are two digital I/O channels allocated. If the system was running in
|
||||
* automatic mode (round robin) when the new sensor is added, it is stopped,
|
||||
* the sensor is added, then automatic mode is restored.
|
||||
* automatic mode (round robin) when the new sensor is added, it is stopped, the
|
||||
* sensor is added, then automatic mode is restored.
|
||||
*/
|
||||
void Ultrasonic::Initialize() {
|
||||
bool originalMode = m_automaticEnabled;
|
||||
SetAutomaticMode(false); // kill task when adding a new sensor
|
||||
// link this instance on the list
|
||||
SetAutomaticMode(false); // Kill task when adding a new sensor
|
||||
// Link this instance on the list
|
||||
m_sensors.insert(this);
|
||||
|
||||
m_counter.SetMaxPeriod(1.0);
|
||||
m_counter.SetSemiPeriodMode(true);
|
||||
m_counter.Reset();
|
||||
m_enabled = true; // make it available for round robin scheduling
|
||||
m_enabled = true; // Make it available for round robin scheduling
|
||||
SetAutomaticMode(originalMode);
|
||||
|
||||
static int instances = 0;
|
||||
@@ -85,8 +89,7 @@ void Ultrasonic::Initialize() {
|
||||
/**
|
||||
* Create an instance of the Ultrasonic Sensor.
|
||||
*
|
||||
* This is designed to support the Daventech SRF04 and Vex ultrasonic
|
||||
* sensors.
|
||||
* This is designed to support the Daventech SRF04 and Vex ultrasonic sensors.
|
||||
*
|
||||
* @param pingChannel The digital output channel that sends the pulse to
|
||||
* initiate the sensor sending the ping.
|
||||
@@ -222,10 +225,9 @@ void Ultrasonic::SetAutomaticMode(bool enabling) {
|
||||
// Wait for background task to stop running
|
||||
m_thread.join();
|
||||
|
||||
/* Clear all the counters (data now invalid) since automatic mode is
|
||||
* disabled. No synchronization is needed because the background task is
|
||||
* stopped.
|
||||
*/
|
||||
// Clear all the counters (data now invalid) since automatic mode is
|
||||
// disabled. No synchronization is needed because the background task is
|
||||
// stopped.
|
||||
for (auto& sensor : m_sensors) {
|
||||
sensor->m_counter.Reset();
|
||||
}
|
||||
@@ -242,9 +244,12 @@ void Ultrasonic::SetAutomaticMode(bool enabling) {
|
||||
*/
|
||||
void Ultrasonic::Ping() {
|
||||
wpi_assert(!m_automaticEnabled);
|
||||
m_counter.Reset(); // reset the counter to zero (invalid data now)
|
||||
m_pingChannel->Pulse(
|
||||
kPingTime); // do the ping to start getting a single range
|
||||
|
||||
// Reset the counter to zero (invalid data now)
|
||||
m_counter.Reset();
|
||||
|
||||
// Do the ping to start getting a single range
|
||||
m_pingChannel->Pulse(kPingTime);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -259,9 +264,9 @@ bool Ultrasonic::IsRangeValid() const { return m_counter.Get() > 1; }
|
||||
/**
|
||||
* Get the range in inches from the ultrasonic sensor.
|
||||
*
|
||||
* @return double Range in inches of the target returned from the ultrasonic
|
||||
* sensor. If there is no valid value yet, i.e. at least one
|
||||
* measurement hasn't completed, then return 0.
|
||||
* @return Range in inches of the target returned from the ultrasonic sensor. If
|
||||
* there is no valid value yet, i.e. at least one measurement hasn't
|
||||
* completed, then return 0.
|
||||
*/
|
||||
double Ultrasonic::GetRangeInches() const {
|
||||
if (IsRangeValid())
|
||||
@@ -273,9 +278,9 @@ double Ultrasonic::GetRangeInches() const {
|
||||
/**
|
||||
* Get the range in millimeters from the ultrasonic sensor.
|
||||
*
|
||||
* @return double Range in millimeters of the target returned by the ultrasonic
|
||||
* sensor. If there is no valid value yet, i.e. at least one
|
||||
* measurement hasn't completed, then return 0.
|
||||
* @return Range in millimeters of the target returned by the ultrasonic sensor.
|
||||
* If there is no valid value yet, i.e. at least one measurement hasn't
|
||||
* completed, then return 0.
|
||||
*/
|
||||
double Ultrasonic::GetRangeMM() const { return GetRangeInches() * 25.4; }
|
||||
|
||||
|
||||
@@ -26,9 +26,9 @@ using namespace frc;
|
||||
|
||||
/**
|
||||
* Assert implementation.
|
||||
* This allows breakpoints to be set on an assert.
|
||||
* The users don't call this, but instead use the wpi_assert macros in
|
||||
* Utility.h.
|
||||
*
|
||||
* This allows breakpoints to be set on an assert. The users don't call this,
|
||||
* but instead use the wpi_assert macros in Utility.h.
|
||||
*/
|
||||
bool wpi_assert_impl(bool conditionValue, llvm::StringRef conditionText,
|
||||
llvm::StringRef message, llvm::StringRef fileName,
|
||||
@@ -79,7 +79,8 @@ bool wpi_assert_impl(bool conditionValue, llvm::StringRef conditionText,
|
||||
}
|
||||
|
||||
/**
|
||||
* Common error routines for wpi_assertEqual_impl and wpi_assertNotEqual_impl
|
||||
* Common error routines for wpi_assertEqual_impl and wpi_assertNotEqual_impl.
|
||||
*
|
||||
* This should not be called directly; it should only be used by
|
||||
* wpi_assertEqual_impl and wpi_assertNotEqual_impl.
|
||||
*/
|
||||
@@ -132,10 +133,10 @@ void wpi_assertEqual_common_impl(llvm::StringRef valueA, llvm::StringRef valueB,
|
||||
|
||||
/**
|
||||
* Assert equal implementation.
|
||||
* This determines whether the two given integers are equal. If not,
|
||||
* the value of each is printed along with an optional message string.
|
||||
* The users don't call this, but instead use the wpi_assertEqual macros in
|
||||
* Utility.h.
|
||||
*
|
||||
* This determines whether the two given integers are equal. If not, the value
|
||||
* of each is printed along with an optional message string. The users don't
|
||||
* call this, but instead use the wpi_assertEqual macros in Utility.h.
|
||||
*/
|
||||
bool wpi_assertEqual_impl(int valueA, int valueB, llvm::StringRef valueAString,
|
||||
llvm::StringRef valueBString, llvm::StringRef message,
|
||||
@@ -150,10 +151,10 @@ bool wpi_assertEqual_impl(int valueA, int valueB, llvm::StringRef valueAString,
|
||||
|
||||
/**
|
||||
* Assert not equal implementation.
|
||||
* This determines whether the two given integers are equal. If so,
|
||||
* the value of each is printed along with an optional message string.
|
||||
* The users don't call this, but instead use the wpi_assertNotEqual macros in
|
||||
* Utility.h.
|
||||
*
|
||||
* This determines whether the two given integers are equal. If so, the value of
|
||||
* each is printed along with an optional message string. The users don't call
|
||||
* this, but instead use the wpi_assertNotEqual macros in Utility.h.
|
||||
*/
|
||||
bool wpi_assertNotEqual_impl(int valueA, int valueB,
|
||||
llvm::StringRef valueAString,
|
||||
@@ -173,6 +174,7 @@ namespace frc {
|
||||
* Return the FPGA Version number.
|
||||
*
|
||||
* For now, expect this to be competition year.
|
||||
*
|
||||
* @return FPGA Version number.
|
||||
*/
|
||||
int GetFPGAVersion() {
|
||||
@@ -184,10 +186,11 @@ int GetFPGAVersion() {
|
||||
|
||||
/**
|
||||
* Return the FPGA Revision number.
|
||||
* The format of the revision is 3 numbers.
|
||||
* The 12 most significant bits are the Major Revision.
|
||||
* the next 8 bits are the Minor Revision.
|
||||
* The 12 least significant bits are the Build Number.
|
||||
*
|
||||
* The format of the revision is 3 numbers. The 12 most significant bits are the
|
||||
* Major Revision. The next 8 bits are the Minor Revision. The 12 least
|
||||
* significant bits are the Build Number.
|
||||
*
|
||||
* @return FPGA Revision number.
|
||||
*/
|
||||
int64_t GetFPGARevision() {
|
||||
@@ -251,6 +254,7 @@ static std::string demangle(char const* mangledSymbol) {
|
||||
|
||||
/**
|
||||
* Get a stack trace, ignoring the first "offset" symbols.
|
||||
*
|
||||
* @param offset The number of symbols at the top of the stack to ignore
|
||||
*/
|
||||
std::string GetStackTrace(int offset) {
|
||||
|
||||
@@ -61,8 +61,7 @@ void VisionRunnerBase::RunOnce() {
|
||||
* must be run in a dedicated thread, and cannot be used in the main robot
|
||||
* thread because it will freeze the robot program.
|
||||
*
|
||||
* <p><strong>Do not call this method directly from the main
|
||||
* thread.</strong></p>
|
||||
* <strong>Do not call this method directly from the main thread.</strong>
|
||||
*/
|
||||
void VisionRunnerBase::RunForever() {
|
||||
if (std::this_thread::get_id() == RobotBase::GetThreadId()) {
|
||||
|
||||
Reference in New Issue
Block a user