libstp
Robotics library for Botball
Loading...
Searching...
No Matches
chassis_control_context.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <atomic>
4
6{
11 using ChassisVelocitySink = bool (*)(double vx, double vy, double wz);
12
30 {
31 public:
34
36 void setSink(ChassisVelocitySink sink) noexcept
37 {
38 sink_.store(sink, std::memory_order_release);
39 }
40
42 [[nodiscard]] bool hasSink() const noexcept
43 {
44 return sink_.load(std::memory_order_acquire) != nullptr;
45 }
46
49 [[nodiscard]] bool command(double vx, double vy, double wz) const noexcept
50 {
51 const ChassisVelocitySink s = sink_.load(std::memory_order_acquire);
52 return s != nullptr && s(vx, vy, wz);
53 }
54
59
60 private:
61 ChassisControlContext() = default;
62
63 std::atomic<ChassisVelocitySink> sink_{nullptr};
64 };
65}
bool command(double vx, double vy, double wz) const noexcept
ChassisControlContext(ChassisControlContext &&)=delete
ChassisControlContext & operator=(const ChassisControlContext &)=delete
ChassisControlContext & operator=(ChassisControlContext &&)=delete
void setSink(ChassisVelocitySink sink) noexcept
Register the on-MCU chassis sink. Called once by the platform bundle.
bool hasSink() const noexcept
True when an on-MCU chassis loop is registered.
static ChassisControlContext & instance()
Access the process-wide instance.
ChassisControlContext(const ChassisControlContext &)=delete
bool(*)(double vx, double vy, double wz) ChassisVelocitySink