Skip to content

Led behaviour #262

Closed
Closed

Description

@verytallrobot
  • ev3dev version: 4.4.32-17-ev3dev-ev3
  • ev3dev-lang-python version: 0.8.0

Hi All,
I'm trying to make a super simple tutorial for my high school students (Hong Kong) to introduce them to programming on Python and so I'm trying to get a lot of snippets of code working by typing at the Python console so they can try ideas quickly before editing a .py file.

I have set colour of the left LED to red already.
On the samples on this site it says I can use the code:

Leds.set(LEFT, brightness_pct=0.5, trigger='timer')

But I get:

File "<stdin>", line 1, in <module>
NameError: name 'LEFT' is not defined

The following works...sort of.
Leds.set(Leds.LEFT, brightness_pct=0.5, trigger='timer')
It flashes off, green then red!

If I run the following it works as expected but I have had to use the trigger argument on the first line to solve the problem that @ndward had on his site.

Leds.set(Leds.LEFT, brightness_pct=0.5, trigger='timer')
Leds.set(Leds.LEFT, brightness_pct=0.5, delay_on=1000, delay_off=500)
Leds.set_color(Leds.LEFT, Leds.RED)

I turn off the LEDs and then tried the following.
Why can't I do this?

Leds.set(Leds.LEFT, brightness_pct=0.5, trigger='timer', delay_on=1000, delay_off=500)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3/dist-packages/ev3dev/ev3.py", line 90, in set
    setattr(led, k, kwargs[k])
  File "/usr/lib/python3/dist-packages/ev3dev/core.py", line 2233, in delay_on
    self._delay_on = self.set_attr_int(self._delay_on, 'delay_on', value)
  File "/usr/lib/python3/dist-packages/ev3dev/core.py", line 215, in set_attr_int
    return self._set_attribute(attribute, name, str(int(value)))
  File "/usr/lib/python3/dist-packages/ev3dev/core.py", line 201, in _set_attribute
    attribute = self._attribute_file_open( name )
  File "/usr/lib/python3/dist-packages/ev3dev/core.py", line 184, in _attribute_file_open
    return io.FileIO(path, mode)
PermissionError: [Errno 13] Permission denied: '/sys/class/leds/ev3:left:red:ev3dev/delay_on'

On a separate note, I couldn't find the function list_motors in the API although it was in some demo code. Is that documented somewhere?

Cheers

