← Home
Docs/Software/Calibration & Tuning

Calibration & Tuning Guide

Achieving consistent, repeatable motion in mobile robotics requires empirical calibration and gentle, balanced steering corrections.

This guide covers motion distance calculations, empirical encoder rollout, gyro bias nulling, dual-sensor steering balance, and stopping cleanly without wheel slip.


1. Understanding Target Distances & Motion Stages

In mobile robotics, precise position measurement requires establishing a clear reference point and accounting for physical vehicle dimensions.

Reference Measurement Points & Multi-Stage Tasks

  • Reference Point (Pointer / Dowel): You can define your vehicle's reference point using a front or rear pointer, sensor mast, or axle center.
  • Multi-Stage Execution:
    1. Forward Leg: The vehicle accelerates from the start mark, cruises at a steady target speed, and decelerates cleanly to a designated waypoint or obstacle.
    2. Secondary / Reverse Stage: The vehicle can execute a reverse maneuver, pivot, or return trip, demonstrating bidirectional closed-loop accuracy.

Accounting for Vehicle Dimensions & Offsets

Because any physical robot has length, front bumper or sensor contacts are separated from the drive wheels and reference points by chassis dimensions:

  • Account for the physical distance from your drive axle to front bumpers or sensors.
  • When evaluating positioning accuracy with a tape measure or optical sensor during testing, always compare commanded travel against how far your vehicle actually rolled.

2. Calibrating Distance (Rollout Test)

Calculating travel distance using theoretical wheel diameter math (d=π×Dd = \pi \times D) introduces systematic error. Tire rubber compresses under chassis weight, altering the effective rolling radius, and microstepping variations change step counts. You must calibrate distance empirically.

The Physical Push-Roll Method

  1. Disarm the Motors: Set driver enable pins HIGH so the motor coils are free and the wheels spin smoothly by hand.
  2. Align on a Reference Mark: Position the car at an exact start mark on the floor.
  3. Push Forward a Known Distance: Carefully push the vehicle straight forward along a tape measure for an exact distance (such as 1.000 or 2.000 meters).
  4. Record Encoder Counts: Read accumulated encoder counts on both wheels.
  5. Calculate Scaling Factor: Average the counts from both wheels and divide by the distance pushed:

TicksPerMeter=TicksLeft+TicksRight2×Distancemeters\text{TicksPerMeter} = \frac{\text{Ticks}_{\text{Left}} + \text{Ticks}_{\text{Right}}}{2 \times \text{Distance}_{\text{meters}}}

Store this constant in your code to convert target distance in meters into target encoder counts:

TargetTicks=TargetDistance×TicksPerMeter\text{TargetTicks} = \text{TargetDistance} \times \text{TicksPerMeter}

Fine-Tuning at Speed

Low-speed push calibration establishes your baseline scaling. However, when driving at higher speeds, slight tire shear or braking overshoot may cause the vehicle to stop slightly ahead of or behind the target mark.

Run the car at speed, measure where it actually stops with a tape measure, and adjust your distance scaling factor by:

CorrectionFactor=Target DistanceActual Measured Distance\text{CorrectionFactor} = \frac{\text{Target Distance}}{\text{Actual Measured Distance}}


3. Driving Straight: Balancing Gyro & Encoders

Physical vehicles inevitably drift due to surface seams, floor friction variations, slight wheel diameter differences, and uneven weight distribution. EVDrive provides two independent sensing streams:

  • MPU-6050 Gyro: Measures rotational velocity (yaw rate). Highly responsive to quick angular deflections and floor bumps.
  • AS5600 Encoders: Measures differential wheel rotation. Tracks differences in physical distance between the left and right wheels.

Mechanical Balance First

Before adjusting software steering gains, balance the vehicle mechanically. Center the battery pack and heavy components evenly between the drive wheels. If one wheel carries less normal force, it slips more easily, creating artificial drift that software cannot cleanly solve.

Zeroing Gyroscope Bias

Stationary gyros exhibit a small DC rate offset. Even sitting completely still, raw readings might report a slight rotation rate.

A best practice is to sample stationary readings immediately before each launch and subtract the average offset from raw sensor values:

BiasZ=1N∑i=1NGz,i\text{Bias}_Z = \frac{1}{N} \sum_{i=1}^{N} G_{z, i} ωz=Gz,raw−BiasZ\omega_z = G_{z,\text{raw}} - \text{Bias}_Z

Important: Keep the vehicle completely motionless from the moment the start button is pressed until the wheels begin rolling so the zero reference is clean.

Finding the Gain Balance

