You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have tried to create a python program to do the same but I get file open error
#!/usr/bin/env python3 from ev3dev.ev3 import * import ev3dev.ev3 as ev3
p = ev3.LegoPort('outA') assert p.connected p.mode = 'dc-motor' m = ev3.DcMotor('outA') m.run_direct(duty_cycle_sp=75)
it fails with robot@ev3dev:~$ python3 train.py Traceback (most recent call last): File "train.py", line 9, in <module> m.run_direct(duty_cycle_sp=75) File "/usr/lib/python3/dist-packages/ev3dev/core.py", line 1302, in run_direct setattr(self, key, kwargs[key]) File "/usr/lib/python3/dist-packages/ev3dev/core.py", line 1154, in duty_cycle_sp self._duty_cycle_sp = self.set_attr_int(self._duty_cycle_sp, 'duty_cycle_sp', value) File "/usr/lib/python3/dist-packages/ev3dev/core.py", line 217, in set_attr_int return self._set_attribute(attribute, name, str(int(value))) File "/usr/lib/python3/dist-packages/ev3dev/core.py", line 206, in _set_attribute attribute.write(value.encode()) io.UnsupportedOperation: File not open for writing
what am I doing wrong?
What user are you doing this under? Also, could you do ls -l /sys/class/dc-motor/motor0/ after the python script fails? It looks like the duty_cycle_sp attribute is opened for reading, which means that group 'w' bit is not set (the file is opened here).
Another thought: can you try to add time.sleep(500) after p.mode = 'dc-motor'? Its possible that the duty_cycle_sp attribute is accessed before its permissions were fully set.
Activity
ddemidov commentedon Apr 3, 2017
What user are you doing this under? Also, could you do
ls -l /sys/class/dc-motor/motor0/after the python script fails? It looks like theduty_cycle_spattribute is opened for reading, which means that group 'w' bit is not set (the file is opened here).ddemidov commentedon Apr 3, 2017
Another thought: can you try to add
time.sleep(500)afterp.mode = 'dc-motor'? Its possible that theduty_cycle_spattribute is accessed before its permissions were fully set.flynder commentedon Apr 3, 2017
it works! after googling time.sleep and seeing that it is defined in seconds ;)
a sleep(0.5) is enough to get it started, thx a lot
ddemidov commentedon Apr 3, 2017
Ah, sorry about that. I hope you decided to google before it was finished :).
flynder commentedon Apr 3, 2017
yes, didnt have patience for an 8 minute wait