Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] run_until_stalled() doesn't return correct angle value in 3.2.0b1 #662

Closed
jononi opened this issue Jun 8, 2022 · 6 comments
Closed
Labels
bug Something isn't working topic: motors Issues involving motors

Comments

@jononi
Copy link

jononi commented Jun 8, 2022

Describe the bug
motor.run_until_stalled() used to block until motor is stalled then it returns the angle at which is stopped. With 3.2.0b1 it seems like it doesn't block anymore and it returns a wrong value, although the motor runs until it stalls .

To reproduce

(...)
>>> print(pybricks.version)
('technichub', '3.2.0b1', 'v3.2.0b1 on 2022-06-03')
steer = Motor(Port.C)
>>> steer.angle()
-102
>>> steer.run_until_stalled(300, duty_limit=30)
-102
>>> steer.angle()
105

Expected behavior
run motor until it stalls, then return the angle value it stopped at.

@jononi jononi added the triage Issues that have not been triaged yet label Jun 8, 2022
@laurensvalk laurensvalk added bug Something isn't working topic: motors Issues involving motors labels Jun 9, 2022
@laurensvalk
Copy link
Member

Thanks for reporting! There's certainly something wrong here, even though the behavior I'm seeing seems to be different.

When I run this, the command does block and return the correct value upon stalling. But then it keeps going instead of stopping.

In your example snippet above, was there anything before this? Do you see the same behavior after a full reset and running only those commands?

@laurensvalk
Copy link
Member

This bug affects only the coast and brake stop type. As a workaround, you could use hold for now:

from pybricks.pupdevices import Motor
from pybricks.parameters import Port, Stop
from pybricks.tools import wait

# Initialize a motor on port A.
example_motor = Motor(Port.A)

# Run at 500 deg/s until the motor stalls
angle = example_motor.run_until_stalled(500, duty_limit=30, then=Stop.HOLD)

print("Stopped at", angle)

@laurensvalk laurensvalk removed the triage Issues that have not been triaged yet label Jun 9, 2022
@laurensvalk
Copy link
Member

laurensvalk commented Jun 9, 2022

This was broken in pybricks/pybricks-micropython@4efeee2#diff-9c5fdeeb615547288d3470c9ca282d080197673d1d9bb2c2800584a46f336d67L352.

A fix for not stopping on completion has now been pushed.

@laurensvalk
Copy link
Member

laurensvalk commented Jun 9, 2022

About returning right away --- it seems like this could be correct behavior.

Which motor are you using? With the Medium Angular Motor" found in SPIKE Prime and Robot Inventor, 30% duty cycle is barely enough to get moving, so it really does "stall".

Does it still return right away if you use duty_limit=50?

@laurensvalk
Copy link
Member

laurensvalk commented Jun 9, 2022

In case want to try out the fix on the Move Hub / City Hub / Technic Hub, you can use these instructions and install this build.

@jononi
Copy link
Author

jononi commented Jun 10, 2022

Thank you for the quick support. I tried the workarounds you suggested but none of them solved my issue, unless I add wait() and then read the angle again.
However the updated firmware (Build #1764) did fix the non blocking issue. Now it waits until it stalls to return with the correct angle reading. By the way, I was just running the steering calibration sequence of the 42099 truck example code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working topic: motors Issues involving motors
Projects
None yet
Development

No branches or pull requests

2 participants