feat: task-2 中 arrow 也默认采用 ai,同时 img-raw 默认返回 rgb,适配 line 相关需求。
This commit is contained in:
		
							parent
							
								
									84ffa50dc1
								
							
						
					
					
						commit
						1ce8266c62
					
				
							
								
								
									
										40
									
								
								main.py
									
									
									
									
									
								
							
							
						
						
									
										40
									
								
								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
 | 
			
		||||
 | 
			
		||||
@ -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)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -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:
 | 
			
		||||
                # 获取当前相机帧
 | 
			
		||||
 | 
			
		||||
@ -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:
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user