Up Distance Sensor のエラー/システム破壊 作成: 2021-04-11
更新: 2021-04-12


    Distance Sensor の使用は,以下に示すエラーを発生する。
    "I2C bus lock up" の可能性も疑われないではないが,症状の重篤化が進行している点を鑑みれば,システム破壊が疑われてくる。

    test.py
    #!/usr/bin/env python import gopigo3 from easygopigo3 import EasyGoPiGo3 from di_sensors.easy_distance_sensor import EasyDistanceSensor from time import sleep import sys gpg = gopigo3.GoPiGo3() egpg = EasyGoPiGo3() # Servo # The case the servo cable is connected to Servo2. servo_n = gpg.SERVO_2 # Distance sensor faces the front when gpg.set_servo(servo_n, 1400) servo_center = 1400 def servo_front(): gpg.set_servo(servo_n, servo_center) # Distance Sensor dist_sensor = EasyDistanceSensor() #Distance from obstacle where the GoPiGo should stop : 30cm distance_to_stop = 30 # Moving # go forward 1sec def go_fwd(): egpg.set_speed(100) egpg.forward() sleep(1) egpg.stop() # Exit def destroy(): gpg.reset_all() egpg.reset_all() sys.exit() #### The Program starts from here ############### print("Press ENTER to start") #Wait for input to start input() #Start moving servo_front() go_fwd() try: while True: #Find the distance of the object in front dist = dist_sensor.read() sleep(1) print("Dist:",dist,'cm') #If the object is closer than distance_to_stop, stop the GoPiGo if dist < distance_to_stop: print("obstacle!") egpg.stop() destroy() sys.exit() else: go_fwd() # except the program gets interrupted by Ctrl+C on the keyboard. except KeyboardInterrupt: egpg.stop() destroy()


    $ vi test.py

    $ chmod +x test.py


    実行すると,途中から "[Errno 5] Input/output error" が現れる。
    このエラーが出ると,dist は 0 になり,よって "obstacle!" となってプログラムは終了する:
    $ ./test.py Press ENTER to start Dist: 178 cm Dist: 167 cm Dist: 161 cm Dist: 155 cm Dist: 148 cm Dist: 140 cm Dist: 133 cm Dist: 124 cm Dist: 117 cm Dist: 110 cm [Errno 5] Input/output error Dist: 0 cm obstacle!
    起動を繰り返すごとに,エラー発生が早くなる:
    $ ./test.py Press ENTER to start Dist: 173 cm [Errno 5] Input/output error Dist: 0 cm obstacle!
    そして,起動でつぎのエラーが返されるようになる:
    $ ./test.py Traceback (most recent call last): File "./obstacle_stop.py", line 8, in <module> dist_sensor = EasyDistanceSensor() File "/usr/local/lib/python3.7/dist-packages/DI_Sensors-1.0.0-py3.7.egg/di_sensors/easy_distance_sensor.py", line 56, in __init__ File "/usr/local/lib/python3.7/dist-packages/DI_Sensors-1.0.0-py3.7.egg/di_sensors/distance_sensor.py", line 28, in __init__ File "/usr/local/lib/python3.7/dist-packages/DI_Sensors-1.0.0-py3.7.egg/di_sensors/VL53L0X.py", line 126, in __init__ File "/usr/local/lib/python3.7/dist-packages/Dexter_AutoDetection_and_I2C_Mutex-0.0.0-py3.7.egg/di_i2c.py", line 220, in write_reg_8 File "/usr/local/lib/python3.7/dist-packages/Dexter_AutoDetection_and_I2C_Mutex-0.0.0-py3.7.egg/di_i2c.py", line 185, in transfer File "/usr/local/lib/python3.7/dist-packages/Dexter_AutoDetection_and_I2C_Mutex-0.0.0-py3.7.egg/di_i2c.py", line 469, in transfer OSError: [Errno 5] Input/output error
    このエラーは,EasyDistanceSensor() の呼び込みで起こっている: $ python >>> from di_sensors.easy_distance_sensor import EasyDistanceSensor >>> >>> dist_sensor = EasyDistanceSensor() Traceback (most recent call last): File "./obstacle_stop.py", line 8, in <module> dist_sensor = EasyDistanceSensor() File "/usr/local/lib/python3.7/dist-packages/DI_Sensors-1.0.0-py3.7.egg/di_sensors/easy_distance_sensor.py", line 56, in __init__ File "/usr/local/lib/python3.7/dist-packages/DI_Sensors-1.0.0-py3.7.egg/di_sensors/distance_sensor.py", line 28, in __init__ File "/usr/local/lib/python3.7/dist-packages/DI_Sensors-1.0.0-py3.7.egg/di_sensors/VL53L0X.py", line 126, in __init__ File "/usr/local/lib/python3.7/dist-packages/Dexter_AutoDetection_and_I2C_Mutex-0.0.0-py3.7.egg/di_i2c.py", line 220, in write_reg_8 File "/usr/local/lib/python3.7/dist-packages/Dexter_AutoDetection_and_I2C_Mutex-0.0.0-py3.7.egg/di_i2c.py", line 185, in transfer File "/usr/local/lib/python3.7/dist-packages/Dexter_AutoDetection_and_I2C_Mutex-0.0.0-py3.7.egg/di_i2c.py", line 469, in transfer OSError: [Errno 5] Input/output error >>> quit()
    起動エラーの症状は,Raspberry Pi をパワーオフ・オンした後も残るようになる。

    起動エラーが発生せずに起動しても,Distance Sensor がおかしい値を返してくるようになる: $ ./test.py Press ENTER to start Dist: 300 cm Dist: 300 cm Dist: 300 cm [Errno 5] Input/output error [Errno 5] Input/output error [Errno 5] Input/output error Dist: 0 cm obstacle!
    症状は,プログラムの起動を重ねるほど,重篤化する。
    Distance Sensor を呼び込むごとにシステム破壊が起こっており,システム破壊が進行するということである。


    註. 「Traceback (most recent call last)」に書かれているファイル/ディレクトリは,この通りの形では存在していない:
    $ ls -la /usr/local/lib/python3/dist-packages -rw-r--r-- 1 root staff 27098 Apr 7 14:35 Dexter_AutoDetection_and_I2C_Mutex-0.0.0-py3.7.egg -rw-r--r-- 1 root staff 117346 Apr 7 13:03 DI_Sensors-1.0.0-py3.7.egg $ ls -la /usr/local/lib/python3.7/dist-packages -rw-r--r-- 1 root staff 117346 Apr 7 13:03 DI_Sensors-1.0.0-py3.7.egg $ find /usr -name easy_distance_sensor.py (無し) $ find /usr -name distance_sensor.py (無し) $ find /usr -name VL53L0X.py (無し) $ find /usr -name di_i2c.py (無し) $ find ~ -name easy_distance_sensor.py /home/pi/Dexter/DI_Sensors/Python/di_sensors/easy_distance_sensor.py $ find ~ -name distance_sensor.py /home/pi/Dexter/DI_Sensors/Python/di_sensors/distance_sensor.py $ find ~ -name VL53L0X.py /home/pi/Dexter/DI_Sensors/Python/di_sensors/VL53L0X.py $ find ~ -name di_i2c.py /home/pi/Dexter/lib/Dexter/RFR_Tools/miscellaneous/di_i2c.py