ev3dev / ev3dev-lang-python

Pure python bindings for ev3dev
MIT License
425 stars 144 forks source link

Actounix L12 100 not recognized #733

Open trinidadg opened 4 years ago

trinidadg commented 4 years ago

I've been working with ev3-dev for the past weeks and successfully configured various sensors and actuators. However I can't get the Actuonix Linear Actuator working.

When I try to initialize the class, it says the motor is not connected.

I checked for the driver and it is there:

robot@ev3dev:~$ cat /sys/bus/lego/drivers/ev3-motor/driver_names 

lego-nxt-motor lego-ev3-l-motor lego-ev3-m-motor act-l12-ev3-50 act-l12-ev3-100

I have changed the port and the cable just in case and had no luck.

When I create a simple Motor class in that port It uses the lego-ev3-l-motor driver. Using that it responds to the on(vel) command, going both ways and stopping on the edges. I can't use stop() (it does nothing) and when asked for position it says 0 or 1 being fully retracted or fully extended.

Really hope for some help! Thanks

Desktop :

Robot:

ev3dev-sysinfo -m output:

Image file:         ev3dev-stretch-ev3-generic-2019-10-23
Kernel version:     4.14.117-ev3dev-2.3.4-ev3
Brickman:           0.10.2
BogoMIPS:           148.88
Bluetooth:          
Board:              board0
BOARD_INFO_HW_REV=8
BOARD_INFO_MODEL=LEGO MINDSTORMS EV3
BOARD_INFO_ROM_REV=6
BOARD_INFO_SERIAL_NUM=00165365FFCA
BOARD_INFO_TYPE=main
dlech commented 4 years ago

Using a LegoPort object it is possible to override the detected device. There is a similar example for how to do this with sensors at https://github.com/ev3dev/ev3dev-lang-python-demo/blob/stretch/platform/brickpi3-motor-and-sensor.py.

In your case port.set_device = 'act-l12-ev3-100' should do the trick.

trinidadg commented 4 years ago

Hi, thank you for your immediate answer!

I created this scipt:

#!/usr/bin/env python3
from ev3dev2.motor import ActuonixL12100Motor, OUTPUT_C
from ev3dev2.port import LegoPort

p = LegoPort(OUTPUT_C)

p.set_device = 'act-l12-ev3-100'

motor = ActuonixL12100Motor(OUTPUT_C)

But when i run it i get this error:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/ev3dev2/__init__.py", line 244, in _get_attribute
    attribute = self._attribute_file_open( name )
  File "/usr/lib/python3/dist-packages/ev3dev2/__init__.py", line 227, in _attribute_file_open
    mode = stat.S_IMODE(os.stat(path)[stat.ST_MODE])
FileNotFoundError: [Errno 2] No such file or directory: '/sys/class/tacho-motor/linear9/count_per_rot'

And results in:

ev3dev2.DeviceNotFound: ActuonixL12100Motor(ev3-ports:outC) is no longer connected
dlech commented 4 years ago

Try adding a time delay between set_device and ActuonixL12100Motor as in the linked example.

trinidadg commented 4 years ago

Tried that and I keep getting the same error. Changed the time delay up to 20 seconds just in case it was being slow, but nothing.

dlech commented 4 years ago

FileNotFoundError: [Errno 2] No such file or directory: '/sys/class/tacho-motor/linear9/count_per_rot'

OK, I think this is a bug in the python library then. linear9 should probably be motor9. You can check for sure in a SSH terminal.

$ ls /sys/class/tacho-motor/
WasabiFan commented 4 years ago

Is the count_per_rot attribute omitted for linear actuators? If not, it definetely looks like a library bug somehow.

dlech commented 4 years ago

It's been a long time. My memory is probably faulty :wink: Better check the docs: http://docs.ev3dev.org/projects/lego-linux-drivers/en/ev3dev-stretch/motors.html#tacho-motor-subsystem

So maybe linear is right and the attributes are slightly different.

WasabiFan commented 4 years ago

I suspect it is trying to cache count_per_rot on initialization and failing because it doesn't exist... I'll take a look at this today.

trinidadg commented 4 years ago

