2

I want node A to send the details of the trajectory in which node B should move.

For example, I want node B to move to location [2.m,0,0] with a speed 1m/s. I will send a datagram with data [2,0,0,1]. Now how can node B extract the information from the received datagram to and change its trajectory accordingly?

notthetup
  • 1,129
  • 9
  • 17

1 Answers1

2

On node B, ensure that mobility is enabled, and the location and origin are set, so that you're in local coordinate systems in meters. If your coordinate system is not geo-referenced, you can set origin to [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

Now, when you receive your datagram on node B, your agent can set the node.speed and node.heading to your desired speed and heading. For example:

node.heading = 90          // head East
node.speed = 1             // at 1 m/s

In reality, you may want to compute the heading to your desired waypoint.

Your agent can monitor the position of the node (perhaps using a TickerBehavior), and when it's time to stop (e.g. you've reached close enough to your way point [2,0,0]), set the speed to 0:

// if within 1 m of waypoint, stop
if (MathUtils.distance(node.location, [2,0,0] as double[]) < 1) {
  node.speed = 0
}
Mandar Chitre
  • 2,110
  • 6
  • 14