feat: 调整PID控制器参数,优化着陆阶段的速度和位置控制逻辑

This commit is contained in:
2026-01-31 14:22:01 +08:00
parent a9f6b25581
commit 4587b13f72

View File

@@ -14,6 +14,9 @@ class LandingState(str, Enum):
TARGET_LAT = -0.097179090928
TARGET_LON = -74.5576787510
# # VBA房顶
# TARGET_LAT = -0.09684801697319373
# TARGET_LON = -74.61749199803717
class SpaceX_Lander:
def __init__(self):
@@ -43,8 +46,8 @@ class SpaceX_Lander:
# 速度控制 PID (内环):速度误差 -> 倾斜角度
# 增加 kp 提高跟随性,大幅增加 kd (0.8 -> 2.0) 强化刹车阻尼
self.horizontal_north_pid = PID(kp=4.0, ki=0.02, kd=2.0, integral_limit=15.0, alpha=0.5, output_limit=(-20.0, 20.0))
self.horizontal_east_pid = PID(kp=4.0, ki=0.02, kd=2.0, integral_limit=15.0, alpha=0.5, output_limit=(-20.0, 20.0))
self.horizontal_north_pid = PID(kp=4.0, ki=0.02, kd=2.0, integral_limit=15.0, alpha=0.2, output_limit=(-20.0, 20.0))
self.horizontal_east_pid = PID(kp=4.0, ki=0.02, kd=2.0, integral_limit=15.0, alpha=0.2, output_limit=(-20.0, 20.0))
# 状态
self.state = LandingState.GLIDE
@@ -156,6 +159,9 @@ class SpaceX_Lander:
if new_state != self.state:
self._switch_state(new_state)
if self.state == LandingState.FINAL :
# 最终阶段 展开着陆
self.vessel.control.legs = True
# 2. 状态执行逻辑
throttle = 0.0
@@ -197,7 +203,7 @@ class SpaceX_Lander:
elif self.state == LandingState.FINAL:
# 匀速下降阶段
target_landing_speed = max(- (h_err / 3.0), -1.5)
target_landing_speed = min(- (h_err / 3.0), -1.5)
raw_throttle = self.vertical_speed_pid.update(target_landing_speed - current_vertical_speed, dt)
throttle = raw_throttle / math.cos(tilt_rad) if math.cos(tilt_rad) > 0.5 else raw_throttle
print(f"高度: {h_err:.1f}m, 目标速: {target_landing_speed:.1f}m/s, 当前速: {current_vertical_speed:.1f}m/s, 状态: FINAL", " "*5, end="\r")
@@ -227,16 +233,16 @@ class SpaceX_Lander:
# 根据不同阶段动态调整 PID 灵敏度
if new_state == LandingState.FIXED:
# 精确悬停模式:低速、高阻尼
self.pos_north_pid.output_limit = (-5.0, 5.0)
self.pos_east_pid.output_limit = (-5.0, 5.0)
self.pos_north_pid.output_limit = (-30.0, 30.0)
self.pos_east_pid.output_limit = (-30.0, 30.0)
self.horizontal_north_pid.kd = 2.0
self.horizontal_east_pid.kd = 2.0
else:
# 飞行与减速模式:高速追赶目标,中等阻尼
self.pos_north_pid.output_limit = (-50.0, 50.0)
self.pos_east_pid.output_limit = (-50.0, 50.0)
self.horizontal_north_pid.kd = 0.5
self.horizontal_east_pid.kd = 0.5
self.pos_north_pid.output_limit = (-100.0, 100.0)
self.pos_east_pid.output_limit = (-100.0, 100.0)
self.horizontal_north_pid.kd = 0.8
self.horizontal_east_pid.kd = 0.8
if __name__ == "__main__":
lander = SpaceX_Lander()