RaspberryPiFoundation / python-build-hat

Build HAT Python library
MIT License
52 stars 18 forks source link

Motors keeps momentum after it is stopped #197

Open williamcorsel opened 1 year ago

williamcorsel commented 1 year ago

I noticed that motors seem to keep some momentum after they are stopped and started again when using the current main branch. There also seems to be quite a long spin-up time in this case.

An example script to simulate the behaviour:

from buildhat import Motor
import time

speed = 50
delay = 4
delay_stop = 2

motor = Motor('A')

while True:
    print(f"Start {speed}")
    motor.start(speed)
    time.sleep(delay)

    print("Stop")
    motor.stop()
    time.sleep(delay_stop)

    print(f"Start {-speed}")
    motor.start(-speed)
    time.sleep(delay)

    print("Stop")
    motor.stop()
    time.sleep(delay_stop)

Motor behaviour:

https://user-images.githubusercontent.com/31770711/230624586-2d7e3ba3-9233-42b2-8c76-d8ee5be5a8da.mp4

Are there some settings I can tweak to improve the responsiveness in this case? I noticed that using motor.set_speed_unit_rpm(True) already reduces the momentum issue somewhat (and improves the spin-up time significantly).

chrisruk commented 1 year ago

Thanks for reporting this and especially for the video, that's very helpful!

danielr commented 8 months ago

I can confirm the exact same behavior, which makes controlling a robot almost impossible. 😟 Did you find any solution or workaround?

williamcorsel commented 8 months ago

Sadly no. You could try and use the .pwm function directly.