(trigger, put_on_hold, simultaneous_launcher, sensor_queue)
| 42 | # [simultaneous_launcher] is a Barrier object used for synchronizing the 2 threads. |
| 43 | # [sensor_queue] is a Queue object used for inter-thread communications |
| 44 | def obstacleFinder(trigger, put_on_hold, simultaneous_launcher, sensor_queue): |
| 45 | leftmost_degrees = 30 |
| 46 | rightmost_degrees = 150 |
| 47 | current_servo_position = leftmost_degrees |
| 48 | middle = 90 |
| 49 | step = 10 |
| 50 | servo_delay = 0.035 |
| 51 | wait_before_it_starts = 0 |
| 52 | distance_trigger = 25 |
| 53 | how_much_to_rotate = 150 |
| 54 | to_the_right = True |
| 55 | |
| 56 | # try to connect to the GoPiGo3 |
| 57 | try: |
| 58 | gopigo3_robot = EasyGoPiGo3() |
| 59 | except IOError: |
| 60 | print("GoPiGo3 robot not detected") |
| 61 | simultaneous_launcher.abort() |
| 62 | |
| 63 | # initialize a Servo object |
| 64 | servo = gopigo3_robot.init_servo("SERVO1") |
| 65 | |
| 66 | # try to connect to the distance sensor |
| 67 | try: |
| 68 | distance_sensor = gopigo3_robot.init_distance_sensor() |
| 69 | except IOError: |
| 70 | print("DistanceSensor couldn't be found") |
| 71 | simultaneous_launcher.abort() |
| 72 | except gopigo3.FirmwareVersionError: |
| 73 | print("GoPiGo3 board needs to be updated") |
| 74 | simultaneous_launcher.abort() |
| 75 | except Exception: |
| 76 | print("Unknown error occurred while instantiating GoPiGo3") |
| 77 | simultaneous_launcher.abort() |
| 78 | |
| 79 | # rotate the servo to the desired start-up position |
| 80 | servo.rotate_servo(leftmost_degrees) |
| 81 | sleep(wait_before_it_starts) |
| 82 | |
| 83 | # check if an error has occurred during all the above processes |
| 84 | try: |
| 85 | simultaneous_launcher.wait() |
| 86 | except threading.BrokenBarrierError: |
| 87 | print("[obstacleFinder] thread couldn't be launched") |
| 88 | |
| 89 | if not simultaneous_launcher.broken: |
| 90 | print("[obstacleFinder] thread fully active") |
| 91 | |
| 92 | |
| 93 | # and if everything is okay |
| 94 | # start collecting, interpreting and sending messages |
| 95 | # to the thread-launched [robotController] function |
| 96 | while not trigger.is_set() and not simultaneous_launcher.broken: |
| 97 | possible_routes = 0 |
| 98 | deadends = 0 |
| 99 | sonar_samples = [] |
| 100 | |
| 101 | # if the thread is put on hold by [robotController] |
nothing calls this directly
no test coverage detected