根据Castalia中设备的感应灵敏度来计算感应范围? [英] Calculating sensing range from sensing sensitivity of the device in Castalia?

查看:115
本文介绍了根据Castalia中设备的感应灵敏度来计算感应范围?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Castalia中实现WSN算法.我需要计算感应设备的感应范围.我知道我将需要使用感应灵敏度参数,但是确切的方程式是什么?

I am implementing a WSN algorithm in Castalia. I need to calculate sensing range of the sensing device. I know I will need to use the sensing sensitivity parameter but what will be the exact equation?

推荐答案

答案将因所使用的PhysicalProcess模块​​指定的行为而异.既然您在评论中说您可能正在使用CarsPhysicalProcess,那么我们以它为例.

The answer will vary depending on the behaviour specified by the PhysicalProcess module used. Since you say in your comment that you may be using the CarsPhysicalProcess let's use that as an example.

由应用程序启动的传感器读取请求首先通过SensorReadingMessage消息发送到SensorManager.在SensorManager.cc中,您可以查看其handleMessage函数的处理方式:

A sensor reading request initiated by the application is first sent to the SensorManager via a SensorReadingMessage message. In SensorManager.cc you can see how this is processed in its handleMessage function:

...
case SENSOR_READING_MESSAGE: {
    SensorReadingMessage *rcvPacket =check_and_cast<SensorReadingMessage*>(msg);
    int sensorIndex = rcvPacket->getSensorIndex();

    simtime_t currentTime = simTime();
    simtime_t interval = currentTime - sensorlastSampleTime[sensorIndex];
    int getNewSample = (interval < minSamplingIntervals[sensorIndex]) ? 0 : 1;

    if (getNewSample) { //the last request for sample was more than minSamplingIntervals[sensorIndex] time ago
        PhysicalProcessMessage *requestMsg =
            new PhysicalProcessMessage("sample request", PHYSICAL_PROCESS_SAMPLING);
        requestMsg->setSrcID(self); //insert information about the ID of the node
        requestMsg->setSensorIndex(sensorIndex);    //insert information about the index of the sensor
        requestMsg->setXCoor(nodeMobilityModule->getLocation().x);
        requestMsg->setYCoor(nodeMobilityModule->getLocation().y);

        // send the request to the physical process (using the appropriate 
        // gate index for the respective sensor device )
        send(requestMsg, "toNodeContainerModule", corrPhyProcess[sensorIndex]);

        // update the most recent sample times in sensorlastSampleTime[]
        sensorlastSampleTime[sensorIndex] = currentTime;
    } else {    // send back the old sample value

        rcvPacket->setSensorType(sensorTypes[sensorIndex].c_str());
        rcvPacket->setSensedValue(sensorLastValue[sensorIndex]);
        send(rcvPacket, "toApplicationModule");
        return;
    }
    break;
}
....

如您所见,它的作用是首先计算出自从该传感器的最后一个传感器读取请求以来经过了多少时间.如果时间少于此传感器可能的minSamplingInterval指定的时间(这由SensorManager的maxSampleRates NED参数确定),则它仅返回给定的最后一个传感器读数.如果更大,则会重新读取传感器读数.

As you can see, what it's doing is first working out how much time has elapsed since the last sensor reading request for this sensor. If it's less time than specified by the minSamplingInterval possible for this sensor (this is determined by the maxSampleRates NED parameter of the SensorManager), it just returns the last sensor reading given. If it's greater, a new sensor reading is made.

通过将PhysicalProcessMessage消息发送到PhysicalProcess模块​​(通过toNodeContainerModule门)来获得新的传感器读数.在消息中,我们传递节点的X和Y坐标.

A new sensor reading is made by sending a PhysicalProcessMessage message to the PhysicalProcess module (via the toNodeContainerModule gate). In the message we pass the X and Y coordinates of the node.

现在,如果在omnetpp.ini文件中将CarsPhysicalProcess指定为要使用的物理过程,则CarsPhysicalProcess模块将收到此消息.您可以在CarsPhysicalProcess.cc中看到它:

Now, if we have specified CarsPhysicalProcess as the physical process to be used in our omnetpp.ini file, the CarsPhysicalProcess module will receive this message. You can see this in CarsPhysicalProcess.cc:

....
case PHYSICAL_PROCESS_SAMPLING: {
    PhysicalProcessMessage *phyMsg = check_and_cast < PhysicalProcessMessage * >(msg);

    // get the sensed value based on node location
    phyMsg->setValue(calculateScenarioReturnValue(
        phyMsg->getXCoor(), phyMsg->getYCoor(), phyMsg->getSendingTime()));
    // Send reply back to the node who made the request
    send(phyMsg, "toNode", phyMsg->getSrcID());
    return;
}
...

您可以看到我们根据节点的X和Y坐标以及读取传感器的时间来计算传感器值.响应通过toNode门发送回SensorManager.因此,我们需要查看calculateScenarioReturnValue函数以了解发生了什么:

You can see that we calculate a sensor value based on the X and Y coordinates of the node, and the time at which the sensor reading was made. The response is sent back to the SensorManager via the toNode gate. So we need to look at the calculateScenarioReturnValue function to understand what's going on:

double CarsPhysicalProcess::calculateScenarioReturnValue(const double &x_coo,
                    const double &y_coo, const simtime_t &stime)
{
    double retVal = 0.0f;
    int i;
    double linear_coeff, distance, x, y;

    for (i = 0; i < max_num_cars; i++) {
        if (sources_snapshots[i][1].time >= stime) {
            linear_coeff = (stime - sources_snapshots[i][0].time) /
                (sources_snapshots[i][1].time - sources_snapshots[i][0].time);
            x = sources_snapshots[i][0].x + linear_coeff * 
                (sources_snapshots[i][1].x - sources_snapshots[i][0].x);
            y = sources_snapshots[i][0].y + linear_coeff * 
                (sources_snapshots[i][1].y - sources_snapshots[i][0].y);
            distance = sqrt((x_coo - x) * (x_coo - x) +
             (y_coo - y) * (y_coo - y));
            retVal += pow(K_PARAM * distance + 1, -A_PARAM) * car_value;
        }
    }
    return retVal;
}

我们从传感器的返回值0开始.然后我们遍历行驶中的每辆汽车(如果您查看handleMessage函数中的TIMER_SERVICE case语句,您会看到CarsPhysicalProcess将汽车驶入根据car_interarrival比率随机选择道路,最大数量为max_num_cars个汽车).对于每辆汽车,我们都会计算汽车沿着道路行驶的距离,然后计算汽车与节点之间的距离.然后,根据以下公式,为每辆车添加返回值:

We start with a sensor return value of 0. Then we loop over every car that is on the road (if you look at the TIMER_SERVICE case statement in the handleMessage function, you will see that CarsPhysicalProcess puts cars on the road randomly according to the car_interarrival rate, up to a maximum of max_num_cars number of cars). For every car, we calculate how far the car has travelled down the road, and then calculate the distance between the car and the node. Then for each car we add to the return value based on the formula:

pow(K_PARAM * distance + 1, -A_PARAM) * car_value

其中distance是我们计算的汽车与节点之间的距离,K_PARAM = 0.1A_PARAM = 1(在CarsPhysicalProcess.cc的顶部定义),而car_value是在CarsPhysicalProcess.ned中指定的数字.参数文件(默认为30).

Where distance is the distance we have calculated between the car and the node, K_PARAM = 0.1, A_PARAM = 1 (defined at the top of CarsPhysicalProcess.cc) and car_value is a number specified in the CarsPhysicalProcess.ned parameter file (default is 30).

此值被传递回SensorManager.然后,SensorManager可以根据传感器的灵敏度,分辨率,噪声和偏差(定义为SensorManager参数)更改此值:

This value is passed back to the SensorManager. The SensorManager then may change this value depending on the sensitivity, resolution, noise and bias of the sensor (defined as SensorManager parameters):

