samples/main-random-walk.cc
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Wed, 04 Jul 2007 10:27:49 +0200
changeset 1583 470803bf9961
parent 1580 0d2cf8839aee
child 1612 0981e5bb0cec
permissions -rw-r--r--
use new MobilityModel::Get and remove old one.

/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */

#include "ns3/ptr.h"
#include "ns3/mobility-model.h"
#include "ns3/mobility-model-notifier.h"
#include "ns3/random-walk-mobility-model.h"
#include "ns3/default-value.h"
#include "ns3/command-line.h"
#include "ns3/simulator.h"
#include "ns3/nstime.h"

using namespace ns3;

static void 
CourseChange (Ptr<const MobilityModel> position)
{
  Position pos = position->Get ();
  std::cout << Simulator::Now () << ", pos=" << position << ", x=" << pos.x << ", y=" << pos.y
            << ", z=" << pos.z << std::endl;
}

int main (int argc, char *argv[])
{
  Bind ("RandomWalkMinSpeed", "2");
  Bind ("RandomWalkMaxSpeed", "3");
  Bind ("RandomWalkMode", "Time");
  Bind ("RandomWalkModeDistance", "20");
  Bind ("RandomWalkModeTime", "2s");

  CommandLine::Parse (argc, argv);

  Ptr<MobilityModelNotifier> notifier = Create<MobilityModelNotifier> ();
  Ptr<RandomWalkMobilityModel> position = Create<RandomWalkMobilityModel> ();
  position->AddInterface (notifier);
  notifier->RegisterListener (MakeCallback (&CourseChange));

  Simulator::StopAt (Seconds (20.0));

  Simulator::Run ();
  
  return 0;
}