Skip to content

Flexible relative movement and improved parameter handling - #523

Merged
WasabiFan merged 6 commits into
ev3dev-stretchfrom
flexible-relative-movement
Sep 23, 2018
Merged

WasabiFan merged 6 commits into
ev3dev-stretchfrom
flexible-relative-movement

Conversation

@WasabiFan

@WasabiFan WasabiFan commented Sep 15, 2018 •

Copy link
Copy Markdown
Member

The primary goals here were to:

  • Remove unnecessary cases where we warn or throw an error
  • Make handling of negative speeds and distances intuitive/logical, like multiplication
  • Fix cases of zero distance and/or speed

In the process, I:

  • Refactored _set_position_rotations and _set_position_degrees
    • To minimize duplication there is now only one, which operates on degrees, and rotations-based methods call the degree versions. This is one more function call (which is slow) but I figure it's worth it.
    • The method is called _set_rel_position_degrees_and_speed_sp and handles setting both position_sp and speed_sp so it can normalize negatives
  • Replaced our custom position_sp = position + delta; command = 'run-to-abs-pos' with using run-to-rel-pos. I read through EV3-G API: motors #360 where this was originally implemented, and don't see why it was done this way. (let me know if I missed something, @dwalton76)
  • Updated the logic to choose distances for each motor so that it correctly handles negative speeds
  • Removed a warning that really wasn't helpful

One question: On an individual motor, if you ask it to move a nonzero distance at zero speed, it will return immediately because the driver calls that a "stalling" state. However, with a motor pair, I adopted a different behavior: in that particular case it throws a ValueError. Do others agree with this set of behaviors or should one of them be changed?

Closes #516 (supersedes changes)
Fixes #504
Fixes #505
Fixes #507

Comment thread ev3dev2/motor.py Outdated
"""

if left_speed == 0 and right_speed == 0 and degrees != 0:
raise ValueError("Can't travel a nonzero distance at zero speed")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two points:

  • There is probably some larger than zero speed threshold where motor will stall, so zero is not that special
  • I can imagine a situation where speed is set by some function (e.g. based on user input), where it may legitimately cross zero. Not sure if raising an exception would be a good idea in this case.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went back-and-forth on this so I'm not attached to this behavior. I agree with your points; what would you suggest the behavior be?

If we ask the motor driver to go a nonzero distance with zero speed, it will report being running stalled indefinetely, and in turn will immediately cause our wait_until_not_moving to return. So would your suggestion be to adopt that behavior? That feels weird to me, but it's consistent with our single-motor methods (#515) so probably makes sense.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we ask the motor driver to go a nonzero distance with zero speed, it will report being running stalled indefinetely, and in turn will immediately cause our wait_until_not_moving to return.

I think a return from wait_until_not_moving() here is an expected outcome. The speed the user asked was too small, so the motor is stalled, and is not moving.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, thanks for the second opinion; I've updated the PR.

@WasabiFan

Copy link
Copy Markdown
Member Author

@ddemidov When you have the chance, can you take another look at this? Once this PR and #524 are good-to-go I plan to release a new version of the package.

@WasabiFan

Copy link
Copy Markdown
Member Author

I'm going to merge this now and do some end-to-end testing so I can release the package today. If there are any issues here that I haven't caught, we can fix them in a separate PR.

@WasabiFan
WasabiFan merged commit b5e658a into ev3dev-stretch Sep 23, 2018
@WasabiFan
WasabiFan deleted the flexible-relative-movement branch November 10, 2018 00:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants