Repository navigation
Description
- 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
ddemidov commentedon Nov 21, 2016
LEFTis a list of leds defined in theLedsclass, so yo definitely have to use it asLeds.LEFT. Can you point me to the exact place on this site where it says one can useLEFTdirectly, so I could fix the documentation bug?I can reproduce this. There is a certain delay after the trigger attribute is set for each led, and
LEFTgroup 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?you need to split the command into two commands:
The reason is that keyword arguments are passed to a python function as a dictionary, which is unsorted. So
delay_on,delay_offarguments may be applied before trigger is set to 'timer'.WasabiFan commentedon Nov 21, 2016
@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.)?
WasabiFan commentedon Nov 21, 2016
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?
WasabiFan commentedon Nov 21, 2016
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 beforedelay_*=1000, so you have to do it in two separate calls.Document list_device_names(), list_devices(), list_motors()
ddemidov commentedon Nov 21, 2016
281101f deals with that. The functions are now listed here: http://python-ev3dev.readthedocs.io/en/latest/spec.html
dlech commentedon Nov 21, 2016
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.
WasabiFan commentedon Nov 21, 2016
What if we created our own trigger that operated like
timerbut 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?dlech commentedon Nov 21, 2016
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.
WasabiFan commentedon Nov 21, 2016
That sounds great! Two birds with one stone.
dlech commentedon Nov 21, 2016
Does that mean you are volunteering to write the driver? 😃
WasabiFan commentedon Nov 21, 2016
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.
ddemidov commentedon Nov 22, 2016
I could try to do this if you point me in a general direction.
dlech commentedon Nov 22, 2016
Cool. First step would be to open an issue on the main ev3dev GitHub issues.
ndward commentedon Nov 27, 2016
With this code
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.
WasabiFan commentedon Sep 17, 2017
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.