Squashed 'third_party/allwpilib_2016/' content from commit 7f61816
Change-Id: If9d9245880859cdf580f5d7f77045135d0521ce7
git-subtree-dir: third_party/allwpilib_2016
git-subtree-split: 7f618166ed253a24629934fcf89c3decb0528a3b
diff --git a/wpilibc/shared/include/Base.h b/wpilibc/shared/include/Base.h
new file mode 100644
index 0000000..b1b806f
--- /dev/null
+++ b/wpilibc/shared/include/Base.h
@@ -0,0 +1,115 @@
+/*----------------------------------------------------------------------------*/
+/* 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
+
+// Provide std::decay_t when using GCC < 4.9
+#if defined(__GNUC__)
+ #if __GNUC__ == 4 && __GNUC_MINOR__ < 9
+ #include <type_traits>
+ namespace std {
+ template <class T> using decay_t = typename decay<T>::type;
+ }
+ #endif
+#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.
+template<class T>
+struct
+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
diff --git a/wpilibc/shared/include/Buttons/Button.h b/wpilibc/shared/include/Buttons/Button.h
new file mode 100644
index 0000000..8897569
--- /dev/null
+++ b/wpilibc/shared/include/Buttons/Button.h
@@ -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
diff --git a/wpilibc/shared/include/Buttons/ButtonScheduler.h b/wpilibc/shared/include/Buttons/ButtonScheduler.h
new file mode 100644
index 0000000..6222da7
--- /dev/null
+++ b/wpilibc/shared/include/Buttons/ButtonScheduler.h
@@ -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
diff --git a/wpilibc/shared/include/Buttons/CancelButtonScheduler.h b/wpilibc/shared/include/Buttons/CancelButtonScheduler.h
new file mode 100644
index 0000000..ba3ba24
--- /dev/null
+++ b/wpilibc/shared/include/Buttons/CancelButtonScheduler.h
@@ -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
diff --git a/wpilibc/shared/include/Buttons/HeldButtonScheduler.h b/wpilibc/shared/include/Buttons/HeldButtonScheduler.h
new file mode 100644
index 0000000..6dcd7a3
--- /dev/null
+++ b/wpilibc/shared/include/Buttons/HeldButtonScheduler.h
@@ -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
diff --git a/wpilibc/shared/include/Buttons/InternalButton.h b/wpilibc/shared/include/Buttons/InternalButton.h
new file mode 100644
index 0000000..fdad6f9
--- /dev/null
+++ b/wpilibc/shared/include/Buttons/InternalButton.h
@@ -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
diff --git a/wpilibc/shared/include/Buttons/JoystickButton.h b/wpilibc/shared/include/Buttons/JoystickButton.h
new file mode 100644
index 0000000..028efea
--- /dev/null
+++ b/wpilibc/shared/include/Buttons/JoystickButton.h
@@ -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
diff --git a/wpilibc/shared/include/Buttons/NetworkButton.h b/wpilibc/shared/include/Buttons/NetworkButton.h
new file mode 100644
index 0000000..9dcba58
--- /dev/null
+++ b/wpilibc/shared/include/Buttons/NetworkButton.h
@@ -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
diff --git a/wpilibc/shared/include/Buttons/PressedButtonScheduler.h b/wpilibc/shared/include/Buttons/PressedButtonScheduler.h
new file mode 100644
index 0000000..62ff7a8
--- /dev/null
+++ b/wpilibc/shared/include/Buttons/PressedButtonScheduler.h
@@ -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
diff --git a/wpilibc/shared/include/Buttons/ReleasedButtonScheduler.h b/wpilibc/shared/include/Buttons/ReleasedButtonScheduler.h
new file mode 100644
index 0000000..2a29981
--- /dev/null
+++ b/wpilibc/shared/include/Buttons/ReleasedButtonScheduler.h
@@ -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
diff --git a/wpilibc/shared/include/Buttons/ToggleButtonScheduler.h b/wpilibc/shared/include/Buttons/ToggleButtonScheduler.h
new file mode 100644
index 0000000..d79b456
--- /dev/null
+++ b/wpilibc/shared/include/Buttons/ToggleButtonScheduler.h
@@ -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
diff --git a/wpilibc/shared/include/Buttons/Trigger.h b/wpilibc/shared/include/Buttons/Trigger.h
new file mode 100644
index 0000000..3a05995
--- /dev/null
+++ b/wpilibc/shared/include/Buttons/Trigger.h
@@ -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;
+};
+
+#endif
diff --git a/wpilibc/shared/include/Commands/Command.h b/wpilibc/shared/include/Commands/Command.h
new file mode 100644
index 0000000..6ec5512
--- /dev/null
+++ b/wpilibc/shared/include/Commands/Command.h
@@ -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;
+};
+
+#endif
diff --git a/wpilibc/shared/include/Commands/CommandGroup.h b/wpilibc/shared/include/Commands/CommandGroup.h
new file mode 100644
index 0000000..7f289ca
--- /dev/null
+++ b/wpilibc/shared/include/Commands/CommandGroup.h
@@ -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
diff --git a/wpilibc/shared/include/Commands/CommandGroupEntry.h b/wpilibc/shared/include/Commands/CommandGroupEntry.h
new file mode 100644
index 0000000..442a02c
--- /dev/null
+++ b/wpilibc/shared/include/Commands/CommandGroupEntry.h
@@ -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 = -1.0;
+ Command *m_command = nullptr;
+ Sequence m_state = kSequence_InSequence;
+};
+
+#endif
diff --git a/wpilibc/shared/include/Commands/PIDCommand.h b/wpilibc/shared/include/Commands/PIDCommand.h
new file mode 100644
index 0000000..d67c063
--- /dev/null
+++ b/wpilibc/shared/include/Commands/PIDCommand.h
@@ -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
diff --git a/wpilibc/shared/include/Commands/PIDSubsystem.h b/wpilibc/shared/include/Commands/PIDSubsystem.h
new file mode 100644
index 0000000..ff05514
--- /dev/null
+++ b/wpilibc/shared/include/Commands/PIDSubsystem.h
@@ -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
diff --git a/wpilibc/shared/include/Commands/PrintCommand.h b/wpilibc/shared/include/Commands/PrintCommand.h
new file mode 100644
index 0000000..cbb3e5e
--- /dev/null
+++ b/wpilibc/shared/include/Commands/PrintCommand.h
@@ -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
diff --git a/wpilibc/shared/include/Commands/Scheduler.h b/wpilibc/shared/include/Commands/Scheduler.h
new file mode 100644
index 0000000..065fbad
--- /dev/null
+++ b/wpilibc/shared/include/Commands/Scheduler.h
@@ -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;
+ bool m_runningCommandsChanged = false;
+};
+#endif
diff --git a/wpilibc/shared/include/Commands/StartCommand.h b/wpilibc/shared/include/Commands/StartCommand.h
new file mode 100644
index 0000000..8f53d14
--- /dev/null
+++ b/wpilibc/shared/include/Commands/StartCommand.h
@@ -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
diff --git a/wpilibc/shared/include/Commands/Subsystem.h b/wpilibc/shared/include/Commands/Subsystem.h
new file mode 100644
index 0000000..8762ec8
--- /dev/null
+++ b/wpilibc/shared/include/Commands/Subsystem.h
@@ -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;
+};
+
+#endif
diff --git a/wpilibc/shared/include/Commands/WaitCommand.h b/wpilibc/shared/include/Commands/WaitCommand.h
new file mode 100644
index 0000000..6db6dac
--- /dev/null
+++ b/wpilibc/shared/include/Commands/WaitCommand.h
@@ -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
diff --git a/wpilibc/shared/include/Commands/WaitForChildren.h b/wpilibc/shared/include/Commands/WaitForChildren.h
new file mode 100644
index 0000000..858d243
--- /dev/null
+++ b/wpilibc/shared/include/Commands/WaitForChildren.h
@@ -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
diff --git a/wpilibc/shared/include/Commands/WaitUntilCommand.h b/wpilibc/shared/include/Commands/WaitUntilCommand.h
new file mode 100644
index 0000000..fd77f8e
--- /dev/null
+++ b/wpilibc/shared/include/Commands/WaitUntilCommand.h
@@ -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
diff --git a/wpilibc/shared/include/Controller.h b/wpilibc/shared/include/Controller.h
new file mode 100644
index 0000000..d852307
--- /dev/null
+++ b/wpilibc/shared/include/Controller.h
@@ -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;
+};
diff --git a/wpilibc/shared/include/Error.h b/wpilibc/shared/include/Error.h
new file mode 100644
index 0000000..f9e301d
--- /dev/null
+++ b/wpilibc/shared/include/Error.h
@@ -0,0 +1,59 @@
+/*----------------------------------------------------------------------------*/
+/* 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>
+#include "llvm/StringRef.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, llvm::StringRef contextMessage,
+ llvm::StringRef filename, llvm::StringRef 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;
+};
diff --git a/wpilibc/shared/include/ErrorBase.h b/wpilibc/shared/include/ErrorBase.h
new file mode 100644
index 0000000..4730a29
--- /dev/null
+++ b/wpilibc/shared/include/ErrorBase.h
@@ -0,0 +1,106 @@
+/*----------------------------------------------------------------------------*/
+/* 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"
+#include "llvm/StringRef.h"
+
+#define wpi_setErrnoErrorWithContext(context) \
+ this->SetErrnoError((context), __FILE__, __FUNCTION__, __LINE__)
+#define wpi_setErrnoError() wpi_setErrnoErrorWithContext("")
+#define wpi_setImaqErrorWithContext(code, context) \
+ do { \
+ if ((code) != 0) \
+ this->SetImaqError((code), (context), __FILE__, __FUNCTION__, __LINE__); \
+ } while (0)
+#define wpi_setErrorWithContext(code, context) \
+ do { \
+ if ((code) != 0) \
+ this->SetError((code), (context), __FILE__, __FUNCTION__, __LINE__); \
+ } while (0)
+#define wpi_setError(code) wpi_setErrorWithContext(code, "")
+#define wpi_setStaticErrorWithContext(object, code, context) \
+ do { \
+ if ((code) != 0) \
+ object->SetError((code), (context), __FILE__, __FUNCTION__, __LINE__); \
+ } while (0)
+#define wpi_setStaticError(object, code) \
+ wpi_setStaticErrorWithContext(object, code, "")
+#define wpi_setGlobalErrorWithContext(code, context) \
+ do { \
+ if ((code) != 0) \
+ ErrorBase::SetGlobalError((code), (context), __FILE__, __FUNCTION__, \
+ __LINE__); \
+ } while (0)
+#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(llvm::StringRef contextMessage,
+ llvm::StringRef filename, llvm::StringRef function,
+ uint32_t lineNumber) const;
+ virtual void SetImaqError(int success, llvm::StringRef contextMessage,
+ llvm::StringRef filename, llvm::StringRef function,
+ uint32_t lineNumber) const;
+ virtual void SetError(Error::Code code, llvm::StringRef contextMessage,
+ llvm::StringRef filename, llvm::StringRef function,
+ uint32_t lineNumber) const;
+ virtual void SetWPIError(llvm::StringRef errorMessage, Error::Code code,
+ llvm::StringRef contextMessage,
+ llvm::StringRef filename, llvm::StringRef 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, llvm::StringRef contextMessage,
+ llvm::StringRef filename, llvm::StringRef function,
+ uint32_t lineNumber);
+ static void SetGlobalWPIError(llvm::StringRef errorMessage,
+ llvm::StringRef contextMessage,
+ llvm::StringRef filename,
+ llvm::StringRef 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;
+};
diff --git a/wpilibc/shared/include/GenericHID.h b/wpilibc/shared/include/GenericHID.h
new file mode 100644
index 0000000..bf1fe8e
--- /dev/null
+++ b/wpilibc/shared/include/GenericHID.h
@@ -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;
+};
diff --git a/wpilibc/shared/include/HLUsageReporting.h b/wpilibc/shared/include/HLUsageReporting.h
new file mode 100644
index 0000000..5d8d34f
--- /dev/null
+++ b/wpilibc/shared/include/HLUsageReporting.h
@@ -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();
+};
diff --git a/wpilibc/shared/include/LiveWindow/LiveWindow.h b/wpilibc/shared/include/LiveWindow/LiveWindow.h
new file mode 100644
index 0000000..7b40f67
--- /dev/null
+++ b/wpilibc/shared/include/LiveWindow/LiveWindow.h
@@ -0,0 +1,78 @@
+#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 = false;
+
+ 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();
+ 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);
+ 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);
+
+ 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
diff --git a/wpilibc/shared/include/LiveWindow/LiveWindowSendable.h b/wpilibc/shared/include/LiveWindow/LiveWindowSendable.h
new file mode 100644
index 0000000..4f2023a
--- /dev/null
+++ b/wpilibc/shared/include/LiveWindow/LiveWindowSendable.h
@@ -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_ */
diff --git a/wpilibc/shared/include/LiveWindow/LiveWindowStatusListener.h b/wpilibc/shared/include/LiveWindow/LiveWindowStatusListener.h
new file mode 100644
index 0000000..4fa3eb7
--- /dev/null
+++ b/wpilibc/shared/include/LiveWindow/LiveWindowStatusListener.h
@@ -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
diff --git a/wpilibc/shared/include/Notifier.h b/wpilibc/shared/include/Notifier.h
new file mode 100644
index 0000000..056ed0a
--- /dev/null
+++ b/wpilibc/shared/include/Notifier.h
@@ -0,0 +1,57 @@
+/*----------------------------------------------------------------------------*/
+/* 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 priority_mutex halMutex;
+ static void *m_notifier;
+ static std::atomic<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();
+};
diff --git a/wpilibc/shared/include/PIDController.h b/wpilibc/shared/include/PIDController.h
new file mode 100644
index 0000000..301356c
--- /dev/null
+++ b/wpilibc/shared/include/PIDController.h
@@ -0,0 +1,132 @@
+/*----------------------------------------------------------------------------*/
+/* 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
+ 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 = 0;
+ 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;
+};
diff --git a/wpilibc/shared/include/PIDInterface.h b/wpilibc/shared/include/PIDInterface.h
new file mode 100644
index 0000000..5d50199
--- /dev/null
+++ b/wpilibc/shared/include/PIDInterface.h
@@ -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;
+};
diff --git a/wpilibc/shared/include/PIDOutput.h b/wpilibc/shared/include/PIDOutput.h
new file mode 100644
index 0000000..40421d0
--- /dev/null
+++ b/wpilibc/shared/include/PIDOutput.h
@@ -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;
+};
diff --git a/wpilibc/shared/include/PIDSource.h b/wpilibc/shared/include/PIDSource.h
new file mode 100644
index 0000000..8f46ea4
--- /dev/null
+++ b/wpilibc/shared/include/PIDSource.h
@@ -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;
+};
diff --git a/wpilibc/shared/include/Resource.h b/wpilibc/shared/include/Resource.h
new file mode 100644
index 0000000..f7061c8
--- /dev/null
+++ b/wpilibc/shared/include/Resource.h
@@ -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;
+};
diff --git a/wpilibc/shared/include/RobotState.h b/wpilibc/shared/include/RobotState.h
new file mode 100644
index 0000000..53bf32a
--- /dev/null
+++ b/wpilibc/shared/include/RobotState.h
@@ -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();
+};
diff --git a/wpilibc/shared/include/SensorBase.h b/wpilibc/shared/include/SensorBase.h
new file mode 100644
index 0000000..8638b5e
--- /dev/null
+++ b/wpilibc/shared/include/SensorBase.h
@@ -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 = nullptr;
+};
diff --git a/wpilibc/shared/include/SmartDashboard/NamedSendable.h b/wpilibc/shared/include/SmartDashboard/NamedSendable.h
new file mode 100644
index 0000000..0dd1b24
--- /dev/null
+++ b/wpilibc/shared/include/SmartDashboard/NamedSendable.h
@@ -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_ */
diff --git a/wpilibc/shared/include/SmartDashboard/Sendable.h b/wpilibc/shared/include/SmartDashboard/Sendable.h
new file mode 100644
index 0000000..613c7f8
--- /dev/null
+++ b/wpilibc/shared/include/SmartDashboard/Sendable.h
@@ -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
diff --git a/wpilibc/shared/include/SmartDashboard/SendableChooser.h b/wpilibc/shared/include/SmartDashboard/SendableChooser.h
new file mode 100644
index 0000000..bfdf877
--- /dev/null
+++ b/wpilibc/shared/include/SmartDashboard/SendableChooser.h
@@ -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
diff --git a/wpilibc/shared/include/SmartDashboard/SmartDashboard.h b/wpilibc/shared/include/SmartDashboard/SmartDashboard.h
new file mode 100644
index 0000000..a1cfb22
--- /dev/null
+++ b/wpilibc/shared/include/SmartDashboard/SmartDashboard.h
@@ -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
diff --git a/wpilibc/shared/include/Task.h b/wpilibc/shared/include/Task.h
new file mode 100644
index 0000000..7752d0d
--- /dev/null
+++ b/wpilibc/shared/include/Task.h
@@ -0,0 +1,52 @@
+/*----------------------------------------------------------------------------*/
+/* 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>
+
+/**
+ * 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"
diff --git a/wpilibc/shared/include/Task.inc b/wpilibc/shared/include/Task.inc
new file mode 100644
index 0000000..3514b92
--- /dev/null
+++ b/wpilibc/shared/include/Task.inc
@@ -0,0 +1,26 @@
+#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(std::forward<std::decay_t<Function>>(function),
+ std::forward<Args>(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());
+}
diff --git a/wpilibc/shared/include/Timer.h b/wpilibc/shared/include/Timer.h
new file mode 100644
index 0000000..60b9604
--- /dev/null
+++ b/wpilibc/shared/include/Timer.h
@@ -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;
+};
diff --git a/wpilibc/shared/include/Utility.h b/wpilibc/shared/include/Utility.h
new file mode 100644
index 0000000..69edb63
--- /dev/null
+++ b/wpilibc/shared/include/Utility.h
@@ -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 char *conditionText,
+ const char *message, const char *fileName,
+ uint32_t lineNumber, const char *funcName);
+bool wpi_assertEqual_impl(int valueA, int valueB, const char *valueAString,
+ const char *valueBString, const char *message,
+ const char *fileName, uint32_t lineNumber,
+ const char *funcName);
+bool wpi_assertNotEqual_impl(int valueA, int valueB, const char *valueAString,
+ const char *valueBString, const char *message,
+ const char *fileName, uint32_t lineNumber,
+ const char *funcName);
+
+void wpi_suspendOnAssertEnabled(bool enabled);
+
+uint16_t GetFPGAVersion();
+uint32_t GetFPGARevision();
+uint32_t GetFPGATime();
+bool GetUserButton();
+std::string GetStackTrace(uint32_t offset);
diff --git a/wpilibc/shared/include/WPIErrors.h b/wpilibc/shared/include/WPIErrors.h
new file mode 100644
index 0000000..8346fdf
--- /dev/null
+++ b/wpilibc/shared/include/WPIErrors.h
@@ -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
diff --git a/wpilibc/shared/include/interfaces/Accelerometer.h b/wpilibc/shared/include/interfaces/Accelerometer.h
new file mode 100644
index 0000000..528d120
--- /dev/null
+++ b/wpilibc/shared/include/interfaces/Accelerometer.h
@@ -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;
+};
diff --git a/wpilibc/shared/include/interfaces/Gyro.h b/wpilibc/shared/include/interfaces/Gyro.h
new file mode 100644
index 0000000..8317ca5
--- /dev/null
+++ b/wpilibc/shared/include/interfaces/Gyro.h
@@ -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;
+
+ /**
+ * 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 Calibrate() = 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;
+};
diff --git a/wpilibc/shared/include/interfaces/Potentiometer.h b/wpilibc/shared/include/interfaces/Potentiometer.h
new file mode 100644
index 0000000..d52892d
--- /dev/null
+++ b/wpilibc/shared/include/interfaces/Potentiometer.h
@@ -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