Example #1
0
        private void DetectMotion()
        {
            List <double> devStandardAccSensor1 = UtilityFunctions.DevStandardCalculator(UtilityFunctions.RetrieveModule(this.packets, Sensor.Sensor1, DataInfo.Acc), 60, 9.81D);

            double current   = Double.NaN;
            bool   previous  = false;
            bool   fermo     = false;
            int    startTime = 0;

            for (int i = 0; i < devStandardAccSensor1.Count; i++)
            {
                current = devStandardAccSensor1[i];
                if (current > 0.8D)
                {
                    fermo = false;      //non fermo
                }
                else
                {
                    fermo = true;       //fermo
                }

                if (i != 0)
                {
                    if (previous != fermo)
                    {
                        CheckActionMoveStop(startTime, i, previous);
                        startTime = i;
                    }
                }
                if (lastPacketsFlag && i == devStandardAccSensor1.Count - 1)
                {
                    CheckActionMoveStop(startTime, i, previous);
                }
                previous = fermo;
            }
        }
Example #2
0
        private double RetrieveTheta(Packet packet, Sensor s, DataInfo d)
        {
            List <double> data          = SpecificSensorData(packet, s, d);
            double        resultRadians = UtilityFunctions.FunzioneOrientamento(data, UtilityFunctions.DegreeToRadian(GetSpecificPreviousAngle(s)));

            return(UtilityFunctions.RadianToDegree(resultRadians));
        }
Example #3
0
        private double RetrieveModule(Packet packet, Sensor s, DataInfo d)
        {
            List <double> data = SpecificSensorData(packet, s, d);

            return(UtilityFunctions.ModuleCalculator(data));
        }
Example #4
0
        private void DetectStandLaySit()
        {
            List <Packet> tmp          = new List <Packet>();
            List <double> accXSensor1  = new List <double>();
            List <Packet> correctRange = new List <Packet>();

            if (prevWindowLastPackets.Count > 0)
            {
                correctRange = this.prevWindowLastPackets.GetRange(30, 30);
            }
            tmp.AddRange(correctRange);
            tmp.AddRange(this.packets);

            accXSensor1 = UtilityFunctions.RetrieveComponent(tmp, Sensor.Sensor1, DataInfo.Acc, Axis.X);


            //Smoothing per evitare rilevazioni errate a causa di dati singoli al di sotto di un certo valore
            List <double> smoothingAcc = UtilityFunctions.SmoothingCalculator(accXSensor1, 30, this.pktOffset == 0);

            if (this.pktOffset != 0) //Always except the very first window
            {
                smoothingAcc.RemoveRange(0, 30);
            }

            double current       = Double.NaN;
            int    previous      = -1;
            int    layStandOrSit = -1;
            int    startTime     = 0;

            for (int i = 0; i < smoothingAcc.Count; i++)
            {
                current = smoothingAcc[i];
                if (current <= LAY_THRESHOLD)
                {
                    layStandOrSit = 1; //Lay
                }
                else if (current <= LAY_SIT_THRESHOLD)
                {
                    layStandOrSit = 2; //LaySit
                }
                else if (current <= SIT_THRESHOLD)
                {
                    layStandOrSit = 3; //Sit
                }
                else
                {
                    layStandOrSit = 4; //Stand
                }

                if (this.pktOffset == 0) //If it is the very first window
                {
                    this.sitLayStandActions.Add(new KeyValuePair <int, double>(i + this.pktOffset, current));
                }
                else if (i >= 250) //Do not reconsider the previous 250 values
                {
                    this.sitLayStandActions.Add(new KeyValuePair <int, double>(i + this.pktOffset, current));
                }

                if (i != 0)
                {
                    if (previous != layStandOrSit)
                    {
                        CheckActionLayStandSit(startTime, i, previous);
                        startTime = i;
                    }
                }

                if ((lastPacketsFlag) && (i == smoothingAcc.Count - 1))
                {
                    CheckActionLayStandSit(startTime, i, previous);
                }
                previous = layStandOrSit;
            }

            vThread.AddPointsForSitLayStand(new List <KeyValuePair <int, double> >(sitLayStandActions));
            sitLayStandActions.Clear();
        }
Example #5
0
        private void DetectRotation()
        {
            List <Packet> tmp = new List <Packet>();

            if (this.pktOffset != 0) //Always except the very first window
            {
                tmp.AddRange(this.prevWindowLastPackets.GetRange(0, 60));
            }

            tmp.AddRange(packets);
            List <double> thetas = UtilityFunctions.RetrieveTheta(this.packets, Sensor.Sensor1, DataInfo.Magn, prevThetaForWindow);
            List <double> girX   = UtilityFunctions.RetrieveComponent(tmp, Sensor.Sensor1, DataInfo.Gir, Axis.X);

            girX = UtilityFunctions.SmoothingCalculator(girX, 60, this.pktOffset == 0);

            if (this.pktOffset != 0) //Always except the very first window
            {
                girX.RemoveRange(0, 60);
            }

            bool   started = false;
            int    startTime = -1, endTime = -1;
            double startAngle = 0D, endAngle = 0D;

            for (int i = 0; i < thetas.Count; i++)
            {
                double currentGirX  = girX[i];
                double currentTheta = thetas[i];
                if (i == 249) //Middle of the window, before the start of the next window
                {
                    prevThetaForWindow = thetas[i];
                }

                if (currentGirX > ROTATION_THRESHOLD && !started)
                {
                    startTime  = i;
                    startAngle = currentTheta;
                    started    = true;
                }
                else if (currentGirX < ROTATION_THRESHOLD && started)
                {
                    endTime  = i;
                    endAngle = currentTheta;
                    started  = false;

                    double result = UtilityFunctions.RadianToDegree(Math.Abs(endAngle - startAngle));

                    if (result >= MIN_ROTATION_ANGLE)
                    {
                        if (endAngle > startAngle)
                        {
                            AddAction(startTime, endTime, "Girata sx di " + result + " gradi", ActionClass.Rotation);
                            //Console.WriteLine("Girata sx " + currentGirX + " " + result + " " + (startTime + pktOffset) + " " + (endTime + pktOffset) + " | " + UtilityFunctions.RadianToDegree(startAngle) + " " + UtilityFunctions.RadianToDegree(endAngle) + " || " + startAngle + " " + endAngle);
                        }
                        else
                        {
                            AddAction(startTime, endTime, "Girata dx di " + result + " gradi", ActionClass.Rotation);
                            //Console.WriteLine("Girata dx " + currentGirX + " " + result + " " + (startTime + pktOffset) + " " + (endTime + pktOffset) + " | " + UtilityFunctions.RadianToDegree(startAngle) + " " + UtilityFunctions.RadianToDegree(endAngle) + " || " + startAngle + " " + endAngle);
                        }
                    }
                }
            }
        }