update
This commit is contained in:
@@ -102,6 +102,11 @@ def auto_land_predictive(host='localhost', port=50000, target_altitude=0.5, targ
|
|||||||
# WAIT 阶段按折减推力估算刹车距离(提前点火,补偿点火/推力建立延迟)
|
# WAIT 阶段按折减推力估算刹车距离(提前点火,补偿点火/推力建立延迟)
|
||||||
thrust_discount_wait = 0.9
|
thrust_discount_wait = 0.9
|
||||||
|
|
||||||
|
# 低空/接地参数(用于“最后几米慢下来”)
|
||||||
|
touchdown_vspeed_tol = 0.6 # m/s:认为“软着陆”的竖直速度容差
|
||||||
|
low_altitude_pid_switch = 10.0 # m:低于该高度切换到竖直速度控制
|
||||||
|
vspeed_p_gain = 0.6 # 比例增益:越大越积极(0.3~1.0 之间可调)
|
||||||
|
|
||||||
def _get_g(local_vessel):
|
def _get_g(local_vessel):
|
||||||
try:
|
try:
|
||||||
body = local_vessel.orbit.body
|
body = local_vessel.orbit.body
|
||||||
@@ -217,23 +222,26 @@ def auto_land_predictive(host='localhost', port=50000, target_altitude=0.5, targ
|
|||||||
alt, srf_speed, v_speed, mass, avail_thrust, g_local, situation_name = _read_state()
|
alt, srf_speed, v_speed, mass, avail_thrust, g_local, situation_name = _read_state()
|
||||||
remaining_alt = max(0.0, alt - float(target_altitude))
|
remaining_alt = max(0.0, alt - float(target_altitude))
|
||||||
|
|
||||||
v = max(0.0, float(srf_speed))
|
# BURN 阶段以“竖直下降速度”为控制对象:下降为负,统一转成向下为正的标量 v_down
|
||||||
vf = max(0.0, abs(float(target_vspeed)))
|
v_down = max(0.0, -float(v_speed))
|
||||||
|
vf_down = max(0.0, abs(float(target_vspeed))) # 目标接地竖直速度(向下为正)
|
||||||
|
|
||||||
# 终止条件:以 vessel.situation.name == 'landed' 为准
|
# 终止条件:LANDED 可能会在仍有较大竖直速度时触发(弹跳/碰撞瞬间)
|
||||||
if str(situation_name).strip().lower() == 'landed':
|
# 因此要求:LANDED 且竖直速度足够小才结束
|
||||||
|
is_landed = str(situation_name).strip().lower() == 'landed'
|
||||||
|
if is_landed and v_down <= (vf_down + float(touchdown_vspeed_tol)):
|
||||||
try:
|
try:
|
||||||
vessel.control.throttle = 0.0
|
vessel.control.throttle = 0.0
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
status['result'] = 'landed'
|
status['result'] = 'landed'
|
||||||
status['logs'].append('检测到 vessel.situation=LANDED,着陆完成')
|
status['logs'].append('检测到 vessel.situation=LANDED 且竖直速度满足软着陆阈值,着陆完成')
|
||||||
if verbose:
|
if verbose:
|
||||||
print('检测到 vessel.situation=LANDED,着陆完成')
|
print('检测到 vessel.situation=LANDED 且竖直速度满足软着陆阈值,着陆完成')
|
||||||
break
|
break
|
||||||
|
|
||||||
# 兜底:极低高度 + 速度足够小(防止 situation 迟迟不切换导致卡死)
|
# 兜底:极低高度 + 速度足够小(防止 situation 迟迟不切换导致卡死)
|
||||||
if remaining_alt <= max(0.2, float(target_altitude)) and v <= (vf + 0.5):
|
if remaining_alt <= max(0.2, float(target_altitude)) and v_down <= (vf_down + float(touchdown_vspeed_tol)):
|
||||||
try:
|
try:
|
||||||
vessel.control.throttle = 0.0
|
vessel.control.throttle = 0.0
|
||||||
except Exception:
|
except Exception:
|
||||||
@@ -244,11 +252,16 @@ def auto_land_predictive(host='localhost', port=50000, target_altitude=0.5, targ
|
|||||||
print('达到高度/速度阈值,但 vessel.situation 仍未变为 LANDED')
|
print('达到高度/速度阈值,但 vessel.situation 仍未变为 LANDED')
|
||||||
break
|
break
|
||||||
|
|
||||||
# 计算所需净向上加速度
|
# 低空策略:切换到“竖直速度跟踪”以确保最后几米把速度压到目标值
|
||||||
|
if alt <= float(low_altitude_pid_switch):
|
||||||
|
# 需要的净向上加速度:a_net_up = k * (v_down - vf_down)
|
||||||
|
a_req_up = max(0.0, float(vspeed_p_gain) * max(0.0, (v_down - vf_down)))
|
||||||
|
else:
|
||||||
|
# 中高空:用距离反推所需净向上加速度(使用竖直下降速度)
|
||||||
if remaining_alt <= 1e-3:
|
if remaining_alt <= 1e-3:
|
||||||
a_req_up = 0.0
|
a_req_up = 0.0
|
||||||
else:
|
else:
|
||||||
a_req_up = max(0.0, (v * v - vf * vf) / (2.0 * remaining_alt))
|
a_req_up = max(0.0, (v_down * v_down - vf_down * vf_down) / (2.0 * remaining_alt))
|
||||||
|
|
||||||
# 推力不足时给满油门
|
# 推力不足时给满油门
|
||||||
if mass <= 0 or avail_thrust <= 1e-6:
|
if mass <= 0 or avail_thrust <= 1e-6:
|
||||||
@@ -259,7 +272,7 @@ def auto_land_predictive(host='localhost', port=50000, target_altitude=0.5, targ
|
|||||||
throttle = max(0.0, min(1.0, float(throttle)))
|
throttle = max(0.0, min(1.0, float(throttle)))
|
||||||
|
|
||||||
# 低空兜底:高度<5m 且仍很快 -> 满油门
|
# 低空兜底:高度<5m 且仍很快 -> 满油门
|
||||||
if alt < 5.0 and v > 10.0:
|
if alt < 5.0 and v_down > 10.0:
|
||||||
throttle = 1.0
|
throttle = 1.0
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -271,7 +284,9 @@ def auto_land_predictive(host='localhost', port=50000, target_altitude=0.5, targ
|
|||||||
msg = (
|
msg = (
|
||||||
f'BURN alt={alt:.1f} rem={remaining_alt:.1f} '
|
f'BURN alt={alt:.1f} rem={remaining_alt:.1f} '
|
||||||
f'srf_speed={srf_speed:.2f} vs={v_speed:.2f} '
|
f'srf_speed={srf_speed:.2f} vs={v_speed:.2f} '
|
||||||
f'a_req_up={a_req_up:.2f} throttle={throttle:.2f}'
|
f'v_down={v_down:.2f} vf_down={vf_down:.2f} '
|
||||||
|
f'a_req_up={a_req_up:.2f} throttle={throttle:.2f} '
|
||||||
|
f'landed={int(is_landed)}'
|
||||||
)
|
)
|
||||||
status['logs'].append(msg)
|
status['logs'].append(msg)
|
||||||
print(msg)
|
print(msg)
|
||||||
|
|||||||
Reference in New Issue
Block a user