()
| 49 | print("Debug: " + str(string)) |
| 50 | |
| 51 | def Main(): |
| 52 | |
| 53 | print(" _____ _____ _ _____ ____ ") |
| 54 | print(" / ____| | __ (_)/ ____| |___ \ ") |
| 55 | print(" | | __ ___ | |__) || | __ ___ __) |") |
| 56 | print(" | | |_ |/ _ \| ___/ | | |_ |/ _ \ |__ < ") |
| 57 | print(" | |__| | (_) | | | | |__| | (_) | ___) |") |
| 58 | print(" \_____|\___/|_| |_|\_____|\___/ |____/ ") |
| 59 | print(" ") |
| 60 | |
| 61 | # initializing an EasyGoPiGo3 object and a DistanceSensor object |
| 62 | # used for interfacing with the GoPiGo3 and with the distance sensor |
| 63 | try: |
| 64 | gopigo3 = EasyGoPiGo3() |
| 65 | distance_sensor = gopigo3.init_distance_sensor() |
| 66 | |
| 67 | except IOError as msg: |
| 68 | print("GoPiGo3 robot not detected or DistanceSensor not installed.") |
| 69 | debug(msg) |
| 70 | sys.exit(1) |
| 71 | |
| 72 | except FirmwareVersionError as msg: |
| 73 | print("GoPiGo3 firmware needs to updated.") |
| 74 | debug(msg) |
| 75 | sys.exit(1) |
| 76 | |
| 77 | except Exception as msg: |
| 78 | print("Error occurred. Set debug = True to see more.") |
| 79 | debug(msg) |
| 80 | sys.exit(1) |
| 81 | |
| 82 | if DEBUG is True: |
| 83 | distance_sensor.enableDebug() |
| 84 | |
| 85 | # variable that says whether the GoPiGo3 moves or is stationary |
| 86 | # used during the runtime |
| 87 | gopigo3_stationary = True |
| 88 | |
| 89 | global robot_operating |
| 90 | |
| 91 | # while the script is running |
| 92 | while robot_operating: |
| 93 | # read the distance from the distance sensor |
| 94 | current_distance = distance_sensor.read_mm() |
| 95 | determined_speed = 0 |
| 96 | |
| 97 | # if the sensor can't be detected |
| 98 | if current_distance == ERROR: |
| 99 | print("Cannot reach DistanceSensor. Stopping the process.") |
| 100 | robot_operating = False |
| 101 | |
| 102 | # if the robot is closer to the target |
| 103 | elif current_distance < MIN_DISTANCE: |
| 104 | # then stop the GoPiGo3 |
| 105 | gopigo3_stationary = True |
| 106 | gopigo3.stop() |
| 107 | |
| 108 | # if the robot is far away from the target |
no test coverage detected