You'll run two programs — one where the bot tracks its own speed, and one where it doesn't. Both drive for exactly 3 seconds. Compare the distances to see what the hardware can and can't control.
The bot reads its own wheel sensors to check its actual speed. If it's going too slow, it gives the motors more power. If it's going too fast, it pulls back. The result: a steady, predictable distance every time.
The bot sends a fixed voltage to the motors and never checks whether it's actually moving at the right speed. Friction, low battery, and startup delay all affect the distance — and nothing corrects for them.
This program uses a block called cruise control. That block turns on the bot's speed-correction system. Tiny sensors on each wheel count how fast the wheel is spinning. The controller compares that count to your target speed, then adjusts the motor power to close the gap — dozens of times per second.
let targetSpeed = 0
let minSpeed = 20
let maxSpeed = 50
let SPEED = 6
targetSpeed = minSpeed + ((SPEED - 1) * (maxSpeed - minSpeed)) / (20 - 1)
targetSpeed, which Button B uses.
let maxSpeed = 50
input.onButtonPressed(Button.A, function () {
CutebotPro.cruiseControl(maxSpeed, maxSpeed, CutebotProSpeedUnits.Cms)
basic.pause(3000)
CutebotPro.stopImmediately(CutebotProMotors.ALL)
})
let targetSpeed = 0
input.onButtonPressed(Button.B, function () {
CutebotPro.cruiseControl(targetSpeed, targetSpeed, CutebotProSpeedUnits.Cms)
basic.pause(3000)
CutebotPro.stopImmediately(CutebotProMotors.ALL)
})
targetSpeed, which was calculated from your SPEED stat when the program started.targetSpeed = 27.9 cm/s. The speed-correction system holds that value for the full 3 seconds.The speed-correction system holds 50 cm/s the entire 3 seconds. The distance is consistent run after run because the system corrects for friction and battery changes automatically.
The speed-correction system tracks your SPEED setting. It works well above 20 cm/s. Below that floor, the wheel sensors can't read fast enough and the bot stalls.
This program uses a block called PWM cruise control. PWM stands for Pulse-Width Modulation — it's how the chip controls voltage to the motors. Think of it like a volume dial: 100% means full power, 30% means low power. The wheel sensors are completely ignored. Whatever physics happen, they happen uncorrected.
input.onButtonPressed(Button.A, function () {
CutebotPro.pwmCruiseControl(100, 100)
basic.pause(3000)
CutebotPro.stopImmediately(CutebotProMotors.ALL)
})
input.onButtonPressed(Button.B, function () {
CutebotPro.pwmCruiseControl(30, 30)
basic.pause(3000)
CutebotPro.stopImmediately(CutebotProMotors.ALL)
})
Full power, no corrections. Distance is the highest you'll see — but it's not guaranteed. Run it twice and measure whether the second run was shorter. If it is, that's battery drain.
Low voltage fights gear friction at startup. The motors waste part of the 3-second window just getting moving. No correction system can help because this program doesn't use one.