[ns] How to get a mobile node's current position
Liceven
feixianyexin at 163.com
Thu Jul 24 23:35:17 PDT 2008
Dear Jalaluddin,
Thanks very much for your great suggestion. But it is difficult for me to
modify some cc file to reach the target. And I think I should spend more
time to get understood how TCL communicates with C++ class.
Just as the same as what I said before, there is a way to get a mobile
node’s position. The TCL script codes are shown as bellow:
set node(1) [$ns node]
$ node(1) set X_ 15.0
$ node(1)set Y_ 15.0
$ node(1)set Z_ 0.0
...
for {set i 0} {$i < $val(nn)} {incr i} {
$ns initial_node_pos $node($i) 60
}
….
the script ‘set x_pos [$node(1) set X_]’ could be used to get the x
value of the mobile node at the time 0.0.
So, I am wondering may I write a proc used to record this x value every 0.5
second. The tcl codes are:
proc record {} {
global filepr d pt l lambda gt gr pi node(1) #here I just want to record
node 1
set ns [Simulator instance]
set time 0.5;# record 0.5 second
set pr 0.0
set m [expr (1 /(4 * $pi * $d))]
set pr [expr ($pt * $gr * $gt * $m * $m / 1)]
set d [expr ($d+10)]
# set xp [$n1 set X_]
set now [$ns now]
set node_x [$node(1) set X_]
set node_y [$node(1) set Y_]
puts $filepr "$now\t$pr\t$node_x\t$node_y"
$ns at [expr $now + $time] "record"
}
$ns at 1.0 "record"
But when I run this script, there is an error” node(1), no such variable”.
Today I happen to find the solution about this problem in the internet:
Change ‘global node(1)’ to ‘global node’. Pay attention that node($i) is an
array[I still havn't found the reason yet]. And this function 'record' will
help me to finish the job[record a mobile node’s position (x,y) every 0.5
second]. The result is like this:
....
4 1.4748094279189353e-07 550 500
4.5 1.2392495887374392e-07 475.2091266690191 433.51922370579473
5 1.0559286436579362e-07 475.2091266690191 433.51922370579473
....
And, I think I will think over your idea when i get enough knowledge about
NS.
Thanks very much again.
Best wishes.:jumping:
Liceven
Jalaluddin Qureshi wrote:
>
>
>
>
> Dear Liceven,
>
> While I cant give you step-by-step instruction on how to solve your
> problem. But here is the idea. If you were to go to
> ns-allinone2.xx/ns2.xx/mobile/antenna.cc file you will see the function:
>
> Antenna::Antenna()
> {
> X_ = 0; Y_= 0; Z_= 0;
> bind("X_", &X_);
> bind("Y_", &Y_);
> bind("Z_", &Z_);
> }
>
> Basically this constructors binds the X_ variable in the TCL file with the
> X_ in the C++ file. If you were to add say:
>
> cout << "X position" << X_ << endl;
> cout << "Y position" << Y_ << endl;
> cout << "Z position" << Z_ << endl;
>
> after bind("Z_", &Z_); but before }. And then run the "make clean" and
> "make" command at the Linux command terminal in the
> ns-allinone2.xx/ns2.xx/ prompt area. Once thats done, if you were to run
> your .tcl file, you will see an output, which specifies the position of
> your node in X, Y, Z coordinate.
>
> The glitch with this approach is that it shows you the coordinates for
> time 0.0, mean just at the start of the simulation.
>
> For your problem, YOU need to find the .cc file which is responsible for
> changing the X, Y, Z coordinates. Once you locate that .cc file, then
> locate the function which is changing the value of X, Y, Z, and then you
> can add the above cout lines at the end of that function.
>
> This way, when you run the simulation, you will get live time output of
> the X, Y, Z coordinates. If you know C++ half-decent, then I think it will
> not take you more than 2-5 hours to locate the function and find the
> solution of your problem.
>
> PLEASE ONCE YOU SOLVE YOUR PROBLEM, DO SHARE YOUR SOLUTION WITH OTHERS ON
> THE NS MAILING LIST.
>
> Kind Regards
> Jalaluddin Qureshi
>
> Research Student @ CeMNet, SCE
> Nanayang Technological University
> N4-B2c-06, Nanyang Avenue
> Singapore 639798
> http://www.cemnet.ntu.edu.sg
>
> --Forwarded Message Attachment--
> From: feixianyexin at 163.com
> To: ns-users at ISI.EDU
> Date: Wed, 23 Jul 2008 00:00:36 -0700
> Subject: [ns] How to get a mobile node's current position
>
>
> Hello,everyone:
> I want to simulate a wireless scenario with two access points and a
> mobile node. This mobile node moves randomly, the question is how to
> calculate it's position like(x=?,y=?,z=0) at any given time. It could be
> better if you could give me an example. Of course, any suggestion is
> welcome.
> Regards.
> Liceven
> --
> View this message in context:
> http://www.nabble.com/How-to-get-a-mobile-node%27s-current-position-tp18604950p18604950.html
> Sent from the ns-users mailing list archive at Nabble.com.
>
>
>
> _________________________________________________________________
> Check out Barclays Premier League exclusive video clips here!
> http://fc.sg.msn.com/index.aspx
>
>
>
--
View this message in context: http://www.nabble.com/How-to-get-a-mobile-node%27s-current-position-tp18604950p18645998.html
Sent from the ns-users mailing list archive at Nabble.com.
More information about the Ns-users
mailing list