|
View:
New views
4 Messages
—
Rating Filter:
Alert me
|
|
|
How to get a mobile node's current positionHello,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 |
|
|
Re: How to get a mobile node's current positionHi, today I find we could use tcl script to get a node's position.
codes like this: set n1 [$ns node] $ns set X_ 15.0 $ns set Y_ 15.0 $ns set Z_ 0.0 ... set x_pos [$n1 set X_] ... 'set x_pos [$n1 set X_]' this script could be used to get the x value of n1's starting position. but it could not record the coordinate dynamically. So, If I want to implement this dynamic function, what should i do? thanks very much. Liceven
|
|
|
|
|
|
Re: How to get a mobile node's current positionDear 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. ![]() Liceven
|
| Free embeddable forum powered by Nabble | Forum Help |