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

Comply to ERP5 JsLint

parent 8ca353c0
......@@ -93,7 +93,8 @@
function altitudeReached(altitude, target_altitude) {
console.log(
`[DEMO] Waiting for altitude... (${altitude} , ${target_altitude})`
"[DEMO] Waiting for altitude... ("
+ altitude + " , " + target_altitude + ")"
);
return Math.abs(altitude - target_altitude) < EPSILON_ALTITUDE;
}
......@@ -154,7 +155,7 @@
),
"Failed to set checkpoint coordinates"
);
console.log(`[DEMO] Going to Checkpoint ${me.next_checkpoint}\n`);
console.log("[DEMO] Going to Checkpoint " + me.next_checkpoint + "\n");
} else {
me.loiter();
console.log("[DEMO] Going to landing altitude...\n");
......@@ -178,9 +179,10 @@
);
if (me.distance > EPSILON) {
console.log(
`Waiting for drone to get to destination (${me.distance} m)`);
"Waiting for drone to get to destination (" + me.distance + " m)"
);
} else {
console.log(`[DEMO] Reached Checkpoint ${me.next_checkpoint}\n`);
console.log("[DEMO] Reached Checkpoint " + me.next_checkpoint + "\n");
me.next_checkpoint += 1;
me.direction_set = false;
}
......
/*jslint nomen: true, indent: 2, maxerr: 3, maxlen: 80 */
/*global console, me*/
(function (console, me) {
(function (console, me) {
"use strict";
function displayMessage(message) {
......@@ -120,5 +120,5 @@
console.log(" Command successful");
}
};
}(console, me));
}(console, me));
\ No newline at end of file
me.onStart = function() {
/*jslint nomen: true, indent: 2, maxerr: 3, maxlen: 80 */
/*global me*/
(function (me) {
"use strict";
me.onStart = function () {
me.exit(0);
};
};
}(me));
/*jslint nomen: true, indent: 2, maxerr: 3, maxlen: 80 */
/*global console, me*/
(function (console, me) {
(function (console, me) {
"use strict";
var ALTITUDE_DIFF = 30,
......@@ -60,7 +60,9 @@
function altitudeReached(altitude, target_altitude) {
console.log(
`[DEMO] Waiting for altitude... (${altitude} , ${target_altitude})`);
"[DEMO] Waiting for altitude... ("
+ altitude + " , " + target_altitude + ")"
);
return Math.abs(altitude - target_altitude) < EPSILON_ALTITUDE;
}
......@@ -153,9 +155,9 @@
if (!me.leader_init_alt_reached) {
me.leader_init_alt_reached = leaderReachedInitAltitude(me);
return console.log(
"[DEMO] Waiting for leader to reach altitude " +
leaderStartAltitude(me) +
`(currently ${me.drone_dict[LEADER_ID].altitudeAbs})`,
"[DEMO] Waiting for leader to reach altitude "
+ leaderStartAltitude(me)
+ "(currently " + me.drone_dict[LEADER_ID].altitudeAbs + ")"
);
}
......@@ -185,7 +187,7 @@
),
"Failed to set checkpoint coordinates"
);
console.log(`[DEMO] Going to Checkpoint ${me.next_checkpoint}\n`);
console.log("[DEMO] Going to Checkpoint " + me.next_checkpoint + "\n");
} else {
console.log("[DEMO] Setting last checkpoint coordinates...\n");
me.landing_altitude = groundLevel(me) + PARACHUTE_ALTITUDE;
......@@ -212,12 +214,12 @@
);
if (me.distance > EPSILON) {
console.log(
"Waiting for drone to get to destination (checkpoint " +
`${me.next_checkpoint}: ${me.distance} m)`,
"Waiting for drone to get to destination (checkpoint "
+ me.next_checkpoint + ": " + me.distance + " m)`"
);
} else {
me.loiter(100);
console.log(`[DEMO] Reached Checkpoint ${me.next_checkpoint}\n`);
console.log("[DEMO] Reached Checkpoint " + me.next_checkpoint + "\n");
me.next_checkpoint += 1;
me.sendMsg(JSON.stringify({next_checkpoint: me.next_checkpoint}));
me.direction_set = false;
......@@ -236,8 +238,8 @@
);
if (me.distance > EPSILON) {
console.log(
"Waiting for drone to get to destination (last checkpoint: " +
`${me.distance} m)`,
"Waiting for drone to get to destination (last checkpoint: "
+ me.distance + " m)"
);
} else {
me.loiter(100);
......@@ -278,8 +280,8 @@
);
if (me.distance > EPSILON) {
console.log(
"[DEMO] Waiting to reach landing point (current distance is " +
`${me.distance})`,
"[DEMO] Waiting to reach landing point (current distance is "
+ me.distance + ")"
);
} else {
console.log("[DEMO] Landing...\n");
......@@ -306,5 +308,4 @@
console.log("next checkpoint is", me.next_checkpoint);
}
};
}(console, me));
\ No newline at end of file
}(console, me));
/*jslint indent2 */
/*global console */
const ALTITUDE_DIFF = 30;
const FLIGH_ALTITUDE = 100;
const PARACHUTE_ALTITUDE = 35;
const EPSILON_ALTITUDE = 5;
let INITIAL_ALTITUDE;
let START_ALTITUDE;
/*jslint nomen: true, indent: 2, maxerr: 3, maxlen: 80 */
/*global console, me, sleep*/
(function (console, me, sleep) {
"use strict";
var ALTITUDE_DIFF = 30,
EPSILON_ALTITUDE = 5,
FLIGH_ALTITUDE = 100,
INITIAL_ALTITUDE,
LEADER_ID = 0,
IS_LEADER = me.id === LEADER_ID,
PARACHUTE_ALTITUDE = 35,
START_ALTITUDE,
leaderAltitudeAbs,
leaderAltitudeRel,
leaderLatitude,
leaderLongitude;
var leaderAltitudeAbs;
var leaderAltitudeRel;
var leaderLatitude;
var leaderLongitude;
function exit_on_fail(ret, msg) {
if (ret) {
console.log(msg);
me.exit(1);
}
}
function waitForAltitude(target_altitude) {
var altitude = getAltitude();
while(Math.abs(altitude - target_altitude) > EPSILON_ALTITUDE) {
function waitForAltitude(target_altitude) {
var altitude = me.getAltitude();
while (Math.abs(altitude - target_altitude) > EPSILON_ALTITUDE) {
console.log(
`[DEMO] Waiting for altitude... (${altitude} , ${target_altitude})`);
"[DEMO] Waiting for altitude... ("
+ altitude + " , " + target_altitude + ")"
);
sleep(1000);
altitude = getAltitude();
altitude = me.getAltitude();
}
}
}
function goToAltitude(target_altitude, wait, go) {
if(go) {
function goToAltitude(target_altitude, wait, go) {
if (go) {
exit_on_fail(
setAltitude(target_altitude),
`Failed to go to altitude ${target_altitude} m`
me.setAltitude(target_altitude),
"Failed to go to altitude " + target_altitude + " m"
);
}
if(wait) {
if (wait) {
waitForAltitude(target_altitude);
}
}
}
function followLeader(leaderId, initialAltitude, altitudeDiff) {
function followLeader(leaderId, initialAltitude, altitudeDiff) {
goToAltitude(START_ALTITUDE + ALTITUDE_DIFF, false, true);
while(droneDict[leaderId].altitudeAbs == 0) {
while (me.droneDict[leaderId].altitudeAbs === 0) {
console.log("[DEMO] Waiting for leader to send its altitude");
sleep(1000);
}
while(droneDict[leaderId].altitudeAbs < initialAltitude) {
console.log(`[DEMO] Waiting for leader to reach altitude ${initialAltitude} (currently ${droneDict[leaderId].altitudeAbs})`);
while (me.droneDict[leaderId].altitudeAbs < initialAltitude) {
console.log(
"[DEMO] Waiting for leader to reach altitude " + initialAltitude
+ " (currently " + me.droneDict[leaderId].altitudeAbs + ")"
);
sleep(1000);
}
console.log("[DEMO] Switching to following mode...\n");
do {
leaderAltitudeAbs = droneDict[leaderId].altitudeAbs;
leaderAltitudeRel = droneDict[leaderId].altitudeRel;
leaderLatitude = droneDict[leaderId].latitude;
leaderLongitude = droneDict[leaderId].longitude;
leaderAltitudeAbs = me.droneDict[leaderId].altitudeAbs;
leaderAltitudeRel = me.droneDict[leaderId].altitudeRel;
leaderLatitude = me.droneDict[leaderId].latitude;
leaderLongitude = me.droneDict[leaderId].longitude;
setTargetCoordinates(
me.setTargetCoordinates(
leaderLatitude,
leaderLongitude,
leaderAltitudeAbs + altitudeDiff,
30.001
);
sleep(500);
} while(leaderAltitudeRel > PARACHUTE_ALTITUDE);
} while (leaderAltitudeRel > PARACHUTE_ALTITUDE);
console.log("[DEMO] Stop following...\n");
}
function waitForAltitude(altitude) {
var curAltitude;
do {
sleep(1000);
curAltitude = getAltitude();
console.log(
`[DEMO] Waiting for altitude... (${curAltitude} , ${altitude})`);
}
while(curAltitude < altitude);
}
me.onStart = function() {
INITIAL_ALTITUDE = getInitialAltitude();
me.onStart = function () {
INITIAL_ALTITUDE = me.getInitialAltitude();
START_ALTITUDE = INITIAL_ALTITUDE + FLIGH_ALTITUDE;
goToAltitude(altitude, true, true);
goToAltitude(START_ALTITUDE, true, true);
waitForAltitude(START_ALTITUDE);
console.log("[DEMO] Setting loiter mode...\n");
loiter();
me.loiter();
sleep(3000);
};
};
me.onUpdate = function() {
if(!IS_LEADER) {
me.onUpdate = function () {
if (!IS_LEADER) {
followLeader(LEADER_ID, START_ALTITUDE, ALTITUDE_DIFF);
}
console.log("[DEMO] Loitering until manual intructions are given\n")
while(!landed()) {
console.log("[DEMO] Loitering until manual intructions are given\n");
while (!me.landed()) {
sleep(1000);
}
};
};
}(console, me));
/*jslint nomen: true, indent: 2, maxerr: 3, maxlen: 80 */
/*global console, me*/
(function (console, me) {
(function (console, me) {
"use strict";
var ALTITUDE = 100,
......@@ -73,7 +73,8 @@
me.setTargetCoordinates(
CHECKPOINT_LIST[me.next_checkpoint].latitude,
CHECKPOINT_LIST[me.next_checkpoint].longitude,
CHECKPOINT_LIST[me.next_checkpoint].altitude + ALTITUDE + ALTITUDE * me.id
CHECKPOINT_LIST[me.next_checkpoint].altitude
+ ALTITUDE + ALTITUDE * me.id
);
console.log("[DEMO] Going to Checkpoint %d", me.next_checkpoint);
}
......@@ -107,5 +108,4 @@
me.exit(0);
}
};
}(console, me));
\ No newline at end of file
}(console, me));
me.onStart = function() {
/*jslint nomen: true, indent: 2, maxerr: 3, maxlen: 80 */
/*global console, me*/
(function (console, me) {
"use strict";
me.onStart = function () {
me.f = me.fdopen(me.in, "r");
console.log("Use q to quit");
};
};
me.onUpdate= function(timestamp) {
while(me.f.getline() != "q") {
continue;
me.onUpdate = function (timestamp) {
if (me.f.getline() !== "q") {
return;
}
try {
me.f.close();;
me.f.close();
} catch (error) {
console.error(error);
}
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