【问题标题】:Python: Overshoot target, need vectors or PID tuning?Python:超调目标,需要向量或 PID 调整?
【发布时间】:2019-12-05 22:21:19
【问题描述】:

所以,我正在使用无人机,我想将它放置在两个物体之间的中心,但是,无人机将超出移动操作,然后继续以相反方向返回中心,超出再次并无休止地这样做。 有没有办法补偿或使用某种 PID 使其不会超出中心?

要查看实时的样子: UAV cant center

我现在使用的代码:

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 

【问题讨论】:

  • 我在视频中看到并在代码中注意到,无人机在一个方向上来回移动,我认为这是因为 +0.2,-0.2。也许您可以相对分配它并随着时间的推移使其变得体面。也许你可以使用sensor.leftsensor.right之间的差异来调整它。
  • 根据距离,它会将速度值更改为 + 或 - 0.2。加号使它向左,减去向右。
  • 你能给它多低的速度?我只需要速度刻度与传感器值之间的差异。这样它的速度会随着它越来越接近中心而降低
  • 所以发生的事情是,它向左移动,到达中心,仍然有动力,过冲,然后尝试通过返回 -0.2 来纠正。应该对向量做一些事情,在到达该点之前通过降低速度或增加向后推力使其停止。
  • 我也想看看这些传感器返回什么值,如果说无人机仅在sensor.left 等于sensor.right 时位于中心可能是不现实的。考虑在这两个值之间定义一个可接受的差异量,而不是要求它们完全相等

标签: python python-3.x vector


【解决方案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版本来使用这个近似相等运算符,但你可以在一个小函数中完成它并在你的条件语句中使用它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-11-12
    • 1970-01-01
    • 1970-01-01
    • 2017-08-20
    • 1970-01-01
    • 2020-12-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多