Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
F
flight-scripts
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
flight-scripts
Commits
29e7a5d7
Commit
29e7a5d7
authored
Mar 14, 2023
by
Léo-Paul Géneau
👾
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Comply to ERP5 JsLint
parent
8ca353c0
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
684 additions
and
663 deletions
+684
-663
bouncy-flight.js
bouncy-flight.js
+15
-13
cli.js
cli.js
+120
-120
default.js
default.js
+10
-3
demo.js
demo.js
+308
-307
manual-flight.js
manual-flight.js
+101
-97
simulator-script.js
simulator-script.js
+108
-108
subscribe.js
subscribe.js
+22
-15
No files found.
bouncy-flight.js
View file @
29e7a5d7
...
...
@@ -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
;
}
...
...
cli.js
View file @
29e7a5d7
/*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
default.js
View file @
29e7a5d7
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
));
demo.js
View file @
29e7a5d7
/*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
));
manual-flight.js
View file @
29e7a5d7
/*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
));
simulator-script.js
View file @
29e7a5d7
/*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
));
subscribe.js
View file @
29e7a5d7
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
));
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment