WPILib Reorganization

This is a major restructuring of the WPILib repository to simply build
procedures and remove the remnants of Maven from everything except the
eclipse plugins. Gradle files have been largely simplified or rewritten,
taking advantage of splitting up parts of the build into separate build
files for ease of reading.

The eclipse plugins are now in a separate project, as is ntcore. All
dependencies are resolved via Maven dependencies, with the
Jenkins-maintained WPILib repo. Project structures have also been
simplified: we no longer have separate subprojects inside wpilibc and
wpilibj. Where possible, these changes hav been done with git renames,
to make sure we still have full history for all repositories. Other
unrelated subprojects have also been broken out: OutlineViewer is now a
separate project.

Change-Id: Ib4e2a6e1a2f66427a14f16612b0e0d69ed661878
This commit is contained in:
Fredric Silberberg
2015-09-24 20:26:49 -04:00
parent c20d34c2b6
commit 6d854afb0e
1769 changed files with 2278 additions and 333177 deletions

View File

@@ -0,0 +1,108 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#pragma once
// MSVC 2013 doesn't allow "= default" on move constructors, but since we are
// (currently) only actually using the move constructors in non-MSVC situations
// (ie, wpilibC++Devices), we can just ignore it in MSVC.
#if !defined(_MSC_VER)
#define DEFAULT_MOVE_CONSTRUCTOR(ClassName) \
ClassName(ClassName &&) = default
#else
#define DEFAULT_MOVE_CONSTRUCTOR(ClassName)
#endif
#if (__cplusplus < 201103L)
#if !defined(_MSC_VER)
#define nullptr NULL
#endif
#define constexpr const
#endif
#if defined(_MSC_VER)
#define noexcept throw()
#endif
// [[deprecated(msg)]] is a C++14 feature not supported by MSVC or GCC < 4.9.
// We provide an equivalent warning implementation for those compilers here.
#if defined(_MSC_VER)
#define DEPRECATED(msg) __declspec(deprecated(msg))
#elif defined(__GNUC__)
#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 8)
#define DEPRECATED(msg) [[deprecated(msg)]]
#else
#define DEPRECATED(msg) __attribute__((deprecated(msg)))
#endif
#elif __cplusplus > 201103L
#define DEPRECATED(msg) [[deprecated(msg)]]
#else
#define DEPRECATED(msg) /*nothing*/
#endif
// A struct to use as a deleter when a std::shared_ptr must wrap a raw pointer
// that is being deleted by someone else.
// This should only be called in deprecated functions; using it anywhere else
// will throw warnings.
template<class T>
struct
DEPRECATED("wrapping raw pointer in std::shared_ptr")
NullDeleter {
void operator()(T *) const noexcept {};
};
#include <atomic>
// Use this for determining whether the default move constructor has been
// called on a containing object. This serves the purpose of allowing us to
// use the default move constructor of an object for moving all the data around
// while being able to use this to, for instance, chose not to de-allocate
// a PWM port in a destructor.
struct HasBeenMoved {
HasBeenMoved(HasBeenMoved&& other) {
other.moved = true;
moved = false;
}
HasBeenMoved() = default;
std::atomic<bool> moved{false};
operator bool() const { return moved; }
};
// Define make_unique for C++11-only compilers
#if __cplusplus == 201103L
#include <cstddef>
#include <memory>
#include <type_traits>
#include <utility>
namespace std {
template <class T>
struct _Unique_if {
typedef unique_ptr<T> _Single_object;
};
template <class T>
struct _Unique_if<T[]> {
typedef unique_ptr<T[]> _Unknown_bound;
};
template <class T, size_t N>
struct _Unique_if<T[N]> {
typedef void _Known_bound;
};
template <class T, class... Args>
typename _Unique_if<T>::_Single_object make_unique(Args &&... args) {
return unique_ptr<T>(new T(std::forward<Args>(args)...));
}
template <class T>
typename _Unique_if<T>::_Unknown_bound make_unique(size_t n) {
typedef typename remove_extent<T>::type U;
return unique_ptr<T>(new U[n]());
}
template <class T, class... Args>
typename _Unique_if<T>::_Known_bound make_unique(Args &&...) = delete;
} // namespace std
#endif

View File

@@ -0,0 +1,37 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2011. All Rights Reserved.
*/
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef __BUTTON_H__
#define __BUTTON_H__
#include "Buttons/Trigger.h"
#include "Commands/Command.h"
/**
* 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.
*
* 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.
*
* @author brad
*/
class Button : public Trigger {
public:
virtual void WhenPressed(Command *command);
virtual void WhileHeld(Command *command);
virtual void WhenReleased(Command *command);
virtual void CancelWhenPressed(Command *command);
virtual void ToggleWhenPressed(Command *command);
};
#endif

View File

@@ -0,0 +1,27 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2011. All Rights Reserved.
*/
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef __BUTTON_SCHEDULER_H__
#define __BUTTON_SCHEDULER_H__
class Trigger;
class Command;
class ButtonScheduler {
public:
ButtonScheduler(bool last, Trigger *button, Command *orders);
virtual ~ButtonScheduler() = default;
virtual void Execute() = 0;
void Start();
protected:
bool m_pressedLast;
Trigger *m_button;
Command *m_command;
};
#endif

View File

@@ -0,0 +1,26 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2011. All Rights Reserved.
*/
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef __CANCEL_BUTTON_SCHEDULER_H__
#define __CANCEL_BUTTON_SCHEDULER_H__
#include "Buttons/ButtonScheduler.h"
class Trigger;
class Command;
class CancelButtonScheduler : public ButtonScheduler {
public:
CancelButtonScheduler(bool last, Trigger *button, Command *orders);
virtual ~CancelButtonScheduler() = default;
virtual void Execute();
private:
bool pressedLast;
};
#endif

View File

@@ -0,0 +1,23 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2011. All Rights Reserved.
*/
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef __HELD_BUTTON_SCHEDULER_H__
#define __HELD_BUTTON_SCHEDULER_H__
#include "Buttons/ButtonScheduler.h"
class Trigger;
class Command;
class HeldButtonScheduler : public ButtonScheduler {
public:
HeldButtonScheduler(bool last, Trigger *button, Command *orders);
virtual ~HeldButtonScheduler() = default;
virtual void Execute();
};
#endif

View File

@@ -0,0 +1,29 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2011. All Rights Reserved.
*/
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef __INTERNAL_BUTTON_H__
#define __INTERNAL_BUTTON_H__
#include "Buttons/Button.h"
class InternalButton : public Button {
public:
InternalButton() = default;
InternalButton(bool inverted);
virtual ~InternalButton() = default;
void SetInverted(bool inverted);
void SetPressed(bool pressed);
virtual bool Get();
private:
bool m_pressed = false;
bool m_inverted = false;
};
#endif

View File

@@ -0,0 +1,26 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2011. All Rights Reserved.
*/
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef __JOYSTICK_BUTTON_H__
#define __JOYSTICK_BUTTON_H__
#include "GenericHID.h"
#include "Buttons/Button.h"
class JoystickButton : public Button {
public:
JoystickButton(GenericHID *joystick, int buttonNumber);
virtual ~JoystickButton() = default;
virtual bool Get();
private:
GenericHID *m_joystick;
int m_buttonNumber;
};
#endif

View File

@@ -0,0 +1,28 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2011. All Rights Reserved.
*/
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef __NETWORK_BUTTON_H__
#define __NETWORK_BUTTON_H__
#include "Buttons/Button.h"
#include <string>
#include <memory>
class NetworkButton : public Button {
public:
NetworkButton(const std::string &tableName, const std::string &field);
NetworkButton(std::shared_ptr<ITable> table, const std::string &field);
virtual ~NetworkButton() = default;
virtual bool Get();
private:
std::shared_ptr<ITable> m_netTable;
std::string m_field;
};
#endif

View File

@@ -0,0 +1,23 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2011. All Rights Reserved.
*/
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef __PRESSED_BUTTON_SCHEDULER_H__
#define __PRESSED_BUTTON_SCHEDULER_H__
#include "Buttons/ButtonScheduler.h"
class Trigger;
class Command;
class PressedButtonScheduler : public ButtonScheduler {
public:
PressedButtonScheduler(bool last, Trigger *button, Command *orders);
virtual ~PressedButtonScheduler() = default;
virtual void Execute();
};
#endif

View File

@@ -0,0 +1,23 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2011. All Rights Reserved.
*/
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef __RELEASED_BUTTON_SCHEDULER_H__
#define __RELEASED_BUTTON_SCHEDULER_H__
#include "Buttons/ButtonScheduler.h"
class Trigger;
class Command;
class ReleasedButtonScheduler : public ButtonScheduler {
public:
ReleasedButtonScheduler(bool last, Trigger *button, Command *orders);
virtual ~ReleasedButtonScheduler() = default;
virtual void Execute();
};
#endif

View File

@@ -0,0 +1,26 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2011. All Rights Reserved.
*/
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef __TOGGLE_BUTTON_SCHEDULER_H__
#define __TOGGLE_BUTTON_SCHEDULER_H__
#include "Buttons/ButtonScheduler.h"
class Trigger;
class Command;
class ToggleButtonScheduler : public ButtonScheduler {
public:
ToggleButtonScheduler(bool last, Trigger *button, Command *orders);
virtual ~ToggleButtonScheduler() = default;
virtual void Execute();
private:
bool pressedLast;
};
#endif

View File

