feat: 根据激光测算中心坐标
This commit is contained in:
@@ -102,31 +102,28 @@ class LaserManager:
|
||||
# ==================== 业务方法 ====================
|
||||
|
||||
def load_laser_point(self):
|
||||
"""从配置文件加载激光中心点,失败则使用默认值
|
||||
如果启用硬编码模式,则直接使用硬编码值
|
||||
"""
|
||||
if config.HARDCODE_LASER_POINT:
|
||||
# 硬编码模式:直接使用硬编码值
|
||||
self._laser_point = config.HARDCODE_LASER_POINT_VALUE
|
||||
self.logger.info(f"[LASER] 使用硬编码激光点: {self._laser_point}")
|
||||
return self._laser_point
|
||||
|
||||
# 正常模式:从配置文件加载
|
||||
"""加载激光中心点:优先使用本地保存的坐标,其次硬编码值,最后默认值"""
|
||||
# 优先:从本地持久化文件加载(由 cmd 201 保存)
|
||||
try:
|
||||
if "laser_config.json" in os.listdir("/root"):
|
||||
with open(config.CONFIG_FILE, "r") as f:
|
||||
data = json.load(f)
|
||||
if isinstance(data, list) and len(data) == 2:
|
||||
self._laser_point = (int(data[0]), int(data[1]))
|
||||
self.logger.debug(f"[INFO] 加载激光点: {self._laser_point}")
|
||||
self.logger.info(f"[LASER] 从本地加载激光点: {self._laser_point}")
|
||||
return self._laser_point
|
||||
else:
|
||||
raise ValueError
|
||||
else:
|
||||
self._laser_point = config.DEFAULT_LASER_POINT
|
||||
except:
|
||||
self._laser_point = config.DEFAULT_LASER_POINT
|
||||
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 其次:硬编码值
|
||||
if config.HARDCODE_LASER_POINT:
|
||||
self._laser_point = config.HARDCODE_LASER_POINT_VALUE
|
||||
self.logger.info(f"[LASER] 使用硬编码激光点: {self._laser_point}")
|
||||
return self._laser_point
|
||||
|
||||
# 最后:默认值
|
||||
self._laser_point = config.DEFAULT_LASER_POINT
|
||||
self.logger.info(f"[LASER] 使用默认激光点: {self._laser_point}")
|
||||
return self._laser_point
|
||||
|
||||
def save_laser_point(self, point):
|
||||
@@ -1264,6 +1261,28 @@ class LaserManager:
|
||||
except Exception as e:
|
||||
self.logger.error(f"[LASER] 关闭激光失败: {e}")
|
||||
|
||||
def set_hardcoded_laser_point(self, raw_x, raw_y):
|
||||
"""
|
||||
设置服务下发的硬编码激光点坐标,并保存到本地持久化文件。
|
||||
下次启动时 load_laser_point() 会优先使用此保存的值。
|
||||
|
||||
Args:
|
||||
raw_x: 服务下发的 x 坐标
|
||||
raw_y: 服务下发的 y 坐标
|
||||
|
||||
Returns:
|
||||
(int_x, int_y) 元组
|
||||
"""
|
||||
ix = int(raw_x)
|
||||
iy = int(raw_y)
|
||||
self._laser_point = (ix, iy)
|
||||
try:
|
||||
with open(config.CONFIG_FILE, "w") as f:
|
||||
json.dump([ix, iy], f)
|
||||
self.logger.info(f"[LASER] 设置并持久化激光点: ({ix}, {iy})")
|
||||
except Exception as e:
|
||||
self.logger.error(f"[LASER] 持久化激光点失败: {e}")
|
||||
return ix, iy
|
||||
|
||||
# 创建全局单例实例
|
||||
laser_manager = LaserManager()
|
||||
|
||||
Reference in New Issue
Block a user