Installing WaypointMobilityModel

603 views
Skip to first unread message

Tiago Cerqueira

unread,
Apr 6, 2014, 7:10:55 PM4/6/14
to ns-3-...@googlegroups.com
Hey there,
I want to run a simulation with a node that travels a specified path. I used the following code to try and do this:
//Install mobility model for the UEs
  mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
                                  "MinX", DoubleValue (0.0),
                                  "MinY", DoubleValue (0.0),
                                  "DeltaX", DoubleValue (10.0),
                                  "DeltaY", DoubleValue (20.0),
                                  "GridWidth", UintegerValue (3),
                                  "LayoutType", StringValue ("RowFirst"));
 
   mobility.SetMobilityModel ("ns3::RandomWalk2dMobilityModel",
                              "Bounds", RectangleValue (Rectangle (-50, 50, -50, 50)));
   mobility.Install(ueNodes);
   //Install waypoint based mobility to the last UE in container
   mobility.SetMobilityModel("ns3::WaypointMobilityModel");
   Ptr<WaypointMobilityModel> ueWaypointMobility = CreateObject<WaypointMobilityModel>();
   ueWaypointMobility->SetPosition(Vector (10.0, 10, 0.0));

   ueWaypointMobility->AddWaypoint(Waypoint(Seconds(1.0),Vector(10.0,9,0)));
   ueWaypointMobility->AddWaypoint(Waypoint(Seconds(2.0), Vector(10.0,8,0)));
   ueWaypointMobility->AddWaypoint (Waypoint (Seconds (3.0),Vector (10.0, 7, 0)));
   ueWaypointMobility->AddWaypoint(Waypoint (Seconds (4.0),Vector (10.0, 6,0)));
   mobility.Install(ueNodes.Get(numberOfUEs-1));
From what I gather, the waypoint mobility model isn't being installed, because the last node behaves in a random walk fashion. And if I manually install mobility to each node, the last node on the container is just stopped.
Can anyone please point me in the right direction? If it's necessary, I'm willing to attach the rest of my simulation.
Please let me know if you need more information.
Thanks

Konstantinos

unread,
Apr 7, 2014, 5:02:09 AM4/7/14
to ns-3-...@googlegroups.com
There are two problems in your code.

1) You have installed 2 mobility models on the last UE. 
this installs on ALL nodes
mobility.Install(ueNodes);
This only on the last
mobility.Install(ueNodes.Get(numberOfUEs-1));

2) You have installed a waypoint model on the last node, but you have specified the waypoints on new instance of a waypoint (not the one you installed). You have to specify the "ueWaypointMobilty" as the model to be installed on the node.

Tiago Cerqueira

unread,
Apr 7, 2014, 6:56:00 AM4/7/14
to ns-3-...@googlegroups.com
Thank you very much for your reply!
I knew that issuing mobility.Install(ueNodes) would install that mobility model in all nodes, but I thought that installing a different one after that would override the previous mobility model and install the new model on the node. I'm still new to ns-3, sorry :(.
As for my second problem, I'm having problems understanding what you mean... How can I specify the ueWaypointMobility to install on the node?
Can you share a snippet of a working code?

Tiago Cerqueira

unread,
Apr 7, 2014, 1:23:27 PM4/7/14
to ns-3-...@googlegroups.com
Ok, I think I fixed it, but I'm not really sure if it's the right way to implement this in a script. I used the AggregateObject to link the WaypointMobilityModel to the node.
My code is:
//Install mobility model for the UEs
  mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
                                  "MinX", DoubleValue (0.0),
                                  "MinY", DoubleValue (0.0),
                                  "DeltaX", DoubleValue (10.0),
                                  "DeltaY", DoubleValue (20.0),
                                  "GridWidth", UintegerValue (3),
                                  "LayoutType", StringValue ("RowFirst"));
 
   mobility.SetMobilityModel ("ns3::RandomWalk2dMobilityModel",
                              "Bounds", RectangleValue (Rectangle (-50, 50, -50, 50)));
   mobility.Install(ueNodes.Get(0));
   //Install waypoint based mobility to the last UE in container
   mobility.SetMobilityModel("ns3::WaypointMobilityModel");
   Ptr<WaypointMobilityModel> ueWaypointMobility = CreateObject<WaypointMobilityModel>();
   ueWaypointMobility->SetPosition(Vector (10.0, 10, 0.0));

   ueWaypointMobility->AddWaypoint(Waypoint(Seconds(1.0),Vector(10.0,9,0)));
   ueWaypointMobility->AddWaypoint(Waypoint(Seconds(2.0), Vector(10.0,8,0)));
   ueWaypointMobility->AddWaypoint (Waypoint (Seconds (3.0),Vector (10.0, 7, 0)));
   ueWaypointMobility->AddWaypoint(Waypoint (Seconds (4.0),Vector (10.0, 6,0)));
   ueNodes.Get(numberOfUEs-1)->AggregateObject(ueWaypointMobility);
   mobility.Install(ueNodes.Get(1));
