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
17
namespace
libstp::kinematics
{
struct
IKinematics
; }
18
namespace
libstp::odometry
{
struct
IOdometry; }
19
20
namespace
libstp::hal::platform
21
{
28
enum class
Component
: uint8_t
29
{
30
Stm32Bridge
,
31
Imu
,
32
Motors
,
33
};
34
36
const
char
*
toString
(
Component
component);
37
39
struct
ComponentStatus
40
{
41
Component
component
;
42
bool
ok
;
43
std::string
detail
;
44
};
45
50
struct
ProbeResult
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
67
struct
ProbeOptions
68
{
69
int
stm32_timeout_ms
{1500};
70
int
imu_timeout_ms
{1500};
71
int
motor_timeout_ms
{500};
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
:
88
explicit
ProbeFailedError
(
ProbeResult
result
);
89
[[nodiscard]]
const
ProbeResult
&
result
() const noexcept {
return
result_; }
90
91
private
:
92
ProbeResult
result_;
93
};
94
96
class
Platform
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
114
static
void
clearMockProbeFailures
();
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
}
libstp::hal::platform::Platform
Hardware-health entry point. Implemented per platform bundle.
Definition
Platform.hpp:97
libstp::hal::platform::Platform::probe
static ProbeResult probe(const ProbeOptions &options={})
libstp::hal::platform::Platform::createOdometry
static std::shared_ptr< libstp::odometry::IOdometry > createOdometry(std::shared_ptr< libstp::kinematics::IKinematics > kinematics)
libstp::hal::platform::Platform::commandChassisVelocity
static bool commandChassisVelocity(float vx, float vy, float wz)
libstp::hal::platform::Platform::setMockProbeFailure
static void setMockProbeFailure(Component component, bool fail)
libstp::hal::platform::Platform::requireHealthy
static void requireHealthy(const ProbeOptions &options={})
libstp::hal::platform::Platform::clearMockProbeFailures
static void clearMockProbeFailures()
Reset all forced failures set by setMockProbeFailure.
libstp::hal::platform::ProbeFailedError::result
const ProbeResult & result() const noexcept
Definition
Platform.hpp:89
libstp::hal::platform::ProbeFailedError::ProbeFailedError
ProbeFailedError(ProbeResult result)
libstp::hal::platform
Definition
Platform.hpp:21
libstp::hal::platform::toString
const char * toString(Component component)
Stable string form for logging and Python repr.
libstp::hal::platform::Component
Component
Definition
Platform.hpp:29
libstp::hal::platform::Component::Motors
@ Motors
Definition
Platform.hpp:32
libstp::hal::platform::Component::Stm32Bridge
@ Stm32Bridge
Definition
Platform.hpp:30
libstp::hal::platform::Component::Imu
@ Imu
Definition
Platform.hpp:31
libstp::kinematics
Definition
Platform.hpp:17
libstp::odometry
Definition
angle_utils.hpp:7
libstp::hal::platform::ComponentStatus
Per-component outcome of a probe call.
Definition
Platform.hpp:40
libstp::hal::platform::ComponentStatus::detail
std::string detail
Definition
Platform.hpp:43
libstp::hal::platform::ComponentStatus::ok
bool ok
Definition
Platform.hpp:42
libstp::hal::platform::ComponentStatus::component
Component component
Definition
Platform.hpp:41
libstp::hal::platform::ProbeOptions
Definition
Platform.hpp:68
libstp::hal::platform::ProbeOptions::stm32_timeout_ms
int stm32_timeout_ms
Definition
Platform.hpp:69
libstp::hal::platform::ProbeOptions::require_imu
bool require_imu
Definition
Platform.hpp:74
libstp::hal::platform::ProbeOptions::motor_timeout_ms
int motor_timeout_ms
Definition
Platform.hpp:71
libstp::hal::platform::ProbeOptions::require_motors
bool require_motors
Definition
Platform.hpp:79
libstp::hal::platform::ProbeOptions::imu_timeout_ms
int imu_timeout_ms
Definition
Platform.hpp:70
libstp::hal::platform::ProbeOptions::require_stm32
bool require_stm32
Definition
Platform.hpp:73
libstp::hal::platform::ProbeResult
Definition
Platform.hpp:51
libstp::hal::platform::ProbeResult::components
std::vector< ComponentStatus > components
Definition
Platform.hpp:53
libstp::hal::platform::ProbeResult::ok
bool ok
Definition
Platform.hpp:52
libstp::hal::platform::ProbeResult::failedComponents
std::vector< ComponentStatus > failedComponents() const
Filter components down to the failed ones.
libstp::hal::platform::ProbeResult::summary
std::string summary() const
Multi-line, human-readable summary suitable for logs and CLI output.
libstp::kinematics::IKinematics
Definition
kinematics.hpp:35
modules
libstp-hal
include
hal
Platform.hpp
Generated by
1.15.0