예제 #1
0
        public static List <double> RetrieveTheta(List <Packet> values, Sensor s, DataInfo d, double prevValue)
        {
            //Lista contenente valori senza discontinuità arcotangente
            List <double> thetaValues = new List <double>(values.Count);
            //Lista contenente i tre valori del magnetometro
            List <double> tmpValues = new List <double>(3);

            //Ritorna numero sensore
            int sensorNumber = s.GetSensorNumber();

            List <double> yValues = new List <double>();
            List <double> zValues = new List <double>();

            for (int i = 0; i < values.Count; i++)
            {
                GetDataValues(values, yValues, i, 7, 8, sensorNumber);
                GetDataValues(values, zValues, i, 8, 9, sensorNumber);
            }

            yValues = UtilityFunctions.SmoothingCalculator(yValues, 15, true);
            zValues = UtilityFunctions.SmoothingCalculator(zValues, 15, true);

            List <List <double> > valuesTheta = new List <List <double> >();

            valuesTheta.Add(yValues);
            valuesTheta.Add(zValues);

            //Dato temporaneo
            double previousAngle;

            for (int i = 0; i < valuesTheta[0].Count; i++)
            {
                previousAngle = 0;
                tmpValues.Add(valuesTheta[0][i]);
                tmpValues.Add(valuesTheta[1][i]);

                if (i == 0)
                {
                    thetaValues.Add(FunzioneOrientamento(tmpValues, prevValue));
                }
                else if (i > 0)
                {
                    previousAngle = thetaValues[i - 1];
                    thetaValues.Add(FunzioneOrientamento(tmpValues, previousAngle));
                }
                tmpValues.Clear();
            }
            return(thetaValues);
        }
예제 #2
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();
        }
예제 #3
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);
                        }
                    }
                }
            }
        }