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