libstp
Robotics library for Botball
Loading...
Searching...
No Matches
Platform.hpp
Go to the documentation of this file.
1//
2// Hardware health-check API.
3//
4// Concrete implementations live in the selected platform bundle (wombat or
5// mock). Higher-level code calls `Platform::probe()` once at startup to
6// confirm that required sub-systems (STM32 bridge, IMU, motors) are reachable
7// and producing data before any mission runs.
8//
9#pragma once
10
11#include <cstdint>
12#include <memory>
13#include <stdexcept>
14#include <string>
15#include <vector>
16
17namespace libstp::kinematics { struct IKinematics; }
18namespace libstp::odometry { struct IOdometry; }
19
21{
28 enum class Component : uint8_t
29 {
33 };
34
36 const char* toString(Component component);
37
40 {
42 bool ok;
43 std::string detail;
44 };
45
51 {
52 bool ok{false};
53 std::vector<ComponentStatus> components{};
54
56 [[nodiscard]] std::vector<ComponentStatus> failedComponents() const;
57
59 [[nodiscard]] std::string summary() const;
60 };
61
68 {
70 int imu_timeout_ms{1500};
72
73 bool require_stm32{true};
74 bool require_imu{true};
75 // Off by default: the BEMF channel is published by stm32-data-reader
76 // continuously, but on a freshly powered board the first publish can
77 // take longer than the IMU heading. Treat motor telemetry as a soft
78 // signal unless the caller explicitly opts in.
79 bool require_motors{false};
80 };
81
85 class ProbeFailedError : public std::runtime_error
86 {
87 public:
89 [[nodiscard]] const ProbeResult& result() const noexcept { return result_; }
90
91 private:
92 ProbeResult result_;
93 };
94
97 {
98 public:
101 static ProbeResult probe(const ProbeOptions& options = {});
102
106 static void requireHealthy(const ProbeOptions& options = {});
107
111 static void setMockProbeFailure(Component component, bool fail);
112
115
127 static std::shared_ptr<libstp::odometry::IOdometry> createOdometry(
128 std::shared_ptr<libstp::kinematics::IKinematics> kinematics);
129
140 static bool commandChassisVelocity(float vx, float vy, float wz);
141 };
142}
Hardware-health entry point. Implemented per platform bundle.
Definition Platform.hpp:97
static ProbeResult probe(const ProbeOptions &options={})
static std::shared_ptr< libstp::odometry::IOdometry > createOdometry(std::shared_ptr< libstp::kinematics::IKinematics > kinematics)
static bool commandChassisVelocity(float vx, float vy, float wz)
static void setMockProbeFailure(Component component, bool fail)
static void requireHealthy(const ProbeOptions &options={})
static void clearMockProbeFailures()
Reset all forced failures set by setMockProbeFailure.
const ProbeResult & result() const noexcept
Definition Platform.hpp:89
const char * toString(Component component)
Stable string form for logging and Python repr.
Per-component outcome of a probe call.
Definition Platform.hpp:40
std::vector< ComponentStatus > components
Definition Platform.hpp:53
std::vector< ComponentStatus > failedComponents() const
Filter components down to the failed ones.
std::string summary() const
Multi-line, human-readable summary suitable for logs and CLI output.