Algoritma Saya untuk Mengira Kedudukan Telefon Pintar - Algoritma Bersepadu Berdasarkan Data Sensor dan GPS
Mengatasi Isu Algoritma:
Algoritma yang disediakan tidak mengira halaju akhir dengan betul (kelajuan) peranti. Untuk menangani ralat ini, formula berikut harus digunakan:
finalvelocity = initialVelocity + Double.Parse(currentAcceleration) * (t);
Algoritma Disemak:
Algoritma yang disemak menggabungkan pengiraan kelajuan yang diperbetulkan dan penambahbaikan tambahan untuk memastikan tepat anggaran kedudukan:
var prevLocation = ServerHandler.getLatestPosition(IMEI); var newLocation = new ReceivedDataDTO() { LocationDataDto = new LocationDataDTO(), UsersDto = new UsersDTO(), DeviceDto = new DeviceDTO(), SensorDataDto = new SensorDataDTO() }; //First Reading if (prevLocation.Latitude == null) { //Save GPS Readings newLocation.LocationDataDto.DeviceId = ServerHandler.GetDeviceIdByIMEI(IMEI); newLocation.LocationDataDto.Latitude = Latitude; newLocation.LocationDataDto.Longitude = Longitude; newLocation.LocationDataDto.Acceleration = float.Parse(currentAcceleration); newLocation.LocationDataDto.Direction = float.Parse(currentDirection); newLocation.LocationDataDto.Speed = (float) 0.0; newLocation.LocationDataDto.ReadingDateTime = date; newLocation.DeviceDto.IMEI = IMEI; // saving to database ServerHandler.SaveReceivedData(newLocation); return; } //If Previous Position not NULL --> Calculate New Position **//Algorithm Starts HERE** var oldLatitude = Double.Parse(prevLocation.Latitude); var oldLongitude = Double.Parse(prevLocation.Longitude); var direction = Math.PI * Double.Parse(currentDirection) / 180.0; Double initialVelocity = prevLocation.Speed; //Get Current Time to calculate time Travelling - In seconds var secondsTravelling = date - tripStartTime; var t = secondsTravelling.TotalSeconds; //Calculate Distance using physice formula, s= Vi * t + 0.5 * a * t^2 var distanceTravelled = initialVelocity * t + 0.5 * Double.Parse(currentAcceleration) * t * t; //Calculate the Final Velocity/ Speed of the device. // this Final Velocity is the Initil Velocity of the next reading //Physics Formula: Vf = Vi + a * t var finalvelocity = initialVelocity + Double.Parse(currentAcceleration) * (t); //Convert from Degree to Radians (For Formula) oldLatitude = Math.PI * oldLatitude / 180; oldLongitude = Math.PI * oldLongitude / 180; //Calculate the New Longitude and Latitude var newLatitude = Math.Asin(Math.Sin(oldLatitude) * Math.Cos(distanceTravelled / earthRadius) + Math.Cos(oldLatitude) * Math.Sin(distanceTravelled / earthRadius) * Math.Cos(direction)); var newLongitude = oldLongitude + Math.Atan2(Math.Sin(direction) * Math.Sin(distanceTravelled / earthRadius) * Math.Cos(oldLatitude), Math.Cos(distanceTravelled / earthRadius) - Math.Sin(oldLatitude) * Math.Sin(newLatitude)); //Convert From Radian to degree/Decimal newLatitude = 180 * newLatitude / Math.PI; newLongitude = 180 * newLongitude / Math.PI;
Menggabungkan Data Sensor Penyepaduan:
Algoritma ini menggunakan kedua-dua data pecutan dan magnetometer untuk mengira arah pergerakan. Langkah berikut menggariskan proses:
Tambahan Pertimbangan:
Atas ialah kandungan terperinci Bagaimanakah Algoritma Ini Mengira Kedudukan Telefon Pintar Dengan Tepat Menggunakan Data Sensor dan GPS?. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!