pybricks / support

Pybricks support and general discussion
MIT License
107 stars 6 forks source link

[Question]: Delay between different Infrared Sensor modes #62

Closed TheVinhLuong102 closed 4 years ago

TheVinhLuong102 commented 4 years ago

Hi @laurensvalk @dlech I have programmed the Ev3rstorm with both PyBricks2 and EV3Dev2 and would like to report significantly slower execution by PyBricks2 than by EV3Dev2. My 2 programs are attached for your review.

Ev3rstorm-PyBricks2-vs-EV3Dev2.zip

The 2 programs are trying to perform the same capabilities:

Each of these activities is conditioned on certain "if"s, and the activities are arranged sequentially in a main "while True" loop. No multiprocessing/threading is used.

When I execute the EV3Dev2 program, the performance is pretty smooth: the Ev3rstorm is very responsive to sensory stimuli and actuates the various tricks satisfactorily.

However, when I run the PyBricks2 program, the Ev3rstorm's responses are very laggy/slow, suggesting that each loop in the "while True" takes a significantly longer time to execute.

Could you let me know how I can go about troubleshooting this? Thank you @laurensvalk @dlech .

laurensvalk commented 4 years ago

The infrared sensor takes about 1 second to switch between modes. It is recommended that you use only 1 mode in your program or loop.

During that 1 second switch, the sensor gives unreliable data. This is a known hardware issue that cannot be fixed in software.

For Pybricks, we made the decision to wait for reliable data to come in. This is the same as with the official LEGO EV3-G Labview implementation.

It sounds like ev3dev2 does not do that.

If you want to get the raw sensor data without fixes like these, you can use the iodevices.LUMPDevice class. Then it will probably be the same as ev3dev2.

I hope you don't mind if I change the title of this topic. That will make it easier for other people with the same InfaredSensor latency problem to find this issue. I'm also going to move it to the support issue tracker - this belongs there.

TheVinhLuong102 commented 4 years ago

Thanks @laurensvalk. I was aware of https://github.com/ev3dev/ev3dev/issues/1401 but didn't make the mental connection :) I can confirm now that removing one of the IR-related activities made the delay go away in my PyBricks Ev3rstorm.

Are you considering adding your recommendations above to the PyBricks documentation? These issues and the corresponding technical decisions are not obvious to most users, and others may encounter difficulties from time to time if they are unaware.

laurensvalk commented 4 years ago

Yes, so let's keep this issue open until we've added that, thanks.

laurensvalk commented 4 years ago

Documented in https://github.com/pybricks/pybricks-api.

Thanks for reporting!