Files
allwpilib/wpilibc/src/main/native/cpp/smartdashboard/MechanismRoot2d.cpp

36 lines
933 B
C++
Raw Normal View History

// 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.
2025-11-07 19:56:21 -05:00
#include "wpi/smartdashboard/MechanismRoot2d.hpp"
2025-11-07 19:56:21 -05:00
#include "wpi/util/Color8Bit.hpp"
2025-11-07 20:00:05 -05:00
using namespace wpi;
MechanismRoot2d::MechanismRoot2d(std::string_view name, double x, double y,
const private_init&)
: MechanismObject2d{name}, m_x{x}, m_y{y} {}
void MechanismRoot2d::SetPosition(double x, double y) {
std::scoped_lock lock(m_mutex);
m_x = x;
m_y = y;
Flush();
}
2025-11-07 20:00:05 -05:00
void MechanismRoot2d::UpdateEntries(std::shared_ptr<wpi::nt::NetworkTable> table) {
2022-10-08 10:01:31 -07:00
m_xPub = table->GetDoubleTopic("x").Publish();
m_yPub = table->GetDoubleTopic("y").Publish();
Flush();
}
inline void MechanismRoot2d::Flush() {
2022-10-08 10:01:31 -07:00
if (m_xPub) {
m_xPub.Set(m_x);
}
2022-10-08 10:01:31 -07:00
if (m_yPub) {
m_yPub.Set(m_y);
}
}