CIrcular mobility

189 views
Skip to first unread message

Luiz Baroni

unread,
Mar 13, 2015, 9:59:16 AM3/13/15
to ns-3-...@googlegroups.com
Hello everyone,

I'm trying to creat my own mobility model, but i'm having problems making the nodes walk in a circle. I have all the info i need, i guess, like the radius of the circle, the initial position and the center. but i don't know if my problem is about the mathematical concept of circle, or if i'm doing it wrong in the code. How do i make a node walk in a circle? or semi-circle?
Here's what i'm trying:

void
PaparazziMobilityModel::Arch(Vector current)
{
  // PI/2 -> Pico do Arco, 3*PI/2 - > Vale do Arco
  NS_LOG_FUNCTION_NOARGS ();
  double angle = 3*M_PI/2;
  double speed = m_speed->GetValue ();
  double time = (Simulator::Now().GetSeconds());
  //std::cout << " speed:" << speed << std::endl;
  double angleSpeed = speed / m_radius;
  angle = angle + angleSpeed;
  //Vector pos;
  /*center.x = current.x;
  center.y = current.y - m_radius;
  center.z =  current.z;*/
  double dx = speed*cos(angle);
  double dy = speed*sin(angle);
  double dz = current.z;
  /*double dx = sin(angle) * speed - current.x;
  double dy = cos(angle) * speed - current.y;
  double dz = current.z;*/
  current.x = current.x + dx * time;
  current.y = current.y + dy * time;
  current.z = dz;
  //std::cout << " x:" << dx << " y:" << dy;
  //Vector next = (center.x + m_radius * std::cos(PI/2), center.y + m_radius * std::sin(PI/2), center.z);
  //double k = speed / std::sqrt (dx*dx + dy*dy + dz*dz);
  m_helper.SetVelocity(Vector(current.x,current.y,current.z));
  //return pos;
}

Tommaso Pecorella

unread,
Mar 13, 2015, 11:29:36 AM3/13/15
to ns-3-...@googlegroups.com
Hi,

I guess you need to understand a bit better how a mobility model works.
Please study the MobilityModel class public and virtual functions, and try to figure out what a caller is expecting from your model.
Suggestion: you are not saving the time of the last update

Hope this helps,

T.

Luiz Baroni

unread,
Mar 23, 2015, 7:58:11 AM3/23/15
to ns-3-...@googlegroups.com
Hello,

What is the connection of time and "things happening" (you are not saving the time of the last update) in ns3? I mean, because it is recursive, the only way to keep track of my last position is time? i studied some other mobility models, but they are all random, and i need a deterministic one...

Tommaso Pecorella

unread,
Mar 23, 2015, 11:20:33 AM3/23/15
to ns-3-...@googlegroups.com
Events are not recursive. They are iterative.
You have one event at a given time, then another event in another time. You may be moving in a circle, but what matters is where you are NOW, i.e., when the last event happened.
You can know where you are now only if you know where you was the last time you checked. I.e., you need to save when and where you was when the last check happened.
And no, updates are NOT periodic. They don't need to be, there's no need to have periodic updates, they only would make thing slow.

Have fun (but study the model more).

T.
Reply all
Reply to author
Forward
0 new messages