set_throttle assigns a throttle value to a named motor. It combines a discrete speed setting, a per-motor adjustment, and an optional direction factor, allowing the same operation to drive forward or backward. section 3.7 section 3.6
The operation applies these inputs:
- name selects the motor through the MOTOR mapping, such as R or L. section 3.7
- speed selects a throttle level from THROTTLE_SPEED: 0 stops, while 1, 2, and 3 represent progressively higher settings. section 3.6
- factor controls direction; the default value 1 drives forward, while -1 reverses the motor. section 3.7
- ADJUST compensates independently for the two motors before the resulting value is assigned to throttle. section 3.6
Driving backward
A backward movement calls set_throttle('R', speed, factor=-1) and set_throttle('L', speed, factor=-1), waits for the requested duration, then calls both motors with speed 0 to stop. section 3.7
Joystick control
A joystick client converts each y-axis position into a level from -3 through 3, derives direction from its sign, uses the absolute level as speed, and sends set_throttle arguments over HTTP. section 7.7.1
def set_throttle(name, speed, factor=1):
MOTOR[name].throttle = THROTTLE_SPEED[speed] * ADJUST[name] * factor
The compact implementation shows the complete throttle calculation and assignment. section 3.7
