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
Just getting one LargeMotor on outB to run from a file is throwing up this exception!
Code works from python3 prompt just not when in a .py file which is just crazy.
I'm going to try an older build of the kernel.
Any help greatly appreciated.
from ev3dev.ev3 import * from time import sleep m = LargeMotor('outB', stop_action="hold") m.run_to_rel_pos(position_sp=360, speed_sp=900) sleep(5)
Terminal message:
robot@ev3dev:~$ python3 m3.py
Traceback (most recent call last):
File "m3.py", line 12, in <module>
m.run_to_rel_pos(position_sp=360, speed_sp=900)
File "/usr/lib/python3/dist-packages/ev3dev/core.py", line 774, in run_to_rel_pos
setattr(self, key, kwargs[key])
File "/usr/lib/python3/dist-packages/ev3dev/core.py", line 546, in speed_sp
self._speed_sp = self.set_attr_int(self._speed_sp, 'speed_sp', 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 208, in _set_attribute
raise Exception('Device is not connected')
Exception: Device is not connected
This is wrong. keyword arguments in motor constructor are for finding the correct motor, so you are trying to find a motor which has "hold" as a stop action. This may work from command prompt, because you set the stop action for the same motor earlier yourself, but is not very reliable in general.
To expand on what @ddemidov said: When a device is "not connected", it means that no device could be found which satisfied the given requirements (e.g. port name, motor type).
Thanks ddemidov and wasabiFan. I thought I was initialising the motor not asking the brick to find that motor.
Confused as to why it worked at all from the prompt.
Cheers
Activity
ddemidov commentedon Nov 8, 2016
This is wrong. keyword arguments in motor constructor are for finding the correct motor, so you are trying to find a motor which has "hold" as a stop action. This may work from command prompt, because you set the stop action for the same motor earlier yourself, but is not very reliable in general.
What you should do is
WasabiFan commentedon Nov 8, 2016
To expand on what @ddemidov said: When a device is "not connected", it means that no device could be found which satisfied the given requirements (e.g. port name, motor type).
verytallrobot commentedon Nov 8, 2016
Thanks ddemidov and wasabiFan. I thought I was initialising the motor not asking the brick to find that motor.
Confused as to why it worked at all from the prompt.
Cheers
simoscream commentedon Apr 8, 2018
I confirm that this may happen also because of a command called for incorrect device (ex LargeMotor(outB) where OUt B is connected to a small motor.
Thanks :)