ev3dev / ev3dev-lang-python

Pure python bindings for ev3dev
MIT License
422 stars 146 forks source link

hitechnic IRSeekerV2 #743

Closed bergowitch closed 4 years ago

bergowitch commented 4 years ago

Hello, I try to get the hitechnic IRSeekerV2 on the EV3 with ev3dev in python to work, but I don´t know how... I don´t find any hint. Thanks Stefan

WasabiFan commented 4 years ago

Unfortunately, we don't have a pre-made class which wraps up this sensor's functionality in a nice package. That being said, it is still reasonably easy to use. You will need to use our Sensor class and use its value method to read sensor values.

The documentation for the sensor driver itself is here, for your reference: http://docs.ev3dev.org/projects/lego-linux-drivers/en/ev3dev-stretch/sensor_data.html#hitechnic-nxt-irseeker-v2

And the documentation for our own Sensor class is here: https://ev3dev-lang.readthedocs.io/projects/python-ev3dev/en/ev3dev-stretch/sensors.html#base-sensor

To use the sensor, it should look like this:

from ev3dev2.sensor import Sensor

seeker = Sensor(driver_name='ht-nxt-ir-seek-v2')
seeker.mode = 'DC'
# direction is 0 for no signal, or 1-9 for left-right direction
direction = seeker.value(0)

You can see that I create a Sensor object and use the driver name from the first documentation page I linked to. I then set the mode to DC, which the documentation says gives us direction. If you also want the signal strength measurements, you will need to change the mode to DC-ALL. If the above doesn't work, you might need to use the AC mode instead: I don't know which type of source is being used.

bergowitch commented 4 years ago

Thank you very much! I got the hitechnic compass sensor working the same way! I'm very glad!