Re: View Position in time.

41 views
Skip to first unread message
Message has been deleted

Pavel Boyko

unread,
Jan 31, 2011, 2:26:30 AM1/31/11
to ns-3-...@googlegroups.com
This code sniplet should help (direction part is 2D). You should
call it once when the simulation begins.

void
PositionMonitor::ReportPosition ()
{
NodeContainer const & n = NodeContainer::GetGlobal ();
for (NodeContainer::Iterator i = n.Begin (); i != n.End (); ++i)
{
Ptr<Node> node = *i;
std::string name = Names::FindName (node);
Ptr<MobilityModel> mob = node->GetObject<MobilityModel> ();
if (! mob) continue;

Vector pos = mob->GetPosition ();

PrintPosition (name, pos.x, pos.y);

Vector speed = mob->GetVelocity ();
double angle = 0;
if (speed.x == 0 && speed.y == 0 && speed.z == 0)
angle = -90;
else
angle = atan2 (-speed.y, speed.x) * 180 / M_PI;

PrintDirection (name, angle);
}

Simulator::Schedule (m_period, &PositionMonitor::ReportPosition, this);
}

Best regards,
Pavel


On Mon, Jan 31, 2011 at 5:56 AM, david arzola <arzo...@gmail.com> wrote:
> Hi, David. I'm making a mobility simulation in 3D. I want to know if
> someone knows how to see the positions of nodes every 0.5 sec (call
> function of position every half second) or so, because I would  like
> to see in what position are the nodes and their speed.
>
> Thanks in advance.
>
> --
> You received this message because you are subscribed to the Google Groups "ns-3-users" group.
> To post to this group, send email to ns-3-...@googlegroups.com.
> To unsubscribe from this group, send email to ns-3-users+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/ns-3-users?hl=en.
>
>

david arzola

unread,
Jan 31, 2011, 3:22:48 AM1/31/11
to ns-3-users
I will use it since I was 5 minutes.
Thank you very much Pavel.

On 31 ene, 07:26, Pavel Boyko <pavel.bo...@gmail.com> wrote:
>   This code sniplet should help (direction part is 2D). You should
> call it once when the simulation begins.
>
> void
> PositionMonitor::ReportPosition ()
> {
>   NodeContainer const & n = NodeContainer::GetGlobal ();
>   for (NodeContainer::Iterator i = n.Begin (); i != n.End (); ++i)
>     {
>       Ptr<Node> node = *i;
>       std::string name = Names::FindName (node);
>       Ptr<MobilityModel> mob = node->GetObject<MobilityModel> ();
>       if (! mob) continue;
>
>       Vector pos = mob->GetPosition ();
>
>       PrintPosition (name, pos.x, pos.y);
>
>       Vector speed = mob->GetVelocity ();
>       double angle = 0;
>       if (speed.x == 0 && speed.y == 0 && speed.z == 0)
>         angle = -90;
>       else
>         angle = atan2 (-speed.y, speed.x) * 180 / M_PI;
>
>       PrintDirection (name, angle);
>     }
>
>   Simulator::Schedule (m_period, &PositionMonitor::ReportPosition, this);
>
> }
>
>   Best regards,
>   Pavel
>

Pavel Boyko

unread,
Jan 31, 2011, 3:53:56 AM1/31/11
to ns-3-...@googlegroups.com
By the way, question on how to do periodic position polling is quite
popular on this list, I can publish whole PositionMonitor class with
pure virtual, say, DoReportPosition(node, pos) for code review. Does
anybody support this? (I need at least 5 votes to proceed :)

Pavel

mariem thaalbi

unread,
Jan 31, 2011, 4:53:21 AM1/31/11
to ns-3-...@googlegroups.com
Sure, your class will be helpfull. Can u publish it 
thanks Pavel

2011/1/31 Pavel Boyko <pavel...@gmail.com>



--
--------------------------------------

Mariem Thaalbi

Ingénieur télécommunications
mariem....@ieee.org

david arzola

unread,
Jan 31, 2011, 4:53:31 AM1/31/11
to ns-3-users
The votes you deserve;)

Martin Giachino

unread,
Jan 31, 2011, 7:07:12 AM1/31/11
to ns-3-...@googlegroups.com
I agree, it'll be very usefull

Martín


2011/1/31 david arzola <arzo...@gmail.com>
The votes you deserve;)

--

Fidbek

unread,
Feb 3, 2011, 5:20:53 PM2/3/11
to ns-3-users
would be great :)

Pavel Boyko

unread,
Feb 6, 2011, 6:12:28 AM2/6/11
to ns-3-...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages