mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
Remove old simulation bits (ds_nt, lowfi, print) (#2432)
These are little used, not actively maintained, and the simulation GUI and alternative plans for physics simulation replace the functionality.
This commit is contained in:
@@ -26,13 +26,9 @@ include 'wpilibcIntegrationTests'
|
||||
include 'wpilibjExamples'
|
||||
include 'wpilibjIntegrationTests'
|
||||
include 'wpilibj'
|
||||
include 'simulation:halsim_print'
|
||||
include 'simulation:halsim_lowfi'
|
||||
include 'simulation:halsim_ds_nt'
|
||||
include 'simulation:gz_msgs'
|
||||
include 'simulation:frc_gazebo_plugins'
|
||||
include 'simulation:halsim_gazebo'
|
||||
include 'simulation:lowfi_simulation'
|
||||
include 'simulation:halsim_ds_socket'
|
||||
include 'simulation:halsim_gui'
|
||||
include 'cameraserver'
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
add_subdirectory(halsim_gui)
|
||||
add_subdirectory(halsim_print)
|
||||
add_subdirectory(halsim_lowfi)
|
||||
add_subdirectory(halsim_ds_nt)
|
||||
#add_subdirectory(gz_msgs)
|
||||
#add_subdirectory(frc_gazebo_plugins)
|
||||
#add_subdirectory(halsim_gazebo)
|
||||
#add_subdirectory(lowfi_simulation)
|
||||
add_subdirectory(halsim_ds_socket)
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
project(halsim_ds_nt)
|
||||
|
||||
include(CompileWarnings)
|
||||
|
||||
file(GLOB halsim_ds_nt_src src/main/native/cpp/*.cpp)
|
||||
|
||||
add_library(halsim_ds_nt MODULE ${halsim_ds_nt_src})
|
||||
wpilib_target_warnings(halsim_ds_nt)
|
||||
set_target_properties(halsim_ds_nt PROPERTIES DEBUG_POSTFIX "d")
|
||||
target_link_libraries(halsim_ds_nt PUBLIC hal ntcore)
|
||||
|
||||
target_include_directories(halsim_ds_nt PRIVATE src/main/native/include)
|
||||
|
||||
set_property(TARGET halsim_ds_nt PROPERTY FOLDER "libraries")
|
||||
|
||||
install(TARGETS halsim_ds_nt EXPORT halsim_ds_nt DESTINATION "${main_lib_dest}")
|
||||
@@ -1,9 +0,0 @@
|
||||
description = "A simulation shared object that uses NetworkTables to act as a stand-in for the FRC Driver Station"
|
||||
|
||||
ext {
|
||||
includeNtCore = true
|
||||
includeWpiutil = true
|
||||
pluginName = 'halsim_ds_nt'
|
||||
}
|
||||
|
||||
apply from: "${rootDir}/shared/plugins/setupBuild.gradle"
|
||||
@@ -1,8 +0,0 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
int main() {}
|
||||
@@ -1,194 +0,0 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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 "HALSimDsNt.h"
|
||||
|
||||
void HALSimDSNT::Initialize() {
|
||||
rootTable =
|
||||
nt::NetworkTableInstance::GetDefault().GetTable("sim")->GetSubTable(
|
||||
"DS_CONTROL"); // Not to be confused with sim::DriverStation from
|
||||
// HALSim LowFi
|
||||
|
||||
// LOOP TIMING //
|
||||
|
||||
auto timinghz = rootTable->GetEntry("timing_hz");
|
||||
timinghz.ForceSetDouble(50);
|
||||
timinghz.AddListener(
|
||||
[this](const nt::EntryNotification& ev) -> void {
|
||||
double valIn = ev.value->GetDouble();
|
||||
double val = 0;
|
||||
val = (valIn < 1 ? 1 : valIn > 100 ? 100 : valIn);
|
||||
|
||||
if (val != valIn) {
|
||||
this->rootTable->GetEntry("timing_hz").ForceSetDouble(val);
|
||||
Flush();
|
||||
}
|
||||
|
||||
this->timingHz = val;
|
||||
},
|
||||
NT_NotifyKind::NT_NOTIFY_UPDATE);
|
||||
|
||||
// MODES //
|
||||
|
||||
modeTable = rootTable->GetSubTable("mode");
|
||||
auto mtele = modeTable->GetEntry("teleop?");
|
||||
auto mauto = modeTable->GetEntry("auto?");
|
||||
auto mtest = modeTable->GetEntry("test?");
|
||||
auto enabled = modeTable->GetEntry("enabled?");
|
||||
auto estop = modeTable->GetEntry("estop?");
|
||||
|
||||
mtele.ForceSetBoolean(true);
|
||||
mauto.ForceSetBoolean(false);
|
||||
mtest.ForceSetBoolean(false);
|
||||
enabled.ForceSetBoolean(false);
|
||||
estop.ForceSetBoolean(false);
|
||||
|
||||
mtele.AddListener(
|
||||
[this](const nt::EntryNotification& ev) -> void {
|
||||
this->HandleModePress(HALSimDSNT_Mode::teleop, ev.value->GetBoolean());
|
||||
},
|
||||
NT_NotifyKind::NT_NOTIFY_UPDATE);
|
||||
|
||||
mauto.AddListener(
|
||||
[this](const nt::EntryNotification& ev) -> void {
|
||||
this->HandleModePress(HALSimDSNT_Mode::auton, ev.value->GetBoolean());
|
||||
},
|
||||
NT_NotifyKind::NT_NOTIFY_UPDATE);
|
||||
|
||||
mtest.AddListener(
|
||||
[this](const nt::EntryNotification& ev) -> void {
|
||||
this->HandleModePress(HALSimDSNT_Mode::test, ev.value->GetBoolean());
|
||||
},
|
||||
NT_NotifyKind::NT_NOTIFY_UPDATE);
|
||||
|
||||
enabled.AddListener(
|
||||
[this](const nt::EntryNotification& ev) -> void {
|
||||
std::scoped_lock lock(modeMutex);
|
||||
if (!this->isEstop) {
|
||||
this->isEnabled = ev.value->GetBoolean();
|
||||
} else {
|
||||
this->isEnabled = false;
|
||||
}
|
||||
this->DoModeUpdate();
|
||||
this->UpdateModeButtons();
|
||||
},
|
||||
NT_NotifyKind::NT_NOTIFY_UPDATE);
|
||||
|
||||
estop.AddListener(
|
||||
[this](const nt::EntryNotification& ev) -> void {
|
||||
std::scoped_lock lock(modeMutex);
|
||||
this->isEstop = ev.value->GetBoolean();
|
||||
if (this->isEstop) {
|
||||
this->isEnabled = false;
|
||||
}
|
||||
this->DoModeUpdate();
|
||||
this->UpdateModeButtons();
|
||||
},
|
||||
NT_NotifyKind::NT_NOTIFY_UPDATE);
|
||||
|
||||
// ALLIANCES //
|
||||
|
||||
allianceTable = rootTable->GetSubTable("alliance");
|
||||
auto allianceStation = allianceTable->GetEntry("station");
|
||||
auto allianceColorRed = allianceTable->GetEntry("red?");
|
||||
|
||||
allianceStation.ForceSetDouble(1);
|
||||
allianceColorRed.ForceSetBoolean(true);
|
||||
|
||||
allianceStation.AddListener(
|
||||
[this](const nt::EntryNotification& ev) -> void {
|
||||
double stnIn = ev.value->GetDouble();
|
||||
double stn = 0;
|
||||
stn = (stnIn > 3 ? 3 : stnIn < 1 ? 1 : stnIn);
|
||||
|
||||
if (stn != stnIn) {
|
||||
this->allianceTable->GetEntry("station").ForceSetDouble(stn);
|
||||
Flush();
|
||||
}
|
||||
|
||||
this->allianceStation = stn;
|
||||
this->DoAllianceUpdate();
|
||||
},
|
||||
NT_NotifyKind::NT_NOTIFY_UPDATE);
|
||||
|
||||
allianceColorRed.AddListener(
|
||||
[this](const nt::EntryNotification& ev) -> void {
|
||||
this->isAllianceRed = ev.value->GetBoolean();
|
||||
this->DoAllianceUpdate();
|
||||
},
|
||||
NT_NotifyKind::NT_NOTIFY_UPDATE);
|
||||
|
||||
// FINAL LOGIC //
|
||||
|
||||
Flush();
|
||||
|
||||
loopThread = std::thread([this]() -> void {
|
||||
this->running = true;
|
||||
this->LoopFunc();
|
||||
});
|
||||
loopThread.detach();
|
||||
}
|
||||
|
||||
void HALSimDSNT::HandleModePress(enum HALSimDSNT_Mode mode, bool isPressed) {
|
||||
if (isPressed) {
|
||||
if (mode != currentMode) {
|
||||
std::scoped_lock lock(modeMutex);
|
||||
currentMode = mode;
|
||||
isEnabled = false;
|
||||
this->DoModeUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
this->UpdateModeButtons();
|
||||
}
|
||||
|
||||
void HALSimDSNT::UpdateModeButtons() {
|
||||
modeTable->GetEntry("teleop?").ForceSetBoolean(currentMode ==
|
||||
HALSimDSNT_Mode::teleop);
|
||||
modeTable->GetEntry("auto?").ForceSetBoolean(currentMode ==
|
||||
HALSimDSNT_Mode::auton);
|
||||
modeTable->GetEntry("test?").ForceSetBoolean(currentMode ==
|
||||
HALSimDSNT_Mode::test);
|
||||
modeTable->GetEntry("enabled?").ForceSetBoolean(isEnabled);
|
||||
Flush();
|
||||
}
|
||||
|
||||
void HALSimDSNT::DoModeUpdate() {
|
||||
HALSIM_SetDriverStationAutonomous(currentMode == HALSimDSNT_Mode::auton);
|
||||
HALSIM_SetDriverStationTest(currentMode == HALSimDSNT_Mode::test);
|
||||
HALSIM_SetDriverStationEnabled(isEnabled);
|
||||
if (isEnabled && !lastIsEnabled) {
|
||||
currentMatchTime = 0;
|
||||
}
|
||||
lastIsEnabled = isEnabled;
|
||||
HALSIM_SetDriverStationEStop(isEstop);
|
||||
HALSIM_SetDriverStationFmsAttached(false);
|
||||
HALSIM_SetDriverStationDsAttached(true);
|
||||
HALSIM_NotifyDriverStationNewData();
|
||||
}
|
||||
|
||||
void HALSimDSNT::DoAllianceUpdate() {
|
||||
HALSIM_SetDriverStationAllianceStationId(static_cast<HAL_AllianceStationID>(
|
||||
(isAllianceRed ? HAL_AllianceStationID_kRed1
|
||||
: HAL_AllianceStationID_kBlue1) +
|
||||
(static_cast<int32_t>(allianceStation) - 1)));
|
||||
}
|
||||
|
||||
void HALSimDSNT::LoopFunc() {
|
||||
while (running) {
|
||||
double dt = 1000 / timingHz;
|
||||
std::this_thread::sleep_for(
|
||||
std::chrono::milliseconds(static_cast<int64_t>(dt)));
|
||||
if (isEnabled) {
|
||||
currentMatchTime = currentMatchTime + dt;
|
||||
HALSIM_SetDriverStationMatchTime(currentMatchTime);
|
||||
}
|
||||
HALSIM_NotifyDriverStationNewData();
|
||||
}
|
||||
}
|
||||
|
||||
void HALSimDSNT::Flush() { rootTable->GetInstance().Flush(); }
|
||||
@@ -1,26 +0,0 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017-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 <iostream>
|
||||
|
||||
#include <HALSimDsNt.h>
|
||||
|
||||
static HALSimDSNT dsnt;
|
||||
|
||||
extern "C" {
|
||||
#if defined(WIN32) || defined(_WIN32)
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
int HALSIM_InitExtension(void) {
|
||||
std::cout << "DriverStationNT Initializing." << std::endl;
|
||||
|
||||
dsnt.Initialize();
|
||||
|
||||
std::cout << "DriverStationNT Initialized!" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
} // extern "C"
|
||||
@@ -1,37 +0,0 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017-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 <atomic>
|
||||
#include <memory>
|
||||
#include <thread>
|
||||
|
||||
#include <mockdata/DriverStationData.h>
|
||||
#include <networktables/NetworkTableInstance.h>
|
||||
#include <wpi/mutex.h>
|
||||
|
||||
enum HALSimDSNT_Mode { teleop, auton, test };
|
||||
|
||||
class HALSimDSNT {
|
||||
public:
|
||||
std::shared_ptr<nt::NetworkTable> rootTable, modeTable, allianceTable;
|
||||
enum HALSimDSNT_Mode currentMode;
|
||||
bool isEnabled, lastIsEnabled, isEstop;
|
||||
std::atomic<bool> isAllianceRed, running;
|
||||
std::atomic<double> currentMatchTime, timingHz, allianceStation;
|
||||
std::thread loopThread;
|
||||
wpi::mutex modeMutex;
|
||||
|
||||
void Initialize();
|
||||
void HandleModePress(enum HALSimDSNT_Mode mode, bool isPressed);
|
||||
void UpdateModeButtons();
|
||||
void DoModeUpdate();
|
||||
void DoAllianceUpdate();
|
||||
void LoopFunc();
|
||||
void Flush();
|
||||
};
|
||||
@@ -1,16 +0,0 @@
|
||||
project(halsim_lowfi)
|
||||
|
||||
include(CompileWarnings)
|
||||
|
||||
file(GLOB halsim_lowfi_src src/main/native/cpp/*.cpp)
|
||||
|
||||
add_library(halsim_lowfi MODULE ${halsim_lowfi_src})
|
||||
wpilib_target_warnings(halsim_lowfi)
|
||||
set_target_properties(halsim_lowfi PROPERTIES DEBUG_POSTFIX "d")
|
||||
target_link_libraries(halsim_lowfi PUBLIC hal ntcore)
|
||||
|
||||
target_include_directories(halsim_lowfi PRIVATE src/main/native/include)
|
||||
|
||||
set_property(TARGET halsim_lowfi PROPERTY FOLDER "libraries")
|
||||
|
||||
install(TARGETS halsim_lowfi EXPORT halsim_lowfi DESTINATION "${main_lib_dest}")
|
||||
@@ -1,9 +0,0 @@
|
||||
description = "A simulation shared object that publishes basic robot I/O to NetworkTables."
|
||||
|
||||
ext {
|
||||
includeNtCore = true
|
||||
includeWpiutil = true
|
||||
pluginName = 'halsim_lowfi'
|
||||
}
|
||||
|
||||
apply from: "${rootDir}/shared/plugins/setupBuild.gradle"
|
||||
@@ -1,8 +0,0 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
int main() {}
|
||||
@@ -1,62 +0,0 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017-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 "HALSimLowFi.h"
|
||||
|
||||
#include <wpi/Twine.h>
|
||||
|
||||
void HALSimLowFi::Initialize() {
|
||||
table = nt::NetworkTableInstance::GetDefault().GetTable("sim");
|
||||
}
|
||||
|
||||
void HALSimNTProvider::Inject(std::shared_ptr<HALSimLowFi> parentArg,
|
||||
std::string tableNameArg) {
|
||||
parent = parentArg;
|
||||
tableName = std::move(tableNameArg);
|
||||
table = parent->table->GetSubTable(tableName);
|
||||
|
||||
this->Initialize();
|
||||
}
|
||||
|
||||
void NTProviderBaseCallback(const char* name, void* param,
|
||||
const struct HAL_Value* value) {
|
||||
auto info =
|
||||
static_cast<struct HALSimNTProvider::NTProviderCallbackInfo*>(param);
|
||||
uint32_t chan = static_cast<uint32_t>(info->channel);
|
||||
auto provider = info->provider;
|
||||
auto table = info->table;
|
||||
provider->OnCallback(chan, table);
|
||||
}
|
||||
|
||||
void HALSimNTProvider::InitializeDefault(
|
||||
int numChannels, HALCbRegisterIndexedFunc registerFunc) {
|
||||
this->numChannels = numChannels;
|
||||
cbInfos.reserve(numChannels);
|
||||
for (int i = 0; i < numChannels; i++) {
|
||||
struct NTProviderCallbackInfo info = {
|
||||
this, table->GetSubTable(tableName + wpi::Twine(i)), i};
|
||||
cbInfos.emplace_back(info);
|
||||
}
|
||||
|
||||
for (auto& info : cbInfos) {
|
||||
registerFunc(info.channel, NTProviderBaseCallback, &info, true);
|
||||
OnInitializedChannel(info.channel, info.table);
|
||||
}
|
||||
}
|
||||
|
||||
void HALSimNTProvider::InitializeDefaultSingle(
|
||||
HALCbRegisterSingleFunc registerFunc) {
|
||||
struct NTProviderCallbackInfo info = {this, table, 0};
|
||||
cbInfos.push_back(info);
|
||||
|
||||
for (auto& info : cbInfos) {
|
||||
registerFunc(NTProviderBaseCallback, &info, true);
|
||||
}
|
||||
}
|
||||
|
||||
void HALSimNTProvider::OnInitializedChannel(
|
||||
uint32_t channel, std::shared_ptr<nt::NetworkTable> table) {}
|
||||
@@ -1,56 +0,0 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017-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 "NTProvider_Analog.h"
|
||||
|
||||
#include <hal/Ports.h>
|
||||
#include <mockdata/AnalogInData.h>
|
||||
#include <mockdata/AnalogOutData.h>
|
||||
|
||||
void HALSimNTProviderAnalogIn::Initialize() {
|
||||
InitializeDefault(HAL_GetNumAnalogInputs(),
|
||||
HALSIM_RegisterAnalogInAllCallbacks);
|
||||
}
|
||||
|
||||
void HALSimNTProviderAnalogIn::OnCallback(
|
||||
uint32_t chan, std::shared_ptr<nt::NetworkTable> table) {
|
||||
table->GetEntry("init?").SetBoolean(HALSIM_GetAnalogInInitialized(chan));
|
||||
table->GetEntry("avg_bits").SetDouble(HALSIM_GetAnalogInAverageBits(chan));
|
||||
table->GetEntry("oversample_bits")
|
||||
.SetDouble(HALSIM_GetAnalogInOversampleBits(chan));
|
||||
table->GetEntry("voltage").SetDouble(HALSIM_GetAnalogInVoltage(chan));
|
||||
|
||||
auto accum = table->GetSubTable("accum");
|
||||
accum->GetEntry("init?").SetBoolean(
|
||||
HALSIM_GetAnalogInAccumulatorInitialized(chan));
|
||||
accum->GetEntry("value").SetDouble(HALSIM_GetAnalogInAccumulatorValue(chan));
|
||||
accum->GetEntry("count").SetDouble(HALSIM_GetAnalogInAccumulatorCount(chan));
|
||||
accum->GetEntry("center").SetDouble(
|
||||
HALSIM_GetAnalogInAccumulatorCenter(chan));
|
||||
accum->GetEntry("deadband")
|
||||
.SetDouble(HALSIM_GetAnalogInAccumulatorDeadband(chan));
|
||||
}
|
||||
|
||||
void HALSimNTProviderAnalogIn::OnInitializedChannel(
|
||||
uint32_t chan, std::shared_ptr<nt::NetworkTable> table) {
|
||||
table->GetEntry("voltage").AddListener(
|
||||
[=](const nt::EntryNotification& ev) -> void {
|
||||
HALSIM_SetAnalogInVoltage(chan, ev.value->GetDouble());
|
||||
},
|
||||
NT_NotifyKind::NT_NOTIFY_UPDATE);
|
||||
}
|
||||
|
||||
void HALSimNTProviderAnalogOut::Initialize() {
|
||||
InitializeDefault(HAL_GetNumAnalogOutputs(),
|
||||
HALSIM_RegisterAnalogOutAllCallbacks);
|
||||
}
|
||||
|
||||
void HALSimNTProviderAnalogOut::OnCallback(
|
||||
uint32_t chan, std::shared_ptr<nt::NetworkTable> table) {
|
||||
table->GetEntry("init?").SetBoolean(HALSIM_GetAnalogOutInitialized(chan));
|
||||
table->GetEntry("voltage").SetDouble(HALSIM_GetAnalogOutVoltage(chan));
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017-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 "NTProvider_DIO.h"
|
||||
|
||||
#include <hal/Ports.h>
|
||||
#include <mockdata/DIOData.h>
|
||||
|
||||
void HALSimNTProviderDIO::Initialize() {
|
||||
InitializeDefault(HAL_GetNumDigitalChannels(),
|
||||
HALSIM_RegisterDIOAllCallbacks);
|
||||
}
|
||||
|
||||
void HALSimNTProviderDIO::OnCallback(uint32_t chan,
|
||||
std::shared_ptr<nt::NetworkTable> table) {
|
||||
table->GetEntry("init?").SetBoolean(HALSIM_GetDIOInitialized(chan));
|
||||
table->GetEntry("value").SetBoolean(HALSIM_GetDIOValue(chan));
|
||||
table->GetEntry("pulse_length").SetDouble(HALSIM_GetDIOPulseLength(chan));
|
||||
table->GetEntry("input?").SetBoolean(HALSIM_GetDIOIsInput(chan));
|
||||
}
|
||||
|
||||
void HALSimNTProviderDIO::OnInitializedChannel(
|
||||
uint32_t chan, std::shared_ptr<nt::NetworkTable> table) {
|
||||
table->GetEntry("value").AddListener(
|
||||
[=](const nt::EntryNotification& ev) -> void {
|
||||
if (HALSIM_GetDIOIsInput(chan)) {
|
||||
HALSIM_SetDIOValue(chan, ev.value->GetBoolean());
|
||||
}
|
||||
},
|
||||
NT_NotifyKind::NT_NOTIFY_UPDATE);
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017-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 "NTProvider_DriverStation.h"
|
||||
|
||||
#include <hal/Ports.h>
|
||||
#include <mockdata/DriverStationData.h>
|
||||
|
||||
void HALSimNTProviderDriverStation::Initialize() {
|
||||
InitializeDefaultSingle(HALSIM_RegisterDriverStationAllCallbacks);
|
||||
}
|
||||
|
||||
void HALSimNTProviderDriverStation::OnCallback(
|
||||
uint32_t chan, std::shared_ptr<nt::NetworkTable> table) {
|
||||
bool auton = HALSIM_GetDriverStationAutonomous(),
|
||||
test = HALSIM_GetDriverStationTest(),
|
||||
enabled = HALSIM_GetDriverStationEnabled();
|
||||
|
||||
bool teleop = (!auton && !test && enabled);
|
||||
|
||||
table->GetEntry("enabled?").SetBoolean(enabled);
|
||||
table->GetEntry("autonomous?").SetBoolean(auton);
|
||||
table->GetEntry("test?").SetBoolean(test);
|
||||
table->GetEntry("teleop?").SetBoolean(teleop);
|
||||
table->GetEntry("estop?").SetBoolean(HALSIM_GetDriverStationEStop());
|
||||
table->GetEntry("fms?").SetBoolean(HALSIM_GetDriverStationFmsAttached());
|
||||
table->GetEntry("ds?").SetBoolean(HALSIM_GetDriverStationDsAttached());
|
||||
table->GetEntry("match_time").SetDouble(HALSIM_GetDriverStationMatchTime());
|
||||
|
||||
// TODO: Joysticks
|
||||
|
||||
auto alliance = table->GetSubTable("alliance");
|
||||
auto allianceValue = HALSIM_GetDriverStationAllianceStationId();
|
||||
alliance->GetEntry("color").SetString(
|
||||
(allianceValue == HAL_AllianceStationID_kRed1 ||
|
||||
allianceValue == HAL_AllianceStationID_kRed2 ||
|
||||
allianceValue == HAL_AllianceStationID_kRed3)
|
||||
? "red"
|
||||
: "blue");
|
||||
int station = 0;
|
||||
|
||||
switch (allianceValue) {
|
||||
case HAL_AllianceStationID_kRed1:
|
||||
case HAL_AllianceStationID_kBlue1:
|
||||
station = 1;
|
||||
break;
|
||||
case HAL_AllianceStationID_kRed2:
|
||||
case HAL_AllianceStationID_kBlue2:
|
||||
station = 2;
|
||||
break;
|
||||
case HAL_AllianceStationID_kRed3:
|
||||
case HAL_AllianceStationID_kBlue3:
|
||||
station = 3;
|
||||
break;
|
||||
}
|
||||
alliance->GetEntry("station").SetDouble(station);
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017-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 "NTProvider_Encoder.h"
|
||||
|
||||
#include <hal/Ports.h>
|
||||
#include <mockdata/EncoderData.h>
|
||||
|
||||
void HALSimNTProviderEncoder::Initialize() {
|
||||
InitializeDefault(HAL_GetNumEncoders(), HALSIM_RegisterEncoderAllCallbacks);
|
||||
}
|
||||
|
||||
void HALSimNTProviderEncoder::OnCallback(
|
||||
uint32_t chan, std::shared_ptr<nt::NetworkTable> table) {
|
||||
table->GetEntry("init?").SetBoolean(HALSIM_GetEncoderInitialized(chan));
|
||||
table->GetEntry("count").SetDouble(HALSIM_GetEncoderCount(chan));
|
||||
table->GetEntry("period").SetDouble(HALSIM_GetEncoderPeriod(chan));
|
||||
table->GetEntry("reset?").SetBoolean(HALSIM_GetEncoderReset(chan));
|
||||
table->GetEntry("max_period").SetDouble(HALSIM_GetEncoderMaxPeriod(chan));
|
||||
table->GetEntry("direction").SetBoolean(HALSIM_GetEncoderDirection(chan));
|
||||
table->GetEntry("reverse_direction?")
|
||||
.SetBoolean(HALSIM_GetEncoderReverseDirection(chan));
|
||||
table->GetEntry("samples_to_avg")
|
||||
.SetDouble(HALSIM_GetEncoderSamplesToAverage(chan));
|
||||
}
|
||||
|
||||
void HALSimNTProviderEncoder::OnInitializedChannel(
|
||||
uint32_t chan, std::shared_ptr<nt::NetworkTable> table) {
|
||||
table->GetEntry("count").AddListener(
|
||||
[=](const nt::EntryNotification& ev) -> void {
|
||||
HALSIM_SetEncoderCount(chan,
|
||||
static_cast<int32_t>(ev.value->GetDouble()));
|
||||
},
|
||||
NT_NotifyKind::NT_NOTIFY_UPDATE);
|
||||
|
||||
table->GetEntry("direction")
|
||||
.AddListener(
|
||||
[=](const nt::EntryNotification& ev) -> void {
|
||||
HALSIM_SetEncoderDirection(chan, ev.value->GetBoolean());
|
||||
},
|
||||
NT_NotifyKind::NT_NOTIFY_UPDATE);
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017-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 "NTProvider_PWM.h"
|
||||
|
||||
#include <hal/Ports.h>
|
||||
#include <mockdata/PWMData.h>
|
||||
|
||||
void HALSimNTProviderPWM::Initialize() {
|
||||
InitializeDefault(HAL_GetNumPWMChannels(), HALSIM_RegisterPWMAllCallbacks);
|
||||
}
|
||||
|
||||
void HALSimNTProviderPWM::OnCallback(uint32_t chan,
|
||||
std::shared_ptr<nt::NetworkTable> table) {
|
||||
table->GetEntry("init?").SetBoolean(HALSIM_GetPWMInitialized(chan));
|
||||
table->GetEntry("speed").SetDouble(HALSIM_GetPWMSpeed(chan));
|
||||
table->GetEntry("position").SetDouble(HALSIM_GetPWMPosition(chan));
|
||||
table->GetEntry("raw").SetDouble(HALSIM_GetPWMRawValue(chan));
|
||||
table->GetEntry("period_scale").SetDouble(HALSIM_GetPWMPeriodScale(chan));
|
||||
table->GetEntry("zero_latch?").SetBoolean(HALSIM_GetPWMZeroLatch(chan));
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017-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 "NTProvider_Relay.h"
|
||||
|
||||
#include <hal/Ports.h>
|
||||
#include <mockdata/RelayData.h>
|
||||
|
||||
void HALSimNTProviderRelay::Initialize() {
|
||||
InitializeDefault(HAL_GetNumRelayHeaders(), HALSIM_RegisterRelayAllCallbacks);
|
||||
}
|
||||
|
||||
void HALSimNTProviderRelay::OnCallback(
|
||||
uint32_t chan, std::shared_ptr<nt::NetworkTable> table) {
|
||||
table->GetEntry("init_fwd?")
|
||||
.SetBoolean(HALSIM_GetRelayInitializedForward(chan));
|
||||
table->GetEntry("init_rvs?")
|
||||
.SetBoolean(HALSIM_GetRelayInitializedReverse(chan));
|
||||
table->GetEntry("fwd?").SetBoolean(HALSIM_GetRelayForward(chan));
|
||||
table->GetEntry("rvs?").SetBoolean(HALSIM_GetRelayReverse(chan));
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017-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 "NTProvider_RoboRIO.h"
|
||||
|
||||
#include <hal/Ports.h>
|
||||
#include <mockdata/RoboRioData.h>
|
||||
|
||||
void HALSimNTProviderRoboRIO::Initialize() {
|
||||
InitializeDefault(1, HALSIM_RegisterRoboRioAllCallbacks);
|
||||
}
|
||||
|
||||
void HALSimNTProviderRoboRIO::OnCallback(
|
||||
uint32_t chan, std::shared_ptr<nt::NetworkTable> table) {
|
||||
table->GetEntry("fpga_button?").SetBoolean(HALSIM_GetRoboRioFPGAButton(chan));
|
||||
|
||||
table->GetEntry("vin_voltage").SetDouble(HALSIM_GetRoboRioVInVoltage(chan));
|
||||
table->GetEntry("vin_current").SetDouble(HALSIM_GetRoboRioVInCurrent(chan));
|
||||
|
||||
auto t6v = table->GetSubTable("6V");
|
||||
t6v->GetEntry("voltage").SetDouble(HALSIM_GetRoboRioUserVoltage6V(chan));
|
||||
t6v->GetEntry("current").SetDouble(HALSIM_GetRoboRioUserCurrent6V(chan));
|
||||
t6v->GetEntry("active?").SetBoolean(HALSIM_GetRoboRioUserActive6V(chan));
|
||||
t6v->GetEntry("faults").SetDouble(HALSIM_GetRoboRioUserFaults6V(chan));
|
||||
|
||||
auto t5v = table->GetSubTable("5V");
|
||||
t5v->GetEntry("voltage").SetDouble(HALSIM_GetRoboRioUserVoltage5V(chan));
|
||||
t5v->GetEntry("current").SetDouble(HALSIM_GetRoboRioUserCurrent5V(chan));
|
||||
t5v->GetEntry("active?").SetBoolean(HALSIM_GetRoboRioUserActive5V(chan));
|
||||
t5v->GetEntry("faults").SetDouble(HALSIM_GetRoboRioUserFaults5V(chan));
|
||||
|
||||
auto t3v3 = table->GetSubTable("3V3");
|
||||
t3v3->GetEntry("voltage").SetDouble(HALSIM_GetRoboRioUserVoltage3V3(chan));
|
||||
t3v3->GetEntry("current").SetDouble(HALSIM_GetRoboRioUserCurrent3V3(chan));
|
||||
t3v3->GetEntry("active?").SetBoolean(HALSIM_GetRoboRioUserActive3V3(chan));
|
||||
t3v3->GetEntry("faults").SetDouble(HALSIM_GetRoboRioUserFaults3V3(chan));
|
||||
}
|
||||
|
||||
void HALSimNTProviderRoboRIO::OnInitializedChannel(
|
||||
uint32_t chan, std::shared_ptr<nt::NetworkTable> table) {
|
||||
table->GetEntry("fpga_button?")
|
||||
.AddListener(
|
||||
[=](const nt::EntryNotification& ev) -> void {
|
||||
HALSIM_SetRoboRioFPGAButton(chan, ev.value->GetBoolean());
|
||||
},
|
||||
NT_NotifyKind::NT_NOTIFY_UPDATE);
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017-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 "NTProvider_dPWM.h"
|
||||
|
||||
#include <hal/Ports.h>
|
||||
#include <mockdata/DigitalPWMData.h>
|
||||
|
||||
void HALSimNTProviderDigitalPWM::Initialize() {
|
||||
InitializeDefault(HAL_GetNumDigitalPWMOutputs(),
|
||||
HALSIM_RegisterDigitalPWMAllCallbacks);
|
||||
}
|
||||
|
||||
void HALSimNTProviderDigitalPWM::OnCallback(
|
||||
uint32_t chan, std::shared_ptr<nt::NetworkTable> table) {
|
||||
table->GetEntry("init?").SetBoolean(HALSIM_GetDigitalPWMInitialized(chan));
|
||||
table->GetEntry("dio_pin").SetDouble(HALSIM_GetDigitalPWMPin(chan));
|
||||
table->GetEntry("duty_cycle").SetDouble(HALSIM_GetDigitalPWMDutyCycle(chan));
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017-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 <iostream>
|
||||
|
||||
#include <HALSimLowFi.h>
|
||||
#include <NTProvider_Analog.h>
|
||||
#include <NTProvider_DIO.h>
|
||||
#include <NTProvider_DriverStation.h>
|
||||
#include <NTProvider_Encoder.h>
|
||||
#include <NTProvider_PWM.h>
|
||||
#include <NTProvider_Relay.h>
|
||||
#include <NTProvider_RoboRIO.h>
|
||||
#include <NTProvider_dPWM.h>
|
||||
|
||||
static HALSimLowFi halsim_lowfi;
|
||||
|
||||
static HALSimNTProviderPWM pwm_provider;
|
||||
static HALSimNTProviderDigitalPWM dpwm_provider;
|
||||
static HALSimNTProviderDIO dio_provider;
|
||||
static HALSimNTProviderAnalogIn ai_provider;
|
||||
static HALSimNTProviderAnalogOut ao_provider;
|
||||
static HALSimNTProviderDriverStation ds_provider;
|
||||
static HALSimNTProviderEncoder encoder_provider;
|
||||
static HALSimNTProviderRelay relay_provider;
|
||||
static HALSimNTProviderRoboRIO roborio_provider;
|
||||
|
||||
extern "C" {
|
||||
#if defined(WIN32) || defined(_WIN32)
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
int HALSIM_InitExtension(void) {
|
||||
std::cout << "NetworkTables LowFi Simulator Initializing." << std::endl;
|
||||
halsim_lowfi.Initialize();
|
||||
halsim_lowfi.table->GetInstance().StartServer("networktables.ini");
|
||||
halsim_lowfi.table->GetInstance().SetUpdateRate(0.05);
|
||||
auto lowfi = std::make_shared<HALSimLowFi>(halsim_lowfi);
|
||||
|
||||
pwm_provider.Inject(lowfi, "PWM");
|
||||
dpwm_provider.Inject(lowfi, "dPWM");
|
||||
dio_provider.Inject(lowfi, "DIO");
|
||||
ai_provider.Inject(lowfi, "AI");
|
||||
ao_provider.Inject(lowfi, "AO");
|
||||
ds_provider.Inject(lowfi, "DriverStation");
|
||||
encoder_provider.Inject(lowfi, "Encoder");
|
||||
relay_provider.Inject(lowfi, "Relay");
|
||||
roborio_provider.Inject(lowfi, "RoboRIO");
|
||||
|
||||
std::cout << "NetworkTables LowFi Simulator Initialized!" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
} // extern "C"
|
||||
@@ -1,58 +0,0 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017-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 <cinttypes>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <mockdata/NotifyListener.h>
|
||||
#include <networktables/NetworkTableInstance.h>
|
||||
|
||||
class HALSimLowFi {
|
||||
public:
|
||||
std::shared_ptr<nt::NetworkTable> table;
|
||||
void Initialize();
|
||||
};
|
||||
|
||||
typedef void (*HALCbRegisterIndexedFunc)(int32_t index,
|
||||
HAL_NotifyCallback callback,
|
||||
void* param, HAL_Bool initialNotify);
|
||||
typedef void (*HALCbRegisterSingleFunc)(HAL_NotifyCallback callback,
|
||||
void* param, HAL_Bool initialNotify);
|
||||
|
||||
void NTProviderBaseCallback(const char* name, void* param,
|
||||
const struct HAL_Value* value);
|
||||
|
||||
class HALSimNTProvider {
|
||||
public:
|
||||
struct NTProviderCallbackInfo {
|
||||
HALSimNTProvider* provider;
|
||||
std::shared_ptr<nt::NetworkTable> table;
|
||||
int channel;
|
||||
};
|
||||
|
||||
void Inject(std::shared_ptr<HALSimLowFi> parent, std::string table);
|
||||
// Initialize is called by inject.
|
||||
virtual void Initialize() = 0;
|
||||
virtual void InitializeDefault(int numChannels,
|
||||
HALCbRegisterIndexedFunc registerFunc);
|
||||
virtual void InitializeDefaultSingle(HALCbRegisterSingleFunc registerFunc);
|
||||
virtual void OnCallback(uint32_t channel,
|
||||
std::shared_ptr<nt::NetworkTable> table) = 0;
|
||||
virtual void OnInitializedChannel(uint32_t channel,
|
||||
std::shared_ptr<nt::NetworkTable> table);
|
||||
|
||||
int numChannels;
|
||||
std::string tableName;
|
||||
|
||||
std::shared_ptr<HALSimLowFi> parent;
|
||||
std::shared_ptr<nt::NetworkTable> table;
|
||||
std::vector<NTProviderCallbackInfo> cbInfos;
|
||||
};
|
||||
@@ -1,28 +0,0 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017-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 <memory>
|
||||
|
||||
#include <HALSimLowFi.h>
|
||||
|
||||
class HALSimNTProviderAnalogIn : public HALSimNTProvider {
|
||||
public:
|
||||
void Initialize() override;
|
||||
void OnCallback(uint32_t channel,
|
||||
std::shared_ptr<nt::NetworkTable> table) override;
|
||||
void OnInitializedChannel(uint32_t channel,
|
||||
std::shared_ptr<nt::NetworkTable> table) override;
|
||||
};
|
||||
|
||||
class HALSimNTProviderAnalogOut : public HALSimNTProvider {
|
||||
public:
|
||||
void Initialize() override;
|
||||
void OnCallback(uint32_t channel,
|
||||
std::shared_ptr<nt::NetworkTable> table) override;
|
||||
};
|
||||
@@ -1,21 +0,0 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017-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 <memory>
|
||||
|
||||
#include <HALSimLowFi.h>
|
||||
|
||||
class HALSimNTProviderDIO : public HALSimNTProvider {
|
||||
public:
|
||||
void Initialize() override;
|
||||
void OnCallback(uint32_t channel,
|
||||
std::shared_ptr<nt::NetworkTable> table) override;
|
||||
void OnInitializedChannel(uint32_t channel,
|
||||
std::shared_ptr<nt::NetworkTable> table) override;
|
||||
};
|
||||
@@ -1,19 +0,0 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017-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 <memory>
|
||||
|
||||
#include <HALSimLowFi.h>
|
||||
|
||||
class HALSimNTProviderDriverStation : public HALSimNTProvider {
|
||||
public:
|
||||
void Initialize() override;
|
||||
void OnCallback(uint32_t channel,
|
||||
std::shared_ptr<nt::NetworkTable> table) override;
|
||||
};
|
||||
@@ -1,21 +0,0 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017-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 <memory>
|
||||
|
||||
#include <HALSimLowFi.h>
|
||||
|
||||
class HALSimNTProviderEncoder : public HALSimNTProvider {
|
||||
public:
|
||||
void Initialize() override;
|
||||
void OnCallback(uint32_t channel,
|
||||
std::shared_ptr<nt::NetworkTable> table) override;
|
||||
void OnInitializedChannel(uint32_t channel,
|
||||
std::shared_ptr<nt::NetworkTable> table) override;
|
||||
};
|
||||
@@ -1,19 +0,0 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017-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 <memory>
|
||||
|
||||
#include <HALSimLowFi.h>
|
||||
|
||||
class HALSimNTProviderPWM : public HALSimNTProvider {
|
||||
public:
|
||||
void Initialize() override;
|
||||
void OnCallback(uint32_t channel,
|
||||
std::shared_ptr<nt::NetworkTable> table) override;
|
||||
};
|
||||
@@ -1,19 +0,0 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017-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 <memory>
|
||||
|
||||
#include <HALSimLowFi.h>
|
||||
|
||||
class HALSimNTProviderRelay : public HALSimNTProvider {
|
||||
public:
|
||||
void Initialize() override;
|
||||
void OnCallback(uint32_t channel,
|
||||
std::shared_ptr<nt::NetworkTable> table) override;
|
||||
};
|
||||
@@ -1,21 +0,0 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017-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 <memory>
|
||||
|
||||
#include <HALSimLowFi.h>
|
||||
|
||||
class HALSimNTProviderRoboRIO : public HALSimNTProvider {
|
||||
public:
|
||||
void Initialize() override;
|
||||
void OnCallback(uint32_t channel,
|
||||
std::shared_ptr<nt::NetworkTable> table) override;
|
||||
void OnInitializedChannel(uint32_t channel,
|
||||
std::shared_ptr<nt::NetworkTable> table) override;
|
||||
};
|
||||
@@ -1,19 +0,0 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017-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 <memory>
|
||||
|
||||
#include <HALSimLowFi.h>
|
||||
|
||||
class HALSimNTProviderDigitalPWM : public HALSimNTProvider {
|
||||
public:
|
||||
void Initialize() override;
|
||||
void OnCallback(uint32_t channel,
|
||||
std::shared_ptr<nt::NetworkTable> table) override;
|
||||
};
|
||||
@@ -1,16 +0,0 @@
|
||||
project(halsim_print)
|
||||
|
||||
include(CompileWarnings)
|
||||
|
||||
file(GLOB halsim_print_src src/main/native/cpp/*.cpp)
|
||||
|
||||
add_library(halsim_print MODULE ${halsim_print_src})
|
||||
wpilib_target_warnings(halsim_print)
|
||||
set_target_properties(halsim_print PROPERTIES DEBUG_POSTFIX "d")
|
||||
target_link_libraries(halsim_print PUBLIC hal)
|
||||
|
||||
target_include_directories(halsim_print PRIVATE src/main/native/include)
|
||||
|
||||
set_property(TARGET halsim_print PROPERTY FOLDER "libraries")
|
||||
|
||||
install(TARGETS halsim_print EXPORT halsim_print DESTINATION "${main_lib_dest}")
|
||||
@@ -1,7 +0,0 @@
|
||||
description = "A simulation shared object that simply prints robot behaviors"
|
||||
|
||||
ext {
|
||||
pluginName = 'halsim_print'
|
||||
}
|
||||
|
||||
apply from: "${rootDir}/shared/plugins/setupBuild.gradle"
|
||||
@@ -1,16 +0,0 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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 <chrono>
|
||||
#include <thread>
|
||||
|
||||
#include <hal/HALBase.h>
|
||||
|
||||
int main() {
|
||||
HAL_Initialize(500, 0);
|
||||
std::this_thread::sleep_for(std::chrono::seconds(2));
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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 "PrintPWM.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <hal/Value.h>
|
||||
#include <mockdata/NotifyListener.h>
|
||||
#include <mockdata/PWMData.h>
|
||||
|
||||
static void PWMCallback(const char* name, void* param,
|
||||
const struct HAL_Value* value) {
|
||||
auto pwm = static_cast<PrintPWM*>(param);
|
||||
pwm->Publish(value->data.v_double);
|
||||
}
|
||||
|
||||
PrintPWM::PrintPWM(int port) {
|
||||
m_port = port;
|
||||
HALSIM_RegisterPWMSpeedCallback(port, PWMCallback, this, false);
|
||||
}
|
||||
|
||||
void PrintPWM::Publish(double value) {
|
||||
std::cout << "PWM " << m_port << ": " << value << std::endl;
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017-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 <iostream>
|
||||
|
||||
#include <hal/Ports.h>
|
||||
|
||||
#include "HALSimPrint.h"
|
||||
#include "PrintPWM.h"
|
||||
|
||||
// Currently, robots never terminate, so we keep a single static object and it
|
||||
// is never properly released or cleaned up.
|
||||
static HALSimPrint halsim;
|
||||
|
||||
extern "C" {
|
||||
#if defined(WIN32) || defined(_WIN32)
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
int HALSIM_InitExtension(void) {
|
||||
std::cout << "Print Simulator Initializing." << std::endl;
|
||||
|
||||
int pwmCount = HAL_GetNumPWMChannels();
|
||||
halsim.m_pwms.reserve(pwmCount);
|
||||
for (int i = 0; i < pwmCount; i++) halsim.m_pwms.emplace_back(i);
|
||||
|
||||
return 0;
|
||||
}
|
||||
} // extern "C"
|
||||
@@ -1,17 +0,0 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017-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 <vector>
|
||||
|
||||
class PrintPWM;
|
||||
|
||||
class HALSimPrint {
|
||||
public:
|
||||
std::vector<PrintPWM> m_pwms;
|
||||
};
|
||||
@@ -1,19 +0,0 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017-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 "HALSimPrint.h"
|
||||
|
||||
class PrintPWM {
|
||||
public:
|
||||
explicit PrintPWM(int port);
|
||||
void Publish(double value);
|
||||
|
||||
private:
|
||||
int m_port;
|
||||
};
|
||||
@@ -1,194 +0,0 @@
|
||||
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
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
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()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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;
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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
|
||||
@@ -1,24 +0,0 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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
|
||||
@@ -1,40 +0,0 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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
|
||||
@@ -1,28 +0,0 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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
|
||||
@@ -1,31 +0,0 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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
|
||||
@@ -1,41 +0,0 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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
|
||||
@@ -1,24 +0,0 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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
|
||||
@@ -1,24 +0,0 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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
|
||||
@@ -1,24 +0,0 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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
|
||||
@@ -1,30 +0,0 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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
|
||||
@@ -1,25 +0,0 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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
|
||||
@@ -1,44 +0,0 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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
|
||||
@@ -1,35 +0,0 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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
|
||||
@@ -1,29 +0,0 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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
|
||||
@@ -1,33 +0,0 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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
|
||||
@@ -1,28 +0,0 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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
|
||||
@@ -1,40 +0,0 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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
|
||||
@@ -1,32 +0,0 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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
|
||||
@@ -1,31 +0,0 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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
|
||||
@@ -1,37 +0,0 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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
|
||||
@@ -1,110 +0,0 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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());
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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());
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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;
|
||||
}
|
||||
@@ -89,11 +89,6 @@ model {
|
||||
project(':hal').addHalDependency(binary, 'shared')
|
||||
lib project: ':cameraserver', library: 'cameraserver', linkage: 'shared'
|
||||
lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
|
||||
if (binary.targetPlatform.name != nativeUtils.wpi.platforms.roborio) {
|
||||
lib project: ':simulation:halsim_lowfi', library: 'halsim_lowfi', linkage: 'shared'
|
||||
lib project: ':simulation:halsim_print', library: 'halsim_print', linkage: 'shared'
|
||||
lib project: ':simulation:halsim_ds_nt', library: 'halsim_ds_nt', linkage: 'shared'
|
||||
}
|
||||
if (binary.targetPlatform.name == nativeUtils.wpi.platforms.roborio) {
|
||||
nativeUtils.useRequiredLibrary(binary, 'netcomm_shared', 'chipobject_shared', 'visa_shared', 'ni_runtime_shared')
|
||||
}
|
||||
@@ -143,11 +138,6 @@ model {
|
||||
cppCompiler.args "/wd4996"
|
||||
}
|
||||
}
|
||||
if (binary.targetPlatform.name != nativeUtils.wpi.platforms.roborio) {
|
||||
lib project: ':simulation:halsim_lowfi', library: 'halsim_lowfi', linkage: 'shared'
|
||||
lib project: ':simulation:halsim_print', library: 'halsim_print', linkage: 'shared'
|
||||
lib project: ':simulation:halsim_ds_nt', library: 'halsim_ds_nt', linkage: 'shared'
|
||||
}
|
||||
if (binary.targetPlatform.name == nativeUtils.wpi.platforms.roborio) {
|
||||
nativeUtils.useRequiredLibrary(binary, 'netcomm_shared', 'chipobject_shared', 'visa_shared', 'ni_runtime_shared')
|
||||
}
|
||||
@@ -177,41 +167,19 @@ model {
|
||||
binary.tasks.install.doLast {
|
||||
if (binary.targetPlatform.operatingSystem.isWindows()) {
|
||||
// Windows batch scripts
|
||||
def fileName = binary.component.name + 'LowFi.bat'
|
||||
def file = new File(installDir + fileName)
|
||||
file.withWriter { out ->
|
||||
out.println '@ECHO OFF'
|
||||
out.print 'SET HALSIM_EXTENSIONS='
|
||||
out.print '"' + new File(installDir + 'lib\\halsim_lowfi.dll').toString() + '";'
|
||||
out.println '"' + new File(installDir + 'lib\\halsim_ds_nt.dll').toString() + '"'
|
||||
out.println runFile + ' %*'
|
||||
}
|
||||
|
||||
fileName = binary.component.name + 'LowFiRealDS.bat'
|
||||
fileName = binary.component.name + 'RealDS.bat'
|
||||
file = new File(installDir + fileName)
|
||||
file.withWriter { out ->
|
||||
out.println '@ECHO OFF'
|
||||
out.print 'SET HALSIM_EXTENSIONS='
|
||||
out.print '"' + new File(installDir + 'lib\\halsim_lowfi.dll').toString() + '";'
|
||||
out.println '"' + new File(installDir + 'lib\\halsim_ds_socket.dll').toString() + '"'
|
||||
out.println runFile + ' %*'
|
||||
}
|
||||
} else {
|
||||
def fileName = binary.component.name + 'LowFi.sh'
|
||||
def file = new File(installDir + fileName)
|
||||
|
||||
file.withWriter { out ->
|
||||
out.print 'export HALSIM_EXTENSIONS='
|
||||
out.print '"' + new File(installDir + '/lib/libhalsim_lowfi.so').toString() + '";'
|
||||
out.println '"' + new File(installDir + '/lib/libhalsim_ds_nt.so').toString() + '"'
|
||||
out.println runFile + ' "$@"'
|
||||
}
|
||||
|
||||
fileName = binary.component.name + 'LowFiRealDS.sh'
|
||||
fileName = binary.component.name + 'RealDS.sh'
|
||||
file = new File(installDir + fileName)
|
||||
file.withWriter { out ->
|
||||
out.print 'export HALSIM_EXTENSIONS='
|
||||
out.print '"' + new File(installDir + '/lib/libhalsim_lowfi.so').toString() + '":'
|
||||
out.println '"' + new File(installDir + '/lib/libhalsim_ds_socket.so').toString() + '"'
|
||||
out.println runFile + ' "$@"'
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user