-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirm_client.pyi
More file actions
278 lines (226 loc) · 9.19 KB
/
Copy pathfirm_client.pyi
File metadata and controls
278 lines (226 loc) · 9.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
from __future__ import annotations
from enum import IntEnum
from types import TracebackType
from typing import ClassVar, Optional, Type
__version__: str
class DeviceProtocol(IntEnum):
"""Enum of the supported device communication protocols."""
USB = 1
UART = 2
I2C = 3
SPI = 4
class DeviceInfo:
"""Represents information about the FIRM device."""
firmware_version: str
id: int
class DeviceConfig:
"""Represents the configuration of the FIRM device."""
name: str
frequency: int
protocol: DeviceProtocol
class CalibrationValues:
"""Represents the calibration values for the FIRM device."""
imu_accelerometer_offsets: tuple[float, float, float]
imu_accelerometer_scale_matrix: tuple[
float, float, float, float, float, float, float, float, float
]
imu_gyroscope_offsets: tuple[float, float, float]
imu_gyroscope_scale_matrix: tuple[
float, float, float, float, float, float, float, float, float
]
magnetometer_offsets: tuple[float, float, float]
magnetometer_scale_matrix: tuple[
float, float, float, float, float, float, float, float, float
]
class FIRMDataPacket:
"""Represents a data packet received from the FIRM device."""
__struct_fields__: ClassVar[list[str]]
"""List of all field names in this packet."""
timestamp_seconds: float
"""Timestamp of the data packet in seconds."""
temperature_celsius: float
"""Ambient temperature measured in degrees Celsius."""
pressure_pascals: float
"""Atmospheric pressure measured in Pascals."""
raw_acceleration_x_gs: float
"""Raw accelerometer reading for X-axis in Gs."""
raw_acceleration_y_gs: float
"""Raw accelerometer reading for Y-axis in Gs."""
raw_acceleration_z_gs: float
"""Raw accelerometer reading for Z-axis in Gs."""
raw_rotated_acceleration_x_gs: float
"""Raw acceleration X rotated into world frame in Gs."""
raw_rotated_acceleration_y_gs: float
"""Raw acceleration Y rotated into world frame in Gs."""
raw_rotated_acceleration_z_gs: float
"""Raw acceleration Z rotated into world frame in Gs."""
est_tilt_angle_degrees: float
"""Total tilt angle from +Z based on raw acceleration in degrees."""
raw_angular_rate_x_deg_per_s: float
"""Raw gyroscope reading for X-axis in degrees per second."""
raw_angular_rate_y_deg_per_s: float
"""Raw gyroscope reading for Y-axis in degrees per second."""
raw_angular_rate_z_deg_per_s: float
"""Raw gyroscope reading for Z-axis in degrees per second."""
magnetic_field_x_microteslas: float
"""Magnetometer reading for X-axis in micro-Teslas."""
magnetic_field_y_microteslas: float
"""Magnetometer reading for Y-axis in micro-Teslas."""
magnetic_field_z_microteslas: float
"""Magnetometer reading for Z-axis in micro-Teslas."""
est_position_z_meters: float
"""Estimated position along the Z-axis in meters."""
est_velocity_z_meters_per_s: float
"""Estimated velocity along the Z-axis in meters per second."""
est_mach_number: float
"""Estimated Mach number from velocity magnitude and ambient temperature."""
est_quaternion_w: float
"""Estimated orientation quaternion scalar component (W)."""
est_quaternion_x: float
"""Estimated orientation quaternion vector component (X)."""
est_quaternion_y: float
"""Estimated orientation quaternion vector component (Y)."""
est_quaternion_z: float
"""Estimated orientation quaternion vector component (Z)."""
def __init__(
self,
timestamp_seconds: float,
temperature_celsius: float,
pressure_pascals: float,
raw_acceleration_x_gs: float,
raw_acceleration_y_gs: float,
raw_acceleration_z_gs: float,
raw_angular_rate_x_deg_per_s: float,
raw_angular_rate_y_deg_per_s: float,
raw_angular_rate_z_deg_per_s: float,
magnetic_field_x_microteslas: float,
magnetic_field_y_microteslas: float,
magnetic_field_z_microteslas: float,
est_position_z_meters: float,
est_velocity_z_meters_per_s: float,
est_quaternion_w: float,
est_quaternion_x: float,
est_quaternion_y: float,
est_quaternion_z: float,
) -> None:
"""
Initialize a new immutable FIRMDataPacket. All fields are required.
"""
...
@staticmethod
def default_zero() -> "FIRMDataPacket":
"""
Creates a packet with zeroed values (and identity quaternion).
"""
...
def as_dict(self) -> dict[str, float]:
"""
Converts the packet to a standard Python dictionary.
Returns a copy of the data.
"""
...
class MockDeviceHandle:
"""Handle for controlling an in-process mock device."""
def inject_response(self, identifier: int, payload: bytes | bytearray) -> None: ...
"""Inject a response packet (identifier + raw payload bytes) into the mock device."""
def wait_for_command_identifier(self, timeout_seconds: float) -> int | None: ...
"""Wait up to timeout_seconds for a command to be observed; returns its identifier or None."""
class FIRMClient:
"""Client for communicating with the FIRM device.
Args:
port_name: The name of the serial port to connect to.
baud_rate: The baud rate for the serial connection. Default is 2,000,000.
timeout: Read timeout used when get_data_packets(block=True). Default is 0.1 seconds.
"""
def __init__(
self, port_name: str, baud_rate: int = 2_000_000, timeout: float = 0.1
) -> None: ...
@staticmethod
def new_mock(timeout: float = 0.1) -> tuple[FIRMClient, MockDeviceHandle]: ...
"""Create a client + mock device pair for testing."""
def start(self) -> None: ...
"""Start the background reader thread."""
def stop(self) -> None: ...
"""Stop the background reader thread and close the serial port."""
def get_data_packets(self, block: bool = False) -> list[FIRMDataPacket]: ...
"""Retrieve currently-available data packets.
Args:
block: If True, blocks up to `timeout` (from __init__) waiting for packets.
"""
def get_device_info(self, timeout_seconds: float = 5.0) -> DeviceInfo | None: ...
"""Request device info and wait up to timeout_seconds."""
def get_device_config(
self, timeout_seconds: float = 5.0
) -> DeviceConfig | None: ...
"""Request device configuration and wait up to timeout_seconds."""
def set_device_config(
self,
name: str,
frequency: int,
protocol: DeviceProtocol,
timeout_seconds: float = 5.0,
) -> bool: ...
"""Set device config and wait up to timeout_seconds for acknowledgement."""
def set_magnetometer_calibration(
self,
offsets: tuple[float, float, float],
scale_matrix: tuple[
float, float, float, float, float, float, float, float, float
],
timeout_seconds: float = 5.0,
) -> bool: ...
"""Set magnetometer calibration and wait up to timeout_seconds for acknowledgement."""
def set_imu_calibration(
self,
accel_offsets: tuple[float, float, float],
accel_scale_matrix: tuple[
float, float, float, float, float, float, float, float, float
],
gyro_offsets: tuple[float, float, float],
gyro_scale_matrix: tuple[
float, float, float, float, float, float, float, float, float
],
timeout_seconds: float = 5.0,
) -> bool: ...
"""Set IMU calibration and wait up to timeout_seconds for acknowledgement."""
def get_calibration(
self, timeout_seconds: float = 5.0
) -> CalibrationValues | None: ...
"""Request calibration values and wait up to timeout_seconds."""
def cancel(self, timeout_seconds: float = 5.0) -> bool: ...
"""Send cancel and wait up to timeout_seconds for acknowledgement."""
def reboot(self) -> None: ...
"""Send reboot command."""
def start_mock_log_stream(
self,
log_path: str,
realtime: bool = True,
speed: float = 1.0,
chunk_size: int = 8192,
start_timeout_seconds: float = 5.0,
cancel_on_finish: bool = True,
) -> None: ...
"""Start streaming a mock log file asynchronously in the background."""
def is_mock_log_streaming(self) -> bool: ...
"""True if a mock log stream is currently running."""
def stop_mock_log_stream(
self, cancel_device: bool = True, join: bool = True
) -> int | None: ...
"""Stop the async mock log stream. Optionally cancel the device."""
def run_and_apply_magnetometer_calibration(
self,
collection_duration_seconds: float,
apply_timeout_seconds: float = 5.0,
) -> Optional[bool]: ...
"""Run magnetometer calibration procedure and sets the constants on the device."""
def is_running(self) -> bool: ...
"""True if the client reader thread is running."""
def __enter__(self) -> FIRMClient: ...
"""Context manager which calls start()."""
def __exit__(
self,
exc_type: Type[BaseException] | None,
exc_value: BaseException | None,
traceback: TracebackType | None,
) -> None: ...
"""Context manager which calls stop()."""