/// <summary>
        /// Calculates the calibration algorithms where the node to be calibrated is the blind node
        /// </summary>
        /// <param name="dataSet">The dataset to be processed</param>
        private void ExecuteCalibrationBlindNode(DataSet dataSet)
        {
            Console.WriteLine("Executing the two calibration methods");

            foreach (DataRow row in dataSet.Tables[0].Rows)
            {
                currentID = row["node"].ToString();
                Node CurrentNode;

                if (currentID == "11")
                {
                    if (!AnchorNodes.Exists(AN => AN.WsnIdProperty == currentID))
                    {
                        AnchorNodes.Add(new Node(row["node"].ToString(), MyDb));

                        CurrentNode = AnchorNodes.Find(AN => AN.WsnIdProperty == currentID);

                        Console.WriteLine("Enter the position of the blind node in doubles!");
                        Point position = new Point();
                        Console.Write("X: ");
                        position.x = Convert.ToDouble(Console.ReadLine());
                        Console.Write("Y: ");
                        position.y = Convert.ToDouble(Console.ReadLine());

                        CurrentNode.position = new Point(position.x, position.y);
                    }

                    CurrentNode = AnchorNodes.Find(AN => AN.WsnIdProperty == currentID);

                    CurrentNode.UpdateAnchors(row["ANode"].ToString(), Convert.ToDouble(row["RSSI"].ToString()), 1, DateTime.Now);
                }
            }

            RangeBasedPositioning.CalibratePathloss(AnchorNodes, RangeBasedPositioning.AverageFilter);
            Console.WriteLine("Normal Calibration");
            Console.WriteLine(RangeBasedPositioning.pathLossExponent);
            Console.WriteLine(RangeBasedPositioning.baseLoss);
            RangeBasedPositioning.CalibratePathlossLS(AnchorNodes, RangeBasedPositioning.AverageFilter);
            Console.WriteLine("LS Calibration");
            Console.WriteLine(RangeBasedPositioning.pathLossExponent);
            Console.WriteLine(RangeBasedPositioning.baseLoss);

            AnchorNodes.Clear();
        }
        /// <summary>
        /// Calculates the calibration algorithms
        /// </summary>
        /// <param name="dataSet">The dataset to be processed</param>
        private void ExecuteCalibration(DataSet dataSet)
        {
            double baseLoss = 0, pathLossExponent = 0;
            int    counter = 0;

            Console.WriteLine("Executing the two calibration methods");

            Console.WriteLine("Normal Calibration");
            foreach (DataRow row in dataSet.Tables[0].Rows)
            {
                currentID = row["node"].ToString();
                Node CurrentNode;

                if (currentID != "11")
                {
                    if (!AnchorNodes.Exists(AN => AN.WsnIdProperty == currentID))
                    {
                        AnchorNodes.Add(new Node(row["node"].ToString(), MyDb));
                    }

                    CurrentNode = AnchorNodes.Find(AN => AN.WsnIdProperty == currentID);
                    CurrentNode.UpdateAnchors(row["ANode"].ToString(), Convert.ToDouble(row["RSSI"].ToString()), 1, DateTime.Now);

                    RangeBasedPositioning.CalibratePathloss(AnchorNodes, RangeBasedPositioning.NoFilter);
                    pathLossExponent += RangeBasedPositioning.pathLossExponent;
                    counter++;
                }
            }

            pathLossExponent /= counter;
            Console.WriteLine("baseLoss = " + RangeBasedPositioning.baseLoss.ToString());
            Console.WriteLine("pathLossExponent = " + pathLossExponent.ToString());

            baseLoss         = 0;
            pathLossExponent = 0;
            counter          = 0;
            AnchorNodes.Clear();

            Console.WriteLine("LS Calibration");
            foreach (DataRow row in dataSet.Tables[0].Rows)
            {
                currentID = row["node"].ToString();
                Node CurrentNode;

                if (currentID != "11")
                {
                    if (!AnchorNodes.Exists(AN => AN.WsnIdProperty == currentID))
                    {
                        AnchorNodes.Add(new Node(row["node"].ToString(), MyDb));
                    }

                    CurrentNode = AnchorNodes.Find(AN => AN.WsnIdProperty == currentID);
                    CurrentNode.UpdateAnchors(row["ANode"].ToString(), Convert.ToDouble(row["RSSI"].ToString()), 1, DateTime.Now);

                    RangeBasedPositioning.CalibratePathlossLS(AnchorNodes, RangeBasedPositioning.NoFilter);
                    baseLoss         += RangeBasedPositioning.baseLoss;
                    pathLossExponent += RangeBasedPositioning.pathLossExponent;
                    counter++;
                }
            }

            baseLoss         /= counter;
            pathLossExponent /= counter;
            Console.WriteLine("baseLoss = " + baseLoss.ToString());
            Console.WriteLine("pathLossExponent = " + pathLossExponent.ToString());
        }