@@ -0,0 +1,53 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2011. All Rights Reserved.
*/
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef __TRIGGER_H__
#define __TRIGGER_H__
#include "SmartDashboard/Sendable.h"
#include <memory>
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
* link the trigger button of a joystick to a "score" command or an encoder
* 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
* only have to write the {@link Trigger#Get()} method to get the full
* functionality
* of the Trigger class.
*
* @author Brad Miller, Joe Grinstead
*/
class Trigger : public Sendable {
public:
Trigger() = default;
virtual ~Trigger() = default;
bool Grab();
virtual bool Get() = 0;
void WhenActive(Command *command);
void WhileActive(Command *command);
void WhenInactive(Command *command);
void CancelWhenActive(Command *command);
void ToggleWhenActive(Command *command);
virtual void InitTable(std::shared_ptr<ITable> table);
virtual std::shared_ptr<ITable> GetTable() const;
virtual std::string GetSmartDashboardType() const;
protected:
std::shared_ptr<ITable> m_table = nullptr;
};
#endif

View File

@@ -0,0 +1,190 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2011. All Rights Reserved.
*/
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef __COMMAND_H__
#define __COMMAND_H__
#include "ErrorBase.h"
#include "SmartDashboard/NamedSendable.h"
#include "tables/ITableListener.h"
#include <set>
#include <string>
#include <memory>
class CommandGroup;
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>
*
* <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>
*
* <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>
*
* @see CommandGroup
* @see Subsystem
*/
class Command : public ErrorBase, public NamedSendable, public ITableListener {
friend class CommandGroup;
friend class Scheduler;
public:
Command();
Command(const std::string &name);
Command(double timeout);
Command(const std::string &name, double timeout);
virtual ~Command();
double TimeSinceInitialized() const;
void Requires(Subsystem *s);
bool IsCanceled() const;
void Start();
bool Run();
void Cancel();
bool IsRunning() const;
bool IsInterruptible() const;
void SetInterruptible(bool interruptible);
bool DoesRequire(Subsystem *subsystem) const;
typedef std::set<Subsystem *> SubsystemSet;
SubsystemSet GetRequirements() const;
CommandGroup *GetGroup() const;
void SetRunWhenDisabled(bool run);
bool WillRunWhenDisabled() const;
int GetID() const;
protected:
void SetTimeout(double timeout);
bool IsTimedOut() const;
bool AssertUnlocked(const std::string &message);
void SetParent(CommandGroup *parent);
/**
* The initialize method is called the first time this Command is run after
* being started.
*/
virtual void Initialize() = 0;
/**
* The execute method is called repeatedly until this Command either finishes
* or is canceled.
*/
virtual void Execute() = 0;
/**
* Returns whether this command is finished.
* If it is, then the command will be removed
* and {@link Command#end() end()} will be called.
*
* <p>It may be useful for a team to reference the {@link Command#isTimedOut()
* isTimedOut()} method
* for time-sensitive commands.</p>
* @return whether this command is finished.
* @see Command#isTimedOut() isTimedOut()
*/
virtual bool IsFinished() = 0;
/**
* Called when the command ended peacefully. This is where you may want
* to wrap up loose ends, like shutting off a motor that was being used
* in the command.
*/
virtual void End() = 0;
/**
* Called when the command ends because somebody called {@link
*Command#cancel() cancel()}
* or another command shared the same requirements as this one, and booted
* it out.
*
* <p>This is where you may want
* to wrap up loose ends, like shutting off a motor that was being used
* in the command.</p>
*
* <p>Generally, it is useful to simply call the {@link Command#end() end()}
* method
* within this method</p>
*/
virtual void Interrupted() = 0;
virtual void _Initialize();
virtual void _Interrupted();
virtual void _Execute();
virtual void _End();
virtual void _Cancel();
private:
void LockChanges();
/*synchronized*/ void Removed();
void StartRunning();
void StartTiming();
/** The name of this command */
std::string m_name;
/** 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) */
double m_timeout;
/** Whether or not this command has been initialized */
bool m_initialized = false;
/** The requirements (or null if no requirements) */
SubsystemSet m_requirements;
/** Whether or not it is running */
bool m_running = false;
/** Whether or not it is interruptible*/
bool m_interruptible = true;
/** Whether or not it has been canceled */
bool m_canceled = false;
/** Whether or not it has been locked */
bool m_locked = false;
/** Whether this command should run when the robot is disabled */
bool m_runWhenDisabled = false;
/** The {@link CommandGroup} this is in */
CommandGroup *m_parent = nullptr;
int m_commandID = m_commandCounter++;
static int m_commandCounter;
public:
virtual std::string GetName() const;
virtual void InitTable(std::shared_ptr<ITable> table);
virtual std::shared_ptr<ITable> GetTable() const;
virtual std::string GetSmartDashboardType() const;
virtual void ValueChanged(ITable* source, llvm::StringRef key,
std::shared_ptr<nt::Value> value, bool isNew);
protected:
std::shared_ptr<ITable> m_table = nullptr;
};
#endif

View File

@@ -0,0 +1,74 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2011. All Rights Reserved.
*/
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef __COMMAND_GROUP_H__
#define __COMMAND_GROUP_H__
#include "Commands/Command.h"
#include "Commands/CommandGroupEntry.h"
#include <list>
#include <vector>
/**
* A {@link 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>
*
* <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>
*
* <p>CommandGroups can also execute commands in parallel, simply by adding them
* using {@link CommandGroup#AddParallel(Command) AddParallel(...)}.</p>
*
* @see Command
* @see Subsystem
*/
class CommandGroup : public Command {
public:
CommandGroup() = default;
CommandGroup(const std::string &name);
virtual ~CommandGroup() = default;
void AddSequential(Command *command);
void AddSequential(Command *command, double timeout);
void AddParallel(Command *command);
void AddParallel(Command *command, double timeout);
bool IsInterruptible() const;
int GetSize() const;
protected:
virtual void Initialize();
virtual void Execute();
virtual bool IsFinished();
virtual void End();
virtual void Interrupted();
virtual void _Initialize();
virtual void _Interrupted();
virtual void _Execute();
virtual void _End();
private:
void CancelConflicts(Command *command);
/** The commands in this group (stored in entries) */
std::vector<CommandGroupEntry> m_commands;
/** The active children in this group (stored in entries) */
std::list<CommandGroupEntry> m_children;
/** The current command, -1 signifies that none have been run */
int m_currentCommandIndex = -1;
};
#endif

View File

@@ -0,0 +1,30 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2011. All Rights Reserved.
*/
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef __COMMAND_GROUP_ENTRY_H__
#define __COMMAND_GROUP_ENTRY_H__
class Command;
class CommandGroupEntry {
public:
typedef enum {
kSequence_InSequence,
kSequence_BranchPeer,
kSequence_BranchChild
} Sequence;
CommandGroupEntry() = default;
CommandGroupEntry(Command *command, Sequence state, double timeout = -1.0);
bool IsTimedOut() const;
double m_timeout;
Command *m_command = nullptr;
Sequence m_state = kSequence_InSequence;
};
#endif

View File

@@ -0,0 +1,58 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2011. All Rights Reserved.
*/
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef __PID_COMMAND_H__
#define __PID_COMMAND_H__
#include "Commands/Command.h"
#include "PIDController.h"
#include "PIDSource.h"
#include "PIDOutput.h"
#include <memory>
class PIDCommand : public Command, public PIDOutput, public PIDSource {
public:
PIDCommand(const std::string &name, double p, double i, double d);
PIDCommand(const std::string &name, double p, double i, double d, double period);
PIDCommand(const std::string &name, double p, double i, double d, double f,
double period);
PIDCommand(double p, double i, double d);
PIDCommand(double p, double i, double d, double period);
PIDCommand(double p, double i, double d, double f, double period);
virtual ~PIDCommand() = default;
void SetSetpointRelative(double deltaSetpoint);
// PIDOutput interface
virtual void PIDWrite(float output);
// PIDSource interface
virtual double PIDGet();
protected:
std::shared_ptr<PIDController> GetPIDController() const;
virtual void _Initialize();
virtual void _Interrupted();
virtual void _End();
void SetSetpoint(double setpoint);
double GetSetpoint() const;
double GetPosition();
virtual double ReturnPIDInput() = 0;
virtual void UsePIDOutput(double output) = 0;
private:
/** The internal {@link PIDController} */
std::shared_ptr<PIDController> m_controller;
public:
virtual void InitTable(std::shared_ptr<ITable> table);
virtual std::string GetSmartDashboardType() const;
};
#endif

View File

@@ -0,0 +1,76 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2011. All Rights Reserved.
*/
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef __PID_SUBSYSTEM_H__
#define __PID_SUBSYSTEM_H__
#include "Commands/Subsystem.h"
#include "PIDController.h"
#include "PIDSource.h"
#include "PIDOutput.h"
#include <memory>
/**
* 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>
*
*/
class PIDSubsystem : public Subsystem, public PIDOutput, public PIDSource {
public:
PIDSubsystem(const std::string &name, double p, double i, double d);
PIDSubsystem(const std::string &name, double p, double i, double d, double f);
PIDSubsystem(const std::string &name, double p, double i, double d, double f,
double period);
PIDSubsystem(double p, double i, double d);
PIDSubsystem(double p, double i, double d, double f);
PIDSubsystem(double p, double i, double d, double f, double period);
virtual ~PIDSubsystem() = default;
void Enable();
void Disable();
// PIDOutput interface
virtual void PIDWrite(float output);
// PIDSource interface
virtual double PIDGet();
void SetSetpoint(double setpoint);
void SetSetpointRelative(double deltaSetpoint);
void SetInputRange(float minimumInput, float maximumInput);
void SetOutputRange(float minimumOutput, float maximumOutput);
double GetSetpoint();
double GetPosition();
double GetRate();
virtual void SetAbsoluteTolerance(float absValue);
virtual void SetPercentTolerance(float percent);
virtual bool OnTarget() const;
protected:
std::shared_ptr<PIDController> GetPIDController();
virtual double ReturnPIDInput() = 0;
virtual void UsePIDOutput(double output) = 0;
private:
/** The internal {@link PIDController} */
std::shared_ptr<PIDController> m_controller;
public:
virtual void InitTable(std::shared_ptr<ITable> table);
virtual std::string GetSmartDashboardType() const;
};
#endif

View File

@@ -0,0 +1,30 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2011. All Rights Reserved.
*/
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef __PRINT_COMMAND_H__
#define __PRINT_COMMAND_H__
#include "Commands/Command.h"
#include <string>
class PrintCommand : public Command {
public:
PrintCommand(const std::string &message);
virtual ~PrintCommand() = default;
protected:
virtual void Initialize();
virtual void Execute();
virtual bool IsFinished();
virtual void End();
virtual void Interrupted();
private:
std::string m_message;
};
#endif

View File

@@ -0,0 +1,70 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2011. All Rights Reserved.
*/
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef __SCHEDULER_H__
#define __SCHEDULER_H__
#include "Commands/Command.h"
#include "ErrorBase.h"
#include "SmartDashboard/NamedSendable.h"
#include "networktables/NetworkTable.h"
#include "SmartDashboard/SmartDashboard.h"
#include <list>
#include <map>
#include <memory>
#include <set>
#include <string>
#include <vector>
#include "HAL/cpp/priority_mutex.h"
class ButtonScheduler;
class Subsystem;
class Scheduler : public ErrorBase, public NamedSendable {
public:
static Scheduler *GetInstance();
void AddCommand(Command *command);
void AddButton(ButtonScheduler *button);
void RegisterSubsystem(Subsystem *subsystem);
void Run();
void Remove(Command *command);
void RemoveAll();
void ResetAll();
void SetEnabled(bool enabled);
void UpdateTable();
std::string GetSmartDashboardType() const;
void InitTable(std::shared_ptr<ITable> subTable);
std::shared_ptr<ITable> GetTable() const;
std::string GetName() const;
std::string GetType() const;
private:
Scheduler();
virtual ~Scheduler() = default;
void ProcessCommandAddition(Command *command);
Command::SubsystemSet m_subsystems;
priority_mutex m_buttonsLock;
typedef std::vector<ButtonScheduler *> ButtonVector;
ButtonVector m_buttons;
typedef std::vector<Command *> CommandVector;
priority_mutex m_additionsLock;
CommandVector m_additions;
typedef std::set<Command *> CommandSet;
CommandSet m_commands;
bool m_adding = false;
bool m_enabled = true;
std::vector<std::string> commands;
std::vector<double> ids;
std::vector<double> toCancel;
std::shared_ptr<ITable> m_table = nullptr;
bool m_runningCommandsChanged = false;
};
#endif

View File

@@ -0,0 +1,29 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2011. All Rights Reserved.
*/
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef __START_COMMAND_H__
#define __START_COMMAND_H__
#include "Commands/Command.h"
class StartCommand : public Command {
public:
StartCommand(Command *commandToStart);
virtual ~StartCommand() = default;
protected:
virtual void Initialize();
virtual void Execute();
virtual bool IsFinished();
virtual void End();
virtual void Interrupted();
private:
Command *m_commandToFork;
};
#endif

View File

@@ -0,0 +1,50 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2011. All Rights Reserved.
*/
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef __SUBSYSTEM_H__
#define __SUBSYSTEM_H__
#include "ErrorBase.h"
#include "SmartDashboard/NamedSendable.h"
#include <string>
#include <memory>
class Command;
class Subsystem : public ErrorBase, public NamedSendable {
friend class Scheduler;
public:
Subsystem(const std::string &name);
virtual ~Subsystem() = default;
void SetDefaultCommand(Command *command);
Command *GetDefaultCommand();
void SetCurrentCommand(Command *command);
Command *GetCurrentCommand() const;
virtual void InitDefaultCommand();
private:
void ConfirmCommand();
Command *m_currentCommand = nullptr;
bool m_currentCommandChanged = true;
Command *m_defaultCommand = nullptr;
std::string m_name;
bool m_initializedDefaultCommand = false;
public:
virtual std::string GetName() const;
virtual void InitTable(std::shared_ptr<ITable> table);
virtual std::shared_ptr<ITable> GetTable() const;
virtual std::string GetSmartDashboardType() const;
protected:
std::shared_ptr<ITable> m_table = nullptr;
};
#endif

View File

@@ -0,0 +1,27 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2011. All Rights Reserved.
*/
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef __WAIT_COMMAND_H__
#define __WAIT_COMMAND_H__
#include "Commands/Command.h"
class WaitCommand : public Command {
public:
WaitCommand(double timeout);
WaitCommand(const std::string &name, double timeout);
virtual ~WaitCommand() = default;
protected:
virtual void Initialize();
virtual void Execute();
virtual bool IsFinished();
virtual void End();
virtual void Interrupted();
};
#endif

View File

@@ -0,0 +1,27 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2011. All Rights Reserved.
*/
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef __WAIT_FOR_CHILDREN_H__
#define __WAIT_FOR_CHILDREN_H__
#include "Commands/Command.h"
class WaitForChildren : public Command {
public:
WaitForChildren(double timeout);
WaitForChildren(const std::string &name, double timeout);
virtual ~WaitForChildren() = default;
protected:
virtual void Initialize();
virtual void Execute();
virtual bool IsFinished();
virtual void End();
virtual void Interrupted();
};
#endif

View File

@@ -0,0 +1,30 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2011. All Rights Reserved.
*/
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef __WAIT_UNTIL_COMMAND_H__
#define __WAIT_UNTIL_COMMAND_H__
#include "Commands/Command.h"
class WaitUntilCommand : public Command {
public:
WaitUntilCommand(double time);
WaitUntilCommand(const std::string &name, double time);
virtual ~WaitUntilCommand() = default;
protected:
virtual void Initialize();
virtual void Execute();
virtual bool IsFinished();
virtual void End();
virtual void Interrupted();
private:
double m_time;
};
#endif

View File

@@ -0,0 +1,30 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#pragma once
/**
* 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.
*/
class Controller {
public:
virtual ~Controller() = default;
/**
* Allows the control loop to run
*/
virtual void Enable() = 0;
/**
* Stops the control loop from running until explicitly re-enabled by calling
* enable()
*/
virtual void Disable() = 0;
};

View File

@@ -0,0 +1,58 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved.
*/
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#pragma once
#include "Base.h"
#ifdef _WIN32
#include <Windows.h>
//Windows.h defines #define GetMessage GetMessageW, which is stupid and we don't want it.
#undef GetMessage
#endif
#include <string>
#include <stdint.h>
// Forward declarations
class ErrorBase;
/**
* Error object represents a library error.
*/
class Error {
public:
typedef int32_t Code;
Error() = default;
Error(const Error&) = delete;
Error& operator=(const Error&) = delete;
void Clone(const Error& error);
Code GetCode() const;
std::string GetMessage() const;
std::string GetFilename() const;
std::string GetFunction() const;
uint32_t GetLineNumber() const;
const ErrorBase* GetOriginatingObject() const;
double GetTimestamp() const;
void Clear();
void Set(Code code, const std::string& contextMessage,
const std::string& filename, const std::string& function,
uint32_t lineNumber, const ErrorBase* originatingObject);
private:
void Report();
Code m_code = 0;
std::string m_message;
std::string m_filename;
std::string m_function;
uint32_t m_lineNumber = 0;
const ErrorBase* m_originatingObject = nullptr;
double m_timestamp = 0.0;
};

View File

@@ -0,0 +1,98 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved.
*/
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#pragma once
#include "Base.h"
#include "Error.h"
#include "HAL/cpp/priority_mutex.h"
#define wpi_setErrnoErrorWithContext(context) \
(this->SetErrnoError((context), __FILE__, __FUNCTION__, __LINE__))
#define wpi_setErrnoError() (wpi_setErrnoErrorWithContext(""))
#define wpi_setImaqErrorWithContext(code, context) \
(this->SetImaqError((code), (context), __FILE__, __FUNCTION__, __LINE__))
#define wpi_setErrorWithContext(code, context) \
(this->SetError((code), (context), __FILE__, __FUNCTION__, __LINE__))
#define wpi_setError(code) (wpi_setErrorWithContext(code, ""))
#define wpi_setStaticErrorWithContext(object, code, context) \
(object->SetError((code), (context), __FILE__, __FUNCTION__, __LINE__))
#define wpi_setStaticError(object, code) \
(wpi_setStaticErrorWithContext(object, code, ""))
#define wpi_setGlobalErrorWithContext(code, context) \
(ErrorBase::SetGlobalError((code), (context), __FILE__, __FUNCTION__, \
__LINE__))
#define wpi_setGlobalError(code) (wpi_setGlobalErrorWithContext(code, ""))
#define wpi_setWPIErrorWithContext(error, context) \
(this->SetWPIError((wpi_error_s_##error), (wpi_error_value_##error), \
(context), __FILE__, __FUNCTION__, __LINE__))
#define wpi_setWPIError(error) (wpi_setWPIErrorWithContext(error, ""))
#define wpi_setStaticWPIErrorWithContext(object, error, context) \
(object->SetWPIError((wpi_error_s_##error), (context), __FILE__, \
__FUNCTION__, __LINE__))
#define wpi_setStaticWPIError(object, error) \
(wpi_setStaticWPIErrorWithContext(object, error, ""))
#define wpi_setGlobalWPIErrorWithContext(error, context) \
(ErrorBase::SetGlobalWPIError((wpi_error_s_##error), (context), __FILE__, \
__FUNCTION__, __LINE__))
#define wpi_setGlobalWPIError(error) \
(wpi_setGlobalWPIErrorWithContext(error, ""))
/**
* 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
*/
class ErrorBase {
// TODO: Consider initializing instance variables and cleanup in destructor
public:
ErrorBase() = default;
virtual ~ErrorBase() = default;
ErrorBase(const ErrorBase&) = delete;
ErrorBase& operator=(const ErrorBase&) = delete;
virtual Error& GetError();
virtual const Error& GetError() const;
virtual void SetErrnoError(const std::string& contextMessage,
const std::string& filename,
const std::string& function,
uint32_t lineNumber) const;
virtual void SetImaqError(int success, const std::string& contextMessage,
const std::string& filename,
const std::string& function,
uint32_t lineNumber) const;
virtual void SetError(Error::Code code, const std::string& contextMessage,
const std::string& filename,
const std::string& function, uint32_t lineNumber) const;
virtual void SetWPIError(const std::string& errorMessage, Error::Code code,
const std::string& contextMessage,
const std::string& filename,
const std::string& function,
uint32_t lineNumber) const;
virtual void CloneError(const ErrorBase& rhs) const;
virtual void ClearError() const;
virtual bool StatusIsFatal() const;
static void SetGlobalError(Error::Code code,
const std::string& contextMessage,
const std::string& filename,
const std::string& function, uint32_t lineNumber);
static void SetGlobalWPIError(const std::string& errorMessage,
const std::string& contextMessage,
const std::string& filename,
const std::string& function,
uint32_t lineNumber);
static Error& GetGlobalError();
protected:
mutable Error m_error;
// TODO: Replace globalError with a global list of all errors.
static priority_mutex _globalErrorMutex;
static Error _globalError;
};

View File

@@ -0,0 +1,32 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved.
*/
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#pragma once
#include <stdint.h>
/** GenericHID Interface
*/
class GenericHID {
public:
enum JoystickHand { kLeftHand = 0, kRightHand = 1 };
virtual ~GenericHID() = default;
virtual float GetX(JoystickHand hand = kRightHand) const = 0;
virtual float GetY(JoystickHand hand = kRightHand) const = 0;
virtual float GetZ() const = 0;
virtual float GetTwist() const = 0;
virtual float GetThrottle() const = 0;
virtual float GetRawAxis(uint32_t axis) const = 0;
virtual bool GetTrigger(JoystickHand hand = kRightHand) const = 0;
virtual bool GetTop(JoystickHand hand = kRightHand) const = 0;
virtual bool GetBumper(JoystickHand hand = kRightHand) const = 0;
virtual bool GetRawButton(uint32_t button) const = 0;
virtual int GetPOV(uint32_t pov = 0) const = 0;
};

View File

@@ -0,0 +1,23 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#pragma once
class HLUsageReportingInterface {
public:
virtual ~HLUsageReportingInterface() = default;
virtual void ReportScheduler() = 0;
virtual void ReportSmartDashboard() = 0;
};
class HLUsageReporting {
private:
static HLUsageReportingInterface* impl;
public:
static void SetImplementation(HLUsageReportingInterface* i);
static void ReportScheduler();
static void ReportSmartDashboard();
};

View File

@@ -0,0 +1,87 @@
#ifndef _LIVE_WINDOW_H
#define _LIVE_WINDOW_H
#include "LiveWindow/LiveWindowSendable.h"
#include "tables/ITable.h"
#include "Commands/Scheduler.h"
#include <vector>
#include <map>
#include <memory>
struct LiveWindowComponent {
std::string subsystem;
std::string name;
bool isSensor;
LiveWindowComponent() = default;
LiveWindowComponent(std::string subsystem, std::string name, bool isSensor) {
this->subsystem = subsystem;
this->name = name;
this->isSensor = isSensor;
}
};
/**
* The LiveWindow class is the public interface for putting sensors and
* actuators
* on the LiveWindow.
*
* @author Brad Miller
*/
class LiveWindow {
public:
static LiveWindow *GetInstance();
void Run();
DEPRECATED(
"Raw pointers are deprecated; pass the component using shared_ptr "
"instead.")
void AddSensor(const std::string &subsystem, const std::string &name,
LiveWindowSendable *component);
void AddSensor(const std::string &subsystem, const std::string &name,
LiveWindowSendable &component);
void AddSensor(const std::string &subsystem, const std::string &name,
std::shared_ptr<LiveWindowSendable> component);
DEPRECATED(
"Raw pointers are deprecated; pass the component using shared_ptr "
"instead.")
void AddActuator(const std::string &subsystem, const std::string &name,
LiveWindowSendable *component);
void AddActuator(const std::string &subsystem, const std::string &name,
LiveWindowSendable &component);
void AddActuator(const std::string &subsystem, const std::string &name,
std::shared_ptr<LiveWindowSendable> component);
DEPRECATED(
"Raw pointers are deprecated; pass the component using shared_ptr "
"instead.")
void AddSensor(std::string type, int channel, LiveWindowSendable *component);
void AddActuator(std::string type, int channel,
LiveWindowSendable *component);
void AddActuator(std::string type, int module, int channel,
LiveWindowSendable *component);
bool IsEnabled() const { return m_enabled; }
void SetEnabled(bool enabled);
protected:
LiveWindow();
virtual ~LiveWindow() = default;
private:
void UpdateValues();
void Initialize();
void InitializeLiveWindowComponents();
std::vector<std::shared_ptr<LiveWindowSendable>> m_sensors;
std::map<std::shared_ptr<LiveWindowSendable>, LiveWindowComponent> m_components;
std::shared_ptr<ITable> m_liveWindowTable;
std::shared_ptr<ITable> m_statusTable;
Scheduler *m_scheduler;
bool m_enabled = false;
bool m_firstTime = true;
};
#endif

View File

@@ -0,0 +1,38 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) Patrick Plenefisch 2012. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef LIVEWINDOWSENDABLE_H_
#define LIVEWINDOWSENDABLE_H_
#include "SmartDashboard/Sendable.h"
/**
* Live Window Sendable is a special type of object sendable to the live window.
*
* @author Patrick Plenefisch
*/
class LiveWindowSendable : public Sendable {
public:
/**
* 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.
*/
virtual void StartLiveWindowMode() = 0;
/**
* Stop having this sendable object automatically respond to value
* changes.
*/
virtual void StopLiveWindowMode() = 0;
};
#endif /* LIVEWINDOWSENDABLE_H_ */

View File

@@ -0,0 +1,13 @@
#ifndef _LIVE_WINDOW_STATUS_LISTENER_H
#define _LIVE_WINDOW_STATUS_LISTENER_H
#include "tables/ITable.h"
#include "tables/ITableListener.h"
class LiveWindowStatusListener : public ITableListener {
public:
virtual void ValueChanged(ITable* source, llvm::StringRef key,
std::shared_ptr<nt::Value> value, bool isNew);
};
#endif

View File

@@ -0,0 +1,56 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved.
*/
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#pragma once
#include "ErrorBase.h"
#include "HAL/cpp/priority_mutex.h"
#include <thread>
#include <atomic>
typedef void (*TimerEventHandler)(void *param);
class Notifier : public ErrorBase {
public:
Notifier(TimerEventHandler handler, void *param = nullptr);
virtual ~Notifier();
Notifier(const Notifier&) = delete;
Notifier& operator=(const Notifier&) = delete;
void StartSingle(double delay);
void StartPeriodic(double period);
void Stop();
private:
static Notifier *timerQueueHead;
static priority_recursive_mutex queueMutex;
static void *m_notifier;
static int refcount;
static void ProcessQueue(
uint32_t mask, void *params); // process the timer queue on a timer event
static void
UpdateAlarm(); // update the FPGA alarm since the queue has changed
void InsertInQueue(
bool reschedule); // insert this Notifier in the timer queue
void DeleteFromQueue(); // delete this Notifier from the timer queue
TimerEventHandler m_handler; // address of the handler
void *m_param; // a parameter to pass to the handler
double m_period = 0; // the relative time (either periodic or single)
double m_expirationTime = 0; // absolute expiration time for the current event
Notifier *m_nextEvent = nullptr; // next Nofifier event
bool m_periodic = false; // true if this is a periodic event
bool m_queued = false; // indicates if this entry is queued
priority_mutex m_handlerMutex; // held by interrupt manager task while
// handler call is in progress
#ifdef FRC_SIMULATOR
static std::thread m_task;
static std::atomic<bool> m_stopped;
#endif
static void Run();
};

View File

@@ -0,0 +1,133 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved.
*/
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#pragma once
#include "Base.h"
#include "Controller.h"
#include "LiveWindow/LiveWindow.h"
#include "PIDInterface.h"
#include "PIDSource.h"
#include "Notifier.h"
#include "HAL/cpp/priority_mutex.h"
#include <memory>
#include <atomic>
#include <queue>
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
*/
class PIDController : public LiveWindowSendable,
public PIDInterface,
public ITableListener {
public:
PIDController(float p, float i, float d, PIDSource *source, PIDOutput *output,
float period = 0.05);
PIDController(float p, float i, float d, float f, PIDSource *source,
PIDOutput *output, float period = 0.05);
virtual ~PIDController();
PIDController(const PIDController&) = delete;
PIDController& operator=(const PIDController) = delete;
virtual float Get() const;
virtual void SetContinuous(bool continuous = true);
virtual void SetInputRange(float minimumInput, float maximumInput);
virtual void SetOutputRange(float minimumOutput, float maximumOutput);
virtual void SetPID(double p, double i, double d) override;
virtual void SetPID(double p, double i, double d, double f);
virtual double GetP() const override;
virtual double GetI() const override;
virtual double GetD() const override;
virtual double GetF() const;
virtual void SetSetpoint(float setpoint) override;
virtual double GetSetpoint() const override;
virtual float GetError() const;
virtual float GetAvgError() const;
virtual void SetPIDSourceType(PIDSourceType pidSource);
virtual PIDSourceType GetPIDSourceType() const;
virtual void SetTolerance(float percent);
virtual void SetAbsoluteTolerance(float absValue);
virtual void SetPercentTolerance(float percentValue);
virtual void SetToleranceBuffer(unsigned buf = 1);
virtual bool OnTarget() const;
virtual void Enable() override;
virtual void Disable() override;
virtual bool IsEnabled() const override;
virtual void Reset() override;
virtual void InitTable(std::shared_ptr<ITable> table) override;
protected:
PIDSource *m_pidInput;
PIDOutput *m_pidOutput;
std::shared_ptr<ITable> m_table;
virtual void Calculate();
private:
float m_P; // factor for "proportional" control
float m_I; // factor for "integral" control
float m_D; // factor for "derivative" control
float m_F; // factor for "feed forward" control
float m_maximumOutput = 1.0; // |maximum output|
float m_minimumOutput = -1.0; // |minimum output|
float m_maximumInput = 0; // maximum input - limit setpoint to this
float m_minimumInput = 0; // minimum input - limit setpoint to this
bool m_continuous = false; // do the endpoints wrap around? eg. Absolute encoder
bool m_enabled = false; // is the pid controller enabled
bool m_destruct; // should the calculate thread stop running
float m_prevInput = 0; // the prior sensor input (used to compute velocity)
double m_totalError = 0; // the sum of the errors for use in the integral calc
enum {
kAbsoluteTolerance,
kPercentTolerance,
kNoTolerance
} m_toleranceType = kNoTolerance;
// the percetage or absolute error that is considered on target.
float m_tolerance = 0.05;
float m_setpoint = 0;
float m_error;
float m_result = 0;
float m_period;
// Length of buffer for averaging for tolerances.
std::atomic<unsigned> m_bufLength{1};
std::queue<double> m_buf;
double m_bufTotal = 0;
mutable priority_mutex m_mutex;
std::unique_ptr<Notifier> m_controlLoop;
void Initialize(float p, float i, float d, float f, PIDSource *source,
PIDOutput *output, float period = 0.05);
static void CallCalculate(void *controller);
virtual std::shared_ptr<ITable> GetTable() const override;
virtual std::string GetSmartDashboardType() const override;
virtual void ValueChanged(ITable *source, llvm::StringRef key,
std::shared_ptr<nt::Value> value,
bool isNew) override;
virtual void UpdateTable() override;
virtual void StartLiveWindowMode() override;
virtual void StopLiveWindowMode() override;
};

View File

@@ -0,0 +1,21 @@
#pragma once
#include "Base.h"
#include "Controller.h"
#include "LiveWindow/LiveWindow.h"
class PIDInterface : public Controller {
virtual void SetPID(double p, double i, double d) = 0;
virtual double GetP() const = 0;
virtual double GetI() const = 0;
virtual double GetD() const = 0;
virtual void SetSetpoint(float setpoint) = 0;
virtual double GetSetpoint() const = 0;
virtual void Enable() = 0;
virtual void Disable() = 0;
virtual bool IsEnabled() const = 0;
virtual void Reset() = 0;
};

View File

@@ -0,0 +1,20 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved.
*/
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#pragma once
#include "Base.h"
/**
* 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
*/
class PIDOutput {
public:
virtual void PIDWrite(float output) = 0;
};

View File

@@ -0,0 +1,25 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved.
*/
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#pragma once
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.
*/
class PIDSource {
public:
virtual void SetPIDSourceType(PIDSourceType pidSource);
PIDSourceType GetPIDSourceType() const;
virtual double PIDGet() = 0;
protected:
PIDSourceType m_pidSource = PIDSourceType::kDisplacement;
};

View File

@@ -0,0 +1,43 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved.
*/
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#pragma once
#include "ErrorBase.h"
#include <stdint.h>
#include <memory>
#include <vector>
#include "HAL/cpp/priority_mutex.h"
/**
* 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.
*
* 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.
*/
class Resource : public ErrorBase {
public:
virtual ~Resource() = default;
Resource(const Resource&) = delete;
Resource& operator=(const Resource&) = delete;
static void CreateResourceObject(std::unique_ptr<Resource>& r, uint32_t elements);
explicit Resource(uint32_t size);
uint32_t Allocate(const std::string &resourceDesc);
uint32_t Allocate(uint32_t index, const std::string &resourceDesc);
void Free(uint32_t index);
private:
std::vector<bool> m_isAllocated;
priority_recursive_mutex m_allocateLock;
static priority_recursive_mutex m_createLock;
};

View File

@@ -0,0 +1,32 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#pragma once
#include <memory>
class RobotStateInterface {
public:
virtual ~RobotStateInterface() = default;
virtual bool IsDisabled() const = 0;
virtual bool IsEnabled() const = 0;
virtual bool IsOperatorControl() const = 0;
virtual bool IsAutonomous() const = 0;
virtual bool IsTest() const = 0;
};
class RobotState {
private:
static std::shared_ptr<RobotStateInterface> impl;
public:
static void SetImplementation(RobotStateInterface& i);
static void SetImplementation(std::shared_ptr<RobotStateInterface> i);
static bool IsDisabled();
static bool IsEnabled();
static bool IsOperatorControl();
static bool IsAutonomous();
static bool IsTest();
};

View File

@@ -0,0 +1,60 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved.
*/
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#pragma once
#include "ErrorBase.h"
#include <stdio.h>
#include "Base.h"
/**
* Base class for all sensors.
* Stores most recent status information as well as containing utility functions
* for checking
* channels and error processing.
*/
class SensorBase : public ErrorBase {
public:
SensorBase();
virtual ~SensorBase() = default;
SensorBase(const SensorBase&) = delete;
SensorBase& operator=(const SensorBase&) = delete;
static void DeleteSingletons();
static uint32_t GetDefaultSolenoidModule() { return 0; }
static bool CheckSolenoidModule(uint8_t moduleNumber);
static bool CheckDigitalChannel(uint32_t channel);
static bool CheckRelayChannel(uint32_t channel);
static bool CheckPWMChannel(uint32_t channel);
static bool CheckAnalogInput(uint32_t channel);
static bool CheckAnalogOutput(uint32_t channel);
static bool CheckSolenoidChannel(uint32_t channel);
static bool CheckPDPChannel(uint32_t channel);
static const uint32_t kDigitalChannels = 26;
static const uint32_t kAnalogInputs = 8;
static const uint32_t kAnalogOutputs = 2;
static const uint32_t kSolenoidChannels = 8;
static const uint32_t kSolenoidModules = 2;
static const uint32_t kPwmChannels = 20;
static const uint32_t kRelayChannels = 8;
static const uint32_t kPDPChannels = 16;
static const uint32_t kChassisSlots = 8;
protected:
void AddToSingletonList();
static void* m_digital_ports[kDigitalChannels];
static void* m_relay_ports[kRelayChannels];
static void* m_pwm_ports[kPwmChannels];
private:
static SensorBase* m_singletonList;
SensorBase* m_nextSingleton;
};

View File

@@ -0,0 +1,28 @@
/*
* NamedSendable.h
*
* Created on: Oct 19, 2012
* Author: Mitchell Wills
*/
#ifndef NAMEDSENDABLE_H_
#define NAMEDSENDABLE_H_
#include <string>
#include "SmartDashboard/Sendable.h"
/**
* The interface for sendable objects that gives the sendable a default name in
* the Smart Dashboard
*
*/
class NamedSendable : public Sendable {
public:
/**
* @return the name of the subtable of SmartDashboard that the Sendable object
* will use
*/
virtual std::string GetName() const = 0;
};
#endif /* NAMEDSENDABLE_H_ */

View File

@@ -0,0 +1,35 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2011. All Rights Reserved.
*/
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef __SMART_DASHBOARD_DATA__
#define __SMART_DASHBOARD_DATA__
#include <string>
#include <memory>
#include "tables/ITable.h"
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<ITable> subtable) = 0;
/**
* @return the table that is currently associated with the sendable
*/
virtual std::shared_ptr<ITable> GetTable() const = 0;
/**
* @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;
};
#endif

View File

@@ -0,0 +1,52 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2011. All Rights Reserved.
*/
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef __SENDABLE_CHOOSER_H__
#define __SENDABLE_CHOOSER_H__
#include "SmartDashboard/Sendable.h"
#include "tables/ITable.h"
#include <map>
#include <memory>
#include <string>
/**
* The {@link SendableChooser} class is a useful tool for presenting a selection
* of options
* to the {@link 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>
*
* @see SmartDashboard
*/
class SendableChooser : public Sendable {
public:
virtual ~SendableChooser() = default;
void AddObject(const std::string &name, void *object);
void AddDefault(const std::string &name, void *object);
void *GetSelected();
virtual void InitTable(std::shared_ptr<ITable> subtable);
virtual std::shared_ptr<ITable> GetTable() const;
virtual std::string GetSmartDashboardType() const;
private:
std::string m_defaultChoice;
std::map<std::string, void *> m_choices;
std::shared_ptr<ITable> m_table;
};
#endif

View File

@@ -0,0 +1,54 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2011. All Rights Reserved.
*/
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef __SMART_DASHBOARD_H__
#define __SMART_DASHBOARD_H__
#include "SensorBase.h"
#include <map>
#include <string>
#include "SmartDashboard/Sendable.h"
#include "SmartDashboard/NamedSendable.h"
#include "tables/ITable.h"
class SmartDashboard : public SensorBase {
public:
static void init();
static void PutData(llvm::StringRef key, Sendable *data);
static void PutData(NamedSendable *value);
static Sendable *GetData(llvm::StringRef keyName);
static void PutBoolean(llvm::StringRef keyName, bool value);
static bool GetBoolean(llvm::StringRef keyName, bool defaultValue);
static void PutNumber(llvm::StringRef keyName, double value);
static double GetNumber(llvm::StringRef keyName, double defaultValue);
static void PutString(llvm::StringRef keyName, llvm::StringRef value);
static std::string GetString(llvm::StringRef keyName,
llvm::StringRef defaultValue);
static void PutValue(llvm::StringRef keyName,
std::shared_ptr<nt::Value> value);
static std::shared_ptr<nt::Value> GetValue(llvm::StringRef keyName);
private:
virtual ~SmartDashboard() = default;
/** The {@link NetworkTable} used by {@link SmartDashboard} */
static std::shared_ptr<ITable> m_table;
/**
* A map linking tables in the SmartDashboard to the {@link
* SmartDashboardData} objects
* they came from.
*/
static std::map<std::shared_ptr<ITable> , Sendable *> m_tablesToData;
};
#endif

View File

@@ -0,0 +1,54 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved.
*/
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#pragma once
#include "ErrorBase.h"
#include "HAL/Task.hpp"
#include <iostream>
#include <string>
#include <thread>
#include <string>
/**
* Wrapper class around std::thread that allows changing thread priority
*/
class Task : public ErrorBase {
public:
static const uint32_t kDefaultPriority = 60;
Task() = default;
Task(const Task&) = delete;
Task& operator=(const Task&) = delete;
Task& operator=(Task&& task);
template <class Function, class... Args>
Task(const std::string& name, Function&& function, Args&&... args);
virtual ~Task();
bool joinable() const noexcept;
void join();
void detach();
std::thread::id get_id() const noexcept;
std::thread::native_handle_type native_handle();
bool Verify();
int32_t GetPriority();
bool SetPriority(int32_t priority);
std::string GetName() const;
private:
std::thread m_thread;
std::string m_taskName;
bool HandleError(STATUS results);
};
#include "Task.inc"

View File

@@ -0,0 +1,25 @@
#include "HAL/HAL.hpp"
#include <atomic>
/**
* Create and launch a task.
*
* @param name The name of the task. "FRC_" will be prepended to the task name.
* @param function The address of the function to run as the new task.
* @param args A parameter pack of arguments to pass to the function.
*/
template <class Function, class... Args>
Task::Task(const std::string& name, Function&& function, Args&&... args) {
m_taskName = "FRC_";
m_taskName += name;
std::cout << "[HAL] Starting task " << m_taskName << "..." << std::endl;
m_thread = std::thread(function, args...);
//TODO: lvuser does not currently have permissions to set the priority.
//SetPriority(kDefaultPriority);
static std::atomic<int32_t> instances{0};
instances++;
HALReport(HALUsageReporting::kResourceType_Task, instances, 0, m_taskName.c_str());
}

View File

@@ -0,0 +1,54 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved.
*/
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#pragma once
#include "Base.h"
#include "HAL/cpp/priority_mutex.h"
typedef void (*TimerInterruptHandler)(void *param);
void Wait(double seconds);
double GetClock();
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 the time when started and subtracts
* the current time
* whenever the value is requested.
*/
class Timer {
public:
Timer();
virtual ~Timer() = default;
Timer(const Timer&) = delete;
Timer& operator=(const Timer&) = delete;
double Get() const;
void Reset();
void Start();
void Stop();
bool HasPeriodPassed(double period);
static double GetFPGATimestamp();
static double GetPPCTimestamp();
static double GetMatchTime();
// The time, in seconds, at which the 32-bit FPGA timestamp rolls over to 0
static const double kRolloverTime;
private:
double m_startTime = 0.0;
double m_accumulatedTime = 0.0;
bool m_running = false;
mutable priority_mutex m_mutex;
};

View File

@@ -0,0 +1,51 @@
/*---------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved.
*/
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*---------------------------------------------------------------------------*/
#pragma once
/** @file
* Contains global utility functions
*/
#include <stdint.h>
#include <string>
#define wpi_assert(condition) \
wpi_assert_impl(condition, #condition, "", __FILE__, __LINE__, __FUNCTION__)
#define wpi_assertWithMessage(condition, message) \
wpi_assert_impl(condition, #condition, message, __FILE__, __LINE__, \
__FUNCTION__)
#define wpi_assertEqual(a, b) \
wpi_assertEqual_impl(a, b, #a, #b, "", __FILE__, __LINE__, __FUNCTION__)
#define wpi_assertEqualWithMessage(a, b, message) \
wpi_assertEqual_impl(a, b, #a, #b, message, __FILE__, __LINE__, __FUNCTION__)
#define wpi_assertNotEqual(a, b) \
wpi_assertNotEqual_impl(a, b, #a, #b, "", __FILE__, __LINE__, __FUNCTION__)
#define wpi_assertNotEqualWithMessage(a, b, message) \
wpi_assertNotEqual_impl(a, b, #a, #b, message, __FILE__, __LINE__, \
__FUNCTION__)
bool wpi_assert_impl(bool conditionValue, const std::string &conditionText,
const std::string &message, const std::string &fileName,
uint32_t lineNumber, const std::string &funcName);
bool wpi_assertEqual_impl(int valueA, int valueB, const std::string &valueAString,
const std::string &valueBString, const std::string &message,
const std::string &fileName, uint32_t lineNumber,
const std::string &funcName);
bool wpi_assertNotEqual_impl(int valueA, int valueB, const std::string &valueAString,
const std::string &valueBString, const std::string &message,
const std::string &fileName, uint32_t lineNumber,
const std::string &funcName);
void wpi_suspendOnAssertEnabled(bool enabled);
uint16_t GetFPGAVersion();
uint32_t GetFPGARevision();
uint32_t GetFPGATime();
bool GetUserButton();
std::string GetStackTrace(uint32_t offset);

View File

@@ -0,0 +1,102 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved.
*/
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#pragma once
#include "stdint.h"
#ifdef WPI_ERRORS_DEFINE_STRINGS
#define S(label, offset, message) \
const char * wpi_error_s_##label = message; \
const int32_t wpi_error_value_##label = offset
#else
#define S(label, offset, message) \
extern const char * wpi_error_s_##label; \
const int32_t wpi_error_value_##label = offset
#endif
/*
* 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");
S(NotAllocated, -2, "Attempting to free unallocated resource");
S(ResourceAlreadyAllocated, -3, "Attempted to reuse an allocated resource");
S(NoAvailableResources, -4, "No available resources to allocate");
S(NullParameter, -5, "A pointer parameter to a method is nullptr");
S(Timeout, -6, "A timeout has been exceeded");
S(CompassManufacturerError, -7, "Compass manufacturer doesn't match HiTechnic");
S(CompassTypeError, -8,
"Compass type doesn't match expected type for HiTechnic compass");
S(IncompatibleMode, -9, "The object is in an incompatible mode");
S(AnalogTriggerLimitOrderError, -10,
"AnalogTrigger limits error. Lower limit > Upper Limit");
S(AnalogTriggerPulseOutputError, -11,
"Attempted to read AnalogTrigger pulse output.");
S(TaskError, -12, "Task can't be started");
S(TaskIDError, -13, "Task error: Invalid ID.");
S(TaskDeletedError, -14, "Task error: Task already deleted.");
S(TaskOptionsError, -15, "Task error: Invalid options.");
S(TaskMemoryError, -16, "Task can't be started due to insufficient memory.");
S(TaskPriorityError, -17, "Task error: Invalid priority [1-255].");
S(DriveUninitialized, -18, "RobotDrive not initialized for the C interface");
S(CompressorNonMatching, -19,
"Compressor slot/channel doesn't match previous instance");
S(CompressorAlreadyDefined, -20, "Creating a second compressor instance");
S(CompressorUndefined, -21,
"Using compressor functions without defining compressor");
S(InconsistentArrayValueAdded, -22,
"When packing data into an array to the dashboard, not all values added were "
"of the same type.");
S(MismatchedComplexTypeClose, -23,
"When packing data to the dashboard, a Close for a complex type was called "
"without a matching Open.");
S(DashboardDataOverflow, -24,
"When packing data to the dashboard, too much data was packed and the buffer "
"overflowed.");
S(DashboardDataCollision, -25,
"The same buffer was used for packing data and for printing.");
S(EnhancedIOMissing, -26, "IO is not attached or Enhanced IO is not enabled.");
S(LineNotOutput, -27,
"Cannot SetDigitalOutput for a line not configured for output.");
S(ParameterOutOfRange, -28, "A parameter is out of range.");
S(SPIClockRateTooLow, -29, "SPI clock rate was below the minimum supported");
S(JaguarVersionError, -30, "Jaguar firmware version error");
S(JaguarMessageNotFound, -31, "Jaguar message not found");
S(NetworkTablesReadError, -40, "Error reading NetworkTables socket");
S(NetworkTablesBufferFull, -41, "Buffer full writing to NetworkTables socket");
S(NetworkTablesWrongType, -42,
"The wrong type was read from the NetworkTables entry");
S(NetworkTablesCorrupt, -43, "NetworkTables data stream is corrupt");
S(SmartDashboardMissingKey, -43, "SmartDashboard data does not exist");
S(CommandIllegalUse, -50, "Illegal use of Command");
S(UnsupportedInSimulation, -80, "Unsupported in simulation");
/*
* 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]");
S(CompressorTaskError, 3, "Compressor task won't start");
S(LoopTimingError, 4, "Digital module loop timing is not the expected value");
S(NonBinaryDigitalValue, 5, "Digital output value is not 0 or 1");
S(IncorrectBatteryChannel, 6,
"Battery measurement channel is not correct value");
S(BadJoystickIndex, 7, "Joystick index is out of range, should be 0-3");
S(BadJoystickAxis, 8, "Joystick axis or POV is out of range");
S(InvalidMotorIndex, 9, "Motor index is out of range, should be 0-3");
S(DriverStationTaskError, 10, "Driver Station task won't start");
S(EnhancedIOPWMPeriodOutOfRange, 11,
"Driver Station Enhanced IO PWM Output period out of range.");
S(SPIWriteNoMOSI, 12, "Cannot write to SPI port with no MOSI output");
S(SPIReadNoMISO, 13, "Cannot read from SPI port with no MISO input");
S(SPIReadNoData, 14, "No data available to read from SPI");
S(IncompatibleState, 15,
"Incompatible State: The operation cannot be completed");
#undef S

View File

@@ -0,0 +1,45 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2014. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#pragma once
/**
* Interface for 3-axis accelerometers
*/
class Accelerometer {
public:
virtual ~Accelerometer() = default;
enum Range { kRange_2G = 0, kRange_4G = 1, kRange_8G = 2, kRange_16G = 3 };
/**
* 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.
*/
virtual void SetRange(Range range) = 0;
/**
* 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
*
* @return The acceleration along the y axis in g-forces
*/
virtual double GetY() = 0;
/**
* Common interface for getting the z axis acceleration
*
* @return The acceleration along the z axis in g-forces
*/
virtual double GetZ() = 0;
};

View File

@@ -0,0 +1,54 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2014. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#pragma once
/**
* Interface for yaw rate gyros
*/
class Gyro {
public:
virtual ~Gyro() = default;
/**
* Initialize the gyro. Calibrate the gyro by running for a number of samples
* and computing the center value. Then use the center value as the
* Accumulator center value for subsequent measurements. It's important to
* make sure that the robot is not moving while the centering calculations are
* in progress, this is typically done when the robot is first turned on while
* it's sitting at rest before the competition starts.
*/
virtual void InitGyro() = 0;
/**
* Reset the gyro. Resets the gyro to a heading of zero. This can be used if
* there is significant drift in the gyro and it needs to be recalibrated
* after it has been running.
*/
virtual void Reset() = 0;
/**
* Return the actual angle in degrees that the robot is currently facing.
*
* The angle is based on the current accumulator value corrected by the
* oversampling rate, the gyro type and the A/D calibration values. The angle
* is continuous, that is it will continue from 360 to 361 degrees. This
* allows algorithms that wouldn't want to see a discontinuity in the gyro
* output as it sweeps past from 360 to 0 on the second time around.
*
* @return the current heading of the robot in degrees. This heading is based
* on integration of the returned rate from the gyro.
*/
virtual float GetAngle() const = 0;
/**
* Return the rate of rotation of the gyro
*
* The rate is based on the most recent reading of the gyro analog value
*
* @return the current rate in degrees per second
*/
virtual double GetRate() const = 0;
};

View File

@@ -0,0 +1,30 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved.
*/
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef INTERFACES_POTENTIOMETER_H
#define INTERFACES_POTENTIOMETER_H
#include "PIDSource.h"
/**
* Interface for potentiometers.
*/
class Potentiometer : public PIDSource {
public:
virtual ~Potentiometer() = default;
/**
* Common interface for getting the current value of a potentiometer.
*
* @return The current set speed. Value is between -1.0 and 1.0.
*/
virtual double Get() const = 0;
virtual void SetPIDSourceType(PIDSourceType pidSource) override;
};
#endif