Skip to content

python-ev3dev v2 won't allow negative angles for motors #504

Closed

Description

@ndward

ev3dev version: 4.14.61-ev3dev-2.2.2-ev3
ev3dev-lang-python version:
ii python3-ev3dev 1.2.0 all Python language bindings for ev3dev
ii python3-ev3dev2 2.0.0~beta1 all Python language bindings for ev3dev

I have been exploring EV3 Python v2 in depth over two weeks and have sent dozens of comments to @WasabiFan. He has kindly given lots of feedback, suggesting which comments should be raised as issues here. Based on that feedback I am publishing several issues, of which this is no doubt the most serious.

The rule that angles must be positive for on_for_rotations and on_for_degrees for single motors and motor pairs is catastrophic, it seems to me! Even these lines generate errors:

#!/usr/bin/env python3
from ev3dev2.motor import MoveSteering, OUTPUT_B, OUTPUT_C
steer_pair = MoveSteering(OUTPUT_B, OUTPUT_C)
steer_pair.on_for_degrees(steering=100, speed=40, degrees=685)

Error:
Traceback (most recent call last):
File "/home/robot/MINE/Basics_3.py", line 9, in
steer_pair.on_for_degrees(steering=100, speed=40, degrees=685)
File "/usr/lib/python3/dist-packages/ev3dev2/motor.py", line 1899, in on_for_degrees
MoveTank.on_for_degrees(self, SpeedNativeUnits(left_speed), SpeedNativeUnits(right_speed), degrees, brake, block)
File "/usr/lib/python3/dist-packages/ev3dev2/motor.py", line 1807, in on_for_degrees
self.right_motor._set_position_degrees(right_speed_native_units, right_degrees)
File "/usr/lib/python3/dist-packages/ev3dev2/motor.py", line 869, in _set_position_degrees
assert degrees >= 0, "degrees is %s, must be >= 0" % degrees
AssertionError: degrees is -685.0, must be >= 0

It seems that any steering command using steering < -50 or steering > 50 will fail since this attempts to turn a wheel backwards by setting the angle negative, which is forbidden.
This also fails, with the same error:
tank_pair.on_for_degrees(left_speed=30, right_speed=-40, degrees=60)
AssertionError: degrees is -7.619047619047619, must be >= 0

And of course this fails
mB.on_for_degrees(speed_pct=50, degrees=-60)
AssertionError: degrees is -60, must be >= 0

PLEASE allow negative angles! It will make everything so much simpler and anyone smart enough to be able to program in EV3 Python must surely be able to understand that if both the speed and angle are negative then the result will be a turn in the positive angle direction with a positive speed since that is mathematically equivalent to a turn at a negative speed through a negative angle. There is no contradiction. It's a mathematical fact that (-6) * (-3) = (+6) * (+3). That doesn’t mean that -6 is not negative.

You want Python v2 to behave like EV3-G where possible but EV3-G allows negative angles. A negative power and negative angle cause the motor to turn in the positive direction, no problem.

Activity

  1. WasabiFan commented on Sep 8, 2018

    @WasabiFan
    Member

    @ddemidov @dwalton76 I think it makes sense to remove that assertion; what are your thoughts? I believe the logic to allow negative speeds and/or negative distances is already implemented.

  2. dwalton76 commented on Sep 8, 2018

    @dwalton76
    Collaborator

    I think I put this is because it was possible to enter a speed/angle combo that resulted in the motor never moving. Maybe replace it with a smarter assert that would allow negative angles but still catch the “will never move” scenario?

  3. ndward commented on Sep 8, 2018

    @ndward
    Author

    I made a separate issue (#507 ) for the case of the motor(s) being instructed to turn through zero degrees or to turn with zero speed. In that issue I argued that it can be perfectly reasonable for this to happen - it does not necessarily imply an error. The example that I give is a robot whose speed is repeatedly set equal to the ambient light intensity - that will cause the speed argument to be set to zero, so the motor will not turn, but that's not an error that needs to be caught or needs an assert.

  4. WasabiFan commented on Sep 24, 2018

    @WasabiFan
    Member

    Fix released in 2.0.0~beta2. To upgrade:

    sudo apt-get update
    sudo apt-get install --only-upgrade python3-ev3dev2
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions