A modern C++20 metaprogramming project for ADAS (Advanced Driver Assistance Systems) that provides compile-time validated sensor pipelines with type-safe units and coordinate frames.
This project demonstrates advanced C++ metaprogramming techniques applied to real-world robotics and ADAS systems, eliminating entire classes of runtime bugs through compile-time validation.
- β Type-safe units - No more mixing meters with seconds
- β Coordinate frame safety - Prevents accidental frame mixing
- β Zero runtime overhead - All checks at compile time
- β ADAS-focused - Built for sensor fusion, perception, and planning
- Compile-time unit system (Length, Time, Velocity, Frequency, Angle)
- Unit conversions (m β km, m/s β km/h, etc.)
- Coordinate frame types (Vehicle, Lidar, Camera, Radar, Map, IMU)
- Type-safe transforms between frames
- Transform composition
- Compile-time validation via
static_assert
- Sensor message types
- Pipeline DAG representation
- Compile-time graph validation
- Rate and latency checking
- Type-safe state machines
- Transition validation
- Reachability analysis
- Safety-critical constraints
- ISO 26262 inspired checks
- Compile-time proof of safety properties
- Runtime comparison vs. unchecked code
- Zero-overhead validation
- Real-world ADAS scenarios
- C++20 compiler (GCC 10+, Clang 12+, or MSVC 2019+)
- CMake 3.20+
# Clone or navigate to project directory
cd SensorPipeLine
# Create build directory
mkdir build && cd build
# Configure
cmake ..
# Build
cmake --build .
# Run demo
./phase1_demo
# Run tests
ctest --verbose#include "units.hpp"
#include "frames.hpp"
using namespace sensor_pipeline::literals;
int main() {
// β
Type-safe units
auto distance = 150.5_m;
auto time = 5.0_s;
// β This won't compile - different dimensions!
// auto wrong = distance + time;
// β
Coordinate frames
Point3D<LidarFrame> lidar_point(10.0_m, 5.0_m, 2.0_m);
// β
Transform between frames
Transform<LidarFrame, VehicleFrame> T_lidar_vehicle;
Point3D<VehicleFrame> vehicle_point = T_lidar_vehicle(lidar_point);
// β This won't compile - frame mismatch!
// Point3D<VehicleFrame> wrong = lidar_point;
return 0;
}// Define physical dimensions as types
struct Length {};
struct Time {};
struct Velocity {};
// Unit types with compile-time dimension checking
template<typename Dimension, typename Ratio = std::ratio<1>>
struct Unit { /* ... */ };
// Specific units
using Meters = Unit<Length, std::ratio<1>>;
using Kilometers = Unit<Length, std::kilo>;
using MetersPerSecond = Unit<Velocity, std::ratio<1>>;
// User-defined literals
auto distance = 100.0_m;
auto speed = 30.0_mps;
auto freq = 20_Hz;// Frame tags
struct VehicleFrame {};
struct LidarFrame {};
struct CameraFrame {};
struct RadarFrame {};
// Points are tagged with frames
template<Frame F>
struct Point3D {
using frame = F;
Meters x, y, z;
};
// Transforms between frames
template<Frame From, Frame To>
struct Transform {
Point3D<To> operator()(const Point3D<From>& p) const;
};
// Transform composition (automatic frame chaining)
Transform<A, C> = Transform<A, B> * Transform<B, C>;All the following errors are caught at compile time:
auto distance = 100.0_m;
auto time = 5.0_s;
auto wrong = distance + time; // β Compile error!Point3D<LidarFrame> p1;
Point3D<VehicleFrame> p2 = p1; // β Compile error!Transform<LidarFrame, VehicleFrame> T;
Point3D<CameraFrame> camera_point;
auto result = T(camera_point); // β Compile error!Transform<A, B> T1;
Transform<C, D> T2;
auto T3 = T1 * T2; // β Compile error! B β CAll type safety is validated at compile time:
// Dimension checking
static_assert(std::same_as<Meters::dimension, Length>);
static_assert(!std::same_as<Meters::dimension, Time>);
// Frame type checking
static_assert(!std::same_as<VehicleFrame, LidarFrame>);
static_assert(Frame<VehicleFrame>);
// Transform type checking
static_assert(std::same_as<
Transform<LidarFrame, VehicleFrame>::from_frame,
LidarFrame
>);Numerical accuracy validation:
./compile_time_tests- β Type-level programming - Dimensions and frames as types
- β Variadic templates - Flexible unit composition
- β C++20 Concepts - Constrain template parameters
- β
constexprfunctions - Compile-time computations - β
static_assert- Compile-time validation - β
Type traits -
is_in_frame,SameFrame - β
User-defined literals - Ergonomic syntax (
100_m,30_mps) - β SFINAE / Concepts - Prevent invalid operations
This design eliminates bugs commonly seen in:
- β Prevents coordinate frame confusion (Lidar vs. Camera vs. Vehicle)
- β Ensures unit consistency (meters vs. millimeters)
- β Validates transform chains
- β Type-safe message passing
- β Frame alignment verification
- β Rate consistency checks (future phases)
- β Speed limit enforcement (type-safe velocities)
- β Safe distance calculations
- β Collision prediction with correct units
- β Map β Vehicle transform validation
- β GPS coordinate safety
- β IMU integration correctness
- ISO 26262 (Functional Safety for Road Vehicles)
- ROS2 TF2 (Transform Library)
- Modern C++ Design Patterns
- Compile-time dimensional analysis
- Type-safe embedded systems
This is a personal learning project, but feedback and suggestions are welcome!
- Support for more sensors (USS, GPS, IMU)
- Compile-time pipeline optimization
- Integration with ROS2 message types
- ASIL-D safety pattern library
- Performance benchmarking suite
MIT License - feel free to use this for learning and inspiration.
Robotics & ADAS Engineer
Exploring modern C++ metaprogramming for safety-critical systems.
In ADAS and robotics, runtime errors cost lives. By moving validation to compile time:
- π‘οΈ Zero runtime checks - No performance penalty
- π Impossible states - Can't compile invalid code
- π Self-documenting - Types encode domain knowledge
- π Faster development - Catch bugs before testing
This is C++ metaprogramming with purpose.
Phase 1 Complete β - Ready for Phase 2: Pipeline Graphs