重构任务4,更新通过栏杆的功能

- 将任务5中的run_task_5函数重命名为pass_bar,并调整其实现以适应新的步态参数文件路径。
- 在task_4.py中添加通过栏杆的步骤,并更新相关的步态参数文件路径。
- 优化了任务4的执行流程,确保机器人能够顺利通过栏杆并继续后续任务。
This commit is contained in:
Havoc 2025-05-28 02:03:41 +08:00
parent bffcd973e0
commit 6c55201f73
6 changed files with 45 additions and 4999 deletions

View File

@ -1334,3 +1334,4 @@ def follow_left_side_track(ctrl, msg, min_distance=600, max_distance=650, speed=
if observe:
warning("无法检测最终位置的左侧轨迹线", "警告")
return False

File diff suppressed because it is too large Load Diff

View File

@ -33,22 +33,16 @@ robot_cmd = {
'value':0, 'duration':0
}
def run_task_5(ctrl, msg):
def pass_bar(ctrl, msg):
"""
俯身通过一个栅栏
"""
section('任务5步态切换', "启动")
info('开始执行任务5...', "启动")
turn_degree(ctrl, msg, 90, absolute=True)
section('任务5-1切换步态', "启动")
# 切换步态
usergait_msg = file_send_lcmt()
lcm_usergait = lcm.LCM("udpm://239.255.76.67:7671?ttl=255")
try:
steps = toml.load("./task_5/Gait_Params_up.toml")
steps = toml.load("./task_4/Gait_Params_stoop.toml")
full_steps = {'step':[robot_cmd]}
k =0
for i in steps['step']:
@ -75,14 +69,14 @@ def run_task_5(ctrl, msg):
else:
full_steps['step'].append(cmd)
k=k+1
f = open("./task_5/Gait_Params_up_full.toml", 'w')
f = open("./task_4/Gait_Params_stoop_full.toml", 'w')
f.write("# Gait Params\n")
f.writelines(toml.dumps(full_steps))
f.close()
# pre
file_obj_gait_def = open("./task_5/Gait_Def_up.toml",'r')
file_obj_gait_params = open("./task_5/Gait_Params_up_full.toml",'r')
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')
usergait_msg.data = file_obj_gait_def.read()
lcm_usergait.publish("user_gait_file",usergait_msg.encode())
time.sleep(0.5)
@ -92,7 +86,7 @@ def run_task_5(ctrl, msg):
file_obj_gait_def.close()
file_obj_gait_params.close()
file_obj_gait_params = open("./task_5/Gait_Params_up_full.toml",'r')
file_obj_gait_params = open("./task_4/Gait_Params_stoop_full.toml",'r')
usergait_msg.data = file_obj_gait_params.read()
lcm_usergait.publish("user_gait_file", usergait_msg.encode())
time.sleep(0.5)

View File

@ -12,6 +12,8 @@ from base_move.go_straight import go_straight
from utils.log_helper import LogHelper, get_logger, section, info, debug, warning, error, success, timing
from utils.gray_sky_analyzer import analyze_gray_sky_ratio
from task_4.pass_bar import pass_bar
# 创建本模块特定的日志记录器
logger = get_logger("任务4")
@ -22,13 +24,24 @@ def run_task_4(ctrl, msg):
msg: 控制消息对象
image_processor: 可选的图像处理器实例
"""
section('任务4-1直线移动', "移动")
go_straight(ctrl, msg, distance=6)
section('任务4-2移动直到灰色天空比例小于阈值', "天空检测")
section('任务4-1移动直到灰色天空比例小于阈值', "天空检测")
go_straight_until_sky_ratio_below(ctrl, msg, sky_ratio_threshold=0.2)
section('任务4-2通过栏杆', "移动")
pass_bar(ctrl, msg)
section('任务4-3直线移动 - 石板路', "移动")
# 设置机器人运动模式为快步跑
msg.mode = 11 # 运动模式
msg.gait_id = 3 # 步态ID快步跑
msg.vel_des = [0.35, 0, 0] # 期望速度
msg.pos_des = [ 0, 0, 0]
msg.duration = 0 # 零时长表示持续运动,直到接收到新命令
msg.step_height = [0.21, 0.21] # 持续运动时摆动腿的离地高度
msg.life_count += 1
ctrl.Send_cmd(msg)
time.sleep(5000) # 持续5秒钟
def go_straight_until_sky_ratio_below(ctrl, msg, sky_ratio_threshold=0.2, step_distance=0.5, max_distance=10, speed=0.3):
"""
@ -109,5 +122,24 @@ def go_straight_until_sky_ratio_below(ctrl, msg, sky_ratio_threshold=0.2, step_d
return success_flag
def run_task_4_back(ctrl, msg):
section('任务4-1直线移动', "移动")
# 设置机器人运动模式为快步跑
msg.mode = 11 # 运动模式
msg.gait_id = 3 # 步态ID快步跑
msg.vel_des = [0.35, 0, 0] # 期望速度
msg.pos_des = [ 0, 0, 0]
msg.duration = 0 # 零时长表示持续运动,直到接收到新命令
msg.step_height = [0.21, 0.21] # 持续运动时摆动腿的离地高度
msg.life_count += 1
ctrl.Send_cmd(msg)
time.sleep(5000) # 持续5秒钟
section('任务4-2移动直到灰色天空比例小于阈值', "天空检测")
go_straight_until_sky_ratio_below(ctrl, msg, sky_ratio_threshold=0.2)
section('任务4-3通过栏杆', "移动")
pass_bar(ctrl, msg)