....
case PHYSICAL_PROCESS_SAMPLING:
{
    PhysicalProcessMessage *phyReply = check_and_cast<PhysicalProcessMessage*>(msg);
    int sensorIndex = phyReply->getSensorIndex();
    double theValue = phyReply->getValue();

    // add the sensor's Bias and the random noise 
    theValue += sensorBias[sensorIndex];
    theValue += normal(0, sensorNoiseSigma[sensorIndex], 1);

    // process the limitations of the sensing device (sensitivity, resoultion and saturation)
    if (theValue < sensorSensitivity[sensorIndex])
        theValue = sensorSensitivity[sensorIndex];
    if (theValue > sensorSaturation[sensorIndex])
        theValue = sensorSaturation[sensorIndex];

    theValue = sensorResolution[sensorIndex] * lrint(theValue / sensorResolution[sensorIndex]);
....

因此您可以看到,如果该值低于传感器的灵敏度,则会返回灵敏度的下限.

So you can see that if the value is below the sensitivity of the sensor, the floor of the sensitivity is returned.

因此,基本上您可以看到Castalia中没有特定的感应范围",这完全取决于特定的PhysicalProcess处理消息的方式.就CarsPhysicalProcess而言,只要道路上有汽车,它就会始终返回一个值,而不管距离有多远-如果汽车与节点的距离很远,它可能会很小.如果该值很小,您可能会收到最低的传感器灵敏度.您可以增大或减小car_value参数,以从传感器获得更强的响应(因此,这有点像传感器范围)

So basically you can see that there is no specific 'sensing range' in Castalia - it all depends on how the specific PhysicalProcess handles the message. In the case of CarsPhysicalProcess, as long as there is a car on the road, it will always return a value, regardless of the distance - it just might be very small if the car is a long distance away from the node. If the value is very small, you may receive the lowest sensor sensitivity instead. You could increase or decrease the car_value parameter to get a stronger response from the sensor (so this is kind of like a sensor range)

编辑--- 默认灵敏度(您可以在SensorManager.ned中找到)为0.因此,对于CarsPhysicalProcess,应该检测道路上任何距离的任何汽车,并将其返回为大于0的值.换句话说,范围是无限的.如果汽车距离非常非常远,它可能会返回一个很小的数字,该数字会被截断为零(这取决于c ++实现中double值的精度限制)

EDIT--- The default sensitivity (which you can find in SensorManager.ned) is 0. Therefore for CarsPhysicalProcess, any car on the road at any distance should be detected and returned as a value greater than 0. In other words, there is an unlimited range. If the car is very, very far away it may return a number so small it becomes truncated to zero (this depends on the limits in precision of a double value in the implementation of c++)

如果要实现感应范围,则必须在SensorManager.ned中为devicesSensitivity设置一个值.然后在您的应用程序中,您将测试返回的值是否大于灵敏度值-如果是,则汽车处于范围内",如果(几乎)等于灵敏度,则其处于范围之外.我说几乎是因为(如前所述)SensorManager会在返回的值中添加噪声,例如,如果您的敏感度值为5,并且没有汽车,您将获得会略微徘徊在5左右的值(例如5.0001、4.99)

If you wanted to implement a sensing range, you would have to set a value for devicesSensitivity in SensorManager.ned. Then in your application, you would test to see if the returned value is greater than the sensitivity value - if it is, the car is 'in range', if it is (almost) equal to the sensitivity it is out of range. I say almost because (as we have seen earlier) the SensorManager adds noise to the value returned, so for example if you have a sensitivity value of 5, and no cars, you will get values which will hover slightly around 5 (e.g. 5.0001, 4.99)

设置了灵敏度值后,即可计算出感应距离(假设道路上只有1辆汽车),这意味着使用最小灵敏度值作为返回值,简单地求解上述方程式的距离.即如果我们使用的敏感度值为5:

With a sensitivity value set, to calculate the sensing range (assuming only 1 car on the road), this means simply solving the equation above for distance, using the minimum sensitivity value as the returned value. i.e. if we use a sensitivity value of 5:

 5 = pow(K_PARAM * distance + 1, -A_PARAM) * car_value

用参数值代替,并使用代数求解距离.

Substitute values for the parameters, and use algebra to solve for distance.

这篇关于根据Castalia中设备的感应灵敏度来计算感应范围?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