所以,我正在使用无人机,我想将其放置在两个物体之间的中心,但是,无人机将超过移动操作,然后继续以相反的方向返回中心,再次超调并无休止地执行此操作。 有没有办法补偿,或者使用某种PID使其不会超过中心?
要查看实时外观,请执行以下操作: 无人机倾斜中心
我现在使用的代码:
if (sensor.left > sensor.right):
velocity_x = 0.2
print('Moving left')
if (sensor.left < sensor.right):
velocity_x = -0.2
print('Moving right')
if (sensor.left == sensor.right):
velocity_x = 0
uav.move(velocity_x,velocity_y)
有什么建议如何让它保持更稳定吗? 我相信向量更适合保持稳定,但没有关于使用什么的参考点。我在网上看到一些使用矢量的教程,但它们遇到了同样的"过调"问题。
下面是传感器和调试信息的输出: n中心,停止! 在中心,倒车速度!
front=1.924
back=0.66
left=0.516
right=0.447
Moving left
Front = 1.924
Back = 0.66
Left = 0.516
Right = 0.447
Vel X = 0.0
Vel Y = 0.1
--------------------------------
front=1.926
back=0.669
left=0.525
right=0.445
Moving left
Front = 1.926
Back = 0.669
Left = 0.525
Right = 0.445
Vel X = 0.0
Vel Y = 0.1
--------------------------------
front=1.921
back=0.668
left=0.535
right=0.445
Moving left
Front = 1.921
Back = 0.668
Left = 0.535
Right = 0.445
Vel X = 0.0
Vel Y = 0.1
--------------------------------
front=1.912
back=0.676
left=0.54
right=0.443
Moving left
Front = 1.912
Back = 0.676
Left = 0.54
Right = 0.443
Vel X = 0.0
Vel Y = 0.1
我相信这样的东西会根据硬件限制来接受值范围,代码是这样的:
if (sensor.left > sensor.right):
velocity_x = 0.2/i #<====
print('Moving left to center')
if (sensor.left < sensor.right):
velocity_x = -0.2/i #<====
print('Moving right to center')
if (sensor.left == sensor.right):
velocity_x = 0
i+=0.1 # i initial value is equal to 1 <====
uav.move(velocity_x,velocity_y)
或者可能想要更改最后一个 if 语句,因为期望现实世界中的这些传感器完全相同是不公平的。
from __experimental__ import approx
if (sensor.left ~= sensor.right):
velocity_x = 0
使用这个近似相等运算符取决于您的 python 版本,但您可以在一个小函数中执行此操作并在条件语句中使用它。