Squashed 'third_party/allwpilib_2017/' content from commit 35ac87d

Change-Id: I7bb6f5556c30d3f5a092e68de0be9c710c60c9f4
git-subtree-dir: third_party/allwpilib_2017
git-subtree-split: 35ac87d6ff8b7f061c4f18c9ea316e5dccd4888a
diff --git a/wpilibc/sim/include/simulation/MainNode.h b/wpilibc/sim/include/simulation/MainNode.h
new file mode 100644
index 0000000..21e9147
--- /dev/null
+++ b/wpilibc/sim/include/simulation/MainNode.h
@@ -0,0 +1,65 @@
+/*----------------------------------------------------------------------------*/
+/* Copyright (c) FIRST 2014-2017. 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 the root directory of */
+/* the project.                                                               */
+/*----------------------------------------------------------------------------*/
+
+#pragma once
+
+#include <string>
+
+#include <gazebo/gazebo_client.hh>
+#include <gazebo/transport/transport.hh>
+
+#include "simulation/gz_msgs/msgs.h"
+
+namespace frc {
+
+class MainNode {
+ public:
+  static MainNode* GetInstance() {
+    static MainNode instance;
+    return &instance;
+  }
+
+  template <typename M>
+  static gazebo::transport::PublisherPtr Advertise(const std::string& topic,
+                                                   int queueLimit = 10,
+                                                   bool latch = false) {
+    return GetInstance()->main->Advertise<M>(topic, queueLimit, latch);
+  }
+
+  template <typename M, typename T>
+  static gazebo::transport::SubscriberPtr Subscribe(
+      const std::string& topic,
+      void (T::*fp)(const boost::shared_ptr<M const>&), T* obj,
+      bool latching = false) {
+    return GetInstance()->main->Subscribe(topic, fp, obj, latching);
+  }
+
+  template <typename M>
+  static gazebo::transport::SubscriberPtr Subscribe(
+      const std::string& topic, void (*fp)(const boost::shared_ptr<M const>&),
+      bool latching = false) {
+    return GetInstance()->main->Subscribe(topic, fp, latching);
+  }
+
+  gazebo::transport::NodePtr main;
+
+ private:
+  MainNode() {
+    bool success = gazebo::client::setup();
+
+    if (success) {
+      main = gazebo::transport::NodePtr(new gazebo::transport::Node());
+      main->Init("frc");
+      gazebo::transport::run();
+    } else {
+      std::cout << "An error has occured setting up gazebo_client!"
+                << std::endl;
+    }
+  }
+};
+
+}  // namespace frc
diff --git a/wpilibc/sim/include/simulation/SimContinuousOutput.h b/wpilibc/sim/include/simulation/SimContinuousOutput.h
new file mode 100644
index 0000000..819ec64
--- /dev/null
+++ b/wpilibc/sim/include/simulation/SimContinuousOutput.h
@@ -0,0 +1,48 @@
+/*----------------------------------------------------------------------------*/
+/* Copyright (c) FIRST 2014-2017. 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 the root directory of */
+/* the project.                                                               */
+/*----------------------------------------------------------------------------*/
+
+#pragma once
+
+#include <string>
+
+#include <gazebo/transport/transport.hh>
+
+#include "SpeedController.h"
+
+#ifdef _WIN32
+// Ensure that Winsock2.h is included before Windows.h, which can get
+// pulled in by anybody (e.g., Boost).
+#include <Winsock2.h>
+#endif
+
+namespace frc {
+
+class SimContinuousOutput {
+ private:
+  gazebo::transport::PublisherPtr pub;
+  double speed;
+
+ public:
+  explicit SimContinuousOutput(std::string topic);
+
+  /**
+   * Set the output value.
+   *
+   * The value is set using a range of -1.0 to 1.0, appropriately
+   * scaling the value.
+   *
+   * @param value The value between -1.0 and 1.0 to set.
+   */
+  void Set(double value);
+
+  /**
+   * @return The most recently set value.
+   */
+  double Get();
+};
+
+}  // namespace frc
diff --git a/wpilibc/sim/include/simulation/SimDigitalInput.h b/wpilibc/sim/include/simulation/SimDigitalInput.h
new file mode 100644
index 0000000..cddd8e6
--- /dev/null
+++ b/wpilibc/sim/include/simulation/SimDigitalInput.h
@@ -0,0 +1,33 @@
+/*----------------------------------------------------------------------------*/
+/* Copyright (c) FIRST 2014-2017. 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 the root directory of */
+/* the project.                                                               */
+/*----------------------------------------------------------------------------*/
+
+#pragma once
+
+#include <string>
+
+#include <gazebo/transport/transport.hh>
+
+#include "simulation/gz_msgs/msgs.h"
+
+namespace frc {
+
+class SimDigitalInput {
+ public:
+  explicit SimDigitalInput(std::string topic);
+
+  /**
+   * @return The value of the potentiometer.
+   */
+  bool Get();
+
+ private:
+  bool value;
+  gazebo::transport::SubscriberPtr sub;
+  void callback(const gazebo::msgs::ConstBoolPtr& msg);
+};
+
+}  // namespace frc
diff --git a/wpilibc/sim/include/simulation/SimEncoder.h b/wpilibc/sim/include/simulation/SimEncoder.h
new file mode 100644
index 0000000..1c0e9a7
--- /dev/null
+++ b/wpilibc/sim/include/simulation/SimEncoder.h
@@ -0,0 +1,39 @@
+/*----------------------------------------------------------------------------*/
+/* Copyright (c) FIRST 2014-2017. 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 the root directory of */
+/* the project.                                                               */
+/*----------------------------------------------------------------------------*/
+
+#pragma once
+
+#include <string>
+
+#include <gazebo/common/Time.hh>
+#include <gazebo/transport/transport.hh>
+
+#include "simulation/gz_msgs/msgs.h"
+
+namespace frc {
+
+class SimEncoder {
+ public:
+  explicit SimEncoder(std::string topic);
+
+  void Reset();
+  void Start();
+  void Stop();
+  double GetPosition();
+  double GetVelocity();
+
+ private:
+  void sendCommand(std::string cmd);
+
+  double position, velocity;
+  gazebo::transport::SubscriberPtr posSub, velSub;
+  gazebo::transport::PublisherPtr commandPub;
+  void positionCallback(const gazebo::msgs::ConstFloat64Ptr& msg);
+  void velocityCallback(const gazebo::msgs::ConstFloat64Ptr& msg);
+};
+
+}  // namespace frc
diff --git a/wpilibc/sim/include/simulation/SimFloatInput.h b/wpilibc/sim/include/simulation/SimFloatInput.h
new file mode 100644
index 0000000..c5af157
--- /dev/null
+++ b/wpilibc/sim/include/simulation/SimFloatInput.h
@@ -0,0 +1,33 @@
+/*----------------------------------------------------------------------------*/
+/* Copyright (c) FIRST 2014-2017. 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 the root directory of */
+/* the project.                                                               */
+/*----------------------------------------------------------------------------*/
+
+#pragma once
+
+#include <string>
+
+#include <gazebo/transport/transport.hh>
+
+#include "simulation/gz_msgs/msgs.h"
+
+namespace frc {
+
+class SimFloatInput {
+ public:
+  explicit SimFloatInput(std::string topic);
+
+  /**
+   * @return The value of the potentiometer.
+   */
+  double Get();
+
+ private:
+  double value;
+  gazebo::transport::SubscriberPtr sub;
+  void callback(const gazebo::msgs::ConstFloat64Ptr& msg);
+};
+
+}  // namespace frc
diff --git a/wpilibc/sim/include/simulation/SimGyro.h b/wpilibc/sim/include/simulation/SimGyro.h
new file mode 100644
index 0000000..75d774d
--- /dev/null
+++ b/wpilibc/sim/include/simulation/SimGyro.h
@@ -0,0 +1,36 @@
+/*----------------------------------------------------------------------------*/
+/* Copyright (c) FIRST 2014-2017. 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 the root directory of */
+/* the project.                                                               */
+/*----------------------------------------------------------------------------*/
+
+#pragma once
+
+#include <string>
+
+#include <gazebo/transport/transport.hh>
+
+#include "simulation/gz_msgs/msgs.h"
+
+namespace frc {
+
+class SimGyro {
+ public:
+  explicit SimGyro(std::string topic);
+
+  void Reset();
+  double GetAngle();
+  double GetVelocity();
+
+ private:
+  void sendCommand(std::string cmd);
+
+  double position, velocity;
+  gazebo::transport::SubscriberPtr posSub, velSub;
+  gazebo::transport::PublisherPtr commandPub;
+  void positionCallback(const gazebo::msgs::ConstFloat64Ptr& msg);
+  void velocityCallback(const gazebo::msgs::ConstFloat64Ptr& msg);
+};
+
+}  // namespace frc
diff --git a/wpilibc/sim/include/simulation/simTime.h b/wpilibc/sim/include/simulation/simTime.h
new file mode 100644
index 0000000..8f3802e
--- /dev/null
+++ b/wpilibc/sim/include/simulation/simTime.h
@@ -0,0 +1,26 @@
+/*----------------------------------------------------------------------------*/
+/* Copyright (c) FIRST 2014-2017. 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 the root directory of */
+/* the project.                                                               */
+/*----------------------------------------------------------------------------*/
+
+#pragma once
+
+#include <condition_variable>
+#include <mutex>
+
+#include "simulation/SimFloatInput.h"
+
+#ifdef _WIN32
+// Ensure that Winsock2.h is included before Windows.h, which can get
+// pulled in by anybody (e.g., Boost).
+#include <Winsock2.h>
+#endif
+
+namespace wpilib {
+namespace internal {
+extern double simTime;
+extern void time_callback(const gazebo::msgs::ConstFloat64Ptr& msg);
+}
+}