如何使用 GEKKO 在模型预测控制应用程序中管理采样和命令时间
How to manage sampling and command times in a model predictive control application using GEKKO
我正在使用 GEKKO 进行四轴飞行器(模拟)的模型预测控制 (MPC),包括计算四轴飞行器质量和阻力的移动 Horizon 估计器 (MHE)。四轴飞行器的命令功能要求我指定一个时间段(即在 x 秒内保持角度 r、p 和油门 z)。
我的估计器中的离散化指定如下:
m = GEKKO()
m.time = (0,5,2)
模拟函数如下所示:
for i in range(cycles):
#Simulation measurements
#Request measurements
#MV inputs
T.MEAS = throttle_i[i]
roll.MEAS = roll_i[i]
pitch.MEAS = pitch_i[I]
#simulate one step
quad.move(roll_i[i],pitch_i[i],throttle_i[i],dt).join()
其中 dt
是指定命令的时间长度。 (即保持滚转、俯仰和油门 dt
秒)。
如何确保模拟中的离散化与 MHE 离散化匹配?另外,如何在采样率和指令率之间找到一个好的平衡点?恐怕指挥太频繁会对流程进行不必要的小调整,但采样不够频繁又会导致估算不准确。
您总是希望在 Moving Horizon Estimation 和模拟器之间使用相同的采样时间。我建议您使用 numpy.linspace
或 numpy.arange
来定义估算器的时间 horizon。
import numpy as np
from gekko import GEKKO
m = GEKKO()
m.time = np.linspace(0,5,11)
print(m.time)
m.time = np.arange(0,5.01,0.5)
print(m.time)
这给出了 horizon 11 个时间点,时间步长为 0.5:
[0. 0.5 1. 1.5 2. 2.5 3. 3.5 4. 4.5 5. ]
如果您的模拟器采用不同的采样间隔进行测量,那么您可以调整 numpy.arange
中的 0.5。
这里是additional example code for MHE. If you are using a physical system instead of a simulator then the sample time for the MHE needs to be the frequency that you are updating your measurements and solving the MHE. Here is the source code for the figure below,它是从 Arduino 设备采样温度数据。
在这种情况下,每秒测量一次温度,MHE 为 re-solved。总时间 horizon 为 120 秒,间隔 3 秒或 np.linspace(0,120,41)
给出 m.time=[0,3,...,117,120]
.
关于在采样率和命令率之间找到良好平衡的第二个问题,采样率通常受到 MHE 求解速度的限制。如果您需要更快的速度,则可以使用卡尔曼滤波器或替代方法。通常,控制器的命令速度越快越好,因为您能够更快地响应干扰。如果您担心过于频繁地移动参数值,那么您可以在 objective.
中使用 DCOST (penalize movement) or DMAX (hard constraint on movement)
我正在使用 GEKKO 进行四轴飞行器(模拟)的模型预测控制 (MPC),包括计算四轴飞行器质量和阻力的移动 Horizon 估计器 (MHE)。四轴飞行器的命令功能要求我指定一个时间段(即在 x 秒内保持角度 r、p 和油门 z)。 我的估计器中的离散化指定如下:
m = GEKKO()
m.time = (0,5,2)
模拟函数如下所示:
for i in range(cycles):
#Simulation measurements
#Request measurements
#MV inputs
T.MEAS = throttle_i[i]
roll.MEAS = roll_i[i]
pitch.MEAS = pitch_i[I]
#simulate one step
quad.move(roll_i[i],pitch_i[i],throttle_i[i],dt).join()
其中 dt
是指定命令的时间长度。 (即保持滚转、俯仰和油门 dt
秒)。
如何确保模拟中的离散化与 MHE 离散化匹配?另外,如何在采样率和指令率之间找到一个好的平衡点?恐怕指挥太频繁会对流程进行不必要的小调整,但采样不够频繁又会导致估算不准确。
您总是希望在 Moving Horizon Estimation 和模拟器之间使用相同的采样时间。我建议您使用 numpy.linspace
或 numpy.arange
来定义估算器的时间 horizon。
import numpy as np
from gekko import GEKKO
m = GEKKO()
m.time = np.linspace(0,5,11)
print(m.time)
m.time = np.arange(0,5.01,0.5)
print(m.time)
这给出了 horizon 11 个时间点,时间步长为 0.5:
[0. 0.5 1. 1.5 2. 2.5 3. 3.5 4. 4.5 5. ]
如果您的模拟器采用不同的采样间隔进行测量,那么您可以调整 numpy.arange
中的 0.5。
这里是additional example code for MHE. If you are using a physical system instead of a simulator then the sample time for the MHE needs to be the frequency that you are updating your measurements and solving the MHE. Here is the source code for the figure below,它是从 Arduino 设备采样温度数据。
在这种情况下,每秒测量一次温度,MHE 为 re-solved。总时间 horizon 为 120 秒,间隔 3 秒或 np.linspace(0,120,41)
给出 m.time=[0,3,...,117,120]
.
关于在采样率和命令率之间找到良好平衡的第二个问题,采样率通常受到 MHE 求解速度的限制。如果您需要更快的速度,则可以使用卡尔曼滤波器或替代方法。通常,控制器的命令速度越快越好,因为您能够更快地响应干扰。如果您担心过于频繁地移动参数值,那么您可以在 objective.
中使用 DCOST (penalize movement) or DMAX (hard constraint on movement)