How to use a formula with parameters pos.x, pos.y, vel.x and vel.y ?

44 views
Skip to first unread message

Parth Deodia

unread,
Jul 2, 2014, 8:25:21 PM7/2/14
to ns-3-...@googlegroups.com
Hello,
I want to use a formula with above parameters pos.x, pos.y, vel.x and vel.y of a mobile node. I am getting these values in cout, which is perfectly fine.
But when I am using this values in  formula, it is giving me NAN for all the different positions of the mobile node ?

Also, I want to use the communication range of device used in wifi-adhoc in the formula. But I want the formula to take the value automatically when the two nodes are in range of communication.

I am using this formula to calculate the link expiration time between two ad-hoc mobile nodes. So I want both the nodes to calculate the expiration time when they are in the range of each other i.e. for how long they can communicate before the link expires.

I have attached my code.

Please help.

Thank you.


mywifi-adhoc.cc

Tommaso Pecorella

unread,
Jul 3, 2014, 3:13:15 AM7/3/14
to ns-3-...@googlegroups.com
SERIOUSLY ?

Opps, sorry, my caps-lock gets stuck sometimes. I guess your problem may be due to a copy-paste mistake. You have a global / local scope naming conflict.
double px0;
double py0;
double vx0;
double vy0;
double px1;
double py1;
double vx1;
double vy1;
double T;
double r = 40;

void
Experiment::AdvancePosition0 (Ptr<Node> node0)
{
 
Vector pos0 = GetPosition (node0);
 
Vector vel0 = GetVelocity (node0);
 
double px0 = pos0.x;
 
double py0 = pos0.y;
 
double vx0 = vel0.x;
 
double vy0 = vel0.y;
 
double param = ((pow((vx1 - vx0),2) + pow((vy1 - vy0),2)) * pow(r,2)) - pow((((vx1 - vx0) * (py1 - py0)) - ((vy1 - vy0) * (px1 - px0))),2);
 
double T = (-(((vx1 - vx0) * (px1 - px0)) + ((vy1 - vy0) * (py1 - py0))) +  sqrt(param)) / (pow((vx1 - vx0),2) + (pow((vy1 - vy0),2)));


In each function you used one local scoped variable (which is updated) and one global scoped one (which you didn't update).
As a result, in each function there's a variable with an uninitialized value.
This may be the root of your problem.

However, I'd strongly suggest to double check your code design. Such a mixture of local and global scoped variables usually is the symptom of some other kind of issue, Design issues usually.

T.

Parth Deodia

unread,
Jul 4, 2014, 8:00:56 AM7/4/14
to ns-3-...@googlegroups.com
THANK YOU Tommaso Pecorella for showing the correct direction.


--
You received this message because you are subscribed to a topic in the Google Groups "ns-3-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ns-3-users/y5z1O8M6gno/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ns-3-users+...@googlegroups.com.
To post to this group, send email to ns-3-...@googlegroups.com.
Visit this group at http://groups.google.com/group/ns-3-users.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages