Skip to content

Motors and zero speed, degrees, rotations, etc #544

Closed

Description

@dwalton76

The Motor, MoveTank, etc classes are not consistent in how they are handling requests to move at speed 0, degrees 0, etc. Some raise an exception, some use asserts, some log a warning and call set_brake(), etc. We need to decide how we want to handle these scenarios and make them all consistent.

Motor.on_for_rotations

  • raises ValueError is speed or rotations is None

Motor.on_for_degrees

  • raises ValueError is speed or degrees is None

Motor.on_to_position

  • assert speed

Motor.on_for_seconds

  • if not speed or not seconds we log a warning, call set_brake(), then return

Motor.on

  • if not speed we log a warning, call set_brake(), then return

MoveTank.on_for_degrees

  • if degrees or speeds are 0 we log a warning but do not return, we execute the rest of the method

MoveSteering.get_speed_steering

  • assert steering >= -100 and steering <= 100

MoveDifferential.on_for_distance

  • if not speed or not distance_mm log a warning, call set_brake() and return

MoveDifferential._on_arc

  • if not speed, not distance_mm or not radius_mm log a warning, call set_brake() and return

MoveDifferential._turn

  • if not speed or not degrees log a warning, call set_brake() and return

Activity

  1. WasabiFan commented on Oct 30, 2018

    @WasabiFan
    Member

    I think the points here apply: #523 (comment)

    My vote is to follow that behavior: if speed is zero, the call no-ops (no error, no warning; it may or may not command the motor, depending on how the driver handles it).

    Values like radius and steering are separate and exceptions should be thrown if they are invalid.

  2. dwalton76 commented on Oct 30, 2018

    @dwalton76
    CollaboratorAuthor

    That works for me. Just to clarify how I am interpreting this:

    • speed, degrees, rotations and seconds should not have any sanity checks applied, just set them and let the driver do as instructed the best it can.
    • invalid steering or invalid radius should raise an Exception. Any others?
  3. WasabiFan commented on Oct 30, 2018

    @WasabiFan
    Member

    I think one thing to add is that our code should step in if the driver behavior is bad. In the case of moving no distance, the motor drivers did not handle it well, which spawned ev3dev/ev3dev#1170 and ev3dev/ev3dev#1173. So, if sending a zero freezes your code, we need to handle it; if it just immediately returns we're OK.

  4. dwalton76 commented on Oct 30, 2018

    @dwalton76
    CollaboratorAuthor

    ok for the ones that fall into this category how do we want to handle them?

    • silently return?
    • log a warning and return?
    • log a warning, call set_brake() and return?
    • raise ValueError with an explanation that zero is not acceptable for this particular parameter due to the driver

    My vote would be for raising ValueError since we are doing that in other related scenarios. Do we want a more specific error to raise so the user can catch them....MotorValueError perhaps?

  5. WasabiFan commented on Oct 30, 2018

    @WasabiFan
    Member

    It depends on what it is. I'd say we should wait until we have a case where the motor drivers don't handle it correctly and then make a decision for that case.

  6. self-assigned this
    on Oct 31, 2018
  7. dwalton76 commented on Nov 1, 2018

    @dwalton76
    CollaboratorAuthor

    For Motor, MoveTank and MoveSteering I commented out all of our safety checks and tested every permutation of 0 or negative settings for speed, rotation, degrees and seconds. The ONLY scenario I found that causes a driver to barf is if you tell a motor to run for a negative amount of time. The traceback in that scenario is

    Traceback (most recent call last):
      File "/home/robot/ev3dev-lang-python/ev3dev2/__init__.py", line 248, in _set_attribute
        attribute.write(value)
    OSError: [Errno 22] Invalid argument
    
    The above exception was the direct cause of the following exception:
    
    Traceback (most recent call last):
      File "./utils/zero.py", line 222, in <module>
        steer.on_for_seconds(42, SpeedRPM(80), -3) # invalid (negative time)
      File "/home/robot/ev3dev-lang-python/ev3dev2/motor.py", line 1911, in on_for_seconds
        MoveTank.on_for_seconds(self, SpeedNativeUnits(left_speed), SpeedNativeUnits(right_speed), seconds, brake, block)
      File "/home/robot/ev3dev-lang-python/ev3dev2/motor.py", line 1822, in on_for_seconds
        self.left_motor.time_sp = int(seconds * 1000)
      File "/home/robot/ev3dev-lang-python/ev3dev2/motor.py", line 697, in time_sp
        self._time_sp = self.set_attr_int(self._time_sp, 'time_sp', value)
      File "/home/robot/ev3dev-lang-python/ev3dev2/__init__.py", line 281, in set_attr_int
        return self._set_attribute(attribute, name, str(int(value)))
      File "/home/robot/ev3dev-lang-python/ev3dev2/__init__.py", line 251, in _set_attribute
        self._raise_friendly_access_error(ex, name)
      File "/home/robot/ev3dev-lang-python/ev3dev2/__init__.py", line 268, in _raise_friendly_access_error
        chain_exception(ValueError("One or more arguments were out of range or invalid"), driver_error)
      File "/home/robot/ev3dev-lang-python/ev3dev2/__init__.py", line 38, in chain_exception
        raise exception from cause
    ValueError: One or more arguments were out of range or invalid
    

    So Motor.on_for_seconds and MoveTank.on_for_seconds should raise a ValueError exception if seconds is negative. Other than that though we could drop the rest of the safety checks.

    I am seeing odd behavior with MoveSteering in one scenario but I think that may be related to ev3dev/ev3dev#1173 ...still digging

  8. WasabiFan commented on Nov 4, 2018

    @WasabiFan
    Member

    I am seeing odd behavior with MoveSteering in one scenario but I think that may be related to ev3dev/ev3dev#1173 ...still digging

    The way it surfaced for me was that I was doing testing with steering=50 and one motor would sometimes run way longer than it should, often in the wrong direction. It took a few hours to figure out that it wasn't in our code 😆

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

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