Rename our allwpilib (which is now 2020) to not have 2019 in the name
Change-Id: I3c07f85ed32ab8b97db765a9b43f2a6ce7da964a
diff --git a/simulation/lowfi_simulation/build.gradle b/simulation/lowfi_simulation/build.gradle
new file mode 100644
index 0000000..e6e8143
--- /dev/null
+++ b/simulation/lowfi_simulation/build.gradle
@@ -0,0 +1,194 @@
+apply plugin: 'cpp'
+apply plugin: 'google-test-test-suite'
+apply plugin: 'visual-studio'
+apply plugin: 'edu.wpi.first.NativeUtils'
+apply plugin: SingleNativeBuild
+apply plugin: ExtraTasks
+
+
+ext {
+ nativeName = 'lowfi_sim'
+}
+
+apply from: "${rootDir}/shared/config.gradle"
+
+if (!project.hasProperty('onlylinuxathena')) {
+ ext.skiplinuxathena = true
+ ext {
+ sharedCvConfigs = [lowfi_simTest: []]
+ staticCvConfigs = [:]
+ useJava = false
+ useCpp = true
+ }
+ apply from: "${rootDir}/shared/opencv.gradle"
+
+ ext {
+ staticGtestConfigs = [:]
+ }
+ staticGtestConfigs["${nativeName}Test"] = []
+ apply from: "${rootDir}/shared/googletest.gradle"
+
+ project(':').libraryBuild.dependsOn build
+
+ nativeUtils.exportsConfigs {
+ lowfi_sim {
+ x86ExcludeSymbols = ['_CT??_R0?AV_System_error', '_CT??_R0?AVexception', '_CT??_R0?AVfailure',
+ '_CT??_R0?AVruntime_error', '_CT??_R0?AVsystem_error', '_CTA5?AVfailure',
+ '_TI5?AVfailure', '_CT??_R0?AVout_of_range', '_CTA3?AVout_of_range',
+ '_TI3?AVout_of_range', '_CT??_R0?AVbad_cast']
+ x64ExcludeSymbols = ['_CT??_R0?AV_System_error', '_CT??_R0?AVexception', '_CT??_R0?AVfailure',
+ '_CT??_R0?AVruntime_error', '_CT??_R0?AVsystem_error', '_CTA5?AVfailure',
+ '_TI5?AVfailure', '_CT??_R0?AVout_of_range', '_CTA3?AVout_of_range',
+ '_TI3?AVout_of_range', '_CT??_R0?AVbad_cast']
+ }
+ }
+
+ model {
+ components {
+ "${nativeName}Base"(NativeLibrarySpec) {
+ sources {
+ cpp {
+ source {
+ srcDirs = ['src/main/native/cpp']
+ include '**/*.cpp'
+ }
+ exportedHeaders {
+ srcDirs 'src/main/native/include'
+ }
+ }
+ }
+ binaries.all {
+ if (it instanceof SharedLibraryBinarySpec) {
+ it.buildable = false
+ return
+ }
+ if (it.targetPlatform.name == nativeUtils.wpi.platforms.roborio) {
+ it.buildable = false
+ return
+ }
+ project(':hal').addHalDependency(it, 'shared')
+ lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
+ }
+ }
+ "${nativeName}"(NativeLibrarySpec) {
+ sources {
+ cpp {
+ source {
+ srcDirs "${rootDir}/shared/singlelib"
+ include '**/*.cpp'
+ }
+ exportedHeaders {
+ srcDirs 'src/main/native/include'
+ }
+ }
+ }
+ binaries.all {
+ if (it.targetPlatform.name == nativeUtils.wpi.platforms.roborio) {
+ it.buildable = false
+ return
+ }
+ project(':hal').addHalDependency(it, 'shared')
+ lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
+ }
+ }
+ // By default, a development executable will be generated. This is to help the case of
+ // testing specific functionality of the library.
+ "${nativeName}Dev"(NativeExecutableSpec) {
+ targetBuildTypes 'debug'
+ sources {
+ cpp {
+ source {
+ srcDirs 'src/dev/native/cpp'
+ include '**/*.cpp'
+ lib library: "${nativeName}"
+ }
+ exportedHeaders {
+ srcDirs 'src/dev/native/include'
+ }
+ }
+ }
+ binaries.all {
+ if (it.targetPlatform.name == nativeUtils.wpi.platforms.roborio) {
+ it.buildable = false
+ return
+ }
+ project(':hal').addHalDependency(it, 'shared')
+ lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
+ lib library: nativeName, linkage: 'shared'
+ if (it.targetPlatform.name == nativeUtils.wpi.platforms.roborio) {
+ nativeUtils.useRequiredLibrary(it, 'netcomm_shared', 'chipobject_shared', 'visa_shared', 'ni_runtime_shared')
+ }
+ }
+ }
+ }
+ binaries {
+ withType(GoogleTestTestSuiteBinarySpec) {
+ lib project: ':ntcore', library: 'ntcore', linkage: 'shared'
+ lib project: ':cscore', library: 'cscore', linkage: 'shared'
+ project(':hal').addHalDependency(it, 'shared')
+ lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
+ lib project: ':cameraserver', library: 'cameraserver', linkage: 'shared'
+ lib project: ':wpilibc', library: 'wpilibc', linkage: 'shared'
+ lib library: nativeName, linkage: 'shared'
+ if (it.targetPlatform.name == nativeUtils.wpi.platforms.roborio) {
+ nativeUtils.useRequiredLibrary(it, 'netcomm_shared', 'chipobject_shared', 'visa_shared', 'ni_runtime_shared')
+ }
+ }
+ }
+ }
+
+ apply from: "publish.gradle"
+}
+
+model {
+
+ testSuites {
+ if (!project.hasProperty('onlylinuxathena') && !project.hasProperty('onlylinuxraspbian') && !project.hasProperty('onlylinuxaarch64bionic')) {
+ "${nativeName}Test"(GoogleTestTestSuiteSpec) {
+ for(NativeComponentSpec c : $.components) {
+ if (c.name == nativeName) {
+ testing c
+ break
+ }
+ }
+ sources {
+ cpp {
+ source {
+ srcDirs 'src/test/native/cpp'
+ include '**/*.cpp'
+ }
+ exportedHeaders {
+ srcDirs 'src/test/native/include', 'src/main/native/cpp'
+ }
+ }
+ }
+ }
+ }
+ }
+ tasks {
+ def c = $.components
+ project.tasks.create('runCpp', Exec) {
+ def found = false
+ c.each {
+ if (it in NativeExecutableSpec && it.name == "${nativeName}Dev") {
+ it.binaries.each {
+ if (!found) {
+ def arch = it.targetPlatform.architecture.name
+ if (arch == 'x86-64' || arch == 'x86') {
+ dependsOn it.tasks.install
+ commandLine it.tasks.install.runScriptFile.get().asFile.toString()
+
+ found = true
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+}
+
+tasks.withType(RunTestExecutable) {
+ args "--gtest_output=xml:test_detail.xml"
+ outputs.dir outputDir
+}
diff --git a/simulation/lowfi_simulation/publish.gradle b/simulation/lowfi_simulation/publish.gradle
new file mode 100644
index 0000000..1fa3aaf
--- /dev/null
+++ b/simulation/lowfi_simulation/publish.gradle
@@ -0,0 +1,64 @@
+apply plugin: 'maven-publish'
+
+def baseArtifactId = nativeName
+def artifactGroupId = 'edu.wpi.first.halsim'
+def zipBaseName = "_GROUP_edu_wpi_first_halsim_ID_${nativeName}_CLS"
+
+def outputsFolder = file("$project.buildDir/outputs")
+
+task cppSourcesZip(type: Zip) {
+ destinationDirectory = outputsFolder
+ archiveBaseName = zipBaseName
+ classifier = "sources"
+
+ from(licenseFile) {
+ into '/'
+ }
+
+ from('src/main/native/cpp') {
+ into '/'
+ }
+}
+
+task cppHeadersZip(type: Zip) {
+ destinationDirectory = outputsFolder
+ archiveBaseName = zipBaseName
+ classifier = "headers"
+
+ from(licenseFile) {
+ into '/'
+ }
+
+ from('src/main/native/include') {
+ into '/'
+ }
+}
+
+build.dependsOn cppSourcesZip
+build.dependsOn cppHeadersZip
+
+addTaskToCopyAllOutputs(cppSourcesZip)
+addTaskToCopyAllOutputs(cppHeadersZip)
+
+
+model {
+ publishing {
+ def lowfiSimTaskList = createComponentZipTasks($.components, [nativeName], zipBaseName, Zip, project, includeStandardZipFormat)
+
+ publications {
+ cpp(MavenPublication) {
+ lowfiSimTaskList.each {
+ artifact it
+ }
+
+ artifact cppHeadersZip
+ artifact cppSourcesZip
+
+
+ artifactId = baseArtifactId
+ groupId artifactGroupId
+ version wpilibVersioning.version.get()
+ }
+ }
+ }
+}
diff --git a/simulation/lowfi_simulation/src/dev/native/cpp/main.cpp b/simulation/lowfi_simulation/src/dev/native/cpp/main.cpp
new file mode 100644
index 0000000..eb83810
--- /dev/null
+++ b/simulation/lowfi_simulation/src/dev/native/cpp/main.cpp
@@ -0,0 +1,15 @@
+/*----------------------------------------------------------------------------*/
+/* Copyright (c) 2017-2019 FIRST. 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. */
+/*----------------------------------------------------------------------------*/
+
+#include <iostream>
+
+#include <hal/HALBase.h>
+
+int main() {
+ std::cout << "Hello World" << std::endl;
+ std::cout << HAL_GetRuntimeType() << std::endl;
+}
diff --git a/simulation/lowfi_simulation/src/main/native/cpp/lowfisim/MotorEncoderConnector.cpp b/simulation/lowfi_simulation/src/main/native/cpp/lowfisim/MotorEncoderConnector.cpp
new file mode 100644
index 0000000..5e530e6
--- /dev/null
+++ b/simulation/lowfi_simulation/src/main/native/cpp/lowfisim/MotorEncoderConnector.cpp
@@ -0,0 +1,25 @@
+/*----------------------------------------------------------------------------*/
+/* Copyright (c) 2018 FIRST. 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. */
+/*----------------------------------------------------------------------------*/
+
+#include "lowfisim/MotorEncoderConnector.h"
+
+namespace frc {
+namespace sim {
+namespace lowfi {
+
+MotorEncoderConnector::MotorEncoderConnector(MotorSim& motorController,
+ EncoderSim& encoder)
+ : motorSimulator(motorController), encoderSimulator(encoder) {}
+
+void MotorEncoderConnector::Update() {
+ encoderSimulator.SetPosition(motorSimulator.GetPosition());
+ encoderSimulator.SetVelocity(motorSimulator.GetVelocity());
+}
+
+} // namespace lowfi
+} // namespace sim
+} // namespace frc
diff --git a/simulation/lowfi_simulation/src/main/native/cpp/lowfisim/SimulatorComponentBase.cpp b/simulation/lowfi_simulation/src/main/native/cpp/lowfisim/SimulatorComponentBase.cpp
new file mode 100644
index 0000000..a65de3b
--- /dev/null
+++ b/simulation/lowfi_simulation/src/main/native/cpp/lowfisim/SimulatorComponentBase.cpp
@@ -0,0 +1,24 @@
+/*----------------------------------------------------------------------------*/
+/* Copyright (c) 2018 FIRST. 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. */
+/*----------------------------------------------------------------------------*/
+
+#include "lowfisim/SimulatorComponentBase.h"
+
+namespace frc {
+namespace sim {
+namespace lowfi {
+
+const std::string& SimulatorComponentBase::GetDisplayName() const {
+ return m_name;
+}
+
+void SimulatorComponentBase::SetDisplayName(const std::string& displayName) {
+ m_name = displayName;
+}
+
+} // namespace lowfi
+} // namespace sim
+} // namespace frc
diff --git a/simulation/lowfi_simulation/src/main/native/cpp/lowfisim/motormodel/SimpleMotorModel.cpp b/simulation/lowfi_simulation/src/main/native/cpp/lowfisim/motormodel/SimpleMotorModel.cpp
new file mode 100644
index 0000000..226a836
--- /dev/null
+++ b/simulation/lowfi_simulation/src/main/native/cpp/lowfisim/motormodel/SimpleMotorModel.cpp
@@ -0,0 +1,40 @@
+/*----------------------------------------------------------------------------*/
+/* Copyright (c) 2018 FIRST. 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. */
+/*----------------------------------------------------------------------------*/
+
+#include "lowfisim/motormodel/SimpleMotorModel.h"
+
+namespace frc {
+namespace sim {
+namespace lowfi {
+
+SimpleMotorModel::SimpleMotorModel(double maxSpeed) : m_maxSpeed(maxSpeed) {}
+
+void SimpleMotorModel::Reset() {
+ m_position = 0;
+ m_velocity = 0;
+}
+
+void SimpleMotorModel::SetVoltage(double voltage) {
+ m_voltagePercentage = voltage / kMaxExpectedVoltage;
+}
+
+void SimpleMotorModel::Update(double elapsedTime) {
+ m_velocity = m_maxSpeed * m_voltagePercentage;
+ m_position += m_velocity * elapsedTime;
+}
+
+double SimpleMotorModel::GetPosition() const { return m_position; }
+
+double SimpleMotorModel::GetVelocity() const { return m_velocity; }
+
+double SimpleMotorModel::GetAcceleration() const { return 0; }
+
+double SimpleMotorModel::GetCurrent() const { return 0; }
+
+} // namespace lowfi
+} // namespace sim
+} // namespace frc
diff --git a/simulation/lowfi_simulation/src/main/native/cpp/lowfisim/wpisimulators/WpiAnalogGyroSim.cpp b/simulation/lowfi_simulation/src/main/native/cpp/lowfisim/wpisimulators/WpiAnalogGyroSim.cpp
new file mode 100644
index 0000000..63619cc
--- /dev/null
+++ b/simulation/lowfi_simulation/src/main/native/cpp/lowfisim/wpisimulators/WpiAnalogGyroSim.cpp
@@ -0,0 +1,28 @@
+/*----------------------------------------------------------------------------*/
+/* Copyright (c) 2008-2018 FIRST. 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. */
+/*----------------------------------------------------------------------------*/
+
+#include "lowfisim/wpisimulators/WpiAnalogGyroSim.h"
+
+namespace frc {
+namespace sim {
+namespace lowfi {
+
+WpiAnalogGyroSim::WpiAnalogGyroSim(int index) : m_gyroSimulator(index) {}
+
+bool WpiAnalogGyroSim::IsWrapperInitialized() const {
+ return m_gyroSimulator.GetInitialized();
+}
+
+void WpiAnalogGyroSim::SetAngle(double angle) {
+ m_gyroSimulator.SetAngle(angle);
+}
+
+double WpiAnalogGyroSim::GetAngle() { return m_gyroSimulator.GetAngle(); }
+
+} // namespace lowfi
+} // namespace sim
+} // namespace frc
diff --git a/simulation/lowfi_simulation/src/main/native/cpp/lowfisim/wpisimulators/WpiEncoderSim.cpp b/simulation/lowfi_simulation/src/main/native/cpp/lowfisim/wpisimulators/WpiEncoderSim.cpp
new file mode 100644
index 0000000..7425efe
--- /dev/null
+++ b/simulation/lowfi_simulation/src/main/native/cpp/lowfisim/wpisimulators/WpiEncoderSim.cpp
@@ -0,0 +1,31 @@
+/*----------------------------------------------------------------------------*/
+/* Copyright (c) 2018 FIRST. 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. */
+/*----------------------------------------------------------------------------*/
+
+#include "lowfisim/wpisimulators/WpiEncoderSim.h"
+
+namespace frc {
+namespace sim {
+namespace lowfi {
+
+WpiEncoderSim::WpiEncoderSim(int index) : m_encoderSimulator(index) {}
+
+bool WpiEncoderSim::IsWrapperInitialized() const {
+ return m_encoderSimulator.GetInitialized();
+}
+
+void WpiEncoderSim::SetPosition(double position) {
+ m_encoderSimulator.SetCount(
+ static_cast<int>(position / m_encoderSimulator.GetDistancePerPulse()));
+}
+
+void WpiEncoderSim::SetVelocity(double velocity) {
+ m_encoderSimulator.SetPeriod(1.0 / velocity);
+}
+
+} // namespace lowfi
+} // namespace sim
+} // namespace frc
diff --git a/simulation/lowfi_simulation/src/main/native/cpp/lowfisim/wpisimulators/WpiMotorSim.cpp b/simulation/lowfi_simulation/src/main/native/cpp/lowfisim/wpisimulators/WpiMotorSim.cpp
new file mode 100644
index 0000000..0b08cf2
--- /dev/null
+++ b/simulation/lowfi_simulation/src/main/native/cpp/lowfisim/wpisimulators/WpiMotorSim.cpp
@@ -0,0 +1,41 @@
+/*----------------------------------------------------------------------------*/
+/* Copyright (c) 2008-2018 FIRST. 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. */
+/*----------------------------------------------------------------------------*/
+
+#include "lowfisim/wpisimulators/WpiMotorSim.h"
+
+namespace frc {
+namespace sim {
+namespace lowfi {
+
+WpiMotorSim::WpiMotorSim(int index, MotorModel& motorModelSimulator)
+ : m_motorModelSimulation(motorModelSimulator), m_pwmSimulator(index) {}
+
+void WpiMotorSim::Update(double elapsedTime) {
+ m_motorModelSimulation.SetVoltage(m_pwmSimulator.GetSpeed() *
+ kDefaultVoltage);
+ m_motorModelSimulation.Update(elapsedTime);
+}
+
+bool WpiMotorSim::IsWrapperInitialized() const {
+ return m_pwmSimulator.GetInitialized();
+}
+
+double WpiMotorSim::GetPosition() const {
+ return m_motorModelSimulation.GetPosition();
+}
+
+double WpiMotorSim::GetVelocity() const {
+ return m_motorModelSimulation.GetVelocity();
+}
+
+double WpiMotorSim::GetAcceleration() const {
+ return m_motorModelSimulation.GetAcceleration();
+}
+
+} // namespace lowfi
+} // namespace sim
+} // namespace frc
diff --git a/simulation/lowfi_simulation/src/main/native/include/lowfisim/AccelerometerSim.h b/simulation/lowfi_simulation/src/main/native/include/lowfisim/AccelerometerSim.h
new file mode 100644
index 0000000..041f257
--- /dev/null
+++ b/simulation/lowfi_simulation/src/main/native/include/lowfisim/AccelerometerSim.h
@@ -0,0 +1,24 @@
+/*----------------------------------------------------------------------------*/
+/* Copyright (c) 2018-2019 FIRST. 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 "lowfisim/SimulatorComponentBase.h"
+
+namespace frc {
+namespace sim {
+namespace lowfi {
+
+class AccelerometerSim : public SimulatorComponentBase {
+ public:
+ virtual double GetAcceleration() = 0;
+ virtual void SetAcceleration(double acceleration) = 0;
+};
+
+} // namespace lowfi
+} // namespace sim
+} // namespace frc
diff --git a/simulation/lowfi_simulation/src/main/native/include/lowfisim/EncoderSim.h b/simulation/lowfi_simulation/src/main/native/include/lowfisim/EncoderSim.h
new file mode 100644
index 0000000..2e14755
--- /dev/null
+++ b/simulation/lowfi_simulation/src/main/native/include/lowfisim/EncoderSim.h
@@ -0,0 +1,24 @@
+/*----------------------------------------------------------------------------*/
+/* Copyright (c) 2018-2019 FIRST. 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 "lowfisim/SimulatorComponentBase.h"
+
+namespace frc {
+namespace sim {
+namespace lowfi {
+
+class EncoderSim : public SimulatorComponentBase {
+ public:
+ virtual void SetPosition(double position) = 0;
+ virtual void SetVelocity(double velocity) = 0;
+};
+
+} // namespace lowfi
+} // namespace sim
+} // namespace frc
diff --git a/simulation/lowfi_simulation/src/main/native/include/lowfisim/GyroSim.h b/simulation/lowfi_simulation/src/main/native/include/lowfisim/GyroSim.h
new file mode 100644
index 0000000..bc80598
--- /dev/null
+++ b/simulation/lowfi_simulation/src/main/native/include/lowfisim/GyroSim.h
@@ -0,0 +1,24 @@
+/*----------------------------------------------------------------------------*/
+/* Copyright (c) 2018-2019 FIRST. 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 "lowfisim/SimulatorComponentBase.h"
+
+namespace frc {
+namespace sim {
+namespace lowfi {
+
+class GyroSim : public SimulatorComponentBase {
+ public:
+ virtual void SetAngle(double angle) = 0;
+ virtual double GetAngle() = 0;
+};
+
+} // namespace lowfi
+} // namespace sim
+} // namespace frc
diff --git a/simulation/lowfi_simulation/src/main/native/include/lowfisim/MotorEncoderConnector.h b/simulation/lowfi_simulation/src/main/native/include/lowfisim/MotorEncoderConnector.h
new file mode 100644
index 0000000..0cf4873
--- /dev/null
+++ b/simulation/lowfi_simulation/src/main/native/include/lowfisim/MotorEncoderConnector.h
@@ -0,0 +1,30 @@
+/*----------------------------------------------------------------------------*/
+/* Copyright (c) 2018 FIRST. 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 "EncoderSim.h"
+#include "MotorSim.h"
+
+namespace frc {
+namespace sim {
+namespace lowfi {
+
+class MotorEncoderConnector {
+ public:
+ MotorEncoderConnector(MotorSim& motorController, EncoderSim& encoder);
+
+ void Update();
+
+ private:
+ MotorSim& motorSimulator;
+ EncoderSim& encoderSimulator;
+};
+
+} // namespace lowfi
+} // namespace sim
+} // namespace frc
diff --git a/simulation/lowfi_simulation/src/main/native/include/lowfisim/MotorSim.h b/simulation/lowfi_simulation/src/main/native/include/lowfisim/MotorSim.h
new file mode 100644
index 0000000..77532a6
--- /dev/null
+++ b/simulation/lowfi_simulation/src/main/native/include/lowfisim/MotorSim.h
@@ -0,0 +1,25 @@
+/*----------------------------------------------------------------------------*/
+/* Copyright (c) 2018-2019 FIRST. 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 "lowfisim/SimulatorComponentBase.h"
+
+namespace frc {
+namespace sim {
+namespace lowfi {
+
+class MotorSim : public SimulatorComponentBase {
+ public:
+ virtual double GetPosition() const = 0;
+ virtual double GetVelocity() const = 0;
+ virtual double GetAcceleration() const = 0;
+};
+
+} // namespace lowfi
+} // namespace sim
+} // namespace frc
diff --git a/simulation/lowfi_simulation/src/main/native/include/lowfisim/SimpleAccelerometerSim.h b/simulation/lowfi_simulation/src/main/native/include/lowfisim/SimpleAccelerometerSim.h
new file mode 100644
index 0000000..482ac11
--- /dev/null
+++ b/simulation/lowfi_simulation/src/main/native/include/lowfisim/SimpleAccelerometerSim.h
@@ -0,0 +1,44 @@
+/*----------------------------------------------------------------------------*/
+/* Copyright (c) 2018-2019 FIRST. 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 <functional>
+
+#include "lowfisim/AccelerometerSim.h"
+
+namespace frc {
+namespace sim {
+namespace lowfi {
+
+class SimpleAccelerometerSim : public AccelerometerSim {
+ public:
+ SimpleAccelerometerSim(const std::function<bool(void)>& initializedFunction,
+ const std::function<void(double)>& setterFunction,
+ const std::function<double(void)>& getterFunction)
+ : m_isInitializedFunction(initializedFunction),
+ m_setAccelerationFunction(setterFunction),
+ m_getAccelerationFunction(getterFunction) {}
+ double GetAcceleration() override { return m_getAccelerationFunction(); }
+
+ void SetAcceleration(double acceleration) override {
+ m_setAccelerationFunction(acceleration);
+ }
+
+ bool IsWrapperInitialized() const override {
+ return m_isInitializedFunction();
+ }
+
+ private:
+ std::function<bool(void)> m_isInitializedFunction;
+ std::function<void(double)> m_setAccelerationFunction;
+ std::function<double(void)> m_getAccelerationFunction;
+};
+
+} // namespace lowfi
+} // namespace sim
+} // namespace frc
diff --git a/simulation/lowfi_simulation/src/main/native/include/lowfisim/SimpleGyroSim.h b/simulation/lowfi_simulation/src/main/native/include/lowfisim/SimpleGyroSim.h
new file mode 100644
index 0000000..ea69247
--- /dev/null
+++ b/simulation/lowfi_simulation/src/main/native/include/lowfisim/SimpleGyroSim.h
@@ -0,0 +1,35 @@
+/*----------------------------------------------------------------------------*/
+/* Copyright (c) 2018 FIRST. 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 <functional>
+
+#include "lowfisim/GyroSim.h"
+
+namespace frc {
+namespace sim {
+namespace lowfi {
+
+class SimpleGyroSim : public GyroSim {
+ public:
+ SimpleGyroSim(std::function<void(double)>& setterFunction,
+ std::function<double(void)>& getterFunction)
+ : m_setAngleFunction(setterFunction),
+ m_getAngleFunction(getterFunction) {}
+ double GetAngle() override { return m_getAngleFunction(); }
+
+ void SetAngle(double angle) override { m_setAngleFunction(angle); }
+
+ private:
+ std::function<void(double)> m_setAngleFunction;
+ std::function<double(void)> m_getAngleFunction;
+};
+
+} // namespace lowfi
+} // namespace sim
+} // namespace frc
diff --git a/simulation/lowfi_simulation/src/main/native/include/lowfisim/SimulatorComponent.h b/simulation/lowfi_simulation/src/main/native/include/lowfisim/SimulatorComponent.h
new file mode 100644
index 0000000..4eb5e99
--- /dev/null
+++ b/simulation/lowfi_simulation/src/main/native/include/lowfisim/SimulatorComponent.h
@@ -0,0 +1,29 @@
+/*----------------------------------------------------------------------------*/
+/* Copyright (c) 2018 FIRST. 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>
+
+namespace frc {
+namespace sim {
+namespace lowfi {
+
+class SimulatorComponent {
+ public:
+ virtual ~SimulatorComponent() = default;
+
+ virtual bool IsWrapperInitialized() const = 0;
+
+ virtual const std::string& GetDisplayName() const = 0;
+
+ virtual void SetDisplayName(const std::string& displayName) = 0;
+};
+
+} // namespace lowfi
+} // namespace sim
+} // namespace frc
diff --git a/simulation/lowfi_simulation/src/main/native/include/lowfisim/SimulatorComponentBase.h b/simulation/lowfi_simulation/src/main/native/include/lowfisim/SimulatorComponentBase.h
new file mode 100644
index 0000000..c29e68c
--- /dev/null
+++ b/simulation/lowfi_simulation/src/main/native/include/lowfisim/SimulatorComponentBase.h
@@ -0,0 +1,33 @@
+/*----------------------------------------------------------------------------*/
+/* Copyright (c) 2018 FIRST. 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 "lowfisim/SimulatorComponent.h"
+
+namespace frc {
+namespace sim {
+namespace lowfi {
+
+class SimulatorComponentBase : public virtual SimulatorComponent {
+ public:
+ SimulatorComponentBase() = default;
+ virtual ~SimulatorComponentBase() = default;
+
+ const std::string& GetDisplayName() const override;
+
+ void SetDisplayName(const std::string& displayName) override;
+
+ private:
+ std::string m_name;
+};
+
+} // namespace lowfi
+} // namespace sim
+} // namespace frc
diff --git a/simulation/lowfi_simulation/src/main/native/include/lowfisim/motormodel/MotorModel.h b/simulation/lowfi_simulation/src/main/native/include/lowfisim/motormodel/MotorModel.h
new file mode 100644
index 0000000..aeffcb7
--- /dev/null
+++ b/simulation/lowfi_simulation/src/main/native/include/lowfisim/motormodel/MotorModel.h
@@ -0,0 +1,28 @@
+/*----------------------------------------------------------------------------*/
+/* Copyright (c) 2018 FIRST. 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
+
+namespace frc {
+namespace sim {
+namespace lowfi {
+
+class MotorModel {
+ public:
+ virtual void Reset() = 0;
+ virtual void SetVoltage(double voltage) = 0;
+ virtual void Update(double elapsedTime) = 0;
+
+ virtual double GetPosition() const = 0;
+ virtual double GetVelocity() const = 0;
+ virtual double GetAcceleration() const = 0;
+ virtual double GetCurrent() const = 0;
+};
+
+} // namespace lowfi
+} // namespace sim
+} // namespace frc
diff --git a/simulation/lowfi_simulation/src/main/native/include/lowfisim/motormodel/SimpleMotorModel.h b/simulation/lowfi_simulation/src/main/native/include/lowfisim/motormodel/SimpleMotorModel.h
new file mode 100644
index 0000000..ccfc3b9
--- /dev/null
+++ b/simulation/lowfi_simulation/src/main/native/include/lowfisim/motormodel/SimpleMotorModel.h
@@ -0,0 +1,40 @@
+/*----------------------------------------------------------------------------*/
+/* Copyright (c) 2018 FIRST. 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 "lowfisim/motormodel/MotorModel.h"
+
+namespace frc {
+namespace sim {
+namespace lowfi {
+
+class SimpleMotorModel : public MotorModel {
+ public:
+ explicit SimpleMotorModel(double maxSpeed);
+
+ void Reset() override;
+ void SetVoltage(double voltage) override;
+ void Update(double elapsedTime) override;
+
+ double GetPosition() const override;
+ double GetVelocity() const override;
+ double GetAcceleration() const override;
+ double GetCurrent() const override;
+
+ protected:
+ double m_maxSpeed;
+ double m_voltagePercentage{0};
+ double m_position{0};
+ double m_velocity{0};
+
+ static constexpr double kMaxExpectedVoltage = 12;
+};
+
+} // namespace lowfi
+} // namespace sim
+} // namespace frc
diff --git a/simulation/lowfi_simulation/src/main/native/include/lowfisim/wpisimulators/WpiAnalogGyroSim.h b/simulation/lowfi_simulation/src/main/native/include/lowfisim/wpisimulators/WpiAnalogGyroSim.h
new file mode 100644
index 0000000..a5957ef
--- /dev/null
+++ b/simulation/lowfi_simulation/src/main/native/include/lowfisim/wpisimulators/WpiAnalogGyroSim.h
@@ -0,0 +1,32 @@
+/*----------------------------------------------------------------------------*/
+/* Copyright (c) 2008-2019 FIRST. 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 "lowfisim/GyroSim.h"
+#include "simulation/AnalogGyroSim.h"
+
+namespace frc {
+namespace sim {
+namespace lowfi {
+
+class WpiAnalogGyroSim : public GyroSim {
+ public:
+ explicit WpiAnalogGyroSim(int index);
+
+ bool IsWrapperInitialized() const override;
+
+ void SetAngle(double angle) override;
+ double GetAngle() override;
+
+ protected:
+ frc::sim::AnalogGyroSim m_gyroSimulator;
+};
+
+} // namespace lowfi
+} // namespace sim
+} // namespace frc
diff --git a/simulation/lowfi_simulation/src/main/native/include/lowfisim/wpisimulators/WpiEncoderSim.h b/simulation/lowfi_simulation/src/main/native/include/lowfisim/wpisimulators/WpiEncoderSim.h
new file mode 100644
index 0000000..0c936e5
--- /dev/null
+++ b/simulation/lowfi_simulation/src/main/native/include/lowfisim/wpisimulators/WpiEncoderSim.h
@@ -0,0 +1,31 @@
+/*----------------------------------------------------------------------------*/
+/* Copyright (c) 2008-2019 FIRST. 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 "lowfisim/EncoderSim.h"
+#include "simulation/EncoderSim.h"
+
+namespace frc {
+namespace sim {
+namespace lowfi {
+
+class WpiEncoderSim : public EncoderSim {
+ public:
+ explicit WpiEncoderSim(int index);
+ bool IsWrapperInitialized() const override;
+
+ void SetPosition(double position) override;
+ void SetVelocity(double velocity) override;
+
+ protected:
+ frc::sim::EncoderSim m_encoderSimulator;
+};
+
+} // namespace lowfi
+} // namespace sim
+} // namespace frc
diff --git a/simulation/lowfi_simulation/src/main/native/include/lowfisim/wpisimulators/WpiMotorSim.h b/simulation/lowfi_simulation/src/main/native/include/lowfisim/wpisimulators/WpiMotorSim.h
new file mode 100644
index 0000000..9323aec
--- /dev/null
+++ b/simulation/lowfi_simulation/src/main/native/include/lowfisim/wpisimulators/WpiMotorSim.h
@@ -0,0 +1,37 @@
+/*----------------------------------------------------------------------------*/
+/* Copyright (c) 2008-2019 FIRST. 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 "lowfisim/MotorSim.h"
+#include "lowfisim/motormodel/MotorModel.h"
+#include "simulation/PWMSim.h"
+
+namespace frc {
+namespace sim {
+namespace lowfi {
+
+class WpiMotorSim : public MotorSim {
+ public:
+ explicit WpiMotorSim(int index, MotorModel& motorModelSimulator);
+ bool IsWrapperInitialized() const override;
+
+ void Update(double elapsedTime);
+ double GetPosition() const override;
+ double GetVelocity() const override;
+ double GetAcceleration() const override;
+
+ private:
+ MotorModel& m_motorModelSimulation;
+ frc::sim::PWMSim m_pwmSimulator;
+
+ static constexpr double kDefaultVoltage = 12.0;
+};
+
+} // namespace lowfi
+} // namespace sim
+} // namespace frc
diff --git a/simulation/lowfi_simulation/src/test/native/cpp/lowfisim/MotorEncoderSimulatorTest.cpp b/simulation/lowfi_simulation/src/test/native/cpp/lowfisim/MotorEncoderSimulatorTest.cpp
new file mode 100644
index 0000000..9166de3
--- /dev/null
+++ b/simulation/lowfi_simulation/src/test/native/cpp/lowfisim/MotorEncoderSimulatorTest.cpp
@@ -0,0 +1,110 @@
+/*----------------------------------------------------------------------------*/
+/* Copyright (c) 2018-2019 FIRST. 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. */
+/*----------------------------------------------------------------------------*/
+
+#include "frc/Encoder.h"
+#include "frc/Talon.h"
+#include "gtest/gtest.h"
+#include "lowfisim/MotorEncoderConnector.h"
+#include "lowfisim/motormodel/SimpleMotorModel.h"
+#include "lowfisim/wpisimulators/WpiEncoderSim.h"
+#include "lowfisim/wpisimulators/WpiMotorSim.h"
+
+TEST(MotorEncoderConnectorTest, TestWithoutDistancePerPulseFullSpeed) {
+ frc::sim::lowfi::SimpleMotorModel motorModelSim(6000);
+ frc::sim::lowfi::WpiMotorSim motorSim(3, motorModelSim);
+ frc::sim::lowfi::WpiEncoderSim encoderSim(0);
+ frc::sim::lowfi::MotorEncoderConnector connector(motorSim, encoderSim);
+
+ EXPECT_FALSE(motorSim.IsWrapperInitialized());
+ EXPECT_FALSE(encoderSim.IsWrapperInitialized());
+ frc::Talon talon{3};
+ frc::Encoder encoder{3, 1};
+ EXPECT_TRUE(motorSim.IsWrapperInitialized());
+ EXPECT_TRUE(encoderSim.IsWrapperInitialized());
+
+ talon.Set(-1);
+ motorSim.Update(1);
+ connector.Update();
+
+ // Position
+ EXPECT_EQ(-6000, encoder.Get());
+ EXPECT_DOUBLE_EQ(-6000, encoder.GetDistance());
+
+ // Velocity
+ EXPECT_DOUBLE_EQ(-1.0 / 6000, encoder.GetPeriod());
+ EXPECT_DOUBLE_EQ(-6000, encoder.GetRate());
+}
+
+TEST(MotorEncoderConnectorTest, TestWithoutDistancePerPulseRealisitcUpdate) {
+ frc::Talon talon{3};
+ frc::Encoder encoder{3, 1};
+
+ frc::sim::lowfi::SimpleMotorModel motorModelSim(6000);
+ frc::sim::lowfi::WpiMotorSim motorSim(3, motorModelSim);
+ frc::sim::lowfi::WpiEncoderSim encoderSim(0);
+ frc::sim::lowfi::MotorEncoderConnector connector(motorSim, encoderSim);
+
+ talon.Set(0.5);
+ motorSim.Update(0.02);
+ connector.Update();
+
+ // Position
+ EXPECT_EQ(60, encoder.Get());
+ EXPECT_DOUBLE_EQ(60, encoder.GetDistance());
+
+ // Velocity
+ EXPECT_DOUBLE_EQ(1.0 / 3000, encoder.GetPeriod());
+ EXPECT_DOUBLE_EQ(3000, encoder.GetRate());
+}
+
+TEST(MotorEncoderConnectorTest, TestWithDistancePerPulseFullSpeed) {
+ frc::Talon talon{3};
+ frc::Encoder encoder{3, 1};
+ encoder.SetDistancePerPulse(0.001);
+
+ frc::sim::lowfi::SimpleMotorModel motorModelSim(6000);
+ frc::sim::lowfi::WpiMotorSim motorSim(3, motorModelSim);
+ frc::sim::lowfi::WpiEncoderSim encoderSim(0);
+ frc::sim::lowfi::MotorEncoderConnector connector(motorSim, encoderSim);
+
+ talon.Set(-1);
+
+ motorSim.Update(1);
+ connector.Update();
+
+ // Position
+ EXPECT_EQ(-6000000, encoder.Get());
+ EXPECT_DOUBLE_EQ(-6000, encoder.GetDistance());
+
+ // Velocity
+ EXPECT_EQ(-1.0 / 6000, encoder.GetPeriod());
+ EXPECT_DOUBLE_EQ(-6, encoder.GetRate());
+}
+
+TEST(MotorEncoderConnectorTest, TestWithDistancePerPulseRealistic) {
+ frc::Talon talon{3};
+ frc::Encoder encoder{3, 1};
+ encoder.SetDistancePerPulse(0.001);
+
+ frc::sim::lowfi::SimpleMotorModel motorModelSim(6000);
+ frc::sim::lowfi::WpiMotorSim motorSim(3, motorModelSim);
+ frc::sim::lowfi::WpiEncoderSim encoderSim(0);
+ frc::sim::lowfi::MotorEncoderConnector connector(motorSim, encoderSim);
+
+ talon.Set(0.5);
+
+ motorSim.Update(0.02);
+ connector.Update();
+
+ // Position
+ EXPECT_EQ(60000, encoder.Get());
+ EXPECT_DOUBLE_EQ(60, encoder.GetDistance());
+
+ // Velocity
+ EXPECT_EQ(1.0 / 3000, encoder.GetPeriod());
+ EXPECT_DOUBLE_EQ(3, encoder.GetRate());
+}
diff --git a/simulation/lowfi_simulation/src/test/native/cpp/lowfisim/motormodel/SimpleMotorModelSimulationTest.cpp b/simulation/lowfi_simulation/src/test/native/cpp/lowfisim/motormodel/SimpleMotorModelSimulationTest.cpp
new file mode 100644
index 0000000..21c5e7e
--- /dev/null
+++ b/simulation/lowfi_simulation/src/test/native/cpp/lowfisim/motormodel/SimpleMotorModelSimulationTest.cpp
@@ -0,0 +1,33 @@
+/*----------------------------------------------------------------------------*/
+/* Copyright (c) 2018-2019 FIRST. 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. */
+/*----------------------------------------------------------------------------*/
+
+#include "gtest/gtest.h"
+#include "lowfisim/motormodel/SimpleMotorModel.h"
+
+TEST(SimpleMotorModelSimulationTest, TestSimpleModel) {
+ frc::sim::lowfi::SimpleMotorModel motorModelSim(200);
+
+ // Test forward voltage
+ motorModelSim.SetVoltage(6);
+ motorModelSim.Update(0.5);
+
+ EXPECT_DOUBLE_EQ(50, motorModelSim.GetPosition());
+ EXPECT_DOUBLE_EQ(100, motorModelSim.GetVelocity());
+
+ // Test Reset
+ motorModelSim.Reset();
+ EXPECT_DOUBLE_EQ(0, motorModelSim.GetPosition());
+ EXPECT_DOUBLE_EQ(0, motorModelSim.GetVelocity());
+
+ // Test negative voltage
+ motorModelSim.Reset();
+ motorModelSim.SetVoltage(-3);
+ motorModelSim.Update(0.06);
+
+ EXPECT_DOUBLE_EQ(-3, motorModelSim.GetPosition());
+ EXPECT_DOUBLE_EQ(-50, motorModelSim.GetVelocity());
+}
diff --git a/simulation/lowfi_simulation/src/test/native/cpp/main.cpp b/simulation/lowfi_simulation/src/test/native/cpp/main.cpp
new file mode 100644
index 0000000..c6b6c58
--- /dev/null
+++ b/simulation/lowfi_simulation/src/test/native/cpp/main.cpp
@@ -0,0 +1,17 @@
+/*----------------------------------------------------------------------------*/
+/* Copyright (c) 2015-2019 FIRST. 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. */
+/*----------------------------------------------------------------------------*/
+
+#include <hal/HALBase.h>
+
+#include "gtest/gtest.h"
+
+int main(int argc, char** argv) {
+ HAL_Initialize(500, 0);
+ ::testing::InitGoogleTest(&argc, argv);
+ int ret = RUN_ALL_TESTS();
+ return ret;
+}