# Turn Configuration Simplification ## Changes Made The turn calibration system has been simplified to use **auto-calculation only** with separate compensation values for 90° and 180° turns. ### Removed Parameters - `USE_MANUAL_TURN_TICKS` - Manual/auto mode flag (no longer needed) - `MANUAL_TICKS_90` - Manual tick value (no longer needed) - `TURN_COMPENSATION` - Generic compensation (replaced with specific values) - `CALCULATED_TICKS_90` - Intermediate calculation (now inline) ### New Parameters (config.h) ```c #define TURN_90_COMPENSATION 25.0f // Extra ticks for 90° turns #define TURN_180_COMPENSATION 40.0f // Extra ticks for 180° turns ``` Both turns now use **automatic calculation** based on wheel dimensions: - **90° turns**: `(π × WHEELBASE / 4) / (π × WHEEL_DIAMETER) × TICKS_PER_REV + TURN_90_COMPENSATION` - **180° turns**: `(π × WHEELBASE / 2) / (π × WHEEL_DIAMETER) × TICKS_PER_REV + TURN_180_COMPENSATION` ## How to Calibrate ### Method 1: Test Both Angles Independently 1. **Upload the code** and place robot on open floor 2. **Test 90° turns** via serial commands: ``` L → turn left 90° R → turn right 90° ``` - If under-rotates (< 90°): **Increase** `TURN_90_COMPENSATION` by 5 - If over-rotates (> 90°): **Decrease** `TURN_90_COMPENSATION` by 5 3. **Test 180° turn** via serial command: ``` U → turn around 180° ``` - If under-rotates (< 180°): **Increase** `TURN_180_COMPENSATION` by 10 - If over-rotates (> 180°): **Decrease** `TURN_180_COMPENSATION` by 10 4. **Repeat** until both angles are accurate ### Method 2: Mark Floor and Measure 1. **Mark starting orientation** on floor with tape 2. Execute **10 consecutive 90° turns** and check if robot returns to start 3. Execute **5 consecutive 180° turns** and check if robot returns to start 4. Adjust compensations based on accumulated error ## Typical Values | Robot Configuration | TURN_90_COMPENSATION | TURN_180_COMPENSATION | |--------------------|---------------------|----------------------| | Light robot, smooth floor | 15.0f - 20.0f | 30.0f - 35.0f | | Medium robot (current) | 20.0f - 30.0f | 35.0f - 45.0f | | Heavy robot, rough floor | 30.0f - 40.0f | 50.0f - 65.0f | ## Code Impact ### config.h - Cleaner, easier to understand - Only two tuning parameters instead of five - Clear comments explain what each does ### main.c - `turn_left_90()` uses `TICKS_90_DEGREE` - `turn_right_90()` uses `TICKS_90_DEGREE` - `turn_around_180()` uses `TICKS_180_DEGREE` (now pre-calculated) ## Advantages ✅ **Simpler**: Only two parameters to tune ✅ **Independent**: 90° and 180° don't affect each other ✅ **Intuitive**: Direct compensation values in ticks ✅ **Maintainable**: Less code, clearer purpose ✅ **Flexible**: Easy to adjust for different surfaces ## Compilation Result ``` Program: 12,118 bytes (37.0% Flash) Data: 1,840 bytes (89.8% RAM) ``` No size change from previous version - simplified logic with same efficiency.