invole c++
This commit is contained in:
@@ -136,9 +136,8 @@ class LaserManager:
|
||||
written = hardware_manager.distance_serial.write(config.LASER_ON_CMD)
|
||||
self.logger.info(f"[LASER] 写入字节数: {written}")
|
||||
|
||||
# return None
|
||||
time.sleep_ms(60)
|
||||
|
||||
# TODO: 暂时去掉这个等待
|
||||
# 读取回包
|
||||
resp = hardware_manager.distance_serial.read(len=20,timeout=10)
|
||||
if resp:
|
||||
@@ -169,7 +168,8 @@ class LaserManager:
|
||||
# 发送命令
|
||||
written = hardware_manager.distance_serial.write(config.LASER_OFF_CMD)
|
||||
self.logger.info(f"[LASER] 写入字节数: {written}")
|
||||
|
||||
|
||||
time.sleep_ms(60)
|
||||
|
||||
# 读取回包
|
||||
resp = hardware_manager.distance_serial.read(20)
|
||||
@@ -189,23 +189,6 @@ class LaserManager:
|
||||
self.turn_off_laser()
|
||||
except Exception as e:
|
||||
self.logger.error(f"闪激光失败: {e}")
|
||||
|
||||
# def find_red_laser(self, frame, threshold=150):
|
||||
# """在图像中查找最亮的红色激光点(基于 RGB 阈值)"""
|
||||
# w, h = frame.width(), frame.height()
|
||||
# img_bytes = frame.to_bytes()
|
||||
# max_sum = 0
|
||||
# best_pos = None
|
||||
# for y in range(0, h, 2):
|
||||
# for x in range(0, w, 2):
|
||||
# idx = (y * w + x) * 3
|
||||
# r, g, b = img_bytes[idx], img_bytes[idx+1], img_bytes[idx+2]
|
||||
# if r > threshold and r > g * 2 and r > b * 2:
|
||||
# rgb_sum = r + g + b
|
||||
# if rgb_sum > max_sum:
|
||||
# max_sum = rgb_sum
|
||||
# best_pos = (x, y)
|
||||
# return best_pos
|
||||
|
||||
# def find_red_laser(self, frame, threshold=150, search_radius=50):
|
||||
# """
|
||||
@@ -1150,33 +1133,5 @@ class LaserManager:
|
||||
# 创建全局单例实例
|
||||
laser_manager = LaserManager()
|
||||
|
||||
# ==================== 向后兼容的函数接口 ====================
|
||||
|
||||
def load_laser_point():
|
||||
"""加载激光点(向后兼容接口)"""
|
||||
return laser_manager.load_laser_point()
|
||||
|
||||
def save_laser_point(point):
|
||||
"""保存激光点(向后兼容接口)"""
|
||||
return laser_manager.save_laser_point(point)
|
||||
|
||||
def turn_on_laser():
|
||||
"""开启激光(向后兼容接口)"""
|
||||
return laser_manager.turn_on_laser()
|
||||
|
||||
def turn_off_laser():
|
||||
"""关闭激光(向后兼容接口)"""
|
||||
return laser_manager.turn_off_laser()
|
||||
|
||||
def flash_laser(duration_ms=1000):
|
||||
"""闪激光(向后兼容接口)"""
|
||||
return laser_manager.flash_laser(duration_ms)
|
||||
|
||||
def find_red_laser(frame, threshold=150):
|
||||
"""查找红色激光点(向后兼容接口)"""
|
||||
return laser_manager.find_red_laser(frame, threshold)
|
||||
|
||||
def calibrate_laser_position():
|
||||
"""校准激光位置(向后兼容接口)"""
|
||||
return laser_manager.calibrate_laser_position()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user