Commit 08d37fad authored by Léo-Paul Géneau's avatar Léo-Paul Géneau 👾

Add simulator default script

parent 7568df53
/*jslint nomen: true, indent: 2, maxerr: 3, maxlen: 80 */
/*global console, me*/
(function (console, me) {
"use strict";
var ALTITUDE = 100,
EPSILON = 9,
CHECKPOINT_LIST = [
{
altitude: 585.1806861589965,
latitude: 45.64492790560583,
longitude: 14.25334942966329
},
{
altitude: 589.8802607573035,
latitude: 45.64316335436476,
longitude: 14.26332880184475
},
{
altitude: 608.6648153348965,
latitude: 45.64911917196595,
longitude: 14.26214792790128
},
{
altitude: 606.1448368129072,
latitude: 45.64122685351364,
longitude: 14.26590493128597
},
{
altitude: 630.0829598206344,
latitude: 45.64543355564817,
longitude: 14.27242391207985
},
{
altitude: 616.1839898415284,
latitude: 45.6372792927328,
longitude: 14.27533492411138
},
{
altitude: 598.0603137354178,
latitude: 45.64061299543953,
longitude: 14.26161958465814
},
{
altitude: 607.1243119862851,
latitude: 45.64032340702919,
longitude: 14.2682896662383
}
];
function distance(lat1, lon1, lat2, lon2) {
var R = 6371e3, // meters
la1 = lat1 * Math.PI / 180, // lat, lon in radians
la2 = lat2 * Math.PI / 180,
lo1 = lon1 * Math.PI / 180,
lo2 = lon2 * Math.PI / 180,
haversine_phi = Math.pow(Math.sin((la2 - la1) / 2), 2),
sin_lon = Math.sin((lo2 - lo1) / 2),
h = haversine_phi + Math.cos(la1) * Math.cos(la2) * sin_lon * sin_lon;
return 2 * R * Math.asin(Math.sqrt(h));
}
me.onStart = function () {
me.direction_set = false;
me.next_checkpoint = 0;
me.parachute_triggered = false;
};
me.onUpdate = function (timestamp) {
if (!me.direction_set) {
if (me.next_checkpoint < CHECKPOINT_LIST.length) {
me.setTargetCoordinates(
CHECKPOINT_LIST[me.next_checkpoint].latitude,
CHECKPOINT_LIST[me.next_checkpoint].longitude,
CHECKPOINT_LIST[me.next_checkpoint].altitude + ALTITUDE + ALTITUDE * me.id
);
console.log("[DEMO] Going to Checkpoint %d", me.next_checkpoint);
}
me.direction_set = true;
return;
}
if (me.next_checkpoint < CHECKPOINT_LIST.length) {
me.current_position = me.getCurrentPosition();
me.distance = distance(
me.current_position.x,
me.current_position.y,
CHECKPOINT_LIST[me.next_checkpoint].latitude,
CHECKPOINT_LIST[me.next_checkpoint].longitude
);
if (me.distance <= EPSILON) {
console.log("[DEMO] Reached Checkpoint %d", me.next_checkpoint);
me.next_checkpoint += 1;
me.direction_set = false;
}
return;
}
if (!me.parachute_triggered) {
console.log("[DEMO] Deploying parachute...");
me.triggerParachute();
me.parachute_triggered = true;
}
if (me.landed()) {
me.exit(0);
}
};
}(console, me));
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment