ev3dev / ev3dev-lang-python-demo

Python Demo Programs
MIT License
60 stars 28 forks source link

Problem with MINDCUB3R code #47

Closed guinasc2 closed 4 years ago

guinasc2 commented 4 years ago

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?

WasabiFan commented 4 years ago

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

guinasc2 commented 4 years ago

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

WasabiFan commented 4 years ago

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?

guinasc2 commented 4 years ago

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

WasabiFan commented 4 years ago

No problem; let us know when you can.

guinasc2 commented 4 years ago

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?

WasabiFan commented 4 years ago

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
guinasc2 commented 4 years ago

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

ddemidov commented 4 years ago

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

guinasc2 commented 4 years ago

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.

WasabiFan commented 4 years ago

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.

guinasc2 commented 4 years ago

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

WasabiFan commented 4 years ago

Glad to hear it, no problem!