pybricks / support

Pybricks support and general discussion
MIT License
109 stars 7 forks source link

[Bug] Motors strart blocking #1088

Open Tear4Pixelation opened 1 year ago

Tear4Pixelation commented 1 year ago

Describe the bug What is the problem? So I made myself a new Class - see how to reproduce - and rarely, when I put it after for example robot.turn(90) robot.stop(), the motors just start blocking. To reproduce Steps to reproduce the behavior: My class:

class Motorctrl:
    def __init__(self, left_motor, right_motor, dia, wheel_dist):
        self.left_motor = left_motor
        self.right_motor = right_motor
        self.dia = dia
        self.wheel_dist = wheel_dist
    def run(self, speed_left, speed_right):
        self.left_motor.run(speed_left)
        self.right_motor.run(speed_right)
    def stop(self):
        self.left_motor.stop()
        self.right_motor.stop()
    def reset_dist(self):
        self.left_motor.reset_angle(0)
        self.right_motor.reset_angle(0)
    # [...]
    def drive_untl(self, speed_left, speed_right, color_left = None, color_right = None):
        if color_right is not None and color_left is not None:
            while not (cs_right.color() == color_right and cs_left.color() == color_left):
                self.run(speed_left, speed_right)
                wait(10)
        elif color_right is not None:
            while not cs_right.color() == color_right:
                self.run(speed_left, speed_right)
                wait(10)
        elif color_left is not None:
            while not cs_left.color() == color_left:
                self.run(speed_left, speed_right)
                wait(10)
        self.stop()
       # [...]

Definition of motors:

ev3 = EV3Brick()
m_back = Motor(Port.D)
m_back.reset_angle(180)
m_side = Motor(Port.A)
m_side.reset_angle(-90)
wh_left = Motor(Port.C, Direction.COUNTERCLOCKWISE)
wh_right = Motor(Port.B) 
robot = DriveBase(wh_left, wh_right, 56, 195)
robot.settings(400, 650, 300, 250)
wheels = Motorctrl(wh_left, wh_right, 56, 195)

Expected behavior The robot should continue

Screenshots There is a saying that a picture is worth a 1000 words. Screenshots really help to identify and solve problems. Wheels is the name for the Motorctrl class, Robot is the drive base, and wheels.drive_untl() is driving with both motors at a given speed until one or two color sensors reach a specific color as you can see in the class. The motor is trying to run (maybe you can hear it), but it won't move. It's like something is commanding one motor to go in two different directions at once. Sorry for the bad quality, it's recorded on a webcam xD https://github.com/pybricks/support/assets/104512895/72970b06-00d3-4f70-bfd7-7d170a8bde18

laurensvalk commented 1 year ago

Is this using the standard EV3 MicroPython version?

If you have a shorter script that reproduces the problem that would be great.

Not sure if related, but it also helps to have a short wait in your loops:

while some_condition:
    motor.run(...)
    wait(10)  # <<--- Putting a short wait here gives your program time to do other things.
Tear4Pixelation commented 1 year ago

Is this using the standard EV3 MicroPython version?

If you have a shorter script that reproduces the problem that would be great.

Not sure if related, but it also helps to have a short wait in your loops:

while some_condition:
    motor.run(...)
    wait(10)  # <<--- Putting a short wait here gives your program time to do other things.

I'll try making the shown code shorter, I was just trying to get it up quickly because our competition with the robot is soon. I think it is the standard version. I'll try putting a wait in there. Thank you for your quick answer.

Tear4Pixelation commented 1 year ago
while some_condition:
    motor.run(...)
    wait(10)  # <<--- Putting a short wait here gives your program time to do other things.

I have now done that, but it did not help :( I suspect it has something to do with the interference between the drive base and motorcrtl, because I can hear that the motors inside the motors are working, but the axe just does not turn.

laurensvalk commented 1 year ago

Ah, are you using the motors individually, as well as in the Drive Base at the same time?

If you do, you'll want to make sure to call robot.stop() before using the motors again, and likewise call left_motor.stop() and right_motor.stop() before you use the drive base again.

In newer versions this is handled automatically, but you can probably solve this by doing this yourself.

Tear4Pixelation commented 1 year ago

I won't close this issue because it does not feel like the actual issue is fixed, but I started the program again from the start, and then everything worked again (I have a system that lets me skip phases of my program)

Tear4Pixelation commented 1 year ago

Ah, are you using the motors individually, as well as in the Drive Base at the same time?

If you do, you'll want to make sure to call robot.stop() before using the motors again, and likewise call left_motor.stop() and right_motor.stop() before you use the drive base again.

In newer versions this is handled automatically, but you can probably solve this by doing this yourself.

You can look at the video (the link on the bottom of the report), I use robot.stop() or here:

So I made myself a new Class - see how to reproduce - and rarely, when I put it after for example robot.turn(90) robot.stop(), the motors just start blocking.

but that does not matter anymore, because it works

I won't close this issue because it does not feel like the actual issue is fixed, but I started the program again from the start, and then everything worked again (I have a system that lets me skip phases of my program)

Tear4Pixelation commented 1 year ago

Ah, are you using the motors individually, as well as in the Drive Base at the same time?

If you do, you'll want to make sure to call robot.stop() before using the motors again, and likewise call left_motor.stop() and right_motor.stop() before you use the drive base again.

In newer versions this is handled automatically, but you can probably solve this by doing this yourself.

From what version is thin handled? I need to get it xD

laurensvalk commented 1 year ago

In newer versions this is handled automatically, but you can probably solve this by doing this yourself.

From what version is thin handled? I need to get it xD

I really don't recommend changing versions since you say:

our competition with the robot is soon

The EV3 version hasn't had a stable release in a while, as we've been prioritizing all the other hubs.

Tear4Pixelation commented 1 year ago

In newer versions this is handled automatically, but you can probably solve this by doing this yourself.

From what version is thin handled? I need to get it xD

I really don't recommend changing versions since you say:

our competition with the robot is soon

The EV3 version hasn't had a stable release in a while, as we've been prioritizing all the other hubs.

Ok, I might give it a go at some point, but I'll wait if you say so. Thank you a lot for your quick help (Issue opened six hours ago!), the pyricks support is great. Keep it up!