2024-05-21 23:53:47 +08:00
|
|
|
|
from enum import Enum
|
|
|
|
|
|
from loguru import logger
|
2024-05-22 18:50:21 +08:00
|
|
|
|
from utils import label_filter
|
|
|
|
|
|
from utils import tlabel
|
2024-05-23 14:33:20 +08:00
|
|
|
|
import toml
|
2024-05-29 21:23:05 +08:00
|
|
|
|
import zmq
|
2024-05-21 23:53:47 +08:00
|
|
|
|
import time
|
|
|
|
|
|
|
2024-05-29 21:23:05 +08:00
|
|
|
|
context = zmq.Context()
|
|
|
|
|
|
socket = context.socket(zmq.REQ)
|
|
|
|
|
|
socket.connect("tcp://localhost:6667")
|
|
|
|
|
|
logger.info("socket init")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
by_cmd = None
|
|
|
|
|
|
filter = None
|
|
|
|
|
|
def import_obj(_by_cmd):
|
|
|
|
|
|
global by_cmd
|
|
|
|
|
|
global filter
|
|
|
|
|
|
by_cmd = _by_cmd
|
|
|
|
|
|
filter = label_filter(socket)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-05-21 23:53:47 +08:00
|
|
|
|
# 任务类
|
|
|
|
|
|
class task:
|
2024-05-29 21:23:05 +08:00
|
|
|
|
def __init__(self, task_template, find_counts=10, enable=True):
|
2024-05-21 23:53:47 +08:00
|
|
|
|
self.enable = enable
|
2024-05-29 21:23:05 +08:00
|
|
|
|
self.task_t = task_template()
|
|
|
|
|
|
|
|
|
|
|
|
self.counts = 0
|
|
|
|
|
|
self.find_counts = find_counts
|
|
|
|
|
|
def init(self):
|
|
|
|
|
|
self.task_t.init()
|
2024-05-22 12:37:15 +08:00
|
|
|
|
def find(self):
|
|
|
|
|
|
# 检查该任执行标志
|
2024-05-29 21:23:05 +08:00
|
|
|
|
while True:
|
|
|
|
|
|
# if self.func_find():
|
|
|
|
|
|
if self.task_t.find():
|
|
|
|
|
|
self.counts += 1
|
|
|
|
|
|
if self.counts >= self.find_counts:
|
|
|
|
|
|
break
|
|
|
|
|
|
# while self.func_find() is False:
|
|
|
|
|
|
# pass
|
|
|
|
|
|
|
2024-05-22 12:37:15 +08:00
|
|
|
|
def exec(self):
|
2024-05-21 23:53:47 +08:00
|
|
|
|
# 根据标志位确定是否执行该任务
|
|
|
|
|
|
if self.enable is True:
|
2024-05-22 12:37:15 +08:00
|
|
|
|
logger.debug(f"[Task ]# Executing task")
|
2024-05-29 21:23:05 +08:00
|
|
|
|
# self.func_exec()
|
|
|
|
|
|
self.task_t.exec()
|
2024-05-22 12:37:15 +08:00
|
|
|
|
logger.debug(f"[Task ]# Task completed")
|
2024-05-21 23:53:47 +08:00
|
|
|
|
else:
|
2024-05-22 12:37:15 +08:00
|
|
|
|
logger.warning(f"[Task ]# Skip task")
|
2024-05-21 23:53:47 +08:00
|
|
|
|
|
|
|
|
|
|
# 任务队列状态类
|
|
|
|
|
|
class task_queuem_status(Enum):
|
|
|
|
|
|
IDEL = 0
|
|
|
|
|
|
SEARCHING = 1
|
|
|
|
|
|
EXECUTING = 2
|
|
|
|
|
|
|
2024-05-29 21:23:05 +08:00
|
|
|
|
# 任务队列类 非 EXECUTEING 时均执行 huigui,注意互斥操作
|
2024-05-21 23:53:47 +08:00
|
|
|
|
class task_queuem(task):
|
|
|
|
|
|
# task_now = task(None, False)
|
|
|
|
|
|
def __init__(self, queue):
|
|
|
|
|
|
super(task_queuem, self)
|
|
|
|
|
|
self.queue = queue
|
|
|
|
|
|
self.status = task_queuem_status.IDEL
|
|
|
|
|
|
self.busy = True
|
2024-05-22 12:37:15 +08:00
|
|
|
|
logger.info(f"[TaskM]# Task num {self.queue.qsize()}")
|
2024-05-21 23:53:47 +08:00
|
|
|
|
def exec(self):
|
|
|
|
|
|
# 如果空闲状态则将下一个队列任务取出
|
|
|
|
|
|
if self.status is task_queuem_status.IDEL:
|
|
|
|
|
|
if self.queue.qsize() == 0:
|
|
|
|
|
|
self.busy = False
|
2024-05-22 12:37:15 +08:00
|
|
|
|
logger.info(f"[TaskM]# Task queue empty, exit")
|
2024-05-21 23:53:47 +08:00
|
|
|
|
return False
|
|
|
|
|
|
self.task_now = self.queue.get()
|
|
|
|
|
|
|
|
|
|
|
|
# 如果当前任务没有使能,则直接转入执行状态,由任务执行函数打印未执行信息
|
|
|
|
|
|
if self.task_now.enable is True:
|
|
|
|
|
|
self.status = task_queuem_status.SEARCHING
|
2024-05-29 21:23:05 +08:00
|
|
|
|
# 如果使能该任务则执行该任务的初始化动作
|
|
|
|
|
|
self.task_now.init()
|
2024-05-21 23:53:47 +08:00
|
|
|
|
else:
|
|
|
|
|
|
self.status = task_queuem_status.EXECUTING
|
2024-05-22 12:37:15 +08:00
|
|
|
|
logger.info(f"[TaskM]# ---------------------->>>>")
|
2024-05-21 23:53:47 +08:00
|
|
|
|
# 阻塞搜索任务标志位
|
|
|
|
|
|
elif self.status is task_queuem_status.SEARCHING:
|
2024-05-22 12:37:15 +08:00
|
|
|
|
logger.info(f"[TaskM]# Start searching task target")
|
|
|
|
|
|
self.task_now.find()
|
2024-05-21 23:53:47 +08:00
|
|
|
|
self.status = task_queuem_status.EXECUTING
|
|
|
|
|
|
# 执行任务函数
|
|
|
|
|
|
elif self.status is task_queuem_status.EXECUTING:
|
2024-05-22 12:37:15 +08:00
|
|
|
|
logger.info(f"[TaskM]# Start execute task function")
|
|
|
|
|
|
self.task_now.exec() # 执行当前任务函数
|
2024-05-21 23:53:47 +08:00
|
|
|
|
self.queue.task_done() # 弹出已执行的任务
|
|
|
|
|
|
self.status = task_queuem_status.IDEL #
|
2024-05-22 12:37:15 +08:00
|
|
|
|
logger.info(f"[TaskM]# <<<<----------------------")
|
2024-05-21 23:53:47 +08:00
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 人员施救
|
2024-05-22 12:37:15 +08:00
|
|
|
|
class get_block():
|
2024-05-29 21:23:05 +08:00
|
|
|
|
def init(self):
|
|
|
|
|
|
logger.info("人员施救初始化")
|
|
|
|
|
|
def find(self):
|
2024-05-22 18:50:21 +08:00
|
|
|
|
# 目标检测红/蓝方块
|
|
|
|
|
|
ret1, list1 = filter.get(tlabel.RBLOCK)
|
2024-05-29 21:23:05 +08:00
|
|
|
|
if ret1 > 0:
|
|
|
|
|
|
logger.info("[抓方块]# find label")
|
2024-05-22 18:50:21 +08:00
|
|
|
|
return True
|
|
|
|
|
|
else:
|
|
|
|
|
|
return False
|
2024-05-29 21:23:05 +08:00
|
|
|
|
def exec(self):
|
|
|
|
|
|
for _ in range(3):
|
|
|
|
|
|
by_cmd.send_speed_x(7)
|
|
|
|
|
|
by_cmd.send_speed_omega(0)
|
|
|
|
|
|
time.sleep(0.1)
|
|
|
|
|
|
logger.info("abcd")
|
2024-05-23 14:33:20 +08:00
|
|
|
|
cfg = toml.load('cfg_subtask.toml') # 加载任务配置
|
2024-05-29 21:23:05 +08:00
|
|
|
|
while True:
|
|
|
|
|
|
# logger.info("等待进入准确区域")
|
|
|
|
|
|
ret, error = filter.aim_near(tlabel.RBLOCK)
|
|
|
|
|
|
while not ret:
|
|
|
|
|
|
ret, error = filter.aim_near(tlabel.RBLOCK)
|
|
|
|
|
|
# logger.info(error)
|
|
|
|
|
|
if abs(error) < 5:
|
|
|
|
|
|
for _ in range(3):
|
|
|
|
|
|
by_cmd.send_speed_x(0)
|
|
|
|
|
|
time.sleep(0.2)
|
|
|
|
|
|
by_cmd.send_speed_omega(0)
|
|
|
|
|
|
break
|
|
|
|
|
|
ret, error = filter.aim_near(tlabel.RBLOCK)
|
|
|
|
|
|
while not ret:
|
|
|
|
|
|
ret, error = filter.aim_near(tlabel.RBLOCK)
|
|
|
|
|
|
time.sleep(1)
|
|
|
|
|
|
logger.error(error)
|
|
|
|
|
|
if abs(error) > 5:
|
|
|
|
|
|
logger.info("校准中")
|
|
|
|
|
|
if error > 0:
|
|
|
|
|
|
by_cmd.send_distance_x(-10, int(error*3))
|
|
|
|
|
|
else:
|
|
|
|
|
|
by_cmd.send_distance_x(10, int(-error*3))
|
|
|
|
|
|
logger.error(error)
|
|
|
|
|
|
time.sleep(1)
|
|
|
|
|
|
for _ in range(3):
|
|
|
|
|
|
by_cmd.send_speed_x(0)
|
|
|
|
|
|
time.sleep(0.2)
|
|
|
|
|
|
by_cmd.send_speed_omega(0)
|
|
|
|
|
|
time.sleep(2)
|
|
|
|
|
|
|
|
|
|
|
|
by_cmd.send_position_axis_z(10, 150)
|
|
|
|
|
|
time.sleep(5)
|
|
|
|
|
|
by_cmd.send_angle_claw_arm(127)
|
|
|
|
|
|
time.sleep(1)
|
|
|
|
|
|
by_cmd.send_position_axis_x(4, 140)
|
|
|
|
|
|
time.sleep(4)
|
|
|
|
|
|
by_cmd.send_angle_claw_arm(220)
|
|
|
|
|
|
by_cmd.send_angle_claw(90)
|
|
|
|
|
|
time.sleep(1)
|
|
|
|
|
|
by_cmd.send_distance_axis_z(10, -70)
|
|
|
|
|
|
time.sleep(3)
|
|
|
|
|
|
by_cmd.send_angle_claw(27)
|
|
|
|
|
|
by_cmd.send_distance_axis_z(10, 10)
|
|
|
|
|
|
time.sleep(2)
|
|
|
|
|
|
by_cmd.send_distance_axis_x(4, -100)
|
|
|
|
|
|
time.sleep(1)
|
|
|
|
|
|
by_cmd.send_distance_axis_z(10, -40)
|
|
|
|
|
|
time.sleep(3)
|
|
|
|
|
|
by_cmd.send_angle_claw(35)
|
|
|
|
|
|
time.sleep(1)
|
|
|
|
|
|
by_cmd.send_position_axis_z(10, 150)
|
|
|
|
|
|
time.sleep(3)
|
|
|
|
|
|
by_cmd.send_position_axis_x(2, 140)
|
|
|
|
|
|
# 抓取第二个块后 收爪
|
|
|
|
|
|
time.sleep(3)
|
|
|
|
|
|
by_cmd.send_position_axis_x(4, 0)
|
|
|
|
|
|
def nexec(self):
|
2024-05-22 12:37:15 +08:00
|
|
|
|
pass
|
|
|
|
|
|
|
2024-05-21 23:53:47 +08:00
|
|
|
|
|
|
|
|
|
|
# 紧急转移
|
2024-05-22 12:37:15 +08:00
|
|
|
|
class put_block():
|
2024-05-29 21:23:05 +08:00
|
|
|
|
def init(self):
|
|
|
|
|
|
logger.info("紧急转移初始化")
|
|
|
|
|
|
def find(self):
|
2024-05-22 18:50:21 +08:00
|
|
|
|
# 目标检测医院
|
|
|
|
|
|
ret1, list1 = filter.get(tlabel.HOSPITAL)
|
|
|
|
|
|
if ret1 > 0:
|
|
|
|
|
|
return True
|
|
|
|
|
|
else:
|
|
|
|
|
|
return False
|
2024-05-29 21:23:05 +08:00
|
|
|
|
def exec(self):
|
2024-05-23 14:33:20 +08:00
|
|
|
|
cfg = toml.load('cfg_subtask.toml') # 加载任务配置
|
2024-05-29 21:23:05 +08:00
|
|
|
|
logger.info("找到医院")
|
|
|
|
|
|
for _ in range(3):
|
|
|
|
|
|
by_cmd.send_speed_x(0)
|
|
|
|
|
|
time.sleep(0.2)
|
|
|
|
|
|
by_cmd.send_speed_omega(0)
|
|
|
|
|
|
|
|
|
|
|
|
by_cmd.send_position_axis_z(10, 150)
|
|
|
|
|
|
time.sleep(3)
|
|
|
|
|
|
# TODO 切换爪子方向
|
|
|
|
|
|
by_cmd.send_position_axis_x(2, 140)
|
|
|
|
|
|
time.sleep(2)
|
|
|
|
|
|
by_cmd.send_position_axis_z(10, 170)
|
2024-05-22 12:37:15 +08:00
|
|
|
|
pass
|
2024-05-21 23:53:47 +08:00
|
|
|
|
|
|
|
|
|
|
# 整装上阵
|
2024-05-22 12:37:15 +08:00
|
|
|
|
class get_bball():
|
2024-05-29 21:23:05 +08:00
|
|
|
|
def init(self):
|
|
|
|
|
|
by_cmd.send_position_axis_x(2, 140)
|
|
|
|
|
|
logger.info("整装上阵初始化")
|
|
|
|
|
|
time.sleep(0.5)
|
|
|
|
|
|
if (by_cmd.send_angle_camera(90) == -1):
|
|
|
|
|
|
by_cmd.send_angle_camera(90)
|
|
|
|
|
|
def find(self):
|
2024-05-22 18:50:21 +08:00
|
|
|
|
# 目标检测黄球
|
|
|
|
|
|
ret1, list1 = filter.get(tlabel.YBALL)
|
|
|
|
|
|
if ret1 > 0:
|
|
|
|
|
|
return True
|
|
|
|
|
|
else:
|
|
|
|
|
|
return False
|
2024-05-29 21:23:05 +08:00
|
|
|
|
def exec(self):
|
|
|
|
|
|
logger.info("找到黄色球")
|
|
|
|
|
|
for _ in range(3):
|
|
|
|
|
|
by_cmd.send_speed_x(7)
|
|
|
|
|
|
by_cmd.send_speed_omega(0)
|
|
|
|
|
|
time.sleep(0.1)
|
|
|
|
|
|
while True:
|
|
|
|
|
|
# logger.info("等待进入准确区域")
|
|
|
|
|
|
ret, error = filter.aim_near(tlabel.YBALL)
|
|
|
|
|
|
while not ret:
|
|
|
|
|
|
ret, error = filter.aim_near(tlabel.YBALL)
|
|
|
|
|
|
# logger.info(error)
|
|
|
|
|
|
if abs(error) < 5:
|
|
|
|
|
|
for _ in range(3):
|
|
|
|
|
|
by_cmd.send_speed_x(0)
|
|
|
|
|
|
time.sleep(0.2)
|
|
|
|
|
|
by_cmd.send_speed_omega(0)
|
|
|
|
|
|
break
|
|
|
|
|
|
ret, error = filter.aim_near(tlabel.YBALL)
|
|
|
|
|
|
while not ret:
|
|
|
|
|
|
ret, error = filter.aim_near(tlabel.YBALL)
|
|
|
|
|
|
time.sleep(1)
|
|
|
|
|
|
logger.error(error)
|
|
|
|
|
|
if abs(error) > 5:
|
|
|
|
|
|
logger.info("校准中")
|
|
|
|
|
|
if error > 0:
|
|
|
|
|
|
by_cmd.send_distance_x(-10, int(error*3))
|
|
|
|
|
|
else:
|
|
|
|
|
|
by_cmd.send_distance_x(10, int(-error*3))
|
|
|
|
|
|
logger.error(error)
|
|
|
|
|
|
time.sleep(1)
|
|
|
|
|
|
if (by_cmd.send_angle_camera(0) == -1):
|
|
|
|
|
|
by_cmd.send_angle_camera(0)
|
|
|
|
|
|
by_cmd.send_position_axis_z(20, 160)
|
|
|
|
|
|
time.sleep(2)
|
|
|
|
|
|
by_cmd.send_position_axis_x(2, 70)
|
|
|
|
|
|
time.sleep(2)
|
|
|
|
|
|
by_cmd.send_angle_claw(90)
|
|
|
|
|
|
time.sleep(0.2)
|
|
|
|
|
|
by_cmd.send_position_axis_x(2, 0)
|
|
|
|
|
|
time.sleep(2)
|
|
|
|
|
|
by_cmd.send_angle_claw(27)
|
|
|
|
|
|
time.sleep(1)
|
|
|
|
|
|
by_cmd.send_position_axis_z(20, 180)
|
|
|
|
|
|
time.sleep(1)
|
|
|
|
|
|
by_cmd.send_position_axis_x(4, 45)
|
|
|
|
|
|
time.sleep(1)
|
|
|
|
|
|
by_cmd.send_position_axis_z(20, 140)
|
|
|
|
|
|
time.sleep(3)
|
|
|
|
|
|
by_cmd.send_position_axis_x(2, 140)
|
|
|
|
|
|
time.sleep(2)
|
|
|
|
|
|
by_cmd.send_angle_claw(90)
|
2024-05-22 12:37:15 +08:00
|
|
|
|
pass
|
2024-05-21 23:53:47 +08:00
|
|
|
|
|
|
|
|
|
|
# 通信抢修
|
2024-05-22 12:37:15 +08:00
|
|
|
|
class up_tower():
|
2024-05-29 21:23:05 +08:00
|
|
|
|
def init(self):
|
|
|
|
|
|
logger.info("通信抢修初始化")
|
|
|
|
|
|
def find(self):
|
2024-05-22 18:50:21 +08:00
|
|
|
|
# 目标检测通信塔
|
2024-05-29 21:23:05 +08:00
|
|
|
|
ret1, list1 = filter.get(tlabel.TOWER)
|
2024-05-22 18:50:21 +08:00
|
|
|
|
if ret1 > 0:
|
|
|
|
|
|
return True
|
|
|
|
|
|
else:
|
|
|
|
|
|
return False
|
2024-05-29 21:23:05 +08:00
|
|
|
|
def exec(self):
|
|
|
|
|
|
logger.info("找到塔")
|
|
|
|
|
|
for _ in range(3):
|
|
|
|
|
|
by_cmd.send_speed_x(7)
|
|
|
|
|
|
by_cmd.send_speed_omega(0)
|
|
|
|
|
|
time.sleep(0.1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while True:
|
|
|
|
|
|
# logger.info("等待进入准确区域")
|
|
|
|
|
|
ret, error = filter.aim_near(tlabel.TOWER)
|
|
|
|
|
|
while not ret:
|
|
|
|
|
|
ret, error = filter.aim_near(tlabel.TOWER)
|
|
|
|
|
|
# logger.info(error)
|
|
|
|
|
|
if abs(error) < 5:
|
|
|
|
|
|
for _ in range(3):
|
|
|
|
|
|
by_cmd.send_speed_x(0)
|
|
|
|
|
|
time.sleep(0.2)
|
|
|
|
|
|
by_cmd.send_speed_omega(0)
|
|
|
|
|
|
break
|
|
|
|
|
|
ret, error = filter.aim_near(tlabel.TOWER)
|
|
|
|
|
|
while not ret:
|
|
|
|
|
|
ret, error = filter.aim_near(tlabel.TOWER)
|
|
|
|
|
|
time.sleep(1)
|
|
|
|
|
|
logger.error(error)
|
|
|
|
|
|
if abs(error) > 5:
|
|
|
|
|
|
logger.info("校准中")
|
|
|
|
|
|
if error > 0:
|
|
|
|
|
|
by_cmd.send_distance_x(-10, int(error*3))
|
|
|
|
|
|
else:
|
|
|
|
|
|
by_cmd.send_distance_x(10, int(-error*3))
|
|
|
|
|
|
logger.error(error)
|
|
|
|
|
|
time.sleep(1)
|
2024-05-21 23:53:47 +08:00
|
|
|
|
|
|
|
|
|
|
# 高空排险
|
2024-05-22 12:37:15 +08:00
|
|
|
|
class get_rball():
|
2024-05-29 21:23:05 +08:00
|
|
|
|
def init(self):
|
|
|
|
|
|
logger.info("高空排险初始化")
|
|
|
|
|
|
if (by_cmd.send_angle_camera(0) == -1):
|
|
|
|
|
|
by_cmd.send_angle_camera(0)
|
|
|
|
|
|
def find(self):
|
2024-05-22 18:50:21 +08:00
|
|
|
|
# 目标检测红球
|
|
|
|
|
|
ret1, list1 = filter.get(tlabel.RBALL)
|
|
|
|
|
|
if ret1 > 0:
|
|
|
|
|
|
return True
|
|
|
|
|
|
else:
|
|
|
|
|
|
return False
|
2024-05-29 21:23:05 +08:00
|
|
|
|
def exec(self):
|
|
|
|
|
|
logger.info("找到红球")
|
|
|
|
|
|
for _ in range(3):
|
|
|
|
|
|
by_cmd.send_speed_x(0)
|
|
|
|
|
|
time.sleep(0.2)
|
|
|
|
|
|
by_cmd.send_speed_omega(0)
|
|
|
|
|
|
time.sleep(1)
|
2024-05-22 12:37:15 +08:00
|
|
|
|
pass
|
2024-05-21 23:53:47 +08:00
|
|
|
|
|
|
|
|
|
|
# 派发物资
|
2024-05-22 12:37:15 +08:00
|
|
|
|
class put_bball():
|
2024-05-29 21:23:05 +08:00
|
|
|
|
def init(self):
|
|
|
|
|
|
logger.info("派发物资初始化")
|
|
|
|
|
|
if (by_cmd.send_angle_camera(90) == -1):
|
|
|
|
|
|
by_cmd.send_angle_camera(90)
|
|
|
|
|
|
def find(self):
|
2024-05-22 18:50:21 +08:00
|
|
|
|
# 目标检测通信塔
|
|
|
|
|
|
ret1, list1 = filter.get(tlabel.BASKET)
|
|
|
|
|
|
if ret1 > 0:
|
|
|
|
|
|
return True
|
|
|
|
|
|
else:
|
|
|
|
|
|
return False
|
2024-05-29 21:23:05 +08:00
|
|
|
|
def exec(self):
|
|
|
|
|
|
logger.info("找到篮筐")
|
|
|
|
|
|
for _ in range(3):
|
|
|
|
|
|
by_cmd.send_speed_x(0)
|
|
|
|
|
|
time.sleep(0.2)
|
|
|
|
|
|
by_cmd.send_speed_omega(0)
|
|
|
|
|
|
time.sleep(1)
|
|
|
|
|
|
|
2024-05-22 12:37:15 +08:00
|
|
|
|
pass
|
2024-05-29 21:23:05 +08:00
|
|
|
|
direction = tlabel.RMARK
|
|
|
|
|
|
direction_left = 0
|
|
|
|
|
|
direction_right = 0
|
2024-05-21 23:53:47 +08:00
|
|
|
|
# 物资盘点
|
2024-05-22 18:50:21 +08:00
|
|
|
|
class put_hanoi1():
|
2024-05-29 21:23:05 +08:00
|
|
|
|
def init(self):
|
|
|
|
|
|
logger.info("物资盘点 1 初始化")
|
|
|
|
|
|
socket.send_string("2")
|
|
|
|
|
|
socket.recv()
|
|
|
|
|
|
def find(self):
|
|
|
|
|
|
global direction
|
|
|
|
|
|
global direction_left
|
|
|
|
|
|
global direction_right
|
2024-05-22 18:50:21 +08:00
|
|
|
|
# 目标检测左右转向标识
|
2024-05-29 21:23:05 +08:00
|
|
|
|
# TODO 框的大小判断距离
|
|
|
|
|
|
ret1, list1 = filter.get(tlabel.RMARK)
|
|
|
|
|
|
ret2, list2 = filter.get(tlabel.LMARK)
|
|
|
|
|
|
if ret1:
|
|
|
|
|
|
logger.info("向右拐")
|
|
|
|
|
|
direction_right += 1
|
|
|
|
|
|
return True
|
|
|
|
|
|
elif ret2:
|
|
|
|
|
|
logger.info("向左拐")
|
|
|
|
|
|
direction_left += 1
|
2024-05-22 18:50:21 +08:00
|
|
|
|
return True
|
2024-05-29 21:23:05 +08:00
|
|
|
|
return False
|
|
|
|
|
|
def exec(self):
|
|
|
|
|
|
for _ in range(3):
|
|
|
|
|
|
by_cmd.send_speed_x(0)
|
|
|
|
|
|
time.sleep(0.2)
|
|
|
|
|
|
by_cmd.send_speed_omega(0)
|
|
|
|
|
|
time.sleep(0.2)
|
|
|
|
|
|
# if direction == tlabel.RMARK:
|
|
|
|
|
|
if direction_right > direction_left:
|
|
|
|
|
|
by_cmd.send_angle_omega(-20,500)
|
2024-05-22 18:50:21 +08:00
|
|
|
|
else:
|
2024-05-29 21:23:05 +08:00
|
|
|
|
by_cmd.send_angle_omega(20,500)
|
|
|
|
|
|
time.sleep(0.2)
|
|
|
|
|
|
if (by_cmd.send_angle_camera(180) == -1):
|
|
|
|
|
|
by_cmd.send_angle_camera(180)
|
|
|
|
|
|
time.sleep(2)
|
|
|
|
|
|
socket.send_string("1")
|
|
|
|
|
|
socket.recv()
|
2024-05-22 18:50:21 +08:00
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
class put_hanoi2():
|
2024-05-29 21:23:05 +08:00
|
|
|
|
def init(self):
|
|
|
|
|
|
logger.info("物资盘点 2 初始化")
|
|
|
|
|
|
def find(self):
|
2024-05-22 18:50:21 +08:00
|
|
|
|
# 目标检测左右转向标识
|
2024-05-29 21:23:05 +08:00
|
|
|
|
ret1, list1 = filter.get(tlabel.LPILLER)
|
2024-05-22 18:50:21 +08:00
|
|
|
|
|
|
|
|
|
|
if ret1 > 0:
|
|
|
|
|
|
return True
|
|
|
|
|
|
else:
|
|
|
|
|
|
return False
|
2024-05-29 21:23:05 +08:00
|
|
|
|
def exec(self):
|
|
|
|
|
|
logger.info("找到最大块")
|
|
|
|
|
|
for _ in range(3):
|
|
|
|
|
|
by_cmd.send_speed_x(0)
|
|
|
|
|
|
time.sleep(0.2)
|
|
|
|
|
|
by_cmd.send_speed_omega(0)
|
|
|
|
|
|
time.sleep(1)
|
2024-05-22 12:37:15 +08:00
|
|
|
|
pass
|
2024-05-21 23:53:47 +08:00
|
|
|
|
|
|
|
|
|
|
# 应急避险
|
2024-05-22 12:37:15 +08:00
|
|
|
|
class move_area():
|
2024-05-29 21:23:05 +08:00
|
|
|
|
def init(self):
|
|
|
|
|
|
logger.info("应急避险初始化")
|
|
|
|
|
|
if (by_cmd.send_angle_camera(180) == -1):
|
|
|
|
|
|
by_cmd.send_angle_camera(180)
|
|
|
|
|
|
def find(self):
|
2024-05-22 18:50:21 +08:00
|
|
|
|
# 目标检测标志牌
|
|
|
|
|
|
# TODO 如何确保在都检测标志牌的情况下,和下一个任务进行区分
|
|
|
|
|
|
ret1, list1 = filter.get(tlabel.SIGN)
|
|
|
|
|
|
|
|
|
|
|
|
if ret1 > 0:
|
|
|
|
|
|
return True
|
|
|
|
|
|
else:
|
|
|
|
|
|
return False
|
2024-05-29 21:23:05 +08:00
|
|
|
|
def exec(self):
|
|
|
|
|
|
logger.info("找到标示牌")
|
2024-05-22 12:37:15 +08:00
|
|
|
|
pass
|
2024-05-21 23:53:47 +08:00
|
|
|
|
|
|
|
|
|
|
# 扫黑除暴
|
2024-05-22 12:37:15 +08:00
|
|
|
|
class kick_ass():
|
2024-05-29 21:23:05 +08:00
|
|
|
|
def init(self):
|
|
|
|
|
|
logger.info("扫黑除暴初始化")
|
|
|
|
|
|
def find(self):
|
2024-05-22 18:50:21 +08:00
|
|
|
|
# 目标检测标志牌
|
|
|
|
|
|
# TODO 如何确保在都检测标志牌的情况下,和上一个任务进行区分
|
|
|
|
|
|
ret1, list1 = filter.get(tlabel.SIGN)
|
|
|
|
|
|
|
|
|
|
|
|
if ret1 > 0:
|
|
|
|
|
|
return True
|
|
|
|
|
|
else:
|
|
|
|
|
|
return False
|
2024-05-29 21:23:05 +08:00
|
|
|
|
def exec(self):
|
|
|
|
|
|
logger.info("找到标示牌")
|
2024-05-22 12:37:15 +08:00
|
|
|
|
pass
|
2024-05-21 23:53:47 +08:00
|
|
|
|
|