When writing code to correct drift:

  1. Excessive Correction (Gains Too High):
    • Oscillation & Fishtailing: If heading corrections are too aggressive, the vehicle violently overreacts to minor deviations, weaving back and forth down the track in an S-pattern.
    • Motor Jitter: Aggressive adjustments cause motors to rapidly stutter or alternate speeds, leading to audible vibration, step loss, and erratic stopping points.
  2. Insufficient Correction (Gains Too Low):
    • If corrections are too weak, the vehicle cannot overcome mechanical drag or track floor slopes, causing it to veer off-course over long distances.
  3. Sensor Conflict & Cross-Coupling:
    • Encoders track wheel rotations, while the gyro tracks chassis orientation. If encoder correction is tuned too aggressively, a microscopic tire slip on gym dust makes the encoders command a turn, even when the gyro confirms the vehicle is pointed straight. This creates wobble.

Iterative Tuning Strategy

  1. Step 1: Run open-loop with zero steering correction to verify that the chassis rolls reasonably straight on its own.
  2. Step 2: Add a small gyro heading correction. Increase it gradually until the vehicle straightens itself after small bumps without weaving.
  3. Step 3: If one wheel consistently drags over long distances, add a modest encoder differential trim to balance wheel travel. Keep it gentle so momentary tire slips do not fight gyro stabilization.

Multi-Layer Steering Architecture (Optional)

If your team wants to explore more advanced steering control, you can structure corrections into layers:

  • Layer 1: Heading Angle (Proportional): Directly counteracts rotational deviations using the gyro yaw rate.
  • Layer 2: Cross-Track Error: Estimates sideways drift from the starting line and applies a gentle heading angle to guide the car back toward center.
  • Layer 3: Encoder Differential Trim: Corrects small left/right wheel distance divergence over long runs.

Tuning Tip: Keep corrections subtle and tune each layer independently. Ensure gyro heading takes priority so brief wheel slips on gym dust don't cause the feedback loops to fight each other.


4. Stopping Without Skidding

Abrupt stepper motor stops instantly convert vehicle momentum into tire shear stress. If tires break static friction on smooth gym floors:

  • The vehicle skids past the target mark.
  • Encoders register wheel lock while the chassis slides, corrupting distance readings.
  • Motors risk losing step synchronization under sudden inertial torque.

Controlled Deceleration

  • Acceleration Phase: Ramp motor speed up smoothly over the first 1 to 2 seconds to protect wheel traction.
  • Deceleration Phase: Rather than cutting motor power abruptly, calculate remaining distance and ramp velocity down smoothly as you approach the mark.
  • Creep Velocity: Finishing the final centimeters at a low, controlled creep speed before cutting motor steps ensures a clean, zero-skid stop.
  • Holding Torque: Keep motors energized at the end of the run to hold position on the floor until the run is scored.

5. Handling Obstacle Interactions & End-Effectors

When navigating towards physical markers or interacting with obstacles, manage impact dynamics:

  • Moderate Steady Cruise: Choosing a smooth, modest cruise velocity across the entire travel leg absorbs contact cleanly without requiring complex multi-speed profiles.
  • Speed Profiles: In software, you can ease speed down slightly as you approach an obstacle's expected location, make gentle contact, and then execute the next maneuver.
  • Mechanical Bumper Design: A rigid bumper shaped with generous rounded contours and non-slip contact surfaces absorbs contact stably at speed.
  • Sensor-Triggered Contact: Mount a microswitch bumper on the front cross-member (connected to expansion header J6) to detect physical contact and dynamically trigger the next motion phase.

6. Step-by-Step Robotics Tuning Workflow

  1. Check Battery Voltage: Measure battery rail voltage under motor load. Depleted batteries cause voltage sag, motor stutter, and erratic stopping distances. Always test with fully charged cells.
  2. Mechanical Alignment: Center chassis weight between the drive wheels.
  3. Calibrate Distance Rollout: Perform a manual push test over a measured 1.0 or 2.0 meter distance to establish your baseline ticks-per-meter scaling.
  4. Test Forward Travel: Run forward tests, measure stopping accuracy with a tape measure, and fine-tune your distance scaling factor.
  5. Tune Heading Correction: Start with small steering corrections. If the car weaves or vibrates, reduce your gains.
  6. Integrate Multi-Stage Navigation: Test waypoint arrival, obstacle engagement, and return sequences to verify repeatable positioning.
  7. Offline Mode Lockout: Flip the hardware wireless switch (SW4) to OFF and press the Reset button (SW6) when running autonomous offline tests. Confirm the wireless status LED (D1) remains completely dark.