ns/tcl/lib/ns-default.tcl 里有设置默认值的,传输距离250米
更改发射功率,或者接收阀值均能改变通信距离,计算公式在mobile/tworayground.cc里
ns-default.tcl 中的代码如下:
Phy/WirelessPhy set CSThresh_ 1.559e-11 //this sensoring radius
Phy/WirelessPhy set RXThresh_ 3.652e-10 //this is the communication radius
这个是默认的设置,默认的为通信距离为250米
修改步骤:
To set communication radius, you have to set the receiving threshold value, RXThresh_. This can be obtained by running the program~ns/indep-utils/propagation/threshold.cc(compile using g++ and the option –lm) and specifying the propagation model and the desired radius. Then in your script, before creating the simulator, use the command “Phy/WirelessPhy set RXThresh_”.
Ideally, you would also like to set the transmission power, Pt_ and the carrier sensing threshold, CSThresh_. But I still don’t know how to obtain their values. Some standard values for Pt_ are: 7.214e-4 for 100m, 8.5872e-4 for 40m. Also note that the effectiveness of the radius depends on the propagation model. While it works perfectly for FreeSpace, it might not work as well for the other two.
编译threshold.cc文件的时候需要修改以下几点:
#include <iostream.h> 修改为#include <iostream> ,同时加上using namespace std;
再添加头文件:#include <cstring>
[compile threshold.cc]
$ cd ns/indep-utils/propagation/
$ g++ -lm threshold.cc -o threshold
[example]
$ ./threshold -lm TwoRayGround -r 250 250
distance = 250
propagation model: TwoRayGround
Selected parameters:
transmit power: 0.281838
frequency: 9.14e+08
transmit antenna gain: 1
receive antenna gain: 1
system loss: 1
transmit antenna height: 1.5
receive antenna height: 1.5
Receiving threshold RXThresh_ is: 3.65262e-10
其中的参数说明:
-pl <path-loss-exponent 路径损耗指数>
-std <shadowing-deviation 阴影方差>
-Pt <transmit-power 发射功率>
-fr <frequency 频率>
-Gt <transmit-antenna-gain 发射天线增益>
-Gr <receive-antenna-gain 接收天线增益>
-L <system-loss 系统损耗>
-ht <transmit-antenna-height 发射天线高度>
-hr <receive-antenna-height 接收天线高度>
-d0 <reference-distance 参考距离>
上面就是默认情况下传感器的设置;如果你想更改你的传感器通信半径只需要用你的半径值去替代 250参数即可。
参靠柯老师网站:http://140.116.72.80/~smallko/ns2/11b.htm
InNS-2, the default transmitting powerPt is 0.28, and thus thetransmission range (TX_range) andphysical carrier sensing range (PCS_range) are calculated as 250 meters and 550 meters
p.s. (0.28183815×1.52×1.52) / (2504)=3.652e-10