diff --git a/Process/pipe4/temp/lane_following.py b/Process/pipe4/temp/lane_following.py index 345135f..1059fd6 100644 --- a/Process/pipe4/temp/lane_following.py +++ b/Process/pipe4/temp/lane_following.py @@ -1457,14 +1457,16 @@ def follow_lane(out_image, filtered_results, original, previous_left_id=None, pr out_image, vertical_line, right_diagonal, left_diagonal = get_angle_lines(out_image) out_image, in_lane, left_intersections, middle_intersections, right_intersections = find_intersections_and_draw(out_image, vertical_line, right_diagonal, left_diagonal, mask) + image_copy = original.copy() + if in_lane: print("The vehicle is in the lane.") steer = analise_results(in_lane, left_intersections, middle_intersections, right_intersections) - cv2.putText(out_image, f'Steer: {steer:.2f}', (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2) + cv2.putText(image_copy, f'Steer: {steer:.2f}', (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2) - return out_image, mask, steer, previous_left_id, previous_right_id + return image_copy, mask, steer, previous_left_id, previous_right_id else: steer = 0 print("Take manual control of the vehicle.") diff --git a/Process/pipe4/temp/outputUnit.py b/Process/pipe4/temp/outputUnit.py index 1e7bf5b..ab2a322 100644 --- a/Process/pipe4/temp/outputUnit.py +++ b/Process/pipe4/temp/outputUnit.py @@ -66,12 +66,12 @@ def process(self, data_token): cv2.rectangle(annotated_frame, (x_min, y_min), (x_max, y_max), (0, 255, 0), 1) if min_distances and min_distances[i] is not None: - if min_distances[i] is not None: - text = f"{bbox[-1]} Dist: {min_distances[i]:.2f}m" - cv2.putText(annotated_frame, text, (x_min, y_min - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2) - else: - text = f"{bbox[-1]}" - cv2.putText(annotated_frame, text, (x_min, y_min - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2) + if min_distances[i] is not None: + text = f"{bbox[-1]} Dist: {min_distances[i]:.2f}m" + cv2.putText(annotated_frame, text, (x_min, y_min - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2) + else: + text = f"{bbox[-1]}" + cv2.putText(annotated_frame, text, (x_min, y_min - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2) if (self.la or self.all) and data_token.get_flag('has_lane_data'): output = data_token.get_processing_result('laneUnit') diff --git a/Process/pipe4/temp/unit3.py b/Process/pipe4/temp/unit3.py index f963af9..a9a67ff 100644 --- a/Process/pipe4/temp/unit3.py +++ b/Process/pipe4/temp/unit3.py @@ -39,21 +39,35 @@ object_avoidance = False avoid = False +reverse_toggle = False +reverse_gear = False + def get_keyboard_control(vehicle): # Toggle lane following with Q global follow_lane global object_avoidance + global reverse_toggle + global reverse_gear + control = carla.VehicleControl() + + keys = pygame.key.get_pressed() control = carla.VehicleControl() if not follow_lane: - keys = pygame.key.get_pressed() - control = carla.VehicleControl() control.throttle = 1.0 if keys[pygame.K_w] else 0.0 control.brake = 1.0 if keys[pygame.K_s] else 0.0 control.steer = -1.0 if keys[pygame.K_a] else 1.0 if keys[pygame.K_d] else 0.0 control.hand_brake = keys[pygame.K_SPACE] - control.reverse = not control.reverse if keys[pygame.K_r] else control.reverse + + if keys[pygame.K_r] and not reverse_toggle: + reverse_gear = not reverse_gear + reverse_toggle = True + + if not keys[pygame.K_r]: + reverse_toggle = False + + control.reverse = reverse_gear else: control.throttle = 0.3 @@ -523,7 +537,7 @@ def main(pipe): image_surface = convert_array_to_surface(processed_image_array) display.blit(image_surface, (0, 0)) - if pipe.dataToken.get_flag("hasObserverData") and object_avoidance: + if pipe.dataToken.get_flag("hasObeserverData") and object_avoidance: # Render the text "Object avoidance on" text_surface = font.render("Object avoidance on", True, (0, 255, 0)) # Green text display.blit(text_surface, (10, 10)) @@ -537,7 +551,7 @@ def main(pipe): # print(object_avoidance) # print( pipe.dataToken.get_flag("hasObserverData")) - if pipe.dataToken.get_flag("hasObserverData") and object_avoidance: + if pipe.dataToken.get_flag("hasObeserverData") and object_avoidance: print("avoiding") observerToken = pipe.dataToken.get_processing_result('observerUnit') breaking = observerToken['breaking']