Am I doing this the right way?
Thanks,
Tiago

Tiago Cerqueira

unread,
Apr 7, 2014, 2:03:05 PM4/7/14
to ns-3-...@googlegroups.com
Yup, your solution makes a lot more sense.
Thanks for helping me!

Segunda-feira, 7 de Abril de 2014 18:35:48 UTC+1, Konstantinos escreveu:
No, I do not think it is 100% correct. 

I would recommend something like this:

//Install waypoint based mobility to the last UE in container
 mobility
.SetMobilityModel("ns3::WaypointMobilityModel");

 mobility
.Install(ueNodes.Get(1));

Now node_1 has a Waypoint installed but without any waypoints.
Get a smart pointer from that mobility model from that node. This does not create a new mobility model, it is just the one installed on your node; hence pointer! We can not get directly the Waypoint model, but the basic abstract mobility model, which then we 'cast' to waypoint.

Ptr<WaypointMobilityModel> ueWaypointMobility = DynamicCast<WaypointMobilityModel>( ueNodes.Get(1)->GetObject<MobilityModel>());

then you can add the waypoints. 

Kevin Lau

unread,
Apr 25, 2014, 2:44:36 AM4/25/14
to ns-3-...@googlegroups.com
This was helpful, thanks!


On Monday, April 7, 2014 10:35:48 AM UTC-7, Konstantinos wrote:
No, I do not think it is 100% correct. 

I would recommend something like this:

//Install waypoint based mobility to the last UE in container
 mobility
.SetMobilityModel("ns3::WaypointMobilityModel");

 mobility
.Install(ueNodes.Get(1));

Now node_1 has a Waypoint installed but without any waypoints.
Get a smart pointer from that mobility model from that node. This does not create a new mobility model, it is just the one installed on your node; hence pointer! We can not get directly the Waypoint model, but the basic abstract mobility model, which then we 'cast' to waypoint.

Ptr<WaypointMobilityModel> ueWaypointMobility = DynamicCast<WaypointMobilityModel>( ueNodes.Get(1)->GetObject<MobilityModel>());

then you can add the waypoints. 
 ueWaypointMobility->AddWaypoint(Waypoint(Seconds(1.0),Vector(10.0,9,0)));
 ueWaypointMobility
->AddWaypoint(Waypoint(Seconds(2.0), Vector(10.0,8,0)));
 ueWaypointMobility
->AddWaypoint (Waypoint (Seconds (3.0),Vector (10.0, 7, 0)));
 ueWaypointMobility
->AddWaypoint(Waypoint (Seconds (4.0),Vector (10.0, 6,0)));
On Monday, April 7, 2014 6:23:27 PM UTC+1, Tiago Cerqueira wrote:

Konstantinos

unread,
Apr 7, 2014, 1:35:48 PM4/7/14
to ns-3-...@googlegroups.com
No, I do not think it is 100% correct. 

I would recommend something like this:

//Install waypoint based mobility to the last UE in container
 mobility
.SetMobilityModel("ns3::WaypointMobilityModel");

 mobility
.Install(ueNodes.Get(1));

Now node_1 has a Waypoint installed but without any waypoints.
Get a smart pointer from that mobility model from that node. This does not create a new mobility model, it is just the one installed on your node; hence pointer! We can not get directly the Waypoint model, but the basic abstract mobility model, which then we 'cast' to waypoint.

Ptr<WaypointMobilityModel> ueWaypointMobility = DynamicCast<WaypointMobilityModel>( ueNodes.Get(1)->GetObject<MobilityModel>());

then you can add the waypoints. 
 ueWaypointMobility->AddWaypoint(Waypoint(Seconds(1.0),Vector(10.0,9,0)));
 ueWaypointMobility
->AddWaypoint(Waypoint(Seconds(2.0), Vector(10.0,8,0)));
 ueWaypointMobility
->AddWaypoint (Waypoint (Seconds (3.0),Vector (10.0, 7, 0)));
 ueWaypointMobility
->AddWaypoint(Waypoint (Seconds (4.0),Vector (10.0, 6,0)));

On Monday, April 7, 2014 6:23:27 PM UTC+1, Tiago Cerqueira wrote:

yi chung tseng

unread,
Sep 23, 2015, 5:46:21 AM9/23/15
to ns-3-users
this was really helpful thx

Tiago Cerqueira於 2014年4月7日星期一 UTC+8上午7時10分55秒寫道:
Reply all
Reply to author
Forward
Message has been deleted
0 new messages