It's called linear

the output for

ls /sys/class/tacho-motor/linear13/

is

address      duty_cycle         position      speed_pid     time_sp
command      duty_cycle_sp      position_sp   speed_sp      uevent
commands     full_travel_count  power         state
count_per_m  hold_pid           ramp_down_sp  stop_action
device       max_speed          ramp_up_sp    stop_actions
driver_name  polarity           speed         subsystem

so the attributes are different, but i don't know why it tries to get cout_per_rot

WasabiFan commented 4 years ago

Yeah, the issue is here: https://github.com/ev3dev/ev3dev-lang-python/blob/ev3dev-stretch/ev3dev2/motor.py#L425

When we restructured speed unit handling we entirely missed the linear actuator case which lacks that attribute. Right now we have speed units which know how to work for rotational motors but not for linear actuators. I'm inclined to go with the simpler solution of not supporting speed units other than percentages with linear actuators; I'll implement it and we can go from there.

@trinidadg if you'd like an immediate workaround, this should work:

from ev3dev2.motor import Motor
@property
def patch_count_per_rot(self):
    return 1

Motor.count_per_rot = patch_count_per_rot

And then don't try to use SpeedUnits other than SpeedPercent 😆 If you are also using normal rotational motors and would like them to continue working as they currently do, you can (or I can show you how to) replace return 1 with a try/catch which tries the original property and returns 1 if it doesn't work.

WasabiFan commented 4 years ago

@trinidadg Would you be up to test out my fix from #734? If your EV3 has Internet access, you can do the following:

git clone https://github.com/ev3dev/ev3dev-lang-python.git -b fix-linear-actuators
cd ev3dev-lang-python
sudo make install

This should install the development version and you can import/use the library as normal. If you are able to test this, please do let me know how it goes! I tested to confirm normal rotational motors still work but I don't have any linear ones to try.

To undo the installation of the development version, run sudo apt-get --reinstall install python3-ev3dev2.

trinidadg commented 4 years ago

The make failed with this error:

python3 setup.py install
Traceback (most recent call last):
  File "setup.py", line 10, in <module>
    version=git_version(),
  File "/home/robot/ev3dev-lang-python/git_version.py", line 68, in git_version
    raise ValueError("Cannot find the version number!")
ValueError: Cannot find the version number!
Makefile:15: recipe for target 'install' failed
make: *** [install] Error 1
trinidadg commented 4 years ago

Using a LegoPort object it is possible to override the detected device. There is a similar example for how to do this with sensors at https://github.com/ev3dev/ev3dev-lang-python-demo/blob/stretch/platform/brickpi3-motor-and-sensor.py.

In your case port.set_device = 'act-l12-ev3-100' should do the trick.

For some reason, the instruction p.set_device = 'act-l12-ev3-100'stopped working for me. The output error is:

p.set_device = 'act-l12-ev3-100'
  File "/usr/lib/python3/dist-packages/ev3dev2/port.py", line 140, in set_device
    self._set_device = self.set_attr_string(self._set_device, 'set_device', value)
  File "/usr/lib/python3/dist-packages/ev3dev2/__init__.py", line 322, in set_attr_string
    return self._set_attribute(attribute, name, value)
  File "/usr/lib/python3/dist-packages/ev3dev2/__init__.py", line 264, in _set_attribute
    self._raise_friendly_access_error(ex, name, value)
  File "/usr/lib/python3/dist-packages/ev3dev2/__init__.py", line 288, in _raise_friendly_access_error
    raise driver_error
  File "/usr/lib/python3/dist-packages/ev3dev2/__init__.py", line 261, in _set_attribute
    attribute.write(value)
OSError: [Errno 95] Operation not supported

It worked fine for a while but now it keeps throwing that error.

dlech commented 4 years ago

Check the mode of the port. Only certain modes allow set_device.

WasabiFan commented 4 years ago

@trinidadg I haven't gotten a chance to look into the installation error you posted; for our purposes though you can replace line 10 (the middle line below) in setup.py as a workaround:

setup(name='python-ev3dev2',
      version='2.1.0.post3',
      description='v2.x Python language bindings for ev3dev',