What
takes many paragraphs to explain is surprisingly simple to code. Here
is the basic pseudocode of the balance algorithm, complete with the
numbers which made my scooter feel stable and responsive.
Inputs
angle, angle_rate: the tilt angle of the scooter in radians and its derivative in radians/sec steer_knob: the reading from the steering knob, between -1 and +1.
left_motor_pwmandright_motor_pwmdirectly
set the duty cycle of the pulse width modulator for the wheel
controller, and range from -1 to +1 (+1 is 100% forward, -1 is 100%
reverse.)