# Quick Start Guide

Get started with the Motion Sensor Driver in 5 minutes!

## Step 1: Initialize

```moonbit
let config = SensorConfig::default()
let controller = MotionController::new(config)
```

## Step 2: Update with Sensor Data

```moonbit
// Called every 10ms (100Hz)
let state = controller.update(
  Vec3::new(0.0, 0.0, 9.81),  // accel (m/s²)
  Vec3::zero(),                // gyro (rad/s)
  Vec3::new(20.0, 0.0, 40.0),  // mag (μT)
  timestamp_ms,                // Int64
  0.01,                        // dt in seconds
)
```

## Step 3: Get Orientation

```moonbit
// Euler angles in degrees
let (roll, pitch, yaw) = controller.get_euler_degrees()
println("Roll: \{roll}°, Pitch: \{pitch}°, Yaw: \{yaw}°")

// Compass heading
let heading = controller.get_heading_degrees()
println("Heading: \{heading}° from north")
```

## Step 4: Detect Gestures

```moonbit
match controller.detect_gesture() {
  Shaking => println("Shaking!")
  FreeFall => println("Falling!")
  Impact(force) => println("Impact: \{force}")
  Tilting(p, r) => println("Tilted")
  Rotating(speed) => println("Rotating")
  Stationary => ()
}
```

## Complete Example

```moonbit
fn main {
  let controller = MotionController::new(SensorConfig::default())
  
  // Simulate 100 sensor updates
  for i = 0; i < 100; i = i + 1 {
    // Simulated sensor readings (replace with hardware reads)
    let accel = Vec3::new(0.0, 0.0, 9.81)
    let gyro = Vec3::new(0.1, 0.0, 0.0)
    let mag = Vec3::new(20.0, 5.0, 40.0)
    
    controller.update(accel, gyro, mag, i.to_int64() * 10L, 0.01)
    
    // Every 10 frames, print status
    if i % 10 == 0 {
      let (roll, pitch, yaw) = controller.get_euler_degrees()
      println("Frame \{i}: R=\{roll}° P=\{pitch}° Y=\{yaw}°")
    }
  }
}
```

## Hardware Integration Checklist

- [ ] Connect IMU sensor to your board (I2C or SPI)
- [ ] Read raw sensor values (usually 16-bit integers)
- [ ] Convert to proper units (m/s², rad/s, μT)
- [ ] Call `controller.update()` at consistent rate (100Hz recommended)
- [ ] Calibrate sensors for best accuracy

## Next Steps

- Read [README.md](README.md) for feature overview
- See [EXAMPLES.md](EXAMPLES.md) for real-world use cases
- Check [API.md](API.md) for complete API reference
