How to define a constant velocity mobility model?

4,501 views
Skip to first unread message

Victor

unread,
Feb 25, 2014, 3:59:12 PM2/25/14
to ns-3-...@googlegroups.com
Dear all,

I have looked the example 3 in the NS3 tutorial, in which it defines a constantPositionmobilitymodel in a rectangle area for nodes working in the adhoc mode. I am thinking to replace that model with several nodes moving in a constant speed (speed can different on each node) with the constantvelocitymobilitymodel on a straight line. Can anyone suggest me how to do this? Thanks a lot.

Regards,
Victor 

Victor

unread,
Feb 25, 2014, 4:01:26 PM2/25/14
to ns-3-...@googlegroups.com
Sorry, the nodes are not working in the adhoc mode, but connected to an AP in the tutorial.


在 2014年2月25日星期二UTC下午8时59分12秒,Victor写道:

salma subh

unread,
Feb 25, 2014, 4:08:13 PM2/25/14
to ns-3-...@googlegroups.com
try this >>
 
mobility.SetMobilityModel ("ns3::RandomDirection2dMobilityModel",
                              "Bounds", RectangleValue (Rectangle (0, 50, 0, 50)),
                              "Speed", StringValue ("ns3::ConstantRandomVariable[Constant=20]"),
                              "Pause", StringValue ("ns3::ConstantRandomVariable[Constant=0.2]"));

with speed = 20 m/s and node stop every 0.2 sec for example

Konstantinos

unread,
Feb 25, 2014, 4:19:48 PM2/25/14
to ns-3-...@googlegroups.com
The mobility model has nothing to do with the wifi mode.

You can simply change the mobility model as you suggested from constant position, to constant velocity. 
You can use the SetVelocity method to set individual speeds on nodes.

Victor

unread,
Feb 25, 2014, 4:29:30 PM2/25/14
to ns-3-...@googlegroups.com
Hi Salma,

Thanks for the reply. Just wondering why to use RectangleValue (Rectangle (0, 50, 0, 50)) for a straight line rather than something like RectangleValue (Rectangle (0, 50, 0, 0))?



在 2014年2月25日星期二UTC下午9时08分13秒,salma subh写道:

Victor

unread,
Feb 25, 2014, 4:30:58 PM2/25/14
to ns-3-...@googlegroups.com
That's right indeed. Thanks for that. I will have a try.

Cheers,

在 2014年2月25日星期二UTC下午9时19分48秒,Konstantinos写道:

Victor

unread,
Feb 25, 2014, 6:38:42 PM2/25/14
to ns-3-...@googlegroups.com
Hi, 

I have tried to use the following codes to set up the constant velocity model, it compiles correct but it seems that I cannot trace the position changes for those stanodes. Do I need to set the bounds for the rectangle area as well? However can I do that?

Codes:
  
  MobilityHelper mobility;

  mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
                                 "MinX", DoubleValue (0.0),
                                 "MinY", DoubleValue (0.0),
                                 "DeltaX", DoubleValue (5.0),
                                 "DeltaY", DoubleValue (10.0),
                                 "GridWidth", UintegerValue (3),
                                 "LayoutType", StringValue ("RowFirst"));


  mobility.SetMobilityModel ("ns3::ConstantVelocityMobilityModel",
                             "Velocity", Vector3DValue (Vector(20.0, 0.0, 0.0)));
  mobility.Install (wifiStaNodes);

  Thanks

在 2014年2月25日星期二UTC下午9时19分48秒,Konstantinos写道:

Konstantinos

unread,
Feb 25, 2014, 6:50:12 PM2/25/14
to ns-3-...@googlegroups.com
I remember there was a similar problem with ConstantVelocityModel if you used Velocity as attribute. It was not parsed properly.
You should use the SetVelocity method on each node.
Message has been deleted

Konstantinos

unread,
Feb 26, 2014, 5:31:58 AM2/26/14
to ns-3-...@googlegroups.com


On Wednesday, February 26, 2014 12:10:41 AM UTC, Victor wrote:
I have referred some previous post here: https://groups.google.com/forum/#!msg/ns-3-users/P1m9AK66fsQ/vAybS8b_eJAJ 
and I got the following codes for calling the SetVelocity method. It can compile well, but there's still no position changes of the stanodes being reported. Could you give me some hints on how to code this? Thanks a lot.

  ConstantVelocityHelper staVel;
  Vector spd (10.0,0.0,0.0);
  staVel.SetVelocity(spd);
  

You created a constant vel. helper staVel and set its speed. That's fine up to here.
 
  mobility.SetMobilityModel ("ns3::ConstantVelocityMobilityModel",
                             "Velocity", VectorValue (spd));
  mobility.Install (wifiStaNodes);


You create a mobility helper and set the mobility model model to constantvelocity with a certain speed.
This is not related to the previous mobility helper you created.


What I suggest is:
You do not need to use the ConstantVelocityHelper. There is no need.

Install ConstantVelocityModel as you have done with a generic mobility helper, without the use of Velocity attribute.

  mobility.SetMobilityModel ("ns3::ConstantVelocityMobilityModel");
  mobility.Install (wifiStaNodes);

After you have done this, you get the mobility model of each node and set its speed. That way you can have more control on individual speeds (can use random variable to generate speeds)

        for (uint n=0 ; n < wifiStaNodes.GetN() ; n++)
        {
        Ptr<ConstantVelocityMobilityModel> mob = wifiStaNodes.Get(n)->GetObject<ConstantVelocityMobilityModel>();
        mob->SetVelocity(Vector(speed, 0, 0));
        }
  


