Skip to content

issues with the new apis (compared to boost bindings) #64

Closed

Description

@ensonic

= Button =

Nov 05 12:30:28 ev3dev openrobertalab.py[716]: File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner
Nov 05 12:30:28 ev3dev openrobertalab.py[716]: self.run()
Nov 05 12:30:28 ev3dev openrobertalab.py[716]: File "/usr/bin/openrobertalab.py", line 111, in run
Nov 05 12:30:28 ev3dev openrobertalab.py[716]: if self.service.hal.isKeyPressed('back'):
Nov 05 12:30:28 ev3dev openrobertalab.py[716]: File "/usr/lib/python2.7/dist-packages/roberta/ev3.py", line 140, in isKeyPressed
Nov 05 12:30:28 ev3dev openrobertalab.py[716]: return getattr(self.key, key).pressed
Nov 05 12:30:28 ev3dev openrobertalab.py[716]: AttributeError: type object 'Button' has no attribute 'back'

Button.back vs. Button.backspace
I renamed this for now

Nov 05 12:34:03 ev3dev openrobertalab.py[742]: File "/tmp/NEPOprog.py", line 44, in <module>
Nov 05 12:34:03 ev3dev openrobertalab.py[742]: main()
Nov 05 12:34:03 ev3dev openrobertalab.py[742]: File "/tmp/NEPOprog.py", line 40, in main
Nov 05 12:34:03 ev3dev openrobertalab.py[742]: while not hal.isKeyPressed('any'): hal.waitFor(500)
Nov 05 12:34:03 ev3dev openrobertalab.py[742]: File "/usr/lib/python2.7/dist-packages/roberta/ev3.py", line 127, in isKeyPressed
Nov 05 12:34:03 ev3dev openrobertalab.py[742]: if getattr(self.key, key).pressed:
Nov 05 12:34:03 ev3dev openrobertalab.py[742]: AttributeError: 'property' object has no attribute 'pressed'

Button.pressed vs. Button.check_buttons ?
but that'd be repeating the name, since what else should be checked in a Button class.
Same issues with 'buttons_pressed' property on subclasses.

Also why is Buttons.any a property?

Nov 05 13:11:28 ev3dev openrobertalab.py[887]: Traceback (most recent call last):
Nov 05 13:11:28 ev3dev openrobertalab.py[887]: File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner
Nov 05 13:11:28 ev3dev openrobertalab.py[887]: self.run()
Nov 05 13:11:28 ev3dev openrobertalab.py[887]: File "/usr/bin/openrobertalab.py", line 111, in run
Nov 05 13:11:28 ev3dev openrobertalab.py[887]: if self.service.hal.isKeyPressed('back'):
Nov 05 13:11:28 ev3dev openrobertalab.py[887]: File "/usr/lib/python2.7/dist-packages/roberta/ev3.py", line 134, in isKeyPressed
Nov 05 13:11:28 ev3dev openrobertalab.py[887]: return self.keys.check_buttons([key])
Nov 05 13:11:28 ev3dev openrobertalab.py[887]: TypeError: unbound method check_buttons() must be called with Button instance as first argument (got list instance instead)

ev3dev.button became ev3dev.Buttons

= Sound =
since this changed from sync (system) to async.
tone(a,b) becomes tone(a,b).wait()

= Motors =
.state is always []

I expect this to work (works with the boost bindings)

m=ev3dev.LargeMotor(ev3dev.OUTPUT_B)
m.run_to_rel_pos(speed_regulation_enabled='on', position_sp=1000)
while (m.state):
  print m.state

If you change while(m.state) to while(True), it prints [] even though the motor is running.

= Sensors =
.value() return 0

I expect this to work (works with the boost bindings)

s = ev3dev.TouchSensor(ev3dev.INPUT_1)
s.value()

Whether I hold the touch sensor button pressed ot not, it returns 0. Or another one:

s = ev3dev.UltrasonicSensor(ev3dev.INPUT_4)
while(True):
  print s.value()
  time.sleep(0.5)

This prints a static value (191) for me. If instead for any of the sensors I do:

watch -n0.1 cat /sys/class/lego-sensor/sensor*/value0

I see the values changing.

At this point I wonder how you verify the bindings?

Activity

  1. ensonic commented on Nov 5, 2015

    @ensonic
    ContributorAuthor

    Could this be an issue with the file-descriptor caching?

  2. ensonic commented on Nov 5, 2015

    @ensonic
    ContributorAuthor

    All the motor and sensor issues are solved with a 1 liner fix - #68

  3. ddemidov commented on Nov 5, 2015

    @ddemidov
    Member

    Thanks for testing, I'll look into these. Do you still plan to use both versions of the bindings? I mean, how important is API compatibility at this point?

  4. ddemidov commented on Nov 5, 2015

    @ddemidov
    Member

    why is Buttons.any a property?

    Button implementation has changed significantly from boostc version, now you need to instantiate it in order to use the class.

    EDIT: I think I misread your message. Why Button.any being a property is an issue?

  5. ensonic commented on Nov 5, 2015

    @ensonic
    ContributorAuthor

    @ddemidov: I have switched over. I think compatibility is hopeless, people will need to do some editing.

    Re Button.any, it reads weird, don't you think.

  6. ddemidov commented on Nov 5, 2015

    @ddemidov
    Member

    Does Button.any_pressed sound better?

  7. ensonic commented on Nov 5, 2015

    @ensonic
    ContributorAuthor

    I think it should be a function since the property is computed anyway. The normal methods seems to e Button.check_pressed(), so maybe Button.check_any_pressed().

  8. rhempel commented on Nov 6, 2015

    @rhempel
    Member

    I like to think of attributes as "things that you can access as if they were instance variables" - you read and write them. If an attribute accepts a value to write, it does not return a value. The only sideeffect is that the attribute gets the value.

    Button.any is a property - returns True/False is any platform specific button is pressed
    Button.buttons_pressed is a prpperty, returns a list of button names that are pressed.
    Button.check_buttons() is a function that accepts an optional list of buttons to check. True if ALL buttons in the list are checked.

    We can go around and around on semantics - we decided Button.any is the Pythonic way to return if any buttons are pressed.

    I am happy to discuss alternatives, but at some point we need to make a decision and stick to it - I am no Python expert, and yes Button.any read wierd, but so does:

    return any([value.find(pat) >= 0 for pat in pattern])
    

    so I'm OK with Button.any() if we have to...

    @ensonic - is there a missing function or attribute in the Button class that is a showstopper at this point?

  9. ensonic commented on Nov 6, 2015

    @ensonic
    ContributorAuthor

    Lets then keep the Buttons api as it is as I don't wan't to change it further. The main issue was that it was not documented but different to the previous api. I still prefer functions for things that are computed as calling a function makes you aware that it might 'take a while'. For me window.width is a property, since that has a physical representation. Buttons.any is a predicate.

  10. rhempel commented on Nov 6, 2015

    @rhempel
    Member

    I agree with @ensonic re Button.any() - it's not a property and it would be better, I think, if it worked like the Python any() function.
    @ensonic - OK if I change this part of the API?

  11. ensonic commented on Nov 6, 2015

    @ensonic
    ContributorAuthor

    @rhempel yes please and thanks :)

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