In general, going on the path 1 with yours help, I wrote such code, but there are some strange mistakes = (such as 45 km / h at rest). I tested it in my car. Visually it coincides with the speedometer in my smartphone =)
//*********
Serial3.setup (115200, {rx: P0, tx: P1});
var R = 6371e3; //
var Led= require('@amperka/led').connect(A1);
var lastData; //
var lastData2; //
var lastLon; //
var lastLat; //
var LastTime;
var toRad=Math.PI/180;
var i=0;
var gps = require ("GPS"). connect (Serial3, function (data) {
if (lastData,i<50) {
// do stuff here - eg. the difference between the two readings
//****** distance calc
var Lon=data.lon*toRad; // lon в t1
var Lat=data.lat*toRad; //lat в t1
var diffLon=Math.abs(Lon-lastLon*toRad);
var diffLat= Math.abs(Lat-lastLat*toRad);
var a= Math.sin(diffLat/2) * Math.sin(diffLat/2) +
Math.cos(Lat) * Math.cos(lastLat*toRad) *
Math.sin(diffLon/2) * Math.sin(diffLon/2);
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
var distansP = R * c;
//****** time diff
var tTime= data.time.split(':'); // time array
tTime=tTime[2];
var diffTime=tTime-LastTime;
//****** speed
var speed1= distansP/diffTime; // m/s
var speed2= speed1*3.6; // km/h
if(speed2>60){
Led.turnOn();
}
else{Led.turnOff();}
console.log(speed2,speed1);
//console.log ('1',Math.sin(diffLat/2),diffLat/2,'2',Math.cos(Lat), '3',Math.cos(lastLat*toRad),lastLat*toRad,'4',Math.sin(diffLon/2),'5',Math.sin(diffLon/2),'6',Math.sqrt(a),a,'7',Math.sqrt(1-a),'8',diffTime ); Debugging
}
lastData=data;
lastLon=data.lon; // in degrees
lastLat=data.lat; //in degrees
LastTime= data.time.split(':');
LastTime= LastTime[2];
// lastData = data.time.split(':');
//lastData2 = lastData[2];
// lastLon= data.lon;
i=i+1;
});
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
In general, going on the path 1 with yours help, I wrote such code, but there are some strange mistakes = (such as 45 km / h at rest). I tested it in my car. Visually it coincides with the speedometer in my smartphone =)