Skip to main content
Firmware Stable

Cruise and Walk

The speed is maintained using PID control, its parameters can be tuned in the cruise_pid folder.

cruise.png

These functions require a GPIO-connected button. The cruise input (in_cruise) must be mapped to GPIO through input mapping.

tip
  • One physical input can serve both in_cruise (long press) and in_mapswitch (short press)
  • Map changes automatically disable cruise mode

Behaviour

When cruise is activated by long-pressing the cruise button set in Input mapping (/io/IN_cruise), cruise control maintains the current speed level read by the wheel sensor. Brake always deactivates cruise. Deactivation by accelerator or by pressing the button again can be enabled in crsopts.

Cruise activation requires the speed from the wheel to be higher than limits - cr min speed. Below this value, the walk function will activate.

Walk mode helps when pushing a bike uphill. Activate walk assist by pressing and holding the cruise button, this will hold the speed at limits - walk speed until release.

Parameters

info

All parameters are located in the /cruise folder.

ParameterDescription
cruise_pidParameters for tuning the PID controler
setpointShows the desired motor RPM calculated from vehicle speed when cruise is set
maxaccMaximum current for acceleration (0-1)

crsopts

Configuration options for cruise and walk functionality.

limits [km/h]

This is an aray containing various speed limits for cruise and walk. For proper operation these must be set from lowest to highest.

ParameterDescription
walk speedSpeed of the walk function
cr min speedCruise will activate above this speed. This speed will be set if step for PID incrsopts is enabled
cr max speedIf vehicle speed exceeds this value, setpoint will be limited to this value.

PID Tuning

warning

Make sure to perform PID tuning on a secure stand where the motor can spin freely without moving the vehicle. Improper PID tuning can lead to unstable behavior. Proceed with caution and make small adjustments.

  1. Enable the Step Function:
    In the crsopts parameter, enable the Step option by setting the corresponding bit value (64). This will create a step function for PID tuning, where the set speed will be set to cr min speed while the button is pressed. This differs from setting cruise normally, where the speed ramps up gradually.
  2. Set Initial Parameters:
    Navigate to the /cruise/cruise_pid folder and set initial values for the PID parameters:
    • Proportional (P): Leave on default to observe the system's response.
    • Integral (I): Set to 0 initially to isolate the proportional effect.
    • Derivative (D): Set to 0 initially to avoid damping effects.
  3. Perform Step Tests:
    Activate the step function by pressing and holding the cruise button. This will set the speed to cr min speed and allow you to observe the system's response.
    Monitor the system's behavior: If the response is too slow, increase the P value. If the system oscillates rapidly, decrease the P value. Once the system oscilates only slightly, you can start increasing the I value. Slight oscillations are acceptable as they will be dampened when a load is put on the motor.
  4. Fine-Tune the Parameters:
    Gradually increase the I value to eliminate steady-state error. Meaning until the cr min speed matches the actual vehicle speed. Be cautious, as too high an I value can cause instability.
    Adjust the D value to dampen oscillations and improve stability.
  5. Test at Different Speeds:
    Test the PID tuning at various speeds (cr min speed) to ensure consistent performance.
  6. Iterate and Validate:
    Repeat the step tests and adjust the PID parameters until the system achieves a stable and responsive behavior.
info

Note: Performance on a stand may differ from real-world conditions when a rider is on the bike. The added weight and varying terrain introduce additional load and resistance, which can affect the PID tuning. After initial tuning on the stand, further adjustments may be necessary during real-world testing to account for these factors.

Troubleshooting Guide

If the cruise control does not behave as expected, use the following guide to adjust the PID parameters and other settings:

Common Issues and Solutions

IssueCauseSolution
Struggling to maintain speed with a heavy loadP is too low, maxaccc too lowCheck if maxacc current provides enough torque, Gradually increase P.
Cruise control is too slow to respondProportional (P) value is too lowGradually increase the P value to improve response time.
Cruise control oscillates rapidlyProportional (P) value is too highDecrease the P value to reduce oscillations.
Cruise control takes too long to stabilizeIntegral (I) value is too lowIncrease the I value to reduce steady-state error.
Cruise control becomes unstableIntegral (I) value is too highDecrease the I value to improve stability.
Cruise control overshoots the target speedDerivative (D) value is too lowIncrease the D value to dampen overshooting.
Cruise control feels sluggishDerivative (D) value is too highDecrease the D value to make the system more responsive.
Cruise deactivates unexpectedlyBrake or throttle input is interferingCheck if crsopts settings (e.g., Throttle Stop, Button Stop) are correct.