ev3dev / ev3dev-lang-python-demo

Python Demo Programs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Problem with MINDCUB3R code

guinasc2 opened this issue · comments

I followed all the steps on how to install the code for MINDCUB3R. When I try to execute the code, I get an exception saying that the Infrared Sensor is not connected even though it is connected. Is there anything I can do to solve this problem?

Does the device appear in the Device Browser (accessible via the on-screen menu of the brick)?

Yes. I can even see the values the device is reading.

Hmmmm... Are you able to run other Python code that uses the IR sensor? (And to clarify, you're definitely running the code on your EV3?)

Try this: run the command python3 then type:

from ev3dev2.sensor.lego import InfraredSensor
sensor = InfraredSensor()

Does it print an error?

I will only be able to test this code on Thursday. Is there a problem if I answer you later?

No problem; let us know when you can.

Hi. I tested the code you passed on EV3 and returned this error:

from ev3dev2.sensor.lego import InfraredSensor
sensor = InfraredSensor()
Traceback (most recent call last):
File "", line 1, in
File "/usr/lib/python3/dist-packages/ev3dev2/sensor/lego.py", line 744, in init
super(InfraredSensor, self).init(address, name_pattern, name_exact, driver_name='lego-ev3-ir', **kwargs)
File "/usr/lib/python3/dist-packages/ev3dev2/sensor/init.py", line 91, in init
super(Sensor, self).init(self.SYSTEM_CLASS_NAME, name_pattern, name_exact, **kwargs)
File "/usr/lib/python3/dist-packages/ev3dev2/init.py", line 201, in init
chain_exception(DeviceNotFound("%s is not connected." % self), None)
File "/usr/lib/python3/dist-packages/ev3dev2/init.py", line 38, in chain_exception
raise exception from cause
ev3dev2.DeviceNotFound: InfraredSensor is not connected.

What should I do?

Interesting. The Python library certainly isn't seeing the sensor. Do you have a terminal connection to your brick available (e.g. via vscode or SSH)? Can you connect the sensor then run the following commands and give me the output? They will list the port info and detected sensor type for all connected sensors.

tail -n +1 /sys/class/lego-sensor/sensor*/address

and

tail -n +1 /sys/class/lego-sensor/sensor*/driver_name

These are the outputs of the commands:

robot@ev3dev:~$ tail -n +1 /sys/class/lego-sensor/sensor*/address

==> /sys/class/lego-sensor/sensor0/address <==
ev3-ports:in1

==> /sys/class/lego-sensor/sensor1/address <==
ev3-ports:in2

robot@ev3dev:~$ tail -n +1 /sys/class/lego-sensor/sensor*/driver_name

==> /sys/class/lego-sensor/sensor0/driver_name <==
lego-ev3-us

==> /sys/class/lego-sensor/sensor1/driver_name <==
lego-ev3-color

Looks like this is an UltrasonicSensor, and not an infrared one.

That makes sense, but in the building instruction using the Education Sets available at http://mindcuber.com/, the sensor they show is an ultrasonic sensor, so I used it.
I would like to know if it is possible to change the code to make it work with the ultrasonic sensor because I do not have the infrared sensor.

You can probably replace InfraredSensor with UltrasonicSensor here (https://github.com/ev3dev/ev3dev-lang-python-demo/blob/stretch/robots/MINDCUB3R/mindcuber.py#L44) then replace proximity with distance_cm here (https://github.com/ev3dev/ev3dev-lang-python-demo/blob/stretch/robots/MINDCUB3R/mindcuber.py#L478) and change the threshold in the "if" a few lines below from 50 to a smaller number, maybe 5.

I made the changes you suggested and it worked! Many thanks for your help and apologies for the inconvenience.

Glad to hear it, no problem!