在节点B上,确保启用了mobility
,并设置了location
和origin
,这样您就处于以米为单位的本地坐标系中。如果您的坐标系没有地理参考,则可以将origin
设置为[NaN, NaN]
:
def node = agentForService org.arl.unet.Services.NODE_INFO
node.origin = [Float.NaN, Float.NaN] // or GPS coordinates
node.location = [0, 0, 0] // or wherever you want to start
node.mobility = true
现在,当您在节点B上收到数据报时,您的代理可以将node.speed
和node.heading
设置为您所需的速度和方向。例如:
node.heading = 90 // head East
node.speed = 1 // at 1 m/s
实际上,您可能需要计算到达所需路点的航向。
您的代理可以监控节点的位置(可能使用TickerBehavior
),当到了停止时间(例如,您已经到达足够接近您的路点[2,0,0]
)时,将速度设置为0:
// if within 1 m of waypoint, stop
if (MathUtils.distance(node.location, [2,0,0] as double[]) < 1) {
node.speed = 0
}