feat: 新增文心一言接口
This commit is contained in:
224
subtask.py
224
subtask.py
@@ -194,7 +194,7 @@ def explore_calibrate_new(label, offset, run_direc ,run_speed = 3.5):
|
||||
if abs(error) < 8:
|
||||
error = error * 3
|
||||
else:
|
||||
error = error
|
||||
error = error * 2
|
||||
if error > 0:
|
||||
by_cmd.send_distance_x(-10, int(error))
|
||||
else:
|
||||
@@ -324,7 +324,7 @@ class get_block1():
|
||||
return False
|
||||
def exec(self):
|
||||
car_stop()
|
||||
calibrate_new(self.target_label, offset = 15, run = True)
|
||||
calibrate_new(self.target_label, offset = 15, run = True, run_speed = 5)
|
||||
logger.info("抓取块")
|
||||
# act.axis.wait(0.5)
|
||||
# act.axis.z2(60)
|
||||
@@ -350,7 +350,7 @@ class get_block1():
|
||||
by_cmd.send_angle_claw(63)
|
||||
by_cmd.send_position_axis_x(1, 20)
|
||||
time.sleep(2)
|
||||
by_cmd.send_angle_claw(30)
|
||||
by_cmd.send_angle_claw(25)
|
||||
by_cmd.send_beep(1)
|
||||
time.sleep(0.5)
|
||||
by_cmd.send_beep(0)
|
||||
@@ -399,7 +399,7 @@ class get_block2():
|
||||
return False
|
||||
def exec(self):
|
||||
car_stop()
|
||||
calibrate_new(self.target_label, offset = 15, run = True)
|
||||
calibrate_new(self.target_label, offset = 15, run = True, run_speed = 5)
|
||||
logger.info("抓取块")
|
||||
time.sleep(0.5)
|
||||
by_cmd.send_angle_claw_arm(220)
|
||||
@@ -408,7 +408,7 @@ class get_block2():
|
||||
time.sleep(1)
|
||||
by_cmd.send_position_axis_x(1, 20)
|
||||
time.sleep(1)
|
||||
by_cmd.send_angle_claw(30)
|
||||
by_cmd.send_angle_claw(25)
|
||||
by_cmd.send_beep(1)
|
||||
time.sleep(0.5)
|
||||
by_cmd.send_beep(0)
|
||||
@@ -468,7 +468,7 @@ class put_block():
|
||||
time.sleep(0.5)
|
||||
by_cmd.send_position_axis_x(1, 40)
|
||||
time.sleep(2)
|
||||
by_cmd.send_angle_claw(30)
|
||||
by_cmd.send_angle_claw(25)
|
||||
time.sleep(0.5)
|
||||
by_cmd.send_position_axis_z(30, 140)
|
||||
time.sleep(2)
|
||||
@@ -489,7 +489,7 @@ class put_block():
|
||||
def after(self):
|
||||
var.pid_turning.set(cfg["put_block"]["pid_kp"], cfg["put_block"]["pid_ki"], cfg["put_block"]["pid_kd"])
|
||||
# 下一动作预备位置
|
||||
while by_cmd.send_position_axis_z(30, 135) == -1:
|
||||
while by_cmd.send_position_axis_z(30, 130) == -1:
|
||||
pass
|
||||
time.sleep(1)
|
||||
while by_cmd.send_position_axis_x(1, 0) == -1:
|
||||
@@ -536,7 +536,7 @@ class get_bball():
|
||||
car_stop()
|
||||
time.sleep(0.5)
|
||||
for _ in range(3):
|
||||
calibrate_right_new(tlabel.BBALL, offset = 16, run = True, run_speed = 4)
|
||||
calibrate_right_new(tlabel.BBALL, offset = 16, run = True, run_speed = 5)
|
||||
logger.info("抓蓝色球")
|
||||
time.sleep(0.5)
|
||||
by_cmd.send_angle_claw_arm(36)
|
||||
@@ -545,7 +545,7 @@ class get_bball():
|
||||
time.sleep(1)
|
||||
by_cmd.send_angle_claw(60)
|
||||
time.sleep(1)
|
||||
by_cmd.send_angle_claw(30)
|
||||
by_cmd.send_angle_claw(25)
|
||||
time.sleep(1)
|
||||
by_cmd.send_distance_axis_z(30, 20)
|
||||
time.sleep(1)
|
||||
@@ -570,7 +570,8 @@ class get_bball():
|
||||
# 下一动作预备位置
|
||||
by_cmd.send_angle_claw(30)
|
||||
time.sleep(0.5)
|
||||
by_cmd.send_position_axis_z(30, 0)
|
||||
while by_cmd.send_position_axis_z(30, 0) == -1:
|
||||
pass
|
||||
time.sleep(1)
|
||||
# # 任务检查间隔
|
||||
# time.sleep(1)
|
||||
@@ -651,7 +652,7 @@ class get_rball():
|
||||
# by_cmd.send_angle_scoop(15)
|
||||
time.sleep(0.5)
|
||||
by_cmd.send_position_axis_z(30, 170)
|
||||
time.sleep(5)
|
||||
time.sleep(3.5)
|
||||
by_cmd.send_angle_scoop(7)
|
||||
by_cmd.send_distance_y(15, 70)
|
||||
time.sleep(1)
|
||||
@@ -672,9 +673,10 @@ class put_bball():
|
||||
def init(self):
|
||||
logger.info("派发物资初始化")
|
||||
filter.switch_camera(1)
|
||||
by_cmd.send_position_axis_z(30, 0)
|
||||
while (by_cmd.send_angle_camera(90) == -1):
|
||||
by_cmd.send_angle_camera(90)
|
||||
while by_cmd.send_position_axis_z(30, 0) == -1:
|
||||
pass
|
||||
while by_cmd.send_angle_camera(90) == -1:
|
||||
pass
|
||||
def find(self):
|
||||
ret = filter.find(tlabel.BASKET)
|
||||
if ret > 0:
|
||||
@@ -684,9 +686,10 @@ class put_bball():
|
||||
def exec(self):
|
||||
logger.info("找到篮筐")
|
||||
car_stop()
|
||||
calibrate_new(tlabel.BASKET,offset = -21, run = True, run_speed = 5.5)
|
||||
calibrate_new(tlabel.BASKET,offset = -21, run = True, run_speed = 6)
|
||||
by_cmd.send_distance_x(10, 20)
|
||||
by_cmd.send_distance_y(-10, 55)
|
||||
# 向左运动
|
||||
by_cmd.send_distance_y(-10, 35)
|
||||
time.sleep(1)
|
||||
|
||||
by_cmd.send_angle_storage(55)
|
||||
@@ -709,6 +712,7 @@ class put_bball():
|
||||
# 物资盘点
|
||||
class put_hanoi1():
|
||||
def init(self):
|
||||
var.pid_turning.set(cfg["put_bball"]["pid_kp"], cfg["put_bball"]["pid_ki"], cfg["put_bball"]["pid_kd"])
|
||||
logger.info("物资盘点 1 初始化")
|
||||
filter.switch_camera(2)
|
||||
def find(self):
|
||||
@@ -804,23 +808,16 @@ class put_hanoi1():
|
||||
|
||||
class put_hanoi2():
|
||||
def __init__(self):
|
||||
self.pos_lp = cfg['put_hanoi2']['pos_lp']
|
||||
self.pos_mp = cfg['put_hanoi2']['pos_mp']
|
||||
self.pos_sp = 6 - self.pos_lp - self.pos_mp
|
||||
if self.pos_lp == 1:
|
||||
if cfg['put_hanoi2']['first_target'] == "lp":
|
||||
self.target_label = tlabel.LPILLER
|
||||
elif self.pos_mp == 1:
|
||||
elif cfg['put_hanoi2']['first_target'] == "mp":
|
||||
self.target_label = tlabel.MPILLER
|
||||
else:
|
||||
elif cfg['put_hanoi2']['first_target'] == "sp":
|
||||
self.target_label = tlabel.SPILLER
|
||||
self.distance_lp = self.pos_lp * cfg['put_hanoi2']['pos_gap']
|
||||
self.distance_mp = self.pos_mp * cfg['put_hanoi2']['pos_gap']
|
||||
self.distance_sp = self.pos_sp * cfg['put_hanoi2']['pos_gap']
|
||||
logger.info(f"setting hanoi pos_lp[{self.pos_lp}] pos_mp[{self.pos_mp}] pos_sp[{self.pos_sp}]")
|
||||
def init(self):
|
||||
logger.info("物资盘点 2 初始化")
|
||||
if utils.direction == tlabel.RMARK:
|
||||
self.offset = 25
|
||||
self.offset = 22
|
||||
else:
|
||||
self.offset = 10
|
||||
def find(self):
|
||||
@@ -846,28 +843,28 @@ class put_hanoi2():
|
||||
by_cmd.send_position_axis_x(1, 130)
|
||||
by_cmd.send_angle_claw(63)
|
||||
time.sleep(1)
|
||||
by_cmd.send_angle_claw(90)
|
||||
by_cmd.send_angle_claw(81)
|
||||
time.sleep(1.5)
|
||||
by_cmd.send_angle_claw(45)
|
||||
time.sleep(2)
|
||||
by_cmd.send_distance_axis_z(30, 20)
|
||||
by_cmd.send_angle_claw(40)
|
||||
time.sleep(1)
|
||||
by_cmd.send_distance_axis_z(30, 20)
|
||||
time.sleep(0.5)
|
||||
by_cmd.send_position_axis_x(1, 10)
|
||||
time.sleep(2)
|
||||
time.sleep(1)
|
||||
pass
|
||||
else:
|
||||
by_cmd.send_position_axis_z(30, 10)
|
||||
by_cmd.send_position_axis_x(1, 40)
|
||||
by_cmd.send_angle_claw(63)
|
||||
time.sleep(1)
|
||||
by_cmd.send_angle_claw(90)
|
||||
by_cmd.send_angle_claw(81)
|
||||
time.sleep(1.5)
|
||||
by_cmd.send_angle_claw(45)
|
||||
time.sleep(2)
|
||||
by_cmd.send_distance_axis_z(30, 20)
|
||||
by_cmd.send_angle_claw(40)
|
||||
time.sleep(1)
|
||||
by_cmd.send_distance_axis_z(30, 20)
|
||||
time.sleep(0.5)
|
||||
by_cmd.send_position_axis_x(1, 160)
|
||||
time.sleep(2)
|
||||
time.sleep(1)
|
||||
pass
|
||||
explore_calibrate_new(tlabel.TPLATFORM, offset = self.offset, run_direc = -1, run_speed = 5)
|
||||
time.sleep(1)
|
||||
@@ -877,18 +874,24 @@ class put_hanoi2():
|
||||
time.sleep(1.5)
|
||||
by_cmd.send_distance_axis_z(30, -20)
|
||||
time.sleep(1)
|
||||
by_cmd.send_angle_claw(90)
|
||||
time.sleep(1)
|
||||
by_cmd.send_angle_claw(81)
|
||||
time.sleep(0.5)
|
||||
by_cmd.send_angle_claw(63)
|
||||
time.sleep(0.5)
|
||||
by_cmd.send_position_axis_x(1, 10)
|
||||
time.sleep(1)
|
||||
pass
|
||||
else:
|
||||
by_cmd.send_position_axis_x(1, 40)
|
||||
time.sleep(1.5)
|
||||
by_cmd.send_distance_axis_z(30, -20)
|
||||
time.sleep(1)
|
||||
by_cmd.send_angle_claw(90)
|
||||
time.sleep(1)
|
||||
by_cmd.send_angle_claw(81)
|
||||
time.sleep(0.5)
|
||||
by_cmd.send_angle_claw(63)
|
||||
time.sleep(0.5)
|
||||
by_cmd.send_position_axis_x(1, 160)
|
||||
time.sleep(1)
|
||||
|
||||
explore_calibrate_new(tlabel.MPILLER, offset = self.offset, run_direc = 1, run_speed = 5)
|
||||
time.sleep(1)
|
||||
@@ -898,30 +901,30 @@ class put_hanoi2():
|
||||
by_cmd.send_position_axis_x(1, 130)
|
||||
by_cmd.send_angle_claw(63)
|
||||
time.sleep(1)
|
||||
by_cmd.send_angle_claw(85)
|
||||
time.sleep(2)
|
||||
by_cmd.send_angle_claw(40)
|
||||
time.sleep(2)
|
||||
by_cmd.send_distance_axis_z(30, 20)
|
||||
by_cmd.send_angle_claw(75)
|
||||
time.sleep(1)
|
||||
by_cmd.send_angle_claw(35)
|
||||
time.sleep(1)
|
||||
by_cmd.send_distance_axis_z(30, 20)
|
||||
time.sleep(0.5)
|
||||
by_cmd.send_position_axis_x(1, 10)
|
||||
time.sleep(3)
|
||||
time.sleep(1)
|
||||
pass
|
||||
else:
|
||||
by_cmd.send_position_axis_z(30, 10)
|
||||
by_cmd.send_position_axis_x(1, 40)
|
||||
by_cmd.send_angle_claw(63)
|
||||
time.sleep(1)
|
||||
by_cmd.send_angle_claw(85)
|
||||
time.sleep(2)
|
||||
by_cmd.send_angle_claw(40)
|
||||
time.sleep(2)
|
||||
by_cmd.send_distance_axis_z(30, 20)
|
||||
by_cmd.send_angle_claw(75)
|
||||
time.sleep(1)
|
||||
by_cmd.send_angle_claw(35)
|
||||
time.sleep(1)
|
||||
by_cmd.send_distance_axis_z(30, 20)
|
||||
time.sleep(0.5)
|
||||
by_cmd.send_position_axis_x(1, 160)
|
||||
time.sleep(3)
|
||||
time.sleep(1)
|
||||
pass
|
||||
explore_calibrate_new(tlabel.LPILLER, offset = self.offset, run_direc = -1, run_speed = 5)
|
||||
explore_calibrate_new(tlabel.LPILLER, offset = self.offset, run_direc = -1, run_speed = 5)
|
||||
time.sleep(1)
|
||||
logger.info("放中平台")
|
||||
if utils.direction is tlabel.RMARK:
|
||||
@@ -931,7 +934,7 @@ class put_hanoi2():
|
||||
time.sleep(2)
|
||||
by_cmd.send_distance_axis_z(30, -20)
|
||||
time.sleep(0.5)
|
||||
by_cmd.send_angle_claw(90)
|
||||
by_cmd.send_angle_claw(65)
|
||||
time.sleep(0.5)
|
||||
by_cmd.send_position_axis_x(1, 10)
|
||||
time.sleep(1)
|
||||
@@ -943,12 +946,12 @@ class put_hanoi2():
|
||||
time.sleep(2)
|
||||
by_cmd.send_distance_axis_z(30, -20)
|
||||
time.sleep(0.5)
|
||||
by_cmd.send_angle_claw(90)
|
||||
by_cmd.send_angle_claw(65)
|
||||
time.sleep(0.5)
|
||||
by_cmd.send_position_axis_x(1, 160)
|
||||
time.sleep(1)
|
||||
|
||||
explore_calibrate_new(tlabel.SPILLER, offset = self.offset, run_direc = 1, run_speed = 5)
|
||||
explore_calibrate_new(tlabel.SPILLER, offset = self.offset, run_direc = 1, run_speed = 5)
|
||||
time.sleep(1)
|
||||
logger.info("抓小平台")
|
||||
if utils.direction is tlabel.RMARK:
|
||||
@@ -956,30 +959,30 @@ class put_hanoi2():
|
||||
by_cmd.send_position_axis_x(1, 130)
|
||||
by_cmd.send_angle_claw(63)
|
||||
time.sleep(1)
|
||||
by_cmd.send_angle_claw(85)
|
||||
by_cmd.send_angle_claw(70)
|
||||
time.sleep(1)
|
||||
by_cmd.send_angle_claw(30)
|
||||
by_cmd.send_angle_claw(27)
|
||||
time.sleep(1)
|
||||
by_cmd.send_distance_axis_z(30, 10)
|
||||
time.sleep(1)
|
||||
time.sleep(0.5)
|
||||
by_cmd.send_position_axis_x(1, 10)
|
||||
time.sleep(2)
|
||||
time.sleep(1)
|
||||
pass
|
||||
else:
|
||||
by_cmd.send_position_axis_z(30, 10)
|
||||
by_cmd.send_position_axis_x(1, 40)
|
||||
by_cmd.send_angle_claw(63)
|
||||
time.sleep(1)
|
||||
by_cmd.send_angle_claw(85)
|
||||
by_cmd.send_angle_claw(70)
|
||||
time.sleep(1)
|
||||
by_cmd.send_angle_claw(30)
|
||||
by_cmd.send_angle_claw(27)
|
||||
time.sleep(1)
|
||||
by_cmd.send_distance_axis_z(30, 10)
|
||||
time.sleep(1)
|
||||
time.sleep(0.5)
|
||||
by_cmd.send_position_axis_x(1, 160)
|
||||
time.sleep(2)
|
||||
time.sleep(1)
|
||||
pass
|
||||
explore_calibrate_new(tlabel.MPILLER, offset = self.offset, run_direc = -1, run_speed = 5)
|
||||
explore_calibrate_new(tlabel.MPILLER, offset = self.offset, run_direc = -1, run_speed = 5)
|
||||
time.sleep(1)
|
||||
logger.info("放小平台")
|
||||
if utils.direction is tlabel.RMARK:
|
||||
@@ -1031,7 +1034,8 @@ class put_hanoi3():
|
||||
time.sleep(1)
|
||||
return True
|
||||
def exec(self):
|
||||
by_cmd.send_position_axis_z(30, 100)
|
||||
while by_cmd.send_position_axis_z(30, 100) == -1:
|
||||
pass
|
||||
pass
|
||||
def nexec(self):
|
||||
pass
|
||||
@@ -1054,7 +1058,7 @@ class move_area1():
|
||||
# 停车 ocr 识别文字 调用大模型
|
||||
car_stop()
|
||||
time.sleep(2)
|
||||
var.task_speed = 8
|
||||
var.task_speed = 12
|
||||
pass
|
||||
def nexec(self):
|
||||
pass
|
||||
@@ -1068,6 +1072,9 @@ class move_area2():
|
||||
def init(self):
|
||||
logger.info("应急避险第二阶段初始化")
|
||||
self.offset = 15
|
||||
self.delta_x = 0
|
||||
self.delta_y = 0
|
||||
self.delta_omage = 0
|
||||
def find(self):
|
||||
# time.sleep(0.001)
|
||||
ret, box = filter.get(tlabel.SHELTER)
|
||||
@@ -1076,25 +1083,88 @@ class move_area2():
|
||||
if abs(error) < 20:
|
||||
return 5000
|
||||
return False
|
||||
def sub_light(self, delay_time):
|
||||
by_cmd.send_light(1)
|
||||
time.sleep(delay_time)
|
||||
by_cmd.send_light(0)
|
||||
def sub_beep(self,delay_time):
|
||||
by_cmd.send_beep(1)
|
||||
time.sleep(delay_time)
|
||||
by_cmd.send_beep(0)
|
||||
def sub_move(self, x, y):
|
||||
self.delta_x += x
|
||||
self.delta_y += y
|
||||
|
||||
if x != 0:
|
||||
delay_time = int(abs(x) * 500)
|
||||
if x > 0:
|
||||
by_cmd.send_distance_x(15, delay_time)
|
||||
else:
|
||||
by_cmd.send_distance_x(-15, delay_time)
|
||||
elif y != 0:
|
||||
delay_time = int(abs(y) * 500)
|
||||
if y > 0: # 向左
|
||||
by_cmd.send_distance_y(-15, delay_time)
|
||||
else:
|
||||
by_cmd.send_distance_y(15, delay_time)
|
||||
time.sleep(delay_time / 400 * 1.5)
|
||||
pass
|
||||
def sub_turn(self, angle):
|
||||
self.delta_omage += angle
|
||||
delay_time = int(abs(angle) * 400 / 90)
|
||||
if angle < 0:
|
||||
# 左转
|
||||
by_cmd.send_angle_omega(+55, delay_time)
|
||||
else:
|
||||
# 右转
|
||||
by_cmd.send_angle_omega(-55, delay_time)
|
||||
time.sleep(delay_time / 300 * 1.5)
|
||||
def exec(self):
|
||||
var.task_speed = 0
|
||||
logger.info("开始寻找停车区域")
|
||||
car_stop()
|
||||
calibrate_new(tlabel.SHELTER, offset = 15, run = True)
|
||||
time.sleep(1)
|
||||
time.sleep(0.5)
|
||||
# 进入停车区域
|
||||
by_cmd.send_distance_y(10, 450)
|
||||
by_cmd.send_distance_y(15, 300)
|
||||
|
||||
|
||||
time.sleep(3)
|
||||
# time.sleep(1)
|
||||
|
||||
# TODO 调用大模型 然后执行动作
|
||||
by_cmd.send_light(1)
|
||||
time.sleep(2)
|
||||
by_cmd.send_light(0)
|
||||
# 调用大模型 然后执行动作
|
||||
resp_commands = eval(llm_bot.get_command_json("旋转 90 度,发声 1 秒,照亮 1 秒").replace("'''json","").replace("'''",''))
|
||||
for command in resp_commands:
|
||||
logger.info(command)
|
||||
if command['func'] == 'move':
|
||||
self.sub_move(float(command['x']), float(command['y']))
|
||||
elif command['func'] == 'light':
|
||||
self.sub_light(int(command['time']))
|
||||
elif command['func'] == 'beep':
|
||||
self.sub_beep(int(command['time']))
|
||||
elif command['func'] == 'turn':
|
||||
self.sub_turn(int(command['angle']))
|
||||
pass
|
||||
time.sleep(0.5)
|
||||
time.sleep(1)
|
||||
# 回到原位
|
||||
delay_time = int(abs(self.delta_omage) * 400 / 90)
|
||||
if self.delta_omage < 0:
|
||||
# 左转
|
||||
by_cmd.send_angle_omega(-55, delay_time)
|
||||
else:
|
||||
# 右转
|
||||
by_cmd.send_angle_omega(55, delay_time)
|
||||
time.sleep(delay_time / 300 * 1.5)
|
||||
if self.delta_y > 0:
|
||||
# 向左移动的距离就要比进入的时候少一些 因为 action 已经向左运动了
|
||||
delay_time = 300 - (self.delta_y * 500)
|
||||
else:
|
||||
delay_time = 300 + (abs(self.delta_y) * 500)
|
||||
# 离开停车区域
|
||||
by_cmd.send_distance_y(-10, 450)
|
||||
time.sleep(4)
|
||||
by_cmd.send_distance_y(-15, delay_time)
|
||||
time.sleep(delay_time / 400 * 1.5)
|
||||
# FIXME 移动距离指令下发后未完成,再发送速度指令,将不会清除未完成的速度值
|
||||
# by_cmd.send_distance_y(-15, 300)
|
||||
pass
|
||||
def nexec(self):
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user