Activity

  1. ddemidov commented on Nov 21, 2016

    @ddemidov
    Member

    On the samples on this site it says I can use the code:

    Leds.set(LEFT, brightness_pct=0.5, trigger='timer')

    LEFT is a list of leds defined in the Leds class, so yo definitely have to use it as Leds.LEFT. Can you point me to the exact place on this site where it says one can use LEFT directly, so I could fix the documentation bug?

    The following works...sort of.
    Leds.set(Leds.LEFT, brightness_pct=0.5, trigger='timer')
    It flashes off, green then red!

    I can reproduce this. There is a certain delay after the trigger attribute is set for each led, and LEFT group contains two leds (red and green). So I am currently not sure how to deal with this. May be turn off one of the leds, and only flash the other?

    I turn off the LEDs and then tried the following.
    Why can't I do this?

    you need to split the command into two commands:

    Leds.set(Leds.LEFT, brightness_pct=0.5, trigger='timer')
    Leds.set(Leds.LEFT, delay_off=1000, delay_on=500)

    The reason is that keyword arguments are passed to a python function as a dictionary, which is unsorted. So delay_on, delay_off arguments may be applied before trigger is set to 'timer'.

  2. WasabiFan commented on Nov 21, 2016

    @WasabiFan
    Member

    @dlech is there anything that could be done to make it easier to operate multiple LEDs in unison? This seems like a common goal (blinking orange) which is currently pretty difficult.

    @ddemidov I'm thinking that we should add a "blink" method that handles this stuff for the user. What do you think? Where might it go (individual LEDs, groups, etc.)?

  3. WasabiFan commented on Nov 21, 2016

    @WasabiFan
    Member

    On a separate note, I couldn't find the function list_motors in the API although it was in some demo code. Is that documented somewhere?

    It looks like it's defined here, however it doesn't show up in the documentation because it isn't part of a class and isn't explicitly included. @ddemidov I have no idea how to make that show up... what's the directive for including a specific method?

  4. WasabiFan commented on Nov 21, 2016

    @WasabiFan
    Member

    Why can't I do this?

    To expand on what @ddemidov said, the issue is that you can't set the timer delay before you specify that you want to use a timer. Unfortunately, you can't guarantee that trigger='timer' happens before delay_*=1000, so you have to do it in two separate calls.

  5. ddemidov commented on Nov 21, 2016

    @ddemidov
    Member

    I have no idea how to make that show up... what's the directive for including a specific method?

    281101f deals with that. The functions are now listed here: http://python-ev3dev.readthedocs.io/en/latest/spec.html

  6. dlech commented on Nov 21, 2016

    @dlech
    Member

    @dlech is there anything that could be done to make it easier to operate multiple LEDs in unison? This seems like a common goal (blinking orange) which is currently pretty difficult.

    This is an unsolved problem in the mainline kernel driver. There was an attempt to create an RGB LED driver earlier this year, but I don't think anything has come out of that yet.

    The alternatives are to use the "heartbeat" trigger, which creates a blinking pattern similar to the official LEGO firmware or we could create a new trigger in the kernel that can do other fancy things.

  7. WasabiFan commented on Nov 21, 2016

    @WasabiFan
    Member

    What if we created our own trigger that operated like timer but ensured that two LEDs set to the same interval would operate simultaneously (as opposed to operating relative to when they were started)? Is that possible?

  8. dlech commented on Nov 21, 2016

    @dlech
    Member

    The more I think about it, the more I think that a new trigger sounds like a good idea. The iio subsystem has a similar sort of setup to trigger reading data from a data collecting device. There are options to configure triggers via sysfs or configfs. Since the trigger would have it's own device node to set on time/off time, this would solve both the problem of both orange blinking and the race condition with permission on the on/off time attributes of the current timer trigger.

  9. WasabiFan commented on Nov 21, 2016

    @WasabiFan
    Member

    That sounds great! Two birds with one stone.

  10. dlech commented on Nov 21, 2016

    @dlech
    Member

    Does that mean you are volunteering to write the driver? 😃

  11. WasabiFan commented on Nov 21, 2016

    @WasabiFan
    Member

    No, I'm registering my support for that idea with the presumption that it will be available for someone to implement when they are interested. Given that I couldn't even get code into Brickman where I had a basic understanding of all the technologies, I highly doubt I'd be able to do it here.

  12. ddemidov commented on Nov 22, 2016

    @ddemidov
    Member

    Does that mean you are volunteering to write the driver?

    I could try to do this if you point me in a general direction.

  13. dlech commented on Nov 22, 2016

    @dlech
    Member

    Cool. First step would be to open an issue on the main ev3dev GitHub issues.

  14. ndward commented on Nov 27, 2016

    @ndward

    With this code

    Leds.set(Leds.LEFT, brightness_pct=0.5, trigger='timer')
    Leds.set(Leds.LEFT, delay_on=3000, delay_off=500)
    Leds.set_color(Leds.LEFT, Leds.GREEN)
    

    I seem to have success but if I use colors other than RED or GREEN (the 'pure' LED colors) then I get unpredictable colors (e.g. I ask for amber and I get yellow) and sometimes error messages about wrong permissions or permission denied for delay_on or delay_off, just like @verytallrobot. The above script is the one I just posted to , with a warning.

  15. WasabiFan commented on Sep 17, 2017

    @WasabiFan
    Member

    I'm going to close this in favor of #324. Our goal is to re-implement the LED API with a custom service of some sort to handle blinking/fading ourselves, so we can avoid the issues with the internal sysfs API.

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