Netlogo 中的二维比例导航

Two-dimensional Proportional Navigation in Netlogo

我正在尝试在 Netlogo 中实现二维比例导航,因为它是由这些公式定义的:

其中 v_r 是速度差,r 是视线,phi 是角度。 Theta 应该是视线的变化,N 是导航常数。因为我是二维的,所以我正在使用带有罪恶的公式。

我有点迷茫,因为在我当前的实现中,两个移动的物体根本没有发生碰撞。

所以,目前我正在这样计算 v_r 和 r,我相当确定这是正确的,因为使用预定义的 positions/orientations 进行测试会产生所需的结果:

;; line of sight
let rx [xcor] of target - xcor
let ry [ycor] of target - ycor
; difference in velocity components
let vx ([dx] of target * speed) - dx * predator-speed
let vy ([dy] of target * speed) - dy * predator-speed

角度是这样计算的,应该也是正确的:

let dot  (vx * rx + vy * ry)
let det  (vx * ry - vy * rx)
set angle atan det dot

把它们放在一起,theta 是这样的:

let theta (sqrt (vx ^ 2 + vy ^ 2) * sin angle) / sqrt(rx ^ 2 + ry ^ 2)

然后我计算与之前计算的 theta 的差异,因为第一个公式使用它的微分,将它乘以常数并将其转换为度数:

let delta-theta theta - theta-old
set theta-old theta
let turn-rate (delta-theta * N * 180 / pi)
turn-at-most turn-rate max-hunt-turn

当我 运行 它时,会发生以下情况(两只乌龟的速度相同,一只向右移动,一只向上移动)(对于 3 到 5 之间的大多数 N 值变化不大)

我想我在理解最后一步时有一些错误,因为我确实认为这些组件应该没问题。 提出一个问题:为了改变航向,我如何处理 theta(或 delta theta)?

编辑:这里是实际发生的地方:

to turn-at-most [turn max-turn]  ;; turtle procedure
  ifelse abs turn > max-turn
    [ ifelse turn > 0
        [ rt max-turn ]
        [ lt max-turn ] ]
    [ rt turn ]
end

编辑 2:目前的状态是,我认为为 theta 给出的公式实际上已经是 theta 的导数,因为使用 theta 而不是 delta-theta 给了我想要的行为(或者至少它看起来像)。我仍然需要对此进行确认,但我会保持线程更新。

这不是答案,但评论太长了。以下是使用您的代码的完整模型。在我看来角度的计算很好,但是你确定theta的公式吗?无论捕食者的起始角度如何,我得到的 theta 值都非常小(打印有弧度到度数校正)。

globals [N]

breed [predators predator]
breed [preys prey]
turtles-own [speed]
predators-own [angle theta-old]

to setup
  clear-all
  create-preys 1
  [ setxy 0 10
    set heading 90
    set speed 1
    set color blue
  ]
  create-predators 1
  [ setxy 0 0
    set heading 0         ; experiment with this
    set speed 1
    set color red
  ]
  set N 4
  reset-ticks
end

to go
  ask one-of predators
  [ let target one-of preys
    ;; line of sight
    let rx [xcor] of target - xcor
    let ry [ycor] of target - ycor
    ; difference in velocity components
    let vx ([dx] of target * [speed] of target) - dx * speed
    let vy ([dy] of target * [speed] of target) - dy * speed
    ; calculate change in direction
    let dot  (vx * rx + vy * ry)
    let det  (vx * ry - vy * rx)
    set angle atan det dot
    type "Angle is: " print angle
    let theta (sqrt (vx ^ 2 + vy ^ 2) * sin angle) / sqrt (rx ^ 2 + ry ^ 2)
    type "Theta is: " print round (180 * theta / pi)
    let delta-theta theta - theta-old
    type "change in theta is: " print round (180 * delta-theta / pi)
    set theta-old theta
    let turn-rate (delta-theta * N * 180 / pi)
    turn-at-most turn-rate 360
  ]
  ask turtles [forward speed]
end

to turn-at-most [turn max-turn]  ;; turtle procedure
  ifelse abs turn > max-turn
    [ ifelse turn > 0
        [ rt max-turn ]
        [ lt max-turn ] ]
    [ rt turn ]
end

NetLogo 没有使用公式,而是有一些很好的原语来处理方向。这似乎是 subtract-headings.

的工作

已经确认theta已经是差值,所以不用再计算delta-theta。 此外,坐标的计算没有考虑到世界的环面形状,这造成了额外的混乱。

; calculation of LOS using shortest distance in a torus world
let dist-target [distance myself] of target
let angle-target towards target
let rx sin angle-target * dist-target
let ry cos angle-target * dist-target
; difference in velocity components
let vx ([dx] of target * speed) - dx * predator-speed
let vy ([dy] of target * speed) - dy * predator-speed

; angle
let dot  (vx * rx + vy * ry)
let det  (vx * ry - vy * rx)
let angle 0
set angle atan det dot
; finally, theta
let theta (sqrt (vx ^ 2 + vy ^ 2) * sin angle) / sqrt(rx ^ 2 + ry ^ 2) / pi * 180
turn-at-most theta * interceptN max-hunt-turn