official skill

Cruise

cruise.py

Drive forward at a steady speed with a smooth ramp-up.

drive
Author
MyRoboBrick
Build
MRB Build v0.1
Language
MicroPython · SPIKE Prime
cruise.py
1from spike import Motor2import time3 4left = Motor("C")5right = Motor("D")6 7def cruise(speed=40, ramp=0.4):8    for s in range(0, speed, 4):9        left.start(s)10        right.start(s)11        time.sleep(ramp / (speed / 4))12    # Reach the exact target, including speeds that are not multiples of four.13    left.start(speed)14    right.start(speed)15    # hold speed until stopped16    return speed17 18cruise()

Read every line before running it on real hardware.

Have a skill worth sharing?

Submit your own MicroPython skill. Everything is reviewed for safety before it shows up for other builders.