2025-05-26 12:29:48 +00:00
|
|
|
|
import time
|
2025-05-27 01:18:10 +08:00
|
|
|
|
import sys
|
|
|
|
|
import os
|
2025-05-26 12:29:48 +00:00
|
|
|
|
import toml
|
|
|
|
|
import copy
|
|
|
|
|
import math
|
2025-05-27 01:18:10 +08:00
|
|
|
|
import lcm
|
|
|
|
|
|
|
|
|
|
# 添加父目录到路径,以便能够导入utils
|
|
|
|
|
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
|
|
|
# 添加当前目录到路径,确保可以找到local文件
|
|
|
|
|
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
|
|
|
|
|
|
|
|
|
|
from utils.log_helper import LogHelper, get_logger, section, info, debug, warning, error, success, timing
|
|
|
|
|
from base_move.turn_degree import turn_degree
|
|
|
|
|
from base_move.go_straight import go_straight
|
2025-05-26 12:29:48 +00:00
|
|
|
|
from file_send_lcmt import file_send_lcmt
|
|
|
|
|
|
2025-05-27 01:18:10 +08:00
|
|
|
|
# 创建本模块特定的日志记录器
|
|
|
|
|
logger = get_logger("任务3")
|
|
|
|
|
|
|
|
|
|
observe = True
|
|
|
|
|
|
2025-05-26 12:29:48 +00:00
|
|
|
|
robot_cmd = {
|
|
|
|
|
'mode':0, 'gait_id':0, 'contact':0, 'life_count':0,
|
|
|
|
|
'vel_des':[0.0, 0.0, 0.0],
|
|
|
|
|
'rpy_des':[0.0, 0.0, 0.0],
|
|
|
|
|
'pos_des':[0.0, 0.0, 0.0],
|
|
|
|
|
'acc_des':[0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
|
|
|
|
|
'ctrl_point':[0.0, 0.0, 0.0],
|
|
|
|
|
'foot_pose':[0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
|
|
|
|
|
'step_height':[0.0, 0.0],
|
|
|
|
|
'value':0, 'duration':0
|
2025-05-27 01:18:10 +08:00
|
|
|
|
}
|
2025-05-26 12:29:48 +00:00
|
|
|
|
|
2025-05-28 02:03:41 +08:00
|
|
|
|
def pass_bar(ctrl, msg):
|
2025-05-27 01:18:10 +08:00
|
|
|
|
"""
|
|
|
|
|
俯身通过一个栅栏
|
|
|
|
|
"""
|
2025-05-28 12:24:18 +00:00
|
|
|
|
step_num = 8
|
|
|
|
|
|
2025-05-27 01:18:10 +08:00
|
|
|
|
# 切换步态
|
2025-05-26 12:29:48 +00:00
|
|
|
|
usergait_msg = file_send_lcmt()
|
2025-05-28 12:24:18 +00:00
|
|
|
|
# lcm_usergait = lcm.LCM("udpm://239.255.76.67:7671?ttl=255")
|
2025-05-27 01:18:10 +08:00
|
|
|
|
|
2025-05-26 12:29:48 +00:00
|
|
|
|
try:
|
2025-05-28 02:03:41 +08:00
|
|
|
|
steps = toml.load("./task_4/Gait_Params_stoop.toml")
|
2025-05-26 12:29:48 +00:00
|
|
|
|
full_steps = {'step':[robot_cmd]}
|
2025-05-26 13:12:28 +00:00
|
|
|
|
k =0
|
2025-05-26 12:29:48 +00:00
|
|
|
|
for i in steps['step']:
|
|
|
|
|
cmd = copy.deepcopy(robot_cmd)
|
|
|
|
|
cmd['duration'] = i['duration']
|
|
|
|
|
if i['type'] == 'usergait':
|
|
|
|
|
cmd['mode'] = 11 # LOCOMOTION
|
|
|
|
|
cmd['gait_id'] = 110 # USERGAIT
|
|
|
|
|
cmd['vel_des'] = i['body_vel_des']
|
|
|
|
|
cmd['rpy_des'] = i['body_pos_des'][0:3]
|
|
|
|
|
cmd['pos_des'] = i['body_pos_des'][3:6]
|
|
|
|
|
cmd['foot_pose'][0:2] = i['landing_pos_des'][0:2]
|
|
|
|
|
cmd['foot_pose'][2:4] = i['landing_pos_des'][3:5]
|
|
|
|
|
cmd['foot_pose'][4:6] = i['landing_pos_des'][6:8]
|
|
|
|
|
cmd['ctrl_point'][0:2] = i['landing_pos_des'][9:11]
|
|
|
|
|
cmd['step_height'][0] = math.ceil(i['step_height'][0] * 1e3) + math.ceil(i['step_height'][1] * 1e3) * 1e3
|
|
|
|
|
cmd['step_height'][1] = math.ceil(i['step_height'][2] * 1e3) + math.ceil(i['step_height'][3] * 1e3) * 1e3
|
|
|
|
|
cmd['acc_des'] = i['weight']
|
|
|
|
|
cmd['value'] = i['use_mpc_traj']
|
|
|
|
|
cmd['contact'] = math.floor(i['landing_gain'] * 1e1)
|
2025-05-26 13:12:28 +00:00
|
|
|
|
cmd['ctrl_point'][2] = i['mu']
|
2025-05-26 12:29:48 +00:00
|
|
|
|
if k == 0:
|
|
|
|
|
full_steps['step'] = [cmd]
|
|
|
|
|
else:
|
|
|
|
|
full_steps['step'].append(cmd)
|
2025-05-26 13:12:28 +00:00
|
|
|
|
k=k+1
|
2025-05-28 02:03:41 +08:00
|
|
|
|
f = open("./task_4/Gait_Params_stoop_full.toml", 'w')
|
2025-05-26 13:12:28 +00:00
|
|
|
|
f.write("# Gait Params\n")
|
2025-05-26 12:29:48 +00:00
|
|
|
|
f.writelines(toml.dumps(full_steps))
|
|
|
|
|
f.close()
|
|
|
|
|
|
2025-05-27 01:18:10 +08:00
|
|
|
|
# pre
|
2025-05-28 02:03:41 +08:00
|
|
|
|
file_obj_gait_def = open("./task_4/Gait_Def_stoop.toml",'r')
|
|
|
|
|
file_obj_gait_params = open("./task_4/Gait_Params_stoop_full.toml",'r')
|
2025-05-26 12:29:48 +00:00
|
|
|
|
usergait_msg.data = file_obj_gait_def.read()
|
2025-05-28 12:24:18 +00:00
|
|
|
|
ctrl.lc_s.publish("user_gait_file", usergait_msg.encode())
|
2025-05-26 12:29:48 +00:00
|
|
|
|
time.sleep(0.5)
|
|
|
|
|
usergait_msg.data = file_obj_gait_params.read()
|
2025-05-28 12:24:18 +00:00
|
|
|
|
ctrl.lc_s.publish("user_gait_file", usergait_msg.encode())
|
2025-05-26 12:29:48 +00:00
|
|
|
|
time.sleep(0.1)
|
|
|
|
|
file_obj_gait_def.close()
|
|
|
|
|
file_obj_gait_params.close()
|
|
|
|
|
|
2025-05-27 01:18:10 +08:00
|
|
|
|
msg.mode = 62
|
|
|
|
|
msg.value = 0
|
|
|
|
|
msg.contact = 15
|
|
|
|
|
msg.gait_id = 110
|
|
|
|
|
msg.duration = 1000
|
|
|
|
|
msg.life_count += 1
|
|
|
|
|
|
2025-05-28 12:24:18 +00:00
|
|
|
|
for i in range(step_num):
|
2025-05-27 01:18:10 +08:00
|
|
|
|
ctrl.Send_cmd(msg)
|
2025-05-28 12:24:18 +00:00
|
|
|
|
time.sleep(1)
|
2025-05-27 01:18:10 +08:00
|
|
|
|
|
2025-05-26 12:29:48 +00:00
|
|
|
|
except KeyboardInterrupt:
|
2025-05-27 01:18:10 +08:00
|
|
|
|
msg.mode = 7 #PureDamper before KeyboardInterrupt:
|
|
|
|
|
msg.gait_id = 0
|
|
|
|
|
msg.duration = 0
|
|
|
|
|
msg.life_count += 1
|
|
|
|
|
ctrl.Send_cmd(msg)
|
2025-05-26 12:29:48 +00:00
|
|
|
|
pass
|