2020-12-26 14:31:24 -08:00
|
|
|
// Copyright (c) FIRST and other WPILib contributors.
|
|
|
|
|
// Open Source Software; you can modify and/or share it under the terms of
|
|
|
|
|
// the WPILib BSD license file in the root directory of this project.
|
2020-12-23 00:07:44 -05:00
|
|
|
|
2022-12-05 23:06:43 -05:00
|
|
|
#include "glass/networktables/NTMotorController.h"
|
2020-12-23 00:07:44 -05:00
|
|
|
|
2021-06-06 16:13:58 -07:00
|
|
|
#include <fmt/format.h>
|
|
|
|
|
#include <wpi/StringExtras.h>
|
|
|
|
|
|
2020-12-23 00:07:44 -05:00
|
|
|
using namespace glass;
|
|
|
|
|
|
2022-12-05 23:06:43 -05:00
|
|
|
NTMotorControllerModel::NTMotorControllerModel(std::string_view path)
|
|
|
|
|
: NTMotorControllerModel(nt::NetworkTableInstance::GetDefault(), path) {}
|
2020-12-23 00:07:44 -05:00
|
|
|
|
2022-12-05 23:06:43 -05:00
|
|
|
NTMotorControllerModel::NTMotorControllerModel(nt::NetworkTableInstance inst,
|
2021-06-06 16:13:58 -07:00
|
|
|
std::string_view path)
|
2022-10-08 10:01:31 -07:00
|
|
|
: m_inst{inst},
|
2022-12-12 19:28:15 -08:00
|
|
|
m_value{inst.GetDoubleTopic(fmt::format("{}/Value", path)).GetEntry(0)},
|
2022-10-08 10:01:31 -07:00
|
|
|
m_name{inst.GetStringTopic(fmt::format("{}/.name", path)).Subscribe("")},
|
|
|
|
|
m_controllable{inst.GetBooleanTopic(fmt::format("{}/.controllable", path))
|
|
|
|
|
.Subscribe(false)},
|
|
|
|
|
m_valueData{fmt::format("NT_SpdCtrl:{}", path)},
|
|
|
|
|
m_nameValue{wpi::rsplit(path, '/').second} {}
|
2020-12-23 00:07:44 -05:00
|
|
|
|
2022-12-05 23:06:43 -05:00
|
|
|
void NTMotorControllerModel::SetPercent(double value) {
|
2022-10-08 10:01:31 -07:00
|
|
|
m_value.Set(value);
|
2020-12-23 00:07:44 -05:00
|
|
|
}
|
|
|
|
|
|
2022-12-05 23:06:43 -05:00
|
|
|
void NTMotorControllerModel::Update() {
|
2022-10-08 10:01:31 -07:00
|
|
|
for (auto&& v : m_value.ReadQueue()) {
|
|
|
|
|
m_valueData.SetValue(v.value, v.time);
|
|
|
|
|
}
|
|
|
|
|
for (auto&& v : m_name.ReadQueue()) {
|
|
|
|
|
m_nameValue = std::move(v.value);
|
|
|
|
|
}
|
|
|
|
|
for (auto&& v : m_controllable.ReadQueue()) {
|
|
|
|
|
m_controllableValue = v.value;
|
2020-12-23 00:07:44 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-05 23:06:43 -05:00
|
|
|
bool NTMotorControllerModel::Exists() {
|
2022-11-20 17:27:28 -08:00
|
|
|
return m_value.Exists();
|
2020-12-23 00:07:44 -05:00
|
|
|
}
|