Open AntoniLuongPham opened 4 years ago
Sorry for the delay.
We saw this issue here too: https://github.com/ev3dev/ev3dev/issues/1269
The reality is, having two threads concurrently attempt to access the same attribute is likely to cause problems -- there is no synchronization built into the library. If you could restructure your code so that one is always responsible for interacting with the sensor, that would likely solve it. Remember that you could have one thread retrieve data and save it, and the other process it, if that is helpful.
In addition to what @WasabiFan said...
The EV3 IR sensor does not like swapping modes frequently.
Using the IR beacon for heading/distance is one mode of operation and using the remote control buttons is another mode of operation (actually there are two different modes for remote control buttons).
Programs should only use one mode of operation or wait for several seconds after switching modes for best results.
@WasabiFan @dlech thanks for your diagnoses and suggestions.
@dlech is the Beacon button press detection under a different mode to the press detection of other buttons (top/bottom left/right)?
The beacon button press detection is the same mode as the other button press detection. See http://docs.ev3dev.org/projects/lego-linux-drivers/en/ev3dev-stretch/sensor_data.html#lego-ev3-ir for more info on the modes.
@dlech thank you. In that case, I think the above program actually does not make the IR sensor switch among multiple modes, because the program only checks for various button presses. So probably this issue is of the same nature as https://github.com/ev3dev/ev3dev/issues/1269 -- i.e. resulting from multiple threads accessing the sensor values at the same time.
This error is not exclusive to sensor reads- trying to get the motor encoder values from multiple threads yields the same error.
I've got an error in a parallel Thread that uses the InfraredSensor when running the below program. The error message is not easy to understand, so I'm not sure what the problem is. May I have some help troubleshooting this case? Thank you very much.