Up 障害物の手前で止まる : ultrasonic sensor を使う 作成: 2021-03-19
更新: 2021-04-03


    basic_obstacle_avoid.py
    from gopigo import * import time #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 fwd() while True: #Find the distance of the object in front #The pin for the ultrasonic sensor should be pin 15 (Analog Port A1) dist=us_dist(15) 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 stop() break time.sleep(.1)