在 2014年2月25日星期二UTC下午11时50分12秒,Konstantinos写道:

Victor

unread,
Feb 26, 2014, 5:11:29 PM2/26/14
to ns-3-...@googlegroups.com
Hello Konstantinos, thanks. That really helps.

I also found something interesting here regarding to the constantvelocitymobilitymodel. I have also added the trace commands for tracing the movement of the nodes I defined. But I cannot observe the callback for the position changes. The commands I applied was exactly the same as shown in the tutorial by defining the CourseChange function at the very beginning of the code and add Config::Connect at the end of the codes before starting the simulation. Have you meet with this problem before, or is there anything wrong I did for this? Basically, I think the problem is that I cannot use model->GetPosition(); to get the position of the nodes, however, if I remain the mobilitymodel as what it was in the tutorial or changed to some random based mobility model, such as randomwalk2D, then the position of the nodes can be recorded successfully. I am quite confused here.

Thanks for your help.

在 2014年2月26日星期三UTC上午10时31分58秒,Konstantinos写道:

Konstantinos

unread,
Feb 26, 2014, 5:20:50 PM2/26/14
to ns-3-...@googlegroups.com
The "CourseChange" function will be called when the trace source fires. This is defined as:

TracedCallback<Ptr<const MobilityModel> > ns3::MobilityModel::m_courseChangeTrace
private

Used to alert subscribers that a change in direction, velocity, or position has occurred.

Definition at line 117 of file mobility-model.h.

Referenced by GetTypeId(), and NotifyCourseChange().


http://www.nsnam.org/doxygen/classns3_1_1_mobility_model.html

When you have constant position model, there is NO change of direction, velocity or position. 
With constant velocity, it should fire since there is a change in position.

Victor

unread,
Feb 26, 2014, 5:25:28 PM2/26/14
to ns-3-...@googlegroups.com
Yes, I can understand that. But the problem is that, I cannot see any expected outputs from the tracedcallback when I apply the costantvelocitymobilitymodel here. 

在 2014年2月26日星期三UTC下午10时20分50秒,Konstantinos写道:

Tommaso Pecorella

unread,
Feb 26, 2014, 5:44:28 PM2/26/14
to ns-3-...@googlegroups.com
CourseChange...

It's fired when there's a change in the current node path, i.e.:
1) when the position is abruptly changed, or
2) when the speed is changed (including the movement direction)

If you don't change these, it will not be fired.

Cheers,

T.
Message has been deleted

Victor

unread,
Feb 26, 2014, 5:53:26 PM2/26/14
to ns-3-...@googlegroups.com
Dear Tommaso,

Thanks for your reply. What I want to do is to record the position of the nodes I'm interested over the time horizon. Then I can plot those positions. If the coursechange method cannot be used for this application, then what method should I use to record the positions of the nodes with constant speed?

Cheers,
Victor

在 2014年2月27日星期四UTC+8上午6时44分28秒,Tommaso Pecorella写道:
Message has been deleted

Konstantinos

unread,
Feb 27, 2014, 5:19:54 AM2/27/14
to ns-3-...@googlegroups.com
If you move with constant velocity and direction, then you only need the starting point in order to infer a nodes position. 

Be that as it may, since you want periodic printing of position, you need to create an event for that. 
Use Simulator::Schedule to schedule a printing method.

e.g.
this method prints the positions of ALL nodes

void PrintPositions ()
{
for (uint32_t i=0; i <NodeList::GetNNodes(); i++ )
{
Ptr<MobilityModel> mob = nodes.Get(i)->GetObject<MobilityModel>();
Vector pos = mob->GetPosition ();
std::cout << "POS: x=" << pos.x << ", y=" << pos.y << std::endl;
}

Simulator::Schedule(Seconds(1), MakeCallback(&PrintPositions));
}

in your main you need to schedule it
Simulator::Schedule(Seconds(1), MakeCallback(&PrintPositions));


On Thursday, February 27, 2014 12:32:38 AM UTC, Victor wrote:
Hi Konstantinos,

Sorry for the silly problems I asked. I am so unfamiliar with the programming style with NS3. However, I think I got you now. I have changed the codes without using the CourseChange method. Instead, I use the codes below to generate the position I want: (Ref: https://groups.google.com/forum/#!topic/ns-3-users/godXdo-NirY)

Ptr<MobilityModel> mob = nodes.Get(i)->GetObject<MobilityModel>();
Vector pos = mob->GetPosition ();
std::cout << "POS: x=" << pos.x << ", y=" << pos.y << std::endl;


However, this could only report one position (either start position or end position after moving in a constant speed) when I put these codes before or after the command simulator:Run (); I am interested to report all the positions with some time interval that I want, for example, reported every 1second. So, how can I change the codes to make this possible?

Thanks again for your help. 


Victor

unread,
Feb 27, 2014, 11:34:29 AM2/27/14
to ns-3-...@googlegroups.com
Hi Konstantinos,

Yes, that really helps. It would be good to change the nodes::Get(i) to NodeList::GetNode(i) to make it work without giving errors.

Cheers.

在 2014年2月27日星期四UTC上午10时19分54秒,Konstantinos写道:

xavier ashish

unread,
Aug 13, 2019, 3:55:47 AM8/13/19
to ns-3-users
hi
Mr Tommaso P
sir

can you plz guide me  in implementing two set of mobility model in a network.

what i mean is this,
if i deploy three nodes
i assign one node with RWP mobility and rest of the two nodes will be stationary ( constant position mobility model).
is this possible in ns3

Reply all
Reply to author
Forward
0 new messages