我希望节点 A 发送节点 B 应该移动的轨迹的详细信息。
例如,我希望节点 B 以 1m/s 的速度移动到位置 [2.m,0,0]。我将发送一个带有数据 [2,0,0,1] 的数据报。现在节点 B 如何从接收到的数据报中提取信息并相应地改变其轨迹?
我希望节点 A 发送节点 B 应该移动的轨迹的详细信息。
例如,我希望节点 B 以 1m/s 的速度移动到位置 [2.m,0,0]。我将发送一个带有数据 [2,0,0,1] 的数据报。现在节点 B 如何从接收到的数据报中提取信息并相应地改变其轨迹?
在节点 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
实际上,您可能想要计算到所需航路点的航向。
您的代理可以监控节点的位置(可能使用 a 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
}