Skip to content

Commit 17fffc8

Browse files
committed
Update code
1 parent 7dfda9d commit 17fffc8

3 files changed

Lines changed: 290 additions & 27 deletions

File tree

framework/src/lib.rs

Lines changed: 92 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,53 @@
66
//!
77
//! ## Features
88
//!
9-
//! - **Plugin Architecture**: Add sensors without modifying existing code
10-
//! - **Sensor Abstraction**: Hardware-independent sensor interface
9+
//! - **Plugin Architecture**: Add sensors without modifying existing code (Open/Closed Principle)
10+
//! - **Sensor Abstraction**: Hardware-independent sensor interface (Dependency Inversion)
1111
//! - **Extended Kalman Filter**: 7-state sensor fusion (position, velocity, yaw, biases)
1212
//! - **Coordinate Transforms**: Body ↔ Earth ↔ Vehicle frame conversions
13+
//! - **SOLID Principles**: Designed following best practices for maintainability
1314
//! - **Distributed Support**: MQTT-based multi-board sensor networks (optional)
1415
//! - **No-std Compatible**: Works on embedded systems without operating system
1516
//!
1617
//! ## Architecture
1718
//!
19+
//! The framework follows **SOLID principles** for maximum extensibility:
20+
//!
1821
//! ```text
1922
//! ┌─────────────────────────────────────────┐
2023
//! │ Sensor Framework (Traits & Registry) │
24+
//! │ - Sensor (core operations) │
25+
//! │ - CalibratableSensor (optional) │
26+
//! │ - HealthMonitoredSensor (optional) │
27+
//! │ - SensorDataType (extensible data) │
2128
//! ├─────────────────────────────────────────┤
2229
//! │ Sensor Fusion (EKF, Transforms) │
30+
//! │ - Pure algorithms, no sensor coupling │
2331
//! ├─────────────────────────────────────────┤
2432
//! │ Sensor Implementations (Plugins) │
33+
//! │ - IMU, GPS, CAN, Camera, etc. │
2534
//! └─────────────────────────────────────────┘
2635
//! ```
2736
//!
37+
//! ## Primary vs Legacy Abstractions
38+
//!
39+
//! **PRIMARY (Recommended)**: Use `sensor_framework` module
40+
//! - Modern trait-based plugin architecture
41+
//! - Extensible via `SensorDataType` trait
42+
//! - Supports any sensor type without framework changes
43+
//! - Interface segregation (optional traits)
44+
//!
45+
//! **LEGACY**: `sensors` module (ImuSensor, GpsSensor)
46+
//! - Provided for backward compatibility
47+
//! - Simpler for basic IMU/GPS-only applications
48+
//! - Consider migrating to `sensor_framework` for new code
49+
//!
2850
//! ## Example Usage
2951
//!
3052
//! ```rust,no_run
31-
//! use motorsport_telemetry::sensor_framework::{SensorRegistry, Sensor};
53+
//! use motorsport_telemetry::sensor_framework::{
54+
//! SensorRegistry, Sensor, SensorDataType, ImuReading, GpsReading
55+
//! };
3256
//! use motorsport_telemetry::ekf::Ekf;
3357
//!
3458
//! // Create sensor registry
@@ -47,12 +71,39 @@
4771
//! let readings = registry.poll_all();
4872
//!
4973
//! // Process readings and update EKF
50-
//! // for reading in readings {
51-
//! // // Update EKF based on sensor type
52-
//! // }
74+
//! for reading in readings {
75+
//! // Downcast to specific sensor type
76+
//! if let Some(imu) = reading.downcast_data::<ImuReading>() {
77+
//! // Process IMU data
78+
//! } else if let Some(gps) = reading.downcast_data::<GpsReading>() {
79+
//! // Process GPS data
80+
//! }
81+
//! }
5382
//! }
5483
//! ```
5584
//!
85+
//! ## Creating Custom Sensor Types
86+
//!
87+
//! The framework is **open for extension** without modification:
88+
//!
89+
//! ```rust,no_run
90+
//! use motorsport_telemetry::sensor_framework::{SensorDataType, SensorReading};
91+
//!
92+
//! #[derive(Debug)]
93+
//! struct RadarReading {
94+
//! targets: Vec<(f32, f32, f32)>, // (distance, angle, velocity)
95+
//! }
96+
//!
97+
//! impl SensorDataType for RadarReading {
98+
//! fn type_name(&self) -> &'static str { "RadarReading" }
99+
//! fn as_any(&self) -> &dyn core::any::Any { self }
100+
//! fn as_any_mut(&mut self) -> &mut dyn core::any::Any { self }
101+
//! }
102+
//!
103+
//! // Now RadarReading can be used with SensorReading!
104+
//! // No framework changes required (Open/Closed Principle)
105+
//! ```
106+
//!
56107
//! ## Use Cases
57108
//!
58109
//! - **Track Day Data Logging** - Record lap times, g-forces, and racing lines
@@ -63,8 +114,8 @@
63114
//!
64115
//! ## Modules
65116
//!
66-
//! - [`sensor_framework`] - Core plugin architecture and sensor traits
67-
//! - [`sensors`] - Basic sensor trait definitions
117+
//! - [`sensor_framework`] - **PRIMARY**: Plugin architecture with SOLID design
118+
//! - [`sensors`] - **LEGACY**: Simplified IMU/GPS abstractions
68119
//! - [`ekf`] - Extended Kalman Filter for sensor fusion
69120
//! - [`transforms`] - Coordinate frame transformations
70121
@@ -74,8 +125,39 @@ pub mod sensors;
74125
pub mod ekf;
75126
pub mod transforms;
76127

77-
// Re-export commonly used types
128+
// Re-export commonly used types from sensor_framework
78129
pub use sensor_framework::{
79-
Sensor, SensorRegistry, SensorCapabilities, SensorReading, SensorData, SensorId,
130+
// Core traits
131+
Sensor,
132+
CalibratableSensor,
133+
HealthMonitoredSensor,
134+
SensorDataType,
135+
SensorPublisher,
136+
137+
// Registry and metadata
138+
SensorRegistry,
139+
SensorCapabilities,
140+
SensorReading,
141+
SensorId,
142+
143+
// Sensor data types
144+
ImuReading,
145+
GpsReading,
146+
WheelSpeedReading,
147+
CanReading,
148+
LidarReading,
149+
CameraReading,
150+
CustomReading,
151+
Detection,
152+
153+
// Errors
154+
SensorError,
155+
PublishError,
80156
};
157+
158+
// Legacy (deprecated) - kept for backward compatibility
159+
#[allow(deprecated)]
160+
pub use sensor_framework::SensorData;
161+
162+
// Re-export EKF
81163
pub use ekf::Ekf;

0 commit comments

Comments
 (0)