つぎは,GoPiGo を障害物の前で停止させるプログラム :
obstacle_stop.py
#!/usr/bin/env python
from easygopigo3 import EasyGoPiGo3
from di_sensors.easy_distance_sensor import EasyDistanceSensor
from time import sleep
gpg = EasyGoPiGo3()
my_sensor = EasyDistanceSensor()
#Distance from obstacle where the GoPiGo should stop : 20cm
distance_to_stop = 20
print "Press ENTER to start"
#Wait for input to start
raw_input()
#Start moving
gpg.forward()
while True:
#Find the distance of the object in front
dist = my_sensor.read()
#print("distance from object: {} cm".format(dist))
print "Dist:",dist,'cm'
#If the object is closer than the "distance_to_stop" distance, stop the GoPiGo
if dist < distance_to_stop:
print "Stopping"
#Stop the GoPiGo
gpg.stop()
break
sleep(.1)
|
しかしこれの実行は,繰り返されるうちに,つぎのエラーが現れてくる:
[Errno 5] Input/output error
この症状は,obstacle_stop.py の起動を重ねるごとに,ひどくなる。
そして,起動もしなくなる:
$ ./obstacle_stop.py
[Traceback (most recent call last):
File "./obstacle_stop.py", line 8, in
my_sensor = EasyDistanceSensor()
File "/usr/local/lib/python2.7/dist-packages/DI_Sensors-1.0.0-py2.7.egg/di_sensors/easy_distance_sensor.py", line 56, in __init__
File "/usr/local/lib/python2.7/dist-packages/DI_Sensors-1.0.0-py2.7.egg/di_sensors/distance_sensor.py", line 28, in __init__
File "/usr/local/lib/python2.7/dist-packages/DI_Sensors-1.0.0-py2.7.egg/di_sensors/VL53L0X.py", line 126, in __init__
File "/usr/local/lib/python2.7/dist-packages/Dexter_AutoDetection_and_I2C_Mutex-0.0.0-py2.7.egg/di_i2c.py", line 220, in write_reg_8
File "/usr/local/lib/python2.7/dist-packages/Dexter_AutoDetection_and_I2C_Mutex-0.0.0-py2.7.egg/di_i2c.py", line 185, in transfer
File "/usr/local/lib/python2.7/dist-packages/Dexter_AutoDetection_and_I2C_Mutex-0.0.0-py2.7.egg/di_i2c.py", line 469, in transfer
IOError: [Errno 5] Input/output error
python のインタラクティブシェルでテストしてみると,上のエラーは "EasyDistanceSensor()" の実行で発生する:
>>> my_sensor = EasyDistanceSensor()
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python2.7/dist-packages/DI_Sensors-1.0.0-py2.7.egg/di_sensors/easy_distance_sensor.py", line 56, in __init__
File "/usr/local/lib/python2.7/dist-packages/DI_Sensors-1.0.0-py2.7.egg/di_sensors/distance_sensor.py", line 28, in __init__
File "/usr/local/lib/python2.7/dist-packages/DI_Sensors-1.0.0-py2.7.egg/di_sensors/VL53L0X.py", line 126, in __init__
File "/usr/local/lib/python2.7/dist-packages/Dexter_AutoDetection_and_I2C_Mutex-0.0.0-py2.7.egg/di_i2c.py", line 220, in write_reg_8
File "/usr/local/lib/python2.7/dist-packages/Dexter_AutoDetection_and_I2C_Mutex-0.0.0-py2.7.egg/di_i2c.py", line 185, in transfer
File "/usr/local/lib/python2.7/dist-packages/Dexter_AutoDetection_and_I2C_Mutex-0.0.0-py2.7.egg/di_i2c.py", line 469, in transfer
IOError: [Errno 5] Input/output error
エラーが出るタイミングは,一定しない。
>>> my_sensor = EasyDistanceSensor()
が通ることもある。
しかし
>>> read_distance = my_sensor.read()
で,:
>>> read_distance = my_sensor.read()
'int' object is not iterable
[Errno 5] Input/output error
となったり,
'>>> read_distance = my_sensor.read()
'[Errno 5] Input/output error
'[Errno 5] Input/output error
'[Errno 5] Input/output error
となったりする。
|