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

Update bouncy-flight.js

parent a0de0e00
......@@ -10,94 +10,46 @@
(function (console, me) {
"use strict";
var EPSILON = 42,
FLIGH_ALTITUDE = 100,
var ALTITUDE = 100,
EPSILON = 9,
CHECKPOINT_LIST = [
{
"altitude": 604,
"latitude": 45.641,
"longitude": 14.26472
latitude: 45.64492790560583,
longitude: 14.25334942966329
},
{
"altitude": 642,
"latitude": 45.6463889,
"longitude": 14.2516
latitude: 45.64316335436476,
longitude: 14.26332880184475
},
{
"altitude": 596,
"latitude": 45.656,
"longitude": 14.2516
latitude: 45.64911917196595,
longitude: 14.26214792790128
},
{
"altitude": 634,
"latitude": 45.65916,
"longitude": 14.255
latitude: 45.64122685351364,
longitude: 14.26590493128597
},
{
"altitude": 676,
"latitude": 45.6527,
"longitude": 14.2775
latitude: 45.64543355564817,
longitude: 14.27242391207985
},
{
"altitude": 589,
"latitude": 45.6427,
"longitude": 14.2519
latitude: 45.6372792927328,
longitude: 14.27533492411138
},
{
"altitude": 582,
"latitude": 45.641,
"longitude": 14.254
latitude: 45.64061299543953,
longitude: 14.26161958465814
},
{
"altitude": 686,
"latitude": 45.6558,
"longitude": 14.2775
},
{
"altitude": 667,
"latitude": 45.6594,
"longitude": 14.271
},
{
"altitude": 581,
"latitude": 45.641,
"longitude": 14.258
},
{
"altitude": 584,
"latitude": 45.653,
"longitude": 14.2516
},
{
"altitude": 633,
"latitude": 45.6594,
"longitude": 14.26194
},
{
"altitude": 621,
"latitude": 45.641,
"longitude": 14.2716
},
{
"altitude": 642,
"latitude": 45.644,
"longitude": 14.2775
},
{
"altitude": 660,
"latitude": 45.6594,
"longitude": 14.26638
},
{
"altitude": 591,
"latitude": 45.6508,
"longitude": 14.25194
latitude: 45.64032340702919,
longitude: 14.2682896662383
}
];
function distance(lat1, lon1, lat2, lon2) {
var R = 6371e3, // meters
la1 = lat1 * Math.PI / 180, // la, lo in radians
la1 = lat1 * Math.PI / 180, // lat, lon in radians
la2 = lat2 * Math.PI / 180,
lo1 = lon1 * Math.PI / 180,
lo2 = lon2 * Math.PI / 180,
......@@ -107,72 +59,43 @@
return 2 * R * Math.asin(Math.sqrt(h));
}
function exit_on_fail(ret, msg) {
if (ret) {
console.log(msg);
me.exit(1);
}
}
function mustWait(timestamp) {
if (me.timestamp === 0) {
me.timestamp = timestamp;
}
return timestamp - me.timestamp < me.must_wait;
}
me.onStart = function () {
me.onStart = function (timestamp) {
me.direction_set = false;
me.next_checkpoint = 0;
me.takeOff();
};
me.onUpdate = function (timestamp) {
if (me.must_wait > 0) {
if (!mustWait(timestamp)) {
me.must_wait = 0;
me.timestamp = 0;
}
return;
}
if (!me.isReadyToFly()) { return; }
if (!me.direction_set) {
if (me.next_checkpoint < CHECKPOINT_LIST.length) {
exit_on_fail(
me.setTargetCoordinates(
CHECKPOINT_LIST[me.next_checkpoint].latitude,
CHECKPOINT_LIST[me.next_checkpoint].longitude,
CHECKPOINT_LIST[me.next_checkpoint].altitude + FLIGH_ALTITUDE
),
"Failed to set checkpoint coordinates"
ALTITUDE + ALTITUDE * me.id,
5
);
console.log("[DEMO] Going to Checkpoint " + me.next_checkpoint + "\n");
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,
me.current_position.latitude,
me.current_position.longitude,
CHECKPOINT_LIST[me.next_checkpoint].latitude,
CHECKPOINT_LIST[me.next_checkpoint].longitude
);
if (me.distance > EPSILON) {
console.log(
"Waiting for drone to get to destination (" + me.distance + " m)"
);
} else {
console.log("[DEMO] Reached Checkpoint " + me.next_checkpoint + "\n");
if (me.distance <= EPSILON) {
console.log("[DEMO] Reached Checkpoint %d", me.next_checkpoint);
me.next_checkpoint += 1;
me.direction_set = false;
}
return;
}
console.log("[DEMO] Deploying parachute...");
exit_on_fail(me.triggerParachute(), "Failed to deploy parachute");
me.exit(0);
if (!me.isLanding()) { me.land(); }
if (me.getCurrentPosition().altitude <= 0) { me.exit(0); }
};
}(console, me));
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