Skip to content

EV3-G API: motors #353

Closed
Closed

Description

@dwalton76

motor-01
motor-02
motor-03
move-steering-01
move-tank-01

Activity

  1. self-assigned this
    on Sep 19, 2017
  2. ddemidov commented on Sep 20, 2017

    @ddemidov
    Member

    We could merge various on_for_* methods into

    m.on_for(rotations=3, brake=True)
    m.on_for(degrees=45, power=75)
    m.on_for(seconds=1)

    Here on_for could be defined as

    def m.on_for(rotations=None, degrees=None, seconds=None, **kwargs):
      # set attributes from kwargs
      ...
      if rotations is not None:
        ...
      elif degrees is not None:
        ...
  3. dwalton76 commented on Sep 20, 2017

    @dwalton76
    CollaboratorAuthor

    Does EV3-G not provide a way to specify STOP_ACTION_HOLD when using their Motor, MoveTank, MoveSteering blocks? It doesn't look like they do which seems a little odd.

    I am trying to get EV3-G running via wine so that I can check for this kind of stuff but no luck yet

  4. ddemidov commented on Sep 20, 2017

    @ddemidov
    Member

    I think hold is ev3dev specific.

  5. dlech commented on Sep 20, 2017

    @dlech
    Member

    brake is ev3dev-specific. hold in ev3dev == Brake in EV3-G.

    http://docs.ev3dev.org/projects/lego-linux-drivers/en/ev3dev-stretch/motors.html#sysfs

  6. laurensvalk commented on Sep 20, 2017

    @laurensvalk

    I came across this thread after being tagged in something so hopefully I'm not taking this too far off topic...

    Quoting from the table for the yellow blocks:

    current_power = m.measure_current_power()

    I understand the idea here is to obtain functionality close to EV3-G, and I could live with power and speed being used interchangeably for the green blocks, but this one is quite exceptional.

    Measuring "current power" in EV3-G gives you the speed (no relation to current or power at all).

    The wording is kind of justifiable in English (current = instantaneous), but if you'd install the German version of EV3-G, you'd literally see "Measure electrical current" (But it still gives you the speed 😄)


    tldr; Keep the picture in the table as is, but maybe just write: speed = m.measure_speed()

  7. dlech commented on Sep 20, 2017

    @dlech
    Member

    Totally on topic. The tables show word-for-word in Python, what the EV3-G blocks says just for clarity. The idea is that in the actual implementation, they get cleaned up where appropriate.

  8. dwalton76 commented on Sep 20, 2017

    @dwalton76
    CollaboratorAuthor

    If default is hold and the user ctrl-C their program we will leave the motor with power being applied to hold it in place. Thoughts on how we can gracefully set the stop_action to coast when the program exits (without the user coding this into their program)? We could add a __del__ to the Motor class that does this but from googling folks think that implementing a __del__ in python is a horrible sin.

  9. dlech commented on Sep 20, 2017

    @dlech
    Member

    That is why you run your program with brickrun, it stops motors, sound, etc.

    __del__ is for releasing unmanaged resources, like file handles, when an object is garbage collected. There is no guarantee when or even if an object is garbage collected, so it cannot be relied upon for anything that must happen.

  10. dwalton76 commented on Sep 20, 2017

    @dwalton76
    CollaboratorAuthor

    Does brickman set the stop_action to coast? If so that sounds good to me. I

  11. dlech commented on Sep 20, 2017

    @dlech
    Member

    brickrun totally resets the motor, including removing power (setting to to coast)

  12. dwalton76 commented on Sep 20, 2017

    @dwalton76
    CollaboratorAuthor

    For all of these on_for_XYZ() functions do we want the power that we pass it to be a percentage of max_speed from -100% to 100% or do we want this to be the actual speed_sp? Make take is they should be a percentage from -100 to 100 but we need to reach a consensus on this.

  13. WasabiFan commented on Sep 20, 2017

    @WasabiFan
    Member

    On one hand, we could switch to our own scientific units; it would make the behavior of "speed" better-defined than if it were a percentage, but that requires documentation and it's easy to miss. On the other hand, using percentages would make the interface dramatically more intuitive for a typical user.

    I think it comes down to this question: can we adequately document the special behavior? Where would we put the info?

  14. dlech commented on Sep 21, 2017

    @dlech
    Member

    How about we make the default units % just like EV3-G, plus introduce scaling factor constants for those who want scientific units.

    # run the motor at 50% of max speed
    m.run(50)
    # run the motor at 400 degrees/second
    m.run(400 * m.DPS)
    # run the motor at 60 RPM
    m.run(60 * m.RPM)
  15. dlech commented on Sep 21, 2017

    @dlech
    Member

    But we should name our parameter speed instead of power 😉

  16. dwalton76 commented on Sep 21, 2017

    @dwalton76
    CollaboratorAuthor

    Works for me

  17. ddemidov commented on Sep 21, 2017

    @ddemidov
    Member

    m.run(60 * m.RPM)

    why not m.run(speed_pct=50), m.run(dps=400), and m.run(rpm=60)? If we define run as

    def run(self, speed_pct=None, dps=None, rpm=None)

    we could also just use m.run(50) instead of m.run(speed_pct=50). Personally, I think this makes a cleaner interface.

  18. WasabiFan commented on Sep 21, 2017

    @WasabiFan
    Member

    @ddemidov you could still call the run method with one positional argument and it would work as-is (with the version in your code block), right?

  19. ddemidov commented on Sep 21, 2017

    @ddemidov
    Member

    Yes:

    >>> def test(a=None,b=None,c=None):
    ...   if a is not None:
    ...     print('a:', a)
    ...   elif b is not None:
    ...     print('b:', b)
    ...   else:
    ...     print('c:', c)
    ... 
    >>> test(10)
    a: 10
    >>> test(b=42)
    b: 42
    >>> 
  20. dwalton76 commented on Sep 21, 2017

    @dwalton76
    CollaboratorAuthor

    We have other parameters that need to be passed in though (speed) so basically everything becomes a positional arg. So the user would do one of

    m.on_for_degrees(speed_pct=40, degrees=720)
    m.on_for_degrees(speed_dps=90, degrees=720)
    m.on_for_degrees(speed_rps=0.25, degrees=720)
    

    That looks ok to me...one thing nice about forcing the arg= syntax is it makes the code very readable

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