5. Ab.stop()
#covert the measure from cm to inch
def measure_distance_inch():
GPIO.output(TRIG_PIN, True)
time.sleep(0.00001)
GPIO.output(TRIG_PIN, False)
start_time = time.time()
while GPIO.input(ECHO_PIN) == 0:
if (time.time() - start_time) > 0.1:
return -1
echo_start_time = time.time()
while GPIO.input(ECHO_PIN) == 1:
if (time.time() - start_time) > 0.1:
return -1
echo_end_time = time.time()
echo_duration = echo_end_time - echo_start_time
distance_cm = (echo_duration * SPEED_OF_SOUND) / 2
distance_inch = distance_cm * INCHES_PER_CM
return distance_inch
try:
while True:
distance = measure_distance_inch()
print(f"Distance: {distance} in") #Print the distance of the Ultrasonic Sensor
6. time.sleep(1)
while True:
DR_status = GPIO.input(IRR)
DL_status = GPIO.input(IRL)
if((DL_status == 1) and (DR_status == 1)) and (distance>4):
Ab.forward()
print("forward")
elif((DL_status == 0) and (DR_status == 1)) and (distance<3):
Ab.right()
print("right")
elif((DL_status == 1) and (DR_status == 0)) and (distance<3):
Ab.left()
print("left")
else:
Ab.stop()
print("stop")
except KeyboardInterrupt:
GPIO.cleanup();
Design a software system using python for AlphaBot mobile robot( using raspberry pi) to follow
a pre-planned path [( 0 , 0 ) , ( 20 , 0 ) , ( 20 , 20 ) , ( 0 , 20 ) and get from starting point to the
final destination while navigating through obstacles using two infrared sensors, camara(to detect
moving obstacles only), and ultrasonic sensor.( the below code is to detect the obstacles using 2
infrared sensors and get the the distance value|using ultrasonic sensor. Please finish this code for
the missing part, which are detecting moving obstacles using a camera sensor and keeping the
mobile robot to stay and follow the pre-planning path after avoiding any type of obstacle). Thank
you GPI0. setup(self.IRL, GPI0.IN, GPI0.PUD_UP)