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)); }
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); } } } } }