Exemple #3
0
        /// <summary>
        /// Executes the algorithms on the data
        /// Results are written to a log
        /// </summary>
        /// <param name="Set">DataSet containing the RSS data</param>
        /// <param name="numberAnchors">The number of anchors that the dataset should contain</param>
        private void ExecuteAlgorithms(DataSet Set, int numberAnchors)
        {
            Console.WriteLine("Executing each algorithm on the data");

            foreach (DataRow row in Set.Tables[0].Rows)
            {
                currentID = row["node"].ToString();
                Node CurrentNode;

                //Positioning.Point pos = new Positioning.Point(0, 0);
                Point pos = new Point(0, 0);

                if (currentID == "11")
                {
                    CurrentNode = BlindNodes.Find(BN => BN.WsnIdProperty == currentID);
                    CurrentNode.UpdateAnchors(row["ANode"].ToString(), Convert.ToDouble(row["RSSI"].ToString()), 1, DateTime.Now);

                    if (CurrentNode.Anchors.Count == numberAnchors)
                    {
                        logger.Write(row["idlocalization"].ToString() + ",");
                        logger.Write(row["time"].ToString() + ",");
                        logger.Write(currentID + ",");
                        logger.Write(CurrentNode.Anchors.Count + ",");

                        //centroid localization
                        //logger.Write("CL,");
                        pos = CentroidLocalization.CalculatePosition(CurrentNode);
                        LogPosition(pos, CurrentNode, logger);

                        //wcl
                        //logger.Write("WCL - NoFilter,");
                        pos = WCL.CalculatePosition(CurrentNode, RangeBasedPositioning.NoFilter);
                        LogPosition(pos, CurrentNode, logger);

                        //min-max
                        //logger.Write("Min-Max - NoFilter - Ranging,");
                        pos = MinMaxExtended.CalculatePosition(CurrentNode, RangeBasedPositioning.NoFilter, RangeBasedPositioning.Ranging, false);
                        LogPosition(pos, CurrentNode, logger);

                        //logger.Write("Min-Max - NoFilter - DefaultRanging,");
                        pos = MinMaxExtended.CalculatePosition(CurrentNode, RangeBasedPositioning.NoFilter, RangeBasedPositioning.DefaultRanging, false);
                        LogPosition(pos, CurrentNode, logger);

                        //trilateration
                        //logger.Write("TriLat - NoFilter - Ranging,");
                        pos = ExtendedTrilateration.CalculatePosition(CurrentNode, RangeBasedPositioning.NoFilter,
                                                                      RangeBasedPositioning.Ranging, false);
                        LogPosition(pos, CurrentNode, logger);

                        //logger.Write("TriLat - NoFilter - DefaultRanging,");
                        pos = ExtendedTrilateration.CalculatePosition(CurrentNode, RangeBasedPositioning.NoFilter,
                                                                      RangeBasedPositioning.DefaultRanging, false);
                        LogPosition(pos, CurrentNode, logger);

                        //lstrilateration
                        //logger.Write("LSTriLat - NoFilter - Ranging,");
                        pos = LSTrilateration.CalculatePosition(CurrentNode, RangeBasedPositioning.NoFilter,
                                                                RangeBasedPositioning.Ranging, false);
                        LogPosition(pos, CurrentNode, logger);

                        //logger.Write("LSTriLat - NoFilter - DefaultRanging,");
                        pos = LSTrilateration.CalculatePosition(CurrentNode, RangeBasedPositioning.NoFilter,
                                                                RangeBasedPositioning.DefaultRanging, false);
                        LogPosition(pos, CurrentNode, logger);
                    }
                    else if (CurrentNode.Anchors.Count > numberAnchors)
                    {
                        logger.WriteLine("Too many nodes for idlocalization:" + row["idlocalization"].ToString());
                    }

                    logger.WriteLine("");
                    logger.Flush();
                }
                //Performs calibratino
                else
                {
                    if (!AnchorNodes.Exists(AN => AN.WsnIdProperty == currentID))
                    {
                        AnchorNodes.Add(new Node(row["node"].ToString(), MyDb));
                    }

                    CurrentNode = AnchorNodes.Find(AN => AN.WsnIdProperty == currentID);
                    CurrentNode.UpdateAnchors(row["ANode"].ToString(), Convert.ToDouble(row["RSSI"].ToString()), 1, DateTime.Now);
                    //CurrentNode = AnchorNodes.Find(AN => AN.WsnIdProperty == currentID);

                    RangeBasedPositioning.CalibratePathlossLS(AnchorNodes, RangeBasedPositioning.NoFilter);
                }
            }
        }