Difference between revisions of "MobilityHelper"

From Nsnam
Jump to: navigation, search
 
 
(4 intermediate revisions by the same user not shown)
Line 5: Line 5:
 
* Apply the helper to a <code>NodeContainer</code> to position the nodes and assign them mobility models
 
* Apply the helper to a <code>NodeContainer</code> to position the nodes and assign them mobility models
  
A simple example is in <tt>samples/main-grid-topology.cc</tt> in the repositories & packages.
+
A simple example is in <tt>samples/main-grid-topology.cc</tt> in the repositories & packages.  Consult the doxygen or headers to figure out which typeids may be applied, as well as their parameters.
  
 
== Position Allocators ==
 
== Position Allocators ==
Line 18: Line 18:
 
   // and the y interval between each object is 20 meters
 
   // and the y interval between each object is 20 meters
 
   mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
 
   mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
                                 "MinX", Double (-100.0),
+
                                 "MinX", DoubleValue(-100.0),
                                 "MinY", Double (-100.0),
+
                                 "MinY", DoubleValue(-100.0),
                                 "DeltaX", Double (5.0),
+
                                 "DeltaX", DoubleValue(5.0),
                                 "DeltaY", Double (20.0),
+
                                 "DeltaY", DoubleValue(20.0),
                                 "GridWidth", Uinteger (20),
+
                                 "GridWidth", UintegerValue(20),
                                 "LayoutType", String ("RowFirst"));
+
                                 "LayoutType", StringValue("RowFirst"));
 +
</pre></code>
 +
 
 +
=== Manual Allocation ===
 +
<code><pre>
 +
  MobilityHelper mobility;
 +
  // Put everybody into a line
 +
  Ptr<ListPositionAllocator> initialAlloc =
 +
    CreateObject<ListPositionAllocator> ();
 +
  for (uint32_t i = 0; i < mainNodes.GetN (); ++i) {
 +
      initialAlloc->Add (Vector (i, 0., 0.));
 +
  }
 +
  mobilityHelper.SetPositionAllocator(initialAlloc);
 
</pre></code>
 
</pre></code>
  
Line 31: Line 43:
  
 
<code><pre>
 
<code><pre>
 +
  MobilityHelper mobility;
 
   // each object will be attached a static position.
 
   // each object will be attached a static position.
 
   // i.e., once set by the "position allocator", the
 
   // i.e., once set by the "position allocator", the
 
   // position will never change.
 
   // position will never change.
 
   mobility.SetMobilityModel ("ns3::StaticMobilityModel");
 
   mobility.SetMobilityModel ("ns3::StaticMobilityModel");
</code></pre>
+
</pre></code>
 +
 
 +
=== Random 2D Direction ===
 +
 
 +
<code><pre>
 +
  MobilityHelper mobility;
 +
  mobility.SetMobilityModel("ns3::RandomDirection2dMobilityModel",
 +
                            "Bounds", Rectangle(0, 100, 0, 100),
 +
                            "Speed", ConstantVariable(2000),
 +
                            "Pause", ConstantVariable(0.2));
 +
</pre></code>
 +
 
 +
[[Category:Samples]]

Latest revision as of 13:31, 25 June 2008

Here's the basic usage for the mobility helper:

  • Create a MobilityHelper object
  • Set the options on it, i.e. what positioning scheme to use and what mobility models to assign
  • Apply the helper to a NodeContainer to position the nodes and assign them mobility models

A simple example is in samples/main-grid-topology.cc in the repositories & packages. Consult the doxygen or headers to figure out which typeids may be applied, as well as their parameters.

Position Allocators

Grid

  MobilityHelper mobility;
  // setup the grid itself: objects are layed out
  // started from (-100,-100) with 20 objects per row, 
  // the x interval between each object is 5 meters
  // and the y interval between each object is 20 meters
  mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
                                 "MinX", DoubleValue(-100.0),
                                 "MinY", DoubleValue(-100.0),
                                 "DeltaX", DoubleValue(5.0),
                                 "DeltaY", DoubleValue(20.0),
                                 "GridWidth", UintegerValue(20),
                                 "LayoutType", StringValue("RowFirst"));

Manual Allocation

  MobilityHelper mobility;
  // Put everybody into a line
  Ptr<ListPositionAllocator> initialAlloc = 
    CreateObject<ListPositionAllocator> ();
  for (uint32_t i = 0; i < mainNodes.GetN (); ++i) {
      initialAlloc->Add (Vector (i, 0., 0.));
  }
  mobilityHelper.SetPositionAllocator(initialAlloc);

Mobility Model

Static Mobility

  MobilityHelper mobility;
  // each object will be attached a static position.
  // i.e., once set by the "position allocator", the
  // position will never change.
  mobility.SetMobilityModel ("ns3::StaticMobilityModel");

Random 2D Direction

  MobilityHelper mobility;
  mobility.SetMobilityModel("ns3::RandomDirection2dMobilityModel",
                            "Bounds", Rectangle(0, 100, 0, 100),
                            "Speed", ConstantVariable(2000),
                            "Pause", ConstantVariable(0.2));