From 1ce8266c6258c38b14bdb86c428aa6d4dd35ce94 Mon Sep 17 00:00:00 2001 From: havocrao Date: Wed, 20 Aug 2025 00:48:33 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20task-2=20=E4=B8=AD=20arrow=20=E4=B9=9F?= =?UTF-8?q?=E9=BB=98=E8=AE=A4=E9=87=87=E7=94=A8=20ai=EF=BC=8C=E5=90=8C?= =?UTF-8?q?=E6=97=B6=20img-raw=20=E9=BB=98=E8=AE=A4=E8=BF=94=E5=9B=9E=20rg?= =?UTF-8?q?b=EF=BC=8C=E9=80=82=E9=85=8D=20line=20=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E9=9C=80=E6=B1=82=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 40 ++++++++++++++++++---------------------- task_2/task_2.py | 10 ++++------ task_4/task_4.py | 2 +- utils/image_raw.py | 12 ++++++------ 4 files changed, 29 insertions(+), 35 deletions(-) diff --git a/main.py b/main.py index c480aed..cf58238 100755 --- a/main.py +++ b/main.py @@ -23,24 +23,19 @@ from utils.base_msg import BaseMsg from utils.speech_demo import speak # from utils.marker_client import MarkerRunner -from task_1.task_1 import run_task_1 -from task_2_5.task_2_5 import run_task_2_5 -from task_3.task_3 import run_task_3, run_task_3_back, pass_up_down from task_1.task_1 import run_task_1, run_task_1_back from task_2.task_2 import run_task_2, run_task_2_back, run_task_2_demo from task_2_5.task_2_5 import run_task_2_5, run_task_2_5_back +from task_3.task_3 import run_task_3, run_task_3_back, pass_up_down from task_4.task_4 import run_task_4, run_task_4_back, go_straight_with_enhanced_calibration -from task_4.pass_bar import pass_bar -from task_test.task_left_line import run_task_test from task_5.task_5 import run_task_5 from base_move.turn_degree import turn_degree, turn_degree_v2 -from base_move.center_on_dual_tracks import center_on_dual_tracks from base_move.go_to_xy import go_to_x_v2, go_to_y_v2 from utils.log_helper import info pass_marker = True -TIME_SLEEP = 3000 +TIME_SLEEP = 3000 # TODO 比赛时改成 5000 def main(): rclpy.init() # 新增:在主程序中统一初始化 ROS 2 上下文 @@ -50,27 +45,28 @@ def main(): msg = robot_control_cmd_lcmt() print('2') try: - info("Recovery stand", "info") - # Ctrl.base_msg.stand_up() - print('yuyin') - cv_image = Ctrl.image_processor.get_current_image('ai') - print('111') - cv2.imwrite(f"saved_images/firstai.jpg", cv_image) + # print('yuyin') + # cv_image = Ctrl.image_processor.get_current_image('ai') + # print('111') + # cv2.imwrite(f"saved_images/firstai.jpg", cv_image) - print('try out') + # print('try out') # speak('nihao') - # Ctrl.base_msg.stop() # BUG 垃圾指令 for eat - # run_task_1(Ctrl, msg, time_sleep=TIME_SLEEP) + info("Recovery stand", "info") + Ctrl.base_msg.stand_up() + Ctrl.base_msg.stop() # BUG 垃圾指令 for eat # INFO 但是正式比赛或许也有用 + + # TAG task - 1 + run_task_1(Ctrl, msg, time_sleep=TIME_SLEEP) + # go_straight_with_enhanced_calibration(Ctrl, msg, distance = 5, speed=0.5, observe=False, mode=11, gait_id=3, step_height=[0.21, 0.21]) - # run_task_2(Ctrl, msg) # pass_up_down(Ctrl, msg) # pass_bar(Ctrl, msg) - # Ctrl.base_msg.stand_up() + # run_task_2(Ctrl, msg) - # time.sleep(100) # TEST, - - # run_task_1(Ctrl, msg, time_sleep=TIME_SLEEP) - # arrow_direction = run_task_2_demo(Ctrl, msg, xy_flag=False) + + # TAG task - 2 + arrow_direction = run_task_2_demo(Ctrl, msg, xy_flag=False) # print(arrow_direction) # arrow_direction = run_task_2(Ctrl, msg, xy_flag=False) # arrow_direction = 'right' # TEST diff --git a/task_2/task_2.py b/task_2/task_2.py index 80bacc1..8e1625b 100755 --- a/task_2/task_2.py +++ b/task_2/task_2.py @@ -95,7 +95,7 @@ class AsyncArrowDetector: # 按指定间隔检测 if current_time - last_detection_time >= interval: - img = self.image_processor.get_current_image() + img = self.image_processor.get_current_image('ai') if img is not None: try: # 保存最后处理的图像 @@ -207,7 +207,7 @@ def run_task_2(ctrl, msg, xy_flag=False): arrow_detector.start_detection(interval=0.3) arrow_detection_started = True - cv_image = ctrl.image_processor.get_current_image() + cv_image = ctrl.image_processor.get_current_image('ai') print('111') cv2.imwrite(f"saved_images/first{i}.jpg", cv_image) @@ -258,7 +258,7 @@ def run_task_2(ctrl, msg, xy_flag=False): info("异步检测未得到确定结果,尝试在当前图像上直接检测", "箭头检测") # 获取当前图像 - image = ctrl.image_processor.get_current_image() + image = ctrl.image_processor.get_current_image('ai') if image is not None: # 直接在当前图像上检测 arrow_direction = detect_arrow_direction(image, observe=False) @@ -425,8 +425,6 @@ def test_crawl_transition_only(ctrl, msg): return False - - def run_task_2_demo(ctrl, msg, xy_flag=False): # 微调 xy 和角度 go_to_xy_v2(ctrl, msg, 0.9, 0.25, speed=0.5, observe=True) @@ -506,7 +504,7 @@ def run_task_2_demo(ctrl, msg, xy_flag=False): info("异步检测未得到确定结果,尝试在当前图像上直接检测", "箭头检测") # 获取当前图像 - image = ctrl.image_processor.get_current_image() + image = ctrl.image_processor.get_current_image('ai') print(image) diff --git a/task_4/task_4.py b/task_4/task_4.py index 8b4aed7..7b1299b 100755 --- a/task_4/task_4.py +++ b/task_4/task_4.py @@ -366,7 +366,7 @@ def go_straight_with_enhanced_calibration(ctrl, msg, distance, speed=0.5, observ # 更新检查时间 last_check_time = current_time - # 定期进行视觉检查和修正 + # 定期进行视觉检查和修正 # TODO 这个函数如果用于 上下坡的话,感觉或许就不需要了,如果能保证 task 2-5 的效果。 if hasattr(ctrl, 'image_processor') and current_time - last_vision_check >= vision_check_interval: try: # 获取当前相机帧 diff --git a/utils/image_raw.py b/utils/image_raw.py index a75fefd..2e2ba1a 100755 --- a/utils/image_raw.py +++ b/utils/image_raw.py @@ -245,17 +245,17 @@ class ImageProcessor: self.image_subscriber.stop_camera() self.image_subscriber.destroy_node() - def get_current_image(self, text): + def get_current_image(self, text = 'rgb'): + # INFO 默认返回 rgb 图像 if text=='ai': return self.image_subscriber.cv_image_ai - if text=='left': + elif text=='left': return self.image_subscriber.cv_image_left - if text=='right': + elif text=='right': return self.image_subscriber.cv_image_right - if text=='rgb': + else: # text=='rgb': return self.image_subscriber.cv_image_rgb - - + def decode_all_qrcodes(self, img=None): """使用pyzbar解码QR码""" if img is None: