mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +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()) {
|
||||
|
||||
@@ -21,40 +21,19 @@ namespace frc {
|
||||
* ADXL345 Accelerometer on I2C.
|
||||
*
|
||||
* This class allows access to a Analog Devices ADXL345 3-axis accelerometer on
|
||||
* an I2C bus.
|
||||
* This class assumes the default (not alternate) sensor address of 0x1D (7-bit
|
||||
* address).
|
||||
* an I2C bus. This class assumes the default (not alternate) sensor address of
|
||||
* 0x1D (7-bit address).
|
||||
*/
|
||||
class ADXL345_I2C : public Accelerometer, public LiveWindowSendable {
|
||||
protected:
|
||||
static const int kAddress = 0x1D;
|
||||
static const int kPowerCtlRegister = 0x2D;
|
||||
static const int kDataFormatRegister = 0x31;
|
||||
static const int kDataRegister = 0x32;
|
||||
static constexpr double kGsPerLSB = 0.00390625;
|
||||
enum PowerCtlFields {
|
||||
kPowerCtl_Link = 0x20,
|
||||
kPowerCtl_AutoSleep = 0x10,
|
||||
kPowerCtl_Measure = 0x08,
|
||||
kPowerCtl_Sleep = 0x04
|
||||
};
|
||||
enum DataFormatFields {
|
||||
kDataFormat_SelfTest = 0x80,
|
||||
kDataFormat_SPI = 0x40,
|
||||
kDataFormat_IntInvert = 0x20,
|
||||
kDataFormat_FullRes = 0x08,
|
||||
kDataFormat_Justify = 0x04
|
||||
};
|
||||
|
||||
public:
|
||||
enum Axes { kAxis_X = 0x00, kAxis_Y = 0x02, kAxis_Z = 0x04 };
|
||||
|
||||
struct AllAxes {
|
||||
double XAxis;
|
||||
double YAxis;
|
||||
double ZAxis;
|
||||
};
|
||||
|
||||
public:
|
||||
explicit ADXL345_I2C(I2C::Port port, Range range = kRange_2G,
|
||||
int deviceAddress = kAddress);
|
||||
virtual ~ADXL345_I2C() = default;
|
||||
@@ -80,6 +59,27 @@ class ADXL345_I2C : public Accelerometer, public LiveWindowSendable {
|
||||
protected:
|
||||
I2C m_i2c;
|
||||
|
||||
static const int kAddress = 0x1D;
|
||||
static const int kPowerCtlRegister = 0x2D;
|
||||
static const int kDataFormatRegister = 0x31;
|
||||
static const int kDataRegister = 0x32;
|
||||
static constexpr double kGsPerLSB = 0.00390625;
|
||||
|
||||
enum PowerCtlFields {
|
||||
kPowerCtl_Link = 0x20,
|
||||
kPowerCtl_AutoSleep = 0x10,
|
||||
kPowerCtl_Measure = 0x08,
|
||||
kPowerCtl_Sleep = 0x04
|
||||
};
|
||||
|
||||
enum DataFormatFields {
|
||||
kDataFormat_SelfTest = 0x80,
|
||||
kDataFormat_SPI = 0x40,
|
||||
kDataFormat_IntInvert = 0x20,
|
||||
kDataFormat_FullRes = 0x08,
|
||||
kDataFormat_Justify = 0x04
|
||||
};
|
||||
|
||||
private:
|
||||
nt::NetworkTableEntry m_xEntry;
|
||||
nt::NetworkTableEntry m_yEntry;
|
||||
|
||||
@@ -25,32 +25,12 @@ class DigitalOutput;
|
||||
* ADXL345 Accelerometer on SPI.
|
||||
*
|
||||
* This class allows access to an Analog Devices ADXL345 3-axis accelerometer
|
||||
* via SPI.
|
||||
* This class assumes the sensor is wired in 4-wire SPI mode.
|
||||
* via SPI. This class assumes the sensor is wired in 4-wire SPI mode.
|
||||
*/
|
||||
class ADXL345_SPI : public Accelerometer, public LiveWindowSendable {
|
||||
protected:
|
||||
static const int kPowerCtlRegister = 0x2D;
|
||||
static const int kDataFormatRegister = 0x31;
|
||||
static const int kDataRegister = 0x32;
|
||||
static constexpr double kGsPerLSB = 0.00390625;
|
||||
enum SPIAddressFields { kAddress_Read = 0x80, kAddress_MultiByte = 0x40 };
|
||||
enum PowerCtlFields {
|
||||
kPowerCtl_Link = 0x20,
|
||||
kPowerCtl_AutoSleep = 0x10,
|
||||
kPowerCtl_Measure = 0x08,
|
||||
kPowerCtl_Sleep = 0x04
|
||||
};
|
||||
enum DataFormatFields {
|
||||
kDataFormat_SelfTest = 0x80,
|
||||
kDataFormat_SPI = 0x40,
|
||||
kDataFormat_IntInvert = 0x20,
|
||||
kDataFormat_FullRes = 0x08,
|
||||
kDataFormat_Justify = 0x04
|
||||
};
|
||||
|
||||
public:
|
||||
enum Axes { kAxis_X = 0x00, kAxis_Y = 0x02, kAxis_Z = 0x04 };
|
||||
|
||||
struct AllAxes {
|
||||
double XAxis;
|
||||
double YAxis;
|
||||
@@ -82,6 +62,28 @@ class ADXL345_SPI : public Accelerometer, public LiveWindowSendable {
|
||||
protected:
|
||||
SPI m_spi;
|
||||
|
||||
static const int kPowerCtlRegister = 0x2D;
|
||||
static const int kDataFormatRegister = 0x31;
|
||||
static const int kDataRegister = 0x32;
|
||||
static constexpr double kGsPerLSB = 0.00390625;
|
||||
|
||||
enum SPIAddressFields { kAddress_Read = 0x80, kAddress_MultiByte = 0x40 };
|
||||
|
||||
enum PowerCtlFields {
|
||||
kPowerCtl_Link = 0x20,
|
||||
kPowerCtl_AutoSleep = 0x10,
|
||||
kPowerCtl_Measure = 0x08,
|
||||
kPowerCtl_Sleep = 0x04
|
||||
};
|
||||
|
||||
enum DataFormatFields {
|
||||
kDataFormat_SelfTest = 0x80,
|
||||
kDataFormat_SPI = 0x40,
|
||||
kDataFormat_IntInvert = 0x20,
|
||||
kDataFormat_FullRes = 0x08,
|
||||
kDataFormat_Justify = 0x04
|
||||
};
|
||||
|
||||
private:
|
||||
nt::NetworkTableEntry m_xEntry;
|
||||
nt::NetworkTableEntry m_yEntry;
|
||||
|
||||
@@ -16,6 +16,7 @@ namespace frc {
|
||||
|
||||
/**
|
||||
* Use a rate gyro to return the robots heading relative to a starting position.
|
||||
*
|
||||
* The Gyro class tracks the robots heading based on the starting position. As
|
||||
* the robot rotates the new heading is computed by integrating the rate of
|
||||
* rotation returned by the sensor. When the class is instantiated, it does a
|
||||
|
||||
@@ -20,6 +20,7 @@ namespace frc {
|
||||
|
||||
/**
|
||||
* Handle operation of an analog accelerometer.
|
||||
*
|
||||
* The accelerometer reads acceleration directly through the sensor. Many
|
||||
* sensors have multiple axis and can be treated as multiple devices. Each is
|
||||
* calibrated by finding the center value over a period of time.
|
||||
|
||||
@@ -26,8 +26,8 @@ namespace frc {
|
||||
*
|
||||
* Connected to each analog channel is an averaging and oversampling engine.
|
||||
* This engine accumulates the specified ( by SetAverageBits() and
|
||||
* SetOversampleBits() ) number of samples before returning a new value. This
|
||||
* is not a sliding window average. The only difference between the oversampled
|
||||
* SetOversampleBits() ) number of samples before returning a new value. This is
|
||||
* not a sliding window average. The only difference between the oversampled
|
||||
* samples and the averaged samples is that the oversampled samples are simply
|
||||
* accumulated effectively increasing the resolution, while the averaged samples
|
||||
* are divided by the number of samples to retain the resolution, but get more
|
||||
|
||||
@@ -18,30 +18,30 @@
|
||||
namespace frc {
|
||||
|
||||
/**
|
||||
* Class for reading analog potentiometers. Analog potentiometers read
|
||||
* in an analog voltage that corresponds to a position. The position is
|
||||
* in whichever units you choose, by way of the scaling and offset
|
||||
* constants passed to the constructor.
|
||||
* Class for reading analog potentiometers. Analog potentiometers read in an
|
||||
* analog voltage that corresponds to a position. The position is in whichever
|
||||
* units you choose, by way of the scaling and offset constants passed to the
|
||||
* constructor.
|
||||
*/
|
||||
class AnalogPotentiometer : public Potentiometer, public LiveWindowSendable {
|
||||
public:
|
||||
/**
|
||||
* AnalogPotentiometer constructor.
|
||||
*
|
||||
* Use the fullRange and offset values so that the output produces
|
||||
* meaningful values. I.E: you have a 270 degree potentiometer and
|
||||
* you want the output to be degrees with the halfway point as 0
|
||||
* degrees. The fullRange value is 270.0(degrees) and the offset is
|
||||
* -135.0 since the halfway point after scaling is 135 degrees.
|
||||
* Use the fullRange and offset values so that the output produces meaningful
|
||||
* values. I.E: you have a 270 degree potentiometer and you want the output to
|
||||
* be degrees with the halfway point as 0 degrees. The fullRange value is
|
||||
* 270.0 degrees and the offset is -135.0 since the halfway point after
|
||||
* scaling is 135 degrees.
|
||||
*
|
||||
* This will calculate the result from the fullRange times the
|
||||
* fraction of the supply voltage, plus the offset.
|
||||
* This will calculate the result from the fullRange times the fraction of the
|
||||
* supply voltage, plus the offset.
|
||||
*
|
||||
* @param channel The analog channel this potentiometer is plugged into.
|
||||
* @param channel The analog channel this potentiometer is plugged into.
|
||||
* @param fullRange The scaling to multiply the voltage by to get a meaningful
|
||||
* unit.
|
||||
* @param offset The offset to add to the scaled value for controlling the
|
||||
* zero value
|
||||
* unit.
|
||||
* @param offset The offset to add to the scaled value for controlling the
|
||||
* zero value.
|
||||
*/
|
||||
explicit AnalogPotentiometer(int channel, double fullRange = 1.0,
|
||||
double offset = 0.0);
|
||||
|
||||
@@ -15,14 +15,13 @@ namespace frc {
|
||||
/**
|
||||
* This class provides an easy way to link commands to OI inputs.
|
||||
*
|
||||
* It is very easy to link a button to a command. For instance, you could
|
||||
* link the trigger button of a joystick to a "score" command.
|
||||
* It is very easy to link a button to a command. For instance, you could link
|
||||
* the trigger button of a joystick to a "score" command.
|
||||
*
|
||||
* This class represents a subclass of Trigger that is specifically aimed at
|
||||
* buttons on an operator interface as a common use case of the more generalized
|
||||
* Trigger objects. This is a simple wrapper around Trigger with the method
|
||||
* names
|
||||
* renamed to fit the Button object use.
|
||||
* names renamed to fit the Button object use.
|
||||
*/
|
||||
class Button : public Trigger {
|
||||
public:
|
||||
|
||||
@@ -20,17 +20,15 @@ class Command;
|
||||
/**
|
||||
* This class provides an easy way to link commands to inputs.
|
||||
*
|
||||
* It is very easy to link a polled input to a command. For instance, you could
|
||||
* It is very easy to link a polled input to a command. For instance, you could
|
||||
* link the trigger button of a joystick to a "score" command or an encoder
|
||||
* reaching
|
||||
* a particular value.
|
||||
* reaching a particular value.
|
||||
*
|
||||
* It is encouraged that teams write a subclass of Trigger if they want to have
|
||||
* something unusual (for instance, if they want to react to the user holding
|
||||
* a button while the robot is reading a certain sensor input). For this, they
|
||||
* a button while the robot is reading a certain sensor input). For this, they
|
||||
* only have to write the {@link Trigger#Get()} method to get the full
|
||||
* functionality
|
||||
* of the Trigger class.
|
||||
* functionality of the Trigger class.
|
||||
*/
|
||||
class Trigger : public Sendable {
|
||||
public:
|
||||
|
||||
@@ -36,7 +36,7 @@ class CANSpeedController : public SpeedController {
|
||||
kTemperatureFault = 2,
|
||||
kBusVoltageFault = 4,
|
||||
kGateDriverFault = 8,
|
||||
/* SRX extensions */
|
||||
// SRX extensions
|
||||
kFwdLimitSwitch = 0x10,
|
||||
kRevLimitSwitch = 0x20,
|
||||
kFwdSoftLimit = 0x40,
|
||||
@@ -46,22 +46,34 @@ class CANSpeedController : public SpeedController {
|
||||
enum Limits { kForwardLimit = 1, kReverseLimit = 2 };
|
||||
|
||||
enum NeutralMode {
|
||||
/** Use the NeutralMode that is set by the jumper wire on the CAN device */
|
||||
/**
|
||||
* Use the NeutralMode that is set by the jumper wire on the CAN device
|
||||
*/
|
||||
kNeutralMode_Jumper = 0,
|
||||
/** Stop the motor's rotation by applying a force. */
|
||||
/**
|
||||
* Stop the motor's rotation by applying a force.
|
||||
*/
|
||||
kNeutralMode_Brake = 1,
|
||||
/** Do not attempt to stop the motor. Instead allow it to coast to a stop
|
||||
without applying resistance. */
|
||||
/**
|
||||
* Do not attempt to stop the motor. Instead allow it to coast to a stop
|
||||
* without applying resistance.
|
||||
*/
|
||||
kNeutralMode_Coast = 2
|
||||
};
|
||||
|
||||
enum LimitMode {
|
||||
/** Only use switches for limits */
|
||||
/**
|
||||
* Only use switches for limits
|
||||
*/
|
||||
kLimitMode_SwitchInputsOnly = 0,
|
||||
/** Use both switches and soft limits */
|
||||
/**
|
||||
* Use both switches and soft limits
|
||||
*/
|
||||
kLimitMode_SoftPositionLimits = 1,
|
||||
/* SRX extensions */
|
||||
/** Disable switches and disable soft limits */
|
||||
// SRX extensions
|
||||
/**
|
||||
* Disable switches and disable soft limits
|
||||
*/
|
||||
kLimitMode_SrxDisableSwitchInputs = 2,
|
||||
};
|
||||
|
||||
@@ -98,9 +110,6 @@ class CANSpeedController : public SpeedController {
|
||||
virtual void ConfigReverseLimit(double reverseLimitPosition) = 0;
|
||||
virtual void ConfigMaxOutputVoltage(double voltage) = 0;
|
||||
virtual void ConfigFaultTime(double faultTime) = 0;
|
||||
// Hold off on interface until we figure out ControlMode enums.
|
||||
// virtual void SetControlMode(ControlMode mode) = 0;
|
||||
// virtual ControlMode GetControlMode() const = 0;
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
|
||||
@@ -27,6 +27,7 @@ namespace frc {
|
||||
|
||||
/**
|
||||
* Singleton class for creating and keeping camera servers.
|
||||
*
|
||||
* Also publishes camera information to NetworkTables.
|
||||
*/
|
||||
class CameraServer : public ErrorBase {
|
||||
@@ -42,26 +43,25 @@ class CameraServer : public ErrorBase {
|
||||
static CameraServer* GetInstance();
|
||||
|
||||
#ifdef __linux__
|
||||
// USBCamera does not work on anything except linux
|
||||
// USBCamera does not work on anything except Linux.
|
||||
/**
|
||||
* Start automatically capturing images to send to the dashboard.
|
||||
*
|
||||
* <p>You should call this method to see a camera feed on the dashboard.
|
||||
* If you also want to perform vision processing on the roboRIO, use
|
||||
* getVideo() to get access to the camera images.
|
||||
* You should call this method to see a camera feed on the dashboard. If you
|
||||
* also want to perform vision processing on the roboRIO, use getVideo() to
|
||||
* get access to the camera images.
|
||||
*
|
||||
* The first time this overload is called, it calls
|
||||
* {@link #StartAutomaticCapture(int)} with device 0, creating a camera
|
||||
* named "USB Camera 0". Subsequent calls increment the device number
|
||||
* (e.g. 1, 2, etc).
|
||||
* The first time this overload is called, it calls StartAutomaticCapture()
|
||||
* with device 0, creating a camera named "USB Camera 0". Subsequent calls
|
||||
* increment the device number (e.g. 1, 2, etc).
|
||||
*/
|
||||
cs::UsbCamera StartAutomaticCapture();
|
||||
|
||||
/**
|
||||
* Start automatically capturing images to send to the dashboard.
|
||||
*
|
||||
* <p>This overload calls {@link #StartAutomaticCapture(String, int)} with
|
||||
* a name of "USB Camera {dev}".
|
||||
* This overload calls StartAutomaticCapture() with a name of "USB Camera
|
||||
* {dev}".
|
||||
*
|
||||
* @param dev The device number of the camera interface
|
||||
*/
|
||||
@@ -71,7 +71,7 @@ class CameraServer : public ErrorBase {
|
||||
* Start automatically capturing images to send to the dashboard.
|
||||
*
|
||||
* @param name The name to give the camera
|
||||
* @param dev The device number of the camera interface
|
||||
* @param dev The device number of the camera interface
|
||||
*/
|
||||
cs::UsbCamera StartAutomaticCapture(llvm::StringRef name, int dev);
|
||||
|
||||
@@ -96,8 +96,7 @@ class CameraServer : public ErrorBase {
|
||||
/**
|
||||
* Adds an Axis IP camera.
|
||||
*
|
||||
* <p>This overload calls {@link #AddAxisCamera(String, String)} with
|
||||
* name "Axis Camera".
|
||||
* This overload calls AddAxisCamera() with name "Axis Camera".
|
||||
*
|
||||
* @param host Camera host IP or DNS name (e.g. "10.x.y.11")
|
||||
*/
|
||||
@@ -106,8 +105,7 @@ class CameraServer : public ErrorBase {
|
||||
/**
|
||||
* Adds an Axis IP camera.
|
||||
*
|
||||
* <p>This overload calls {@link #AddAxisCamera(String, String)} with
|
||||
* name "Axis Camera".
|
||||
* This overload calls AddAxisCamera() with name "Axis Camera".
|
||||
*
|
||||
* @param host Camera host IP or DNS name (e.g. "10.x.y.11")
|
||||
*/
|
||||
@@ -116,8 +114,7 @@ class CameraServer : public ErrorBase {
|
||||
/**
|
||||
* Adds an Axis IP camera.
|
||||
*
|
||||
* <p>This overload calls {@link #AddAxisCamera(String, String)} with
|
||||
* name "Axis Camera".
|
||||
* This overload calls AddAxisCamera() with name "Axis Camera".
|
||||
*
|
||||
* @param host Camera host IP or DNS name (e.g. "10.x.y.11")
|
||||
*/
|
||||
@@ -126,8 +123,7 @@ class CameraServer : public ErrorBase {
|
||||
/**
|
||||
* Adds an Axis IP camera.
|
||||
*
|
||||
* <p>This overload calls {@link #AddAxisCamera(String, String[])} with
|
||||
* name "Axis Camera".
|
||||
* This overload calls AddAxisCamera() with name "Axis Camera".
|
||||
*
|
||||
* @param hosts Array of Camera host IPs/DNS names
|
||||
*/
|
||||
@@ -136,8 +132,7 @@ class CameraServer : public ErrorBase {
|
||||
/**
|
||||
* Adds an Axis IP camera.
|
||||
*
|
||||
* <p>This overload calls {@link #AddAxisCamera(String, String[])} with
|
||||
* name "Axis Camera".
|
||||
* This overload calls AddAxisCamera() with name "Axis Camera".
|
||||
*
|
||||
* @param hosts Array of Camera host IPs/DNS names
|
||||
*/
|
||||
@@ -253,8 +248,8 @@ class CameraServer : public ErrorBase {
|
||||
/**
|
||||
* Get server for the primary camera feed.
|
||||
*
|
||||
* <p>This is only valid to call after a camera feed has been added
|
||||
* with StartAutomaticCapture() or AddServer().
|
||||
* This is only valid to call after a camera feed has been added with
|
||||
* StartAutomaticCapture() or AddServer().
|
||||
*/
|
||||
cs::VideoSink GetServer();
|
||||
|
||||
@@ -285,7 +280,7 @@ class CameraServer : public ErrorBase {
|
||||
* StartAutomaticCapture method.
|
||||
*
|
||||
* @deprecated Use SetResolution on the UsbCamera returned by
|
||||
* StartAutomaticCapture() instead.
|
||||
* StartAutomaticCapture() instead.
|
||||
* @param size The size to use
|
||||
*/
|
||||
void SetSize(int size);
|
||||
|
||||
@@ -22,29 +22,24 @@ class Subsystem;
|
||||
|
||||
/**
|
||||
* The Command class is at the very core of the entire command framework.
|
||||
* Every command can be started with a call to {@link Command#Start() Start()}.
|
||||
* Once a command is started it will call {@link Command#Initialize()
|
||||
* Initialize()}, and then will repeatedly call
|
||||
* {@link Command#Execute() Execute()} until the
|
||||
* {@link Command#IsFinished() IsFinished()} returns true. Once it does,
|
||||
* {@link Command#End() End()} will be called.
|
||||
*
|
||||
* <p>However, if at any point while it is running {@link Command#Cancel()
|
||||
* Cancel()} is called, then the command will be stopped and
|
||||
* {@link Command#Interrupted() Interrupted()} will be called.</p>
|
||||
* Every command can be started with a call to Start(). Once a command is
|
||||
* started it will call Initialize(), and then will repeatedly call Execute()
|
||||
* until the IsFinished() returns true. Once it does,End() will be called.
|
||||
*
|
||||
* <p>If a command uses a {@link Subsystem}, then it should specify that it does
|
||||
* so by calling the {@link Command#Requires(Subsystem) Requires(...)} method
|
||||
* in its constructor. Note that a Command may have multiple requirements, and
|
||||
* {@link Command#Requires(Subsystem) Requires(...)} should be called for each
|
||||
* one.</p>
|
||||
* However, if at any point while it is running Cancel() is called, then the
|
||||
* command will be stopped and Interrupted() will be called.
|
||||
*
|
||||
* <p>If a command is running and a new command with shared requirements is
|
||||
* started, then one of two things will happen. If the active command is
|
||||
* interruptible, then {@link Command#Cancel() Cancel()} will be called and the
|
||||
* command will be removed to make way for the new one. If the active command
|
||||
* is not interruptible, the other one will not even be started, and the active
|
||||
* one will continue functioning.</p>
|
||||
* If a command uses a Subsystem, then it should specify that it does so by
|
||||
* calling the Requires() method in its constructor. Note that a Command may
|
||||
* have multiple requirements, and Requires() should be called for each one.
|
||||
*
|
||||
* If a command is running and a new command with shared requirements is
|
||||
* started, then one of two things will happen. If the active command is
|
||||
* interruptible, then Cancel() will be called and the command will be removed
|
||||
* to make way for the new one. If the active command is not interruptible, the
|
||||
* other one will not even be started, and the active one will continue
|
||||
* functioning.
|
||||
*
|
||||
* @see CommandGroup
|
||||
* @see Subsystem
|
||||
@@ -88,19 +83,19 @@ class Command : public ErrorBase, public NamedSendable {
|
||||
|
||||
/**
|
||||
* Returns whether this command is finished.
|
||||
* If it is, then the command will be removed and {@link Command#end() end()}
|
||||
* will be called.
|
||||
*
|
||||
* <p>It may be useful for a team to reference the {@link Command#isTimedOut()
|
||||
* isTimedOut()} method for time-sensitive commands.</p>
|
||||
* If it is, then the command will be removed and End() will be called.
|
||||
*
|
||||
* <p>Returning false will result in the command never ending automatically.
|
||||
* It may be useful for a team to reference the IsTimedOut() method for
|
||||
* time-sensitive commands.
|
||||
*
|
||||
* Returning false will result in the command never ending automatically.
|
||||
* It may still be cancelled manually or interrupted by another command.
|
||||
* Returning true will result in the command executing once and finishing
|
||||
* immediately. We recommend using {@link InstantCommand} for this.</p>
|
||||
* immediately. We recommend using InstantCommand for this.
|
||||
*
|
||||
* @return whether this command is finished.
|
||||
* @see Command#isTimedOut() isTimedOut()
|
||||
* @return Whether this command is finished.
|
||||
* @see IsTimedOut()
|
||||
*/
|
||||
virtual bool IsFinished() = 0;
|
||||
|
||||
@@ -117,42 +112,41 @@ class Command : public ErrorBase, public NamedSendable {
|
||||
|
||||
private:
|
||||
void LockChanges();
|
||||
/*synchronized*/ void Removed();
|
||||
void Removed();
|
||||
void StartRunning();
|
||||
void StartTiming();
|
||||
|
||||
/** The name of this command */
|
||||
// The name of this command
|
||||
std::string m_name;
|
||||
|
||||
/** The time since this command was initialized */
|
||||
// The time since this command was initialized
|
||||
double m_startTime = -1;
|
||||
|
||||
/** The time (in seconds) before this command "times out" (or -1 if no
|
||||
* timeout) */
|
||||
// The time (in seconds) before this command "times out" (-1 if no timeout)
|
||||
double m_timeout;
|
||||
|
||||
/** Whether or not this command has been initialized */
|
||||
// Whether or not this command has been initialized
|
||||
bool m_initialized = false;
|
||||
|
||||
/** The requirements (or null if no requirements) */
|
||||
// The requirements (or null if no requirements)
|
||||
SubsystemSet m_requirements;
|
||||
|
||||
/** Whether or not it is running */
|
||||
// Whether or not it is running
|
||||
bool m_running = false;
|
||||
|
||||
/** Whether or not it is interruptible*/
|
||||
// Whether or not it is interruptible
|
||||
bool m_interruptible = true;
|
||||
|
||||
/** Whether or not it has been canceled */
|
||||
// Whether or not it has been canceled
|
||||
bool m_canceled = false;
|
||||
|
||||
/** Whether or not it has been locked */
|
||||
// Whether or not it has been locked
|
||||
bool m_locked = false;
|
||||
|
||||
/** Whether this command should run when the robot is disabled */
|
||||
// Whether this command should run when the robot is disabled
|
||||
bool m_runWhenDisabled = false;
|
||||
|
||||
/** The {@link CommandGroup} this is in */
|
||||
// The CommandGroup this is in
|
||||
CommandGroup* m_parent = nullptr;
|
||||
|
||||
int m_commandID = m_commandCounter++;
|
||||
|
||||
@@ -17,21 +17,18 @@
|
||||
namespace frc {
|
||||
|
||||
/**
|
||||
* A {@link CommandGroup} is a list of commands which are executed in sequence.
|
||||
* A CommandGroup is a list of commands which are executed in sequence.
|
||||
*
|
||||
* <p>Commands in a {@link CommandGroup} are added using the {@link
|
||||
* CommandGroup#AddSequential(Command) AddSequential(...)} method and are
|
||||
* called sequentially. {@link CommandGroup CommandGroups} are themselves
|
||||
* {@link Command Commands} and can be given to other
|
||||
* {@link CommandGroup CommandGroups}.</p>
|
||||
* Commands in a CommandGroup are added using the AddSequential() method and are
|
||||
* called sequentially. CommandGroups are themselves Commands and can be given
|
||||
* to other CommandGroups.
|
||||
*
|
||||
* <p>{@link CommandGroup CommandGroups} will carry all of the requirements of
|
||||
* their {@link Command subcommands}. Additional requirements can be specified
|
||||
* by calling {@link CommandGroup#Requires(Subsystem) Requires(...)} normally
|
||||
* in the constructor.</P>
|
||||
* CommandGroups will carry all of the requirements of their Command
|
||||
* subcommands. Additional requirements can be specified by calling Requires()
|
||||
* normally in the constructor.
|
||||
*
|
||||
* <p>CommandGroups can also execute commands in parallel, simply by adding them
|
||||
* using {@link CommandGroup#AddParallel(Command) AddParallel(...)}.</p>
|
||||
* CommandGroups can also execute commands in parallel, simply by adding them
|
||||
* using AddParallel().
|
||||
*
|
||||
* @see Command
|
||||
* @see Subsystem
|
||||
@@ -63,13 +60,13 @@ class CommandGroup : public Command {
|
||||
private:
|
||||
void CancelConflicts(Command* command);
|
||||
|
||||
/** The commands in this group (stored in entries) */
|
||||
// The commands in this group (stored in entries)
|
||||
std::vector<CommandGroupEntry> m_commands;
|
||||
|
||||
/** The active children in this group (stored in entries) */
|
||||
// The active children in this group (stored in entries)
|
||||
std::list<CommandGroupEntry> m_children;
|
||||
|
||||
/** The current command, -1 signifies that none have been run */
|
||||
// The current command, -1 signifies that none have been run
|
||||
int m_currentCommandIndex = -1;
|
||||
};
|
||||
|
||||
|
||||
@@ -15,25 +15,17 @@
|
||||
namespace frc {
|
||||
|
||||
/**
|
||||
* A {@link ConditionalCommand} is a {@link Command} that starts one of two
|
||||
* commands.
|
||||
* A ConditionalCommand is a Command that starts one of two commands.
|
||||
*
|
||||
* <p>
|
||||
* A {@link ConditionalCommand} uses m_condition to determine whether it should
|
||||
* run m_onTrue or m_onFalse.
|
||||
* </p>
|
||||
* A ConditionalCommand uses m_condition to determine whether it should run
|
||||
* m_onTrue or m_onFalse.
|
||||
*
|
||||
* <p>
|
||||
* A {@link ConditionalCommand} adds the proper {@link Command} to the {@link
|
||||
* Scheduler} during {@link ConditionalCommand#initialize()} and then {@link
|
||||
* ConditionalCommand#isFinished()} will return true once that {@link Command}
|
||||
* has finished executing.
|
||||
* </p>
|
||||
* A ConditionalCommand adds the proper Command to the Scheduler during
|
||||
* Initialize() and then IsFinished() will return true once that Command has
|
||||
* finished executing.
|
||||
*
|
||||
* <p>
|
||||
* If no {@link Command} is specified for m_onFalse, the occurrence of that
|
||||
* condition will be a no-op.
|
||||
* </p>
|
||||
* If no Command is specified for m_onFalse, the occurrence of that condition
|
||||
* will be a no-op.
|
||||
*
|
||||
* @see Command
|
||||
* @see Scheduler
|
||||
@@ -59,21 +51,13 @@ class ConditionalCommand : public Command {
|
||||
void Interrupted() override;
|
||||
|
||||
private:
|
||||
/**
|
||||
* The Command to execute if {@link ConditionalCommand#Condition()} returns
|
||||
* true
|
||||
*/
|
||||
// The Command to execute if Condition() returns true
|
||||
Command* m_onTrue;
|
||||
|
||||
/**
|
||||
* The Command to execute if {@link ConditionalCommand#Condition()} returns
|
||||
* false
|
||||
*/
|
||||
// The Command to execute if Condition() returns false
|
||||
Command* m_onFalse;
|
||||
|
||||
/**
|
||||
* Stores command chosen by condition
|
||||
*/
|
||||
// Stores command chosen by condition
|
||||
Command* m_chosenCommand = nullptr;
|
||||
};
|
||||
|
||||
|
||||
@@ -16,8 +16,7 @@ namespace frc {
|
||||
/**
|
||||
* This command will execute once, then finish immediately afterward.
|
||||
*
|
||||
* <p>Subclassing {@link InstantCommand} is shorthand for returning true from
|
||||
* {@link Command isFinished}.
|
||||
* Subclassing InstantCommand is shorthand for returning true from IsFinished().
|
||||
*/
|
||||
class InstantCommand : public Command {
|
||||
public:
|
||||
|
||||
@@ -50,7 +50,7 @@ class PIDCommand : public Command, public PIDOutput, public PIDSource {
|
||||
virtual void UsePIDOutput(double output) = 0;
|
||||
|
||||
private:
|
||||
/** The internal {@link PIDController} */
|
||||
// The internal PIDController
|
||||
std::shared_ptr<PIDController> m_controller;
|
||||
|
||||
public:
|
||||
|
||||
@@ -18,14 +18,13 @@
|
||||
namespace frc {
|
||||
|
||||
/**
|
||||
* This class is designed to handle the case where there is a {@link Subsystem}
|
||||
* which uses a single {@link PIDController} almost constantly (for instance,
|
||||
* an elevator which attempts to stay at a constant height).
|
||||
*
|
||||
* <p>It provides some convenience methods to run an internal {@link
|
||||
* PIDController}. It also allows access to the internal {@link PIDController}
|
||||
* in order to give total control to the programmer.</p>
|
||||
* This class is designed to handle the case where there is a Subsystem which
|
||||
* uses a single PIDController almost constantly (for instance, an elevator
|
||||
* which attempts to stay at a constant height).
|
||||
*
|
||||
* It provides some convenience methods to run an internal PIDController. It
|
||||
* also allows access to the internal PIDController in order to give total
|
||||
* control to the programmer.
|
||||
*/
|
||||
class PIDSubsystem : public Subsystem, public PIDOutput, public PIDSource {
|
||||
public:
|
||||
@@ -65,7 +64,7 @@ class PIDSubsystem : public Subsystem, public PIDOutput, public PIDSource {
|
||||
virtual void UsePIDOutput(double output) = 0;
|
||||
|
||||
private:
|
||||
/** The internal {@link PIDController} */
|
||||
// The internal PIDController
|
||||
std::shared_ptr<PIDController> m_controller;
|
||||
|
||||
public:
|
||||
|
||||
@@ -14,8 +14,9 @@
|
||||
namespace frc {
|
||||
|
||||
/**
|
||||
* A {@link TimedCommand} will wait for a timeout before finishing.
|
||||
* {@link TimedCommand} is used to execute a command for a given amount of time.
|
||||
* A TimedCommand will wait for a timeout before finishing.
|
||||
*
|
||||
* TimedCommand is used to execute a command for a given amount of time.
|
||||
*/
|
||||
class TimedCommand : public Command {
|
||||
public:
|
||||
|
||||
@@ -20,11 +20,13 @@ namespace frc {
|
||||
|
||||
/**
|
||||
* Class for operating a compressor connected to a %PCM (Pneumatic Control
|
||||
* Module). The %PCM will automatically run in closed loop mode by default
|
||||
* whenever a Solenoid object is created. For most cases, a Compressor object
|
||||
* does not need to be instantiated or used in a robot program. This class is
|
||||
* only required in cases where the robot program needs a more detailed status
|
||||
* of the compressor or to enable/disable closed loop control.
|
||||
* Module).
|
||||
*
|
||||
* The PCM will automatically run in closed loop mode by default whenever a
|
||||
* Solenoid object is created. For most cases, a Compressor object does not need
|
||||
* to be instantiated or used in a robot program. This class is only required in
|
||||
* cases where the robot program needs a more detailed status of the compressor
|
||||
* or to enable/disable closed loop control.
|
||||
*
|
||||
* Note: you cannot operate the compressor directly from this class as doing so
|
||||
* would circumvent the safety provided by using the pressure switch and closed
|
||||
|
||||
@@ -11,6 +11,7 @@ namespace frc {
|
||||
|
||||
/**
|
||||
* Interface for Controllers.
|
||||
*
|
||||
* Common interface for controllers. Controllers run control loops, the most
|
||||
* common are PID controllers and their variants, but this includes anything
|
||||
* that is controlling an actuator in a separate thread.
|
||||
|
||||
@@ -43,6 +43,7 @@ class Counter : public SensorBase,
|
||||
kPulseLength = 2,
|
||||
kExternalDirection = 3
|
||||
};
|
||||
|
||||
explicit Counter(Mode mode = kTwoPulse);
|
||||
explicit Counter(int channel);
|
||||
explicit Counter(DigitalSource* source);
|
||||
@@ -104,13 +105,15 @@ class Counter : public SensorBase,
|
||||
protected:
|
||||
// Makes the counter count up.
|
||||
std::shared_ptr<DigitalSource> m_upSource;
|
||||
|
||||
// Makes the counter count down.
|
||||
std::shared_ptr<DigitalSource> m_downSource;
|
||||
|
||||
// The FPGA counter object
|
||||
HAL_CounterHandle m_counter = HAL_kInvalidHandle;
|
||||
|
||||
private:
|
||||
int m_index = 0; ///< The index of this counter.
|
||||
int m_index = 0; // The index of this counter.
|
||||
|
||||
nt::NetworkTableEntry m_valueEntry;
|
||||
friend class DigitalGlitchFilter;
|
||||
|
||||
@@ -11,6 +11,7 @@ namespace frc {
|
||||
|
||||
/**
|
||||
* Interface for counting the number of ticks on a digital input channel.
|
||||
*
|
||||
* Encoders, Gear tooth sensors, and counters should all subclass this so it can
|
||||
* be used to build more advanced classes for control and driving.
|
||||
*
|
||||
|
||||
@@ -22,6 +22,7 @@ class Counter;
|
||||
|
||||
/**
|
||||
* Class to enable glitch filtering on a set of digital inputs.
|
||||
*
|
||||
* This class will manage adding and removing digital inputs from a FPGA glitch
|
||||
* filter. The filter lets the user configure the time that an input must remain
|
||||
* high or low before it is classified as high or low.
|
||||
@@ -46,7 +47,7 @@ class DigitalGlitchFilter : public SensorBase {
|
||||
uint64_t GetPeriodNanoSeconds();
|
||||
|
||||
private:
|
||||
// Sets the filter for the input to be the requested index. A value of 0
|
||||
// Sets the filter for the input to be the requested index. A value of 0
|
||||
// disables the filter, and the filter value must be between 1 and 3,
|
||||
// inclusive.
|
||||
void DoAdd(DigitalSource* input, int requested_index);
|
||||
|
||||
@@ -20,6 +20,7 @@ class DigitalGlitchFilter;
|
||||
|
||||
/**
|
||||
* Class to read a digital input.
|
||||
*
|
||||
* This class will read digital inputs and return the current value on the
|
||||
* channel. Other devices such as encoders, gear tooth sensors, etc. that are
|
||||
* implemented elsewhere will automatically allocate digital inputs and outputs
|
||||
|
||||
@@ -20,6 +20,7 @@ namespace frc {
|
||||
|
||||
/**
|
||||
* Class to write to digital outputs.
|
||||
*
|
||||
* Write values to the digital output channels. Other devices implemented
|
||||
* elsewhere will allocate channels automatically so for those devices it
|
||||
* shouldn't be done here.
|
||||
|
||||
@@ -15,13 +15,12 @@ namespace frc {
|
||||
|
||||
/**
|
||||
* DigitalSource Interface.
|
||||
*
|
||||
* The DigitalSource represents all the possible inputs for a counter or a
|
||||
* quadrature encoder. The source may be
|
||||
* either a digital input or an analog input. If the caller just provides a
|
||||
* channel, then a digital input will be
|
||||
* quadrature encoder. The source may be either a digital input or an analog
|
||||
* input. If the caller just provides a channel, then a digital input will be
|
||||
* constructed and freed when finished for the source. The source can either be
|
||||
* a digital input or analog trigger
|
||||
* but not both.
|
||||
* a digital input or analog trigger but not both.
|
||||
*/
|
||||
class DigitalSource : public InterruptableSensorBase {
|
||||
public:
|
||||
|
||||
@@ -44,10 +44,10 @@ class DoubleSolenoid : public SolenoidBase, public LiveWindowSendable {
|
||||
void InitTable(std::shared_ptr<nt::NetworkTable> subTable);
|
||||
|
||||
private:
|
||||
int m_forwardChannel; ///< The forward channel on the module to control.
|
||||
int m_reverseChannel; ///< The reverse channel on the module to control.
|
||||
int m_forwardMask; ///< The mask for the forward channel.
|
||||
int m_reverseMask; ///< The mask for the reverse channel.
|
||||
int m_forwardChannel; // The forward channel on the module to control.
|
||||
int m_reverseChannel; // The reverse channel on the module to control.
|
||||
int m_forwardMask; // The mask for the forward channel.
|
||||
int m_reverseMask; // The mask for the reverse channel.
|
||||
HAL_SolenoidHandle m_forwardHandle = HAL_kInvalidHandle;
|
||||
HAL_SolenoidHandle m_reverseHandle = HAL_kInvalidHandle;
|
||||
|
||||
|
||||
@@ -83,24 +83,39 @@ class DriverStation : public SensorBase, public RobotStateInterface {
|
||||
double GetMatchTime() const;
|
||||
double GetBatteryVoltage() const;
|
||||
|
||||
/** Only to be used to tell the Driver Station what code you claim to be
|
||||
* executing for diagnostic purposes only
|
||||
/**
|
||||
* Only to be used to tell the Driver Station what code you claim to be
|
||||
* executing for diagnostic purposes only.
|
||||
*
|
||||
* @param entering If true, starting disabled code; if false, leaving disabled
|
||||
* code */
|
||||
* code.
|
||||
*/
|
||||
void InDisabled(bool entering) { m_userInDisabled = entering; }
|
||||
/** Only to be used to tell the Driver Station what code you claim to be
|
||||
* executing for diagnostic purposes only
|
||||
|
||||
/**
|
||||
* Only to be used to tell the Driver Station what code you claim to be
|
||||
* executing for diagnostic purposes only.
|
||||
*
|
||||
* @param entering If true, starting autonomous code; if false, leaving
|
||||
* autonomous code */
|
||||
* autonomous code.
|
||||
*/
|
||||
void InAutonomous(bool entering) { m_userInAutonomous = entering; }
|
||||
/** Only to be used to tell the Driver Station what code you claim to be
|
||||
* executing for diagnostic purposes only
|
||||
|
||||
/**
|
||||
* Only to be used to tell the Driver Station what code you claim to be
|
||||
* executing for diagnostic purposes only.
|
||||
*
|
||||
* @param entering If true, starting teleop code; if false, leaving teleop
|
||||
* code */
|
||||
* code.
|
||||
*/
|
||||
void InOperatorControl(bool entering) { m_userInTeleop = entering; }
|
||||
/** Only to be used to tell the Driver Station what code you claim to be
|
||||
* executing for diagnostic purposes only
|
||||
* @param entering If true, starting test code; if false, leaving test code */
|
||||
|
||||
/**
|
||||
* Only to be used to tell the Driver Station what code you claim to be
|
||||
* executing for diagnostic purposes only.
|
||||
*
|
||||
* @param entering If true, starting test code; if false, leaving test code.
|
||||
*/
|
||||
void InTest(bool entering) { m_userInTest = entering; }
|
||||
|
||||
protected:
|
||||
@@ -108,6 +123,7 @@ class DriverStation : public SensorBase, public RobotStateInterface {
|
||||
|
||||
private:
|
||||
DriverStation();
|
||||
|
||||
void ReportJoystickUnpluggedError(llvm::StringRef message);
|
||||
void ReportJoystickUnpluggedWarning(llvm::StringRef message);
|
||||
void Run();
|
||||
|
||||
@@ -98,8 +98,8 @@ class Encoder : public SensorBase,
|
||||
|
||||
double DecodingScaleFactor() const;
|
||||
|
||||
std::shared_ptr<DigitalSource> m_aSource; // the A phase of the quad encoder
|
||||
std::shared_ptr<DigitalSource> m_bSource; // the B phase of the quad encoder
|
||||
std::shared_ptr<DigitalSource> m_aSource; // The A phase of the quad encoder
|
||||
std::shared_ptr<DigitalSource> m_bSource; // The B phase of the quad encoder
|
||||
std::unique_ptr<DigitalSource> m_indexSource = nullptr;
|
||||
HAL_EncoderHandle m_encoder = HAL_kInvalidHandle;
|
||||
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
|
||||
namespace frc {
|
||||
|
||||
// Forward declarations
|
||||
class ErrorBase;
|
||||
|
||||
/**
|
||||
|
||||
@@ -65,10 +65,10 @@ namespace frc {
|
||||
|
||||
/**
|
||||
* Base class for most objects.
|
||||
*
|
||||
* ErrorBase is the base class for most objects since it holds the generated
|
||||
* error
|
||||
* for that object. In addition, there is a single instance of a global error
|
||||
* object
|
||||
* error for that object. In addition, there is a single instance of a global
|
||||
* error object.
|
||||
*/
|
||||
class ErrorBase {
|
||||
// TODO: Consider initializing instance variables and cleanup in destructor
|
||||
@@ -113,6 +113,7 @@ class ErrorBase {
|
||||
|
||||
protected:
|
||||
mutable Error m_error;
|
||||
|
||||
// TODO: Replace globalError with a global list of all errors.
|
||||
static wpi::mutex _globalErrorMutex;
|
||||
static Error _globalError;
|
||||
|
||||
@@ -16,19 +16,22 @@ namespace frc {
|
||||
|
||||
/**
|
||||
* Alias for counter class.
|
||||
* Implement the gear tooth sensor supplied by FIRST. Currently there is no
|
||||
*
|
||||
* Implements the gear tooth sensor supplied by FIRST. Currently there is no
|
||||
* reverse sensing on the gear tooth sensor, but in future versions we might
|
||||
* implement the necessary timing in the FPGA to sense direction.
|
||||
*/
|
||||
class GearTooth : public Counter {
|
||||
public:
|
||||
/// 55 uSec for threshold
|
||||
// 55 uSec for threshold
|
||||
static constexpr double kGearToothThreshold = 55e-6;
|
||||
|
||||
explicit GearTooth(int channel, bool directionSensitive = false);
|
||||
explicit GearTooth(DigitalSource* source, bool directionSensitive = false);
|
||||
explicit GearTooth(std::shared_ptr<DigitalSource> source,
|
||||
bool directionSensitive = false);
|
||||
virtual ~GearTooth() = default;
|
||||
|
||||
void EnableDirectionSensing(bool directionSensitive);
|
||||
|
||||
std::string GetSmartDashboardType() const override;
|
||||
|
||||
@@ -20,7 +20,6 @@ namespace frc {
|
||||
*
|
||||
* This class is intended to be used by sensor (and other I2C device) drivers.
|
||||
* It probably should not be used directly.
|
||||
*
|
||||
*/
|
||||
class I2C : SensorBase {
|
||||
public:
|
||||
@@ -39,7 +38,6 @@ class I2C : SensorBase {
|
||||
bool WriteBulk(uint8_t* data, int count);
|
||||
bool Read(int registerAddress, int count, uint8_t* data);
|
||||
bool ReadOnly(int count, uint8_t* buffer);
|
||||
// void Broadcast(int registerAddress, uint8_t data);
|
||||
bool VerifySensor(int registerAddress, int count, const uint8_t* expected);
|
||||
|
||||
private:
|
||||
|
||||
@@ -28,22 +28,33 @@ class InterruptableSensorBase : public SensorBase {
|
||||
|
||||
virtual HAL_Handle GetPortHandleForRouting() const = 0;
|
||||
virtual AnalogTriggerType GetAnalogTriggerTypeForRouting() const = 0;
|
||||
virtual void RequestInterrupts(
|
||||
HAL_InterruptHandlerFunction handler,
|
||||
void* param); ///< Asynchronus handler version.
|
||||
virtual void RequestInterrupts(); ///< Synchronus Wait version.
|
||||
virtual void
|
||||
CancelInterrupts(); ///< Free up the underlying chipobject functions.
|
||||
virtual WaitResult WaitForInterrupt(
|
||||
double timeout,
|
||||
bool ignorePrevious = true); ///< Synchronus version.
|
||||
virtual void
|
||||
EnableInterrupts(); ///< Enable interrupts - after finishing setup.
|
||||
virtual void DisableInterrupts(); ///< Disable, but don't deallocate.
|
||||
virtual double ReadRisingTimestamp(); ///< Return the timestamp for the
|
||||
/// rising interrupt that occurred.
|
||||
virtual double ReadFallingTimestamp(); ///< Return the timestamp for the
|
||||
/// falling interrupt that occurred.
|
||||
|
||||
// Asynchronous handler version.
|
||||
virtual void RequestInterrupts(HAL_InterruptHandlerFunction handler,
|
||||
void* param);
|
||||
|
||||
// Synchronous wait version.
|
||||
virtual void RequestInterrupts();
|
||||
|
||||
// Free up the underlying ChipObject functions.
|
||||
virtual void CancelInterrupts();
|
||||
|
||||
// Synchronous version.
|
||||
virtual WaitResult WaitForInterrupt(double timeout,
|
||||
bool ignorePrevious = true);
|
||||
|
||||
// Enable interrupts - after finishing setup.
|
||||
virtual void EnableInterrupts();
|
||||
|
||||
// Disable, but don't deallocate.
|
||||
virtual void DisableInterrupts();
|
||||
|
||||
// Return the timestamp for the rising interrupt that occurred.
|
||||
virtual double ReadRisingTimestamp();
|
||||
|
||||
// Return the timestamp for the falling interrupt that occurred.
|
||||
virtual double ReadFallingTimestamp();
|
||||
|
||||
virtual void SetUpSourceEdge(bool risingEdge, bool fallingEdge);
|
||||
|
||||
protected:
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
namespace frc {
|
||||
|
||||
/**
|
||||
* Luminary Micro / Vex Robotics Jaguar Speed Controller with PWM control
|
||||
* Luminary Micro / Vex Robotics Jaguar Speed Controller with PWM control.
|
||||
*/
|
||||
class Jaguar : public PWMSpeedController {
|
||||
public:
|
||||
|
||||
@@ -34,8 +34,7 @@ struct LiveWindowComponent {
|
||||
|
||||
/**
|
||||
* The LiveWindow class is the public interface for putting sensors and
|
||||
* actuators
|
||||
* on the LiveWindow.
|
||||
* actuators on the LiveWindow.
|
||||
*/
|
||||
class LiveWindow {
|
||||
public:
|
||||
|
||||
@@ -17,20 +17,18 @@ namespace frc {
|
||||
class LiveWindowSendable : public Sendable {
|
||||
public:
|
||||
/**
|
||||
* Update the table for this sendable object with the latest
|
||||
* values.
|
||||
* Update the table for this sendable object with the latest values.
|
||||
*/
|
||||
virtual void UpdateTable() = 0;
|
||||
|
||||
/**
|
||||
* Start having this sendable object automatically respond to
|
||||
* value changes reflect the value on the table.
|
||||
* Start having this sendable object automatically respond to value changes
|
||||
* reflect the value on the table.
|
||||
*/
|
||||
virtual void StartLiveWindowMode() = 0;
|
||||
|
||||
/**
|
||||
* Stop having this sendable object automatically respond to value
|
||||
* changes.
|
||||
* Stop having this sendable object automatically respond to value changes.
|
||||
*/
|
||||
virtual void StopLiveWindowMode() = 0;
|
||||
};
|
||||
|
||||
@@ -31,19 +31,25 @@ class MotorSafetyHelper : public ErrorBase {
|
||||
static void CheckMotors();
|
||||
|
||||
private:
|
||||
// the expiration time for this object
|
||||
// The expiration time for this object
|
||||
double m_expiration;
|
||||
// true if motor safety is enabled for this motor
|
||||
|
||||
// True if motor safety is enabled for this motor
|
||||
bool m_enabled;
|
||||
// the FPGA clock value when this motor has expired
|
||||
|
||||
// The FPGA clock value when this motor has expired
|
||||
double m_stopTime;
|
||||
// protect accesses to the state for this object
|
||||
|
||||
// Protect accesses to the state for this object
|
||||
mutable wpi::mutex m_syncMutex;
|
||||
// the object that is using the helper
|
||||
|
||||
// The object that is using the helper
|
||||
MotorSafety* m_safeObject;
|
||||
|
||||
// List of all existing MotorSafetyHelper objects.
|
||||
static std::set<MotorSafetyHelper*> m_helperList;
|
||||
// protect accesses to the list of helpers
|
||||
|
||||
// Protect accesses to the list of helpers
|
||||
static wpi::mutex m_listMutex;
|
||||
};
|
||||
|
||||
|
||||
@@ -41,24 +41,31 @@ class Notifier : public ErrorBase {
|
||||
void Stop();
|
||||
|
||||
private:
|
||||
// update the HAL alarm
|
||||
// Update the HAL alarm
|
||||
void UpdateAlarm();
|
||||
|
||||
// HAL callback
|
||||
static void Notify(uint64_t currentTimeInt, HAL_NotifierHandle handle);
|
||||
|
||||
// used to constrain execution between destructors and callback
|
||||
// Used to constrain execution between destructors and callback
|
||||
static wpi::mutex m_destructorMutex;
|
||||
// held while updating process information
|
||||
|
||||
// Held while updating process information
|
||||
wpi::mutex m_processMutex;
|
||||
|
||||
// HAL handle, atomic for proper destruction
|
||||
std::atomic<HAL_NotifierHandle> m_notifier{0};
|
||||
// address of the handler
|
||||
|
||||
// Address of the handler
|
||||
TimerEventHandler m_handler;
|
||||
// the absolute expiration time
|
||||
|
||||
// The absolute expiration time
|
||||
double m_expirationTime = 0;
|
||||
// the relative time (either periodic or single)
|
||||
|
||||
// The relative time (either periodic or single)
|
||||
double m_period = 0;
|
||||
// true if this is a periodic event
|
||||
|
||||
// True if this is a periodic event
|
||||
bool m_periodic = false;
|
||||
};
|
||||
|
||||
|
||||
@@ -30,8 +30,8 @@ class PIDOutput;
|
||||
/**
|
||||
* Class implements a PID Control Loop.
|
||||
*
|
||||
* Creates a separate thread which reads the given PIDSource and takes
|
||||
* care of the integral calculations, as well as writing the given PIDOutput.
|
||||
* Creates a separate thread which reads the given PIDSource and takes care of
|
||||
* the integral calculations, as well as writing the given PIDOutput.
|
||||
*
|
||||
* This feedback controller runs in discrete time, so time deltas are not used
|
||||
* in the integral and derivative calculations. Therefore, the sample rate
|
||||
@@ -105,38 +105,51 @@ class PIDController : public LiveWindowSendable, public PIDInterface {
|
||||
double GetContinuousError(double error) const;
|
||||
|
||||
private:
|
||||
// factor for "proportional" control
|
||||
// Factor for "proportional" control
|
||||
double m_P;
|
||||
// factor for "integral" control
|
||||
|
||||
// Factor for "integral" control
|
||||
double m_I;
|
||||
// factor for "derivative" control
|
||||
|
||||
// Factor for "derivative" control
|
||||
double m_D;
|
||||
// factor for "feed forward" control
|
||||
|
||||
// Factor for "feed forward" control
|
||||
double m_F;
|
||||
|
||||
// |maximum output|
|
||||
double m_maximumOutput = 1.0;
|
||||
|
||||
// |minimum output|
|
||||
double m_minimumOutput = -1.0;
|
||||
// maximum input - limit setpoint to this
|
||||
|
||||
// Maximum input - limit setpoint to this
|
||||
double m_maximumInput = 0;
|
||||
// minimum input - limit setpoint to this
|
||||
|
||||
// Minimum input - limit setpoint to this
|
||||
double m_minimumInput = 0;
|
||||
// do the endpoints wrap around? eg. Absolute encoder
|
||||
|
||||
// Do the endpoints wrap around? eg. Absolute encoder
|
||||
bool m_continuous = false;
|
||||
// is the pid controller enabled
|
||||
|
||||
// Is the pid controller enabled
|
||||
bool m_enabled = false;
|
||||
// the prior error (used to compute velocity)
|
||||
|
||||
// The prior error (used to compute velocity)
|
||||
double m_prevError = 0;
|
||||
// the sum of the errors for use in the integral calc
|
||||
|
||||
// The sum of the errors for use in the integral calc
|
||||
double m_totalError = 0;
|
||||
|
||||
enum {
|
||||
kAbsoluteTolerance,
|
||||
kPercentTolerance,
|
||||
kNoTolerance
|
||||
} m_toleranceType = kNoTolerance;
|
||||
|
||||
// the percetage or absolute error that is considered on target.
|
||||
// The percetage or absolute error that is considered on target.
|
||||
double m_tolerance = 0.05;
|
||||
|
||||
double m_setpoint = 0;
|
||||
double m_prevSetpoint = 0;
|
||||
double m_error = 0;
|
||||
@@ -145,6 +158,7 @@ class PIDController : public LiveWindowSendable, public PIDInterface {
|
||||
|
||||
// Length of buffer for averaging for tolerances.
|
||||
std::atomic<unsigned> m_bufLength{1};
|
||||
|
||||
std::queue<double> m_buf;
|
||||
double m_bufTotal = 0;
|
||||
|
||||
|
||||
@@ -13,9 +13,9 @@ namespace frc {
|
||||
|
||||
/**
|
||||
* PIDOutput interface is a generic output for the PID class.
|
||||
* PWMs use this class.
|
||||
* Users implement this interface to allow for a PIDController to
|
||||
* read directly from the inputs.
|
||||
*
|
||||
* PWMs use this class. Users implement this interface to allow for a
|
||||
* PIDController to read directly from the inputs.
|
||||
*/
|
||||
class PIDOutput {
|
||||
public:
|
||||
|
||||
@@ -13,6 +13,7 @@ enum class PIDSourceType { kDisplacement, kRate };
|
||||
|
||||
/**
|
||||
* PIDSource interface is a generic sensor source for the PID class.
|
||||
*
|
||||
* All sensors that can be used with the PID class will implement the PIDSource
|
||||
* that returns a standard value that will be used in the PID code.
|
||||
*/
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
namespace frc {
|
||||
|
||||
/**
|
||||
* Common base class for all PWM Speed Controllers
|
||||
* Common base class for all PWM Speed Controllers.
|
||||
*/
|
||||
class PWMSpeedController : public SafePWM, public SpeedController {
|
||||
public:
|
||||
|
||||
@@ -12,7 +12,8 @@
|
||||
namespace frc {
|
||||
|
||||
/**
|
||||
* Cross the Road Electronics (CTRE) Talon SRX Speed Controller with PWM control
|
||||
* Cross the Road Electronics (CTRE) Talon SRX Speed Controller with PWM
|
||||
* control.
|
||||
*/
|
||||
class PWMTalonSRX : public PWMSpeedController {
|
||||
public:
|
||||
|
||||
@@ -22,15 +22,15 @@ namespace frc {
|
||||
* The preferences class provides a relatively simple way to save important
|
||||
* values to the roboRIO to access the next time the roboRIO is booted.
|
||||
*
|
||||
* <p>This class loads and saves from a file inside the roboRIO. The user can
|
||||
* not access the file directly, but may modify values at specific fields which
|
||||
* will then be automatically periodically saved to the file by the NetworkTable
|
||||
* server.</p>
|
||||
* This class loads and saves from a file inside the roboRIO. The user cannot
|
||||
* access the file directly, but may modify values at specific fields which will
|
||||
* then be automatically periodically saved to the file by the NetworkTable
|
||||
* server.
|
||||
*
|
||||
* <p>This class is thread safe.</p>
|
||||
* This class is thread safe.
|
||||
*
|
||||
* <p>This will also interact with {@link NetworkTable} by creating a table
|
||||
* called "Preferences" with all the key-value pairs.</p>
|
||||
* This will also interact with {@link NetworkTable} by creating a table called
|
||||
* "Preferences" with all the key-value pairs.
|
||||
*/
|
||||
class Preferences : public ErrorBase {
|
||||
public:
|
||||
|
||||
@@ -24,12 +24,13 @@ class MotorSafetyHelper;
|
||||
|
||||
/**
|
||||
* Class for Spike style relay outputs.
|
||||
*
|
||||
* Relays are intended to be connected to spikes or similar relays. The relay
|
||||
* channels controls a pair of pins that are either both off, one on, the other
|
||||
* on, or both on. This translates into two spike outputs at 0v, one at 12v and
|
||||
* one at 0v, one at 0v and the other at 12v, or two spike outputs at 12V. This
|
||||
* allows off, full forward, or full reverse control of motors without variable
|
||||
* speed. It also allows the two channels (forward and reverse) to be used
|
||||
* speed. It also allows the two channels (forward and reverse) to be used
|
||||
* independently for something that does not care about voltage polarity (like
|
||||
* a solenoid).
|
||||
*/
|
||||
|
||||
@@ -21,12 +21,13 @@ namespace frc {
|
||||
|
||||
/**
|
||||
* The Resource class is a convenient way to track allocated resources.
|
||||
* It tracks them as indicies in the range [0 .. elements - 1].
|
||||
* E.g. the library uses this to track hardware channel allocation.
|
||||
*
|
||||
* It tracks them as indicies in the range [0 .. elements - 1]. E.g. the library
|
||||
* uses this to track hardware channel allocation.
|
||||
*
|
||||
* The Resource class does not allocate the hardware channels or other
|
||||
* resources; it just tracks which indices were marked in use by
|
||||
* Allocate and not yet freed by Free.
|
||||
* resources; it just tracks which indices were marked in use by Allocate and
|
||||
* not yet freed by Free.
|
||||
*/
|
||||
class Resource : public ErrorBase {
|
||||
public:
|
||||
|
||||
@@ -33,6 +33,7 @@ class DriverStation;
|
||||
|
||||
/**
|
||||
* Implement a Robot Program framework.
|
||||
*
|
||||
* The RobotBase class is intended to be subclassed by a user creating a robot
|
||||
* program. Overridden Autonomous() and OperatorControl() methods are called at
|
||||
* the appropriate time as the match proceeds. In the current implementation,
|
||||
|
||||
@@ -24,6 +24,7 @@ class GenericHID;
|
||||
/**
|
||||
* Utility class for handling Robot drive based on a definition of the motor
|
||||
* configuration.
|
||||
*
|
||||
* The robot drive class handles basic driving for a robot. Currently, 2 and 4
|
||||
* motor tank and mecanum drive trains are supported. In the future other drive
|
||||
* types like swerve might be implemented. Motor channel numbers are passed
|
||||
@@ -115,6 +116,7 @@ class RobotDrive : public MotorSafety, public ErrorBase {
|
||||
static const int kMaxNumberOfMotors = 4;
|
||||
double m_sensitivity = 0.5;
|
||||
double m_maxOutput = 1.0;
|
||||
|
||||
std::shared_ptr<SpeedController> m_frontLeftMotor;
|
||||
std::shared_ptr<SpeedController> m_frontRightMotor;
|
||||
std::shared_ptr<SpeedController> m_rearLeftMotor;
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
namespace frc {
|
||||
|
||||
/**
|
||||
* Mindsensors SD540 Speed Controller
|
||||
* Mindsensors SD540 Speed Controller.
|
||||
*/
|
||||
class SD540 : public PWMSpeedController {
|
||||
public:
|
||||
|
||||
@@ -28,6 +28,7 @@ class DigitalInput;
|
||||
class SPI : public SensorBase {
|
||||
public:
|
||||
enum Port { kOnboardCS0 = 0, kOnboardCS1, kOnboardCS2, kOnboardCS3, kMXP };
|
||||
|
||||
explicit SPI(Port port);
|
||||
virtual ~SPI();
|
||||
|
||||
@@ -67,9 +68,9 @@ class SPI : public SensorBase {
|
||||
|
||||
protected:
|
||||
HAL_SPIPort m_port;
|
||||
bool m_msbFirst = false; // default little-endian
|
||||
bool m_sampleOnTrailing = false; // default data updated on falling edge
|
||||
bool m_clk_idle_high = false; // default clock active high
|
||||
bool m_msbFirst = false; // Default little-endian
|
||||
bool m_sampleOnTrailing = false; // Default data updated on falling edge
|
||||
bool m_clk_idle_high = false; // Default clock active high
|
||||
|
||||
private:
|
||||
void Init();
|
||||
|
||||
@@ -19,6 +19,7 @@ namespace frc {
|
||||
|
||||
/**
|
||||
* A safe version of the PWM class.
|
||||
*
|
||||
* It is safe because it implements the MotorSafety interface that provides
|
||||
* timeouts in the event that the motor value is not updated before the
|
||||
* expiration time. This delegates the actual work to a MotorSafetyHelper
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace frc {
|
||||
|
||||
/**
|
||||
* Base class for all sensors.
|
||||
*
|
||||
* Stores most recent status information as well as containing utility functions
|
||||
* for checking channels and error processing.
|
||||
*/
|
||||
|
||||
@@ -36,18 +36,22 @@ class SerialPort : public ErrorBase {
|
||||
kParity_Mark = 3,
|
||||
kParity_Space = 4
|
||||
};
|
||||
|
||||
enum StopBits {
|
||||
kStopBits_One = 10,
|
||||
kStopBits_OnePointFive = 15,
|
||||
kStopBits_Two = 20
|
||||
};
|
||||
|
||||
enum FlowControl {
|
||||
kFlowControl_None = 0,
|
||||
kFlowControl_XonXoff = 1,
|
||||
kFlowControl_RtsCts = 2,
|
||||
kFlowControl_DtrDsr = 4
|
||||
};
|
||||
|
||||
enum WriteBufferMode { kFlushOnAccess = 1, kFlushWhenFull = 2 };
|
||||
|
||||
enum Port { kOnboard = 0, kMXP = 1, kUSB = 2, kUSB1 = 2, kUSB2 = 3 };
|
||||
|
||||
SerialPort(int baudRate, Port port = kOnboard, int dataBits = 8,
|
||||
|
||||
@@ -20,8 +20,7 @@ namespace frc {
|
||||
* Standard hobby style servo.
|
||||
*
|
||||
* The range parameters default to the appropriate values for the Hitec HS-322HD
|
||||
* servo provided
|
||||
* in the FIRST Kit of Parts in 2008.
|
||||
* servo provided in the FIRST Kit of Parts in 2008.
|
||||
*/
|
||||
class Servo : public SafePWM {
|
||||
public:
|
||||
|
||||
@@ -15,13 +15,12 @@ namespace frc {
|
||||
|
||||
/**
|
||||
* The interface for sendable objects that gives the sendable a default name in
|
||||
* the Smart Dashboard
|
||||
*
|
||||
* the Smart Dashboard.
|
||||
*/
|
||||
class NamedSendable : public Sendable {
|
||||
public:
|
||||
/**
|
||||
* @return the name of the subtable of SmartDashboard that the Sendable object
|
||||
* @return The name of the subtable of SmartDashboard that the Sendable object
|
||||
* will use
|
||||
*/
|
||||
virtual std::string GetName() const = 0;
|
||||
|
||||
@@ -18,12 +18,13 @@ class Sendable {
|
||||
public:
|
||||
/**
|
||||
* Initializes a table for this sendable object.
|
||||
*
|
||||
* @param subtable The table to put the values in.
|
||||
*/
|
||||
virtual void InitTable(std::shared_ptr<nt::NetworkTable> subtable) = 0;
|
||||
|
||||
/**
|
||||
* @return the string representation of the named data type that will be used
|
||||
* @return The string representation of the named data type that will be used
|
||||
* by the smart dashboard for this sendable
|
||||
*/
|
||||
virtual std::string GetSmartDashboardType() const = 0;
|
||||
|
||||
@@ -20,15 +20,14 @@
|
||||
namespace frc {
|
||||
|
||||
/**
|
||||
* The {@link SendableChooser} class is a useful tool for presenting a selection
|
||||
* of options to the {@link SmartDashboard}.
|
||||
* The SendableChooser class is a useful tool for presenting a selection of
|
||||
* options to the SmartDashboard.
|
||||
*
|
||||
* <p>For instance, you may wish to be able to select between multiple
|
||||
* autonomous modes. You can do this by putting every possible {@link Command}
|
||||
* you want to run as an autonomous into a {@link SendableChooser} and then put
|
||||
* it into the {@link SmartDashboard} to have a list of options appear on the
|
||||
* laptop. Once autonomous starts, simply ask the {@link SendableChooser} what
|
||||
* the selected value is.</p>
|
||||
* For instance, you may wish to be able to select between multiple autonomous
|
||||
* modes. You can do this by putting every possible Command you want to run as
|
||||
* an autonomous into a SendableChooser and then put it into the SmartDashboard
|
||||
* to have a list of options appear on the laptop. Once autonomous starts,
|
||||
* simply ask the SendableChooser what the selected value is.
|
||||
*
|
||||
* @tparam T The type of values to be stored
|
||||
* @see SmartDashboard
|
||||
|
||||
@@ -18,8 +18,8 @@ namespace frc {
|
||||
/**
|
||||
* Adds the given object to the list of options.
|
||||
*
|
||||
* On the {@link SmartDashboard} on the desktop, the object will appear as the
|
||||
* given name.
|
||||
* On the SmartDashboard on the desktop, the object will appear as the given
|
||||
* name.
|
||||
*
|
||||
* @param name the name of the option
|
||||
* @param object the option
|
||||
@@ -32,9 +32,8 @@ void SendableChooser<T>::AddObject(llvm::StringRef name, T 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.
|
||||
* Functionally, this is very close to 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
|
||||
@@ -49,12 +48,12 @@ void SendableChooser<T>::AddDefault(llvm::StringRef name, T object) {
|
||||
* Returns a copy of the selected option (a raw pointer U* if T =
|
||||
* std::unique_ptr<U> or a std::weak_ptr<U> if T = std::shared_ptr<U>).
|
||||
*
|
||||
* If there is none selected, it will return the default. If there is none
|
||||
* If there is none selected, it will return the default. If there is none
|
||||
* selected and no default, then it will return a value-initialized instance.
|
||||
* For integer types, this is 0. For container types like std::string, this is
|
||||
* an empty string.
|
||||
*
|
||||
* @return the option selected
|
||||
* @return The option selected
|
||||
*/
|
||||
template <class T>
|
||||
auto SendableChooser<T>::GetSelected()
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
namespace frc {
|
||||
|
||||
/**
|
||||
* This class is a non-template base class for {@link SendableChooser}.
|
||||
* This class is a non-template base class for SendableChooser.
|
||||
*
|
||||
* It contains static, non-templated variables to avoid their duplication in the
|
||||
* template class.
|
||||
|
||||
@@ -41,7 +41,7 @@ class Solenoid : public SolenoidBase, public LiveWindowSendable {
|
||||
|
||||
private:
|
||||
HAL_SolenoidHandle m_solenoidHandle = HAL_kInvalidHandle;
|
||||
int m_channel; ///< The channel on the module to control.
|
||||
int m_channel; // The channel on the module to control
|
||||
nt::NetworkTableEntry m_valueEntry;
|
||||
NT_EntryListener m_valueListener = 0;
|
||||
};
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
namespace frc {
|
||||
|
||||
/**
|
||||
* REV Robotics Speed Controller
|
||||
* REV Robotics Speed Controller.
|
||||
*/
|
||||
class Spark : public PWMSpeedController {
|
||||
public:
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
namespace frc {
|
||||
|
||||
/**
|
||||
* Cross the Road Electronics (CTRE) Talon and Talon SR Speed Controller
|
||||
* Cross the Road Electronics (CTRE) Talon and Talon SR Speed Controller.
|
||||
*/
|
||||
class Talon : public PWMSpeedController {
|
||||
public:
|
||||
|
||||
@@ -21,6 +21,7 @@ double GetTime();
|
||||
|
||||
/**
|
||||
* Timer objects measure accumulated time in seconds.
|
||||
*
|
||||
* The timer object functions like a stopwatch. It can be started, stopped, and
|
||||
* cleared. When the timer is running its value counts up in seconds. When
|
||||
* stopped, the timer holds the current value. The implementation simply records
|
||||
|
||||
@@ -26,6 +26,7 @@ class DigitalOutput;
|
||||
|
||||
/**
|
||||
* Ultrasonic rangefinder class.
|
||||
*
|
||||
* The Ultrasonic rangefinder measures absolute distance based on the round-trip
|
||||
* time of a ping generated by the controller. These sensors use two
|
||||
* transducers, a speaker and a microphone both tuned to the ultrasonic range. A
|
||||
@@ -43,10 +44,8 @@ class Ultrasonic : public SensorBase,
|
||||
|
||||
Ultrasonic(DigitalOutput* pingChannel, DigitalInput* echoChannel,
|
||||
DistanceUnit units = kInches);
|
||||
|
||||
Ultrasonic(DigitalOutput& pingChannel, DigitalInput& echoChannel,
|
||||
DistanceUnit units = kInches);
|
||||
|
||||
Ultrasonic(std::shared_ptr<DigitalOutput> pingChannel,
|
||||
std::shared_ptr<DigitalInput> echoChannel,
|
||||
DistanceUnit units = kInches);
|
||||
@@ -79,16 +78,22 @@ class Ultrasonic : public SensorBase,
|
||||
|
||||
// Time (sec) for the ping trigger pulse.
|
||||
static constexpr double kPingTime = 10 * 1e-6;
|
||||
|
||||
// Priority that the ultrasonic round robin task runs.
|
||||
static const int kPriority = 64;
|
||||
|
||||
// Max time (ms) between readings.
|
||||
static constexpr double kMaxUltrasonicTime = 0.1;
|
||||
static constexpr double kSpeedOfSoundInchesPerSec = 1130.0 * 12.0;
|
||||
|
||||
static std::thread
|
||||
m_thread; // thread doing the round-robin automatic sensing
|
||||
static std::set<Ultrasonic*> m_sensors; // ultrasonic sensors
|
||||
static std::atomic<bool> m_automaticEnabled; // automatic round robin mode
|
||||
// Thread doing the round-robin automatic sensing
|
||||
static std::thread m_thread;
|
||||
|
||||
// Ultrasonic sensors
|
||||
static std::set<Ultrasonic*> m_sensors;
|
||||
|
||||
// Automatic round-robin mode
|
||||
static std::atomic<bool> m_automaticEnabled;
|
||||
|
||||
std::shared_ptr<DigitalOutput> m_pingChannel;
|
||||
std::shared_ptr<DigitalInput> m_echoChannel;
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
/** @file
|
||||
* Contains global utility functions
|
||||
/**
|
||||
* @file Contains global utility functions
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
namespace frc {
|
||||
|
||||
/**
|
||||
* Vex Robotics Victor 888 Speed Controller
|
||||
* Vex Robotics Victor 888 Speed Controller.
|
||||
*
|
||||
* The Vex Robotics Victor 884 Speed Controller can also be used with this
|
||||
* class but may need to be calibrated per the Victor 884 user manual.
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
namespace frc {
|
||||
|
||||
/**
|
||||
* Vex Robotics Victor SP Speed Controller
|
||||
* Vex Robotics Victor SP Speed Controller.
|
||||
*/
|
||||
class VictorSP : public PWMSpeedController {
|
||||
public:
|
||||
|
||||
@@ -19,9 +19,7 @@
|
||||
const int wpi_error_value_##label = offset
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Fatal errors
|
||||
*/
|
||||
// Fatal errors
|
||||
S(ModuleIndexOutOfRange, -1,
|
||||
"Allocating module that is out of range or not found");
|
||||
S(ChannelIndexOutOfRange, -1, "Allocating channel that is out of range");
|
||||
@@ -78,9 +76,7 @@ S(CommandIllegalUse, -50, "Illegal use of Command");
|
||||
S(UnsupportedInSimulation, -80, "Unsupported in simulation");
|
||||
S(CameraServerError, -90, "CameraServer error");
|
||||
|
||||
/*
|
||||
* Warnings
|
||||
*/
|
||||
// Warnings
|
||||
S(SampleRateTooHigh, 1, "Analog module sample rate is too high");
|
||||
S(VoltageOutOfRange, 2,
|
||||
"Voltage to convert to raw value is out of range [-10; 10]");
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
namespace frc {
|
||||
|
||||
/**
|
||||
* Interface for 3-axis accelerometers
|
||||
* Interface for 3-axis accelerometers.
|
||||
*/
|
||||
class Accelerometer {
|
||||
public:
|
||||
@@ -22,26 +22,27 @@ class Accelerometer {
|
||||
* Common interface for setting the measuring range of an accelerometer.
|
||||
*
|
||||
* @param range The maximum acceleration, positive or negative, that the
|
||||
* accelerometer will measure. Not all accelerometers support all ranges.
|
||||
* accelerometer will measure. Not all accelerometers support all
|
||||
* ranges.
|
||||
*/
|
||||
virtual void SetRange(Range range) = 0;
|
||||
|
||||
/**
|
||||
* Common interface for getting the x axis acceleration
|
||||
* Common interface for getting the x axis acceleration.
|
||||
*
|
||||
* @return The acceleration along the x axis in g-forces
|
||||
*/
|
||||
virtual double GetX() = 0;
|
||||
|
||||
/**
|
||||
* Common interface for getting the y axis acceleration
|
||||
* Common interface for getting the y axis acceleration.
|
||||
*
|
||||
* @return The acceleration along the y axis in g-forces
|
||||
*/
|
||||
virtual double GetY() = 0;
|
||||
|
||||
/**
|
||||
* Common interface for getting the z axis acceleration
|
||||
* Common interface for getting the z axis acceleration.
|
||||
*
|
||||
* @return The acceleration along the z axis in g-forces
|
||||
*/
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
namespace frc {
|
||||
|
||||
/**
|
||||
* Interface for yaw rate gyros
|
||||
* Interface for yaw rate gyros.
|
||||
*/
|
||||
class Gyro {
|
||||
public:
|
||||
@@ -48,9 +48,9 @@ class Gyro {
|
||||
virtual double GetAngle() const = 0;
|
||||
|
||||
/**
|
||||
* Return the rate of rotation of the gyro
|
||||
* Return the rate of rotation of the gyro.
|
||||
*
|
||||
* The rate is based on the most recent reading of the gyro analog value
|
||||
* The rate is based on the most recent reading of the gyro analog value.
|
||||
*
|
||||
* @return the current rate in degrees per second
|
||||
*/
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user