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
1
Merge Requests
1
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
5e57abdf
Commit
5e57abdf
authored
Mar 02, 2023
by
Léo-Paul Géneau
👾
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Comply to JSLint
parent
5c0b63f0
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
434 additions
and
406 deletions
+434
-406
cli.js
cli.js
+124
-171
demo.js
demo.js
+310
-235
No files found.
cli.js
View file @
5e57abdf
/*jslint indent2 */
/*global console, std */
const
EPSILON_YAW
=
6
;
const
EPSILON_ALTITUDE
=
5
;
const
TARGET_YAW
=
0
;
var
running
=
false
;
const
wrongParameters
=
displayMessage
.
bind
(
null
,
"
Wrong parameters
"
);
function
displayDronePositions
()
{
if
(
!
pubsubRunning
)
console
.
log
(
"
You must start pubsub first !
"
);
else
{
for
(
const
[
id
,
drone
]
of
Object
.
entries
(
droneDict
))
{
console
.
log
(
id
,
drone
.
latitude
,
drone
.
longitude
,
drone
.
altitudeAbs
,
drone
.
altitudeRel
);
}
}
return
0
;
}
function
land
()
{
var
yaw
;
while
(
true
)
{
yaw
=
getYaw
();
console
.
log
(
`[DEMO] Waiting for yaw... (
${
yaw
}
,
${
TARGET_YAW
}
)`
);
if
(
Math
.
abs
(
yaw
-
TARGET_YAW
)
<
EPSILON_YAW
)
{
break
;
}
sleep
(
250
);
}
console
.
log
(
"
[DEMO] Deploying parachute...
"
);
exit_on_fail
(
doParachute
(
2
),
"
Failed to deploy parachute
"
);
}
function
waitForAltitude
(
target_altitude
)
{
var
altitude
=
getAltitude
();
while
(
Math
.
abs
(
altitude
-
target_altitude
)
>
EPSILON_ALTITUDE
)
{
console
.
log
(
`[DEMO] Waiting for altitude... (
${
altitude
}
,
${
target_altitude
}
)`
);
sleep
(
1000
);
altitude
=
getAltitude
();
}
}
function
goToAltitude
(
target_altitude
,
wait
,
go
)
{
if
(
go
)
{
exit_on_fail
(
setAltitude
(
target_altitude
),
`Failed to go to altitude
${
target_altitude
}
m`
);
}
if
(
wait
)
{
waitForAltitude
(
target_altitude
);
}
}
function
checkNumber
(
value
,
toExecute
)
{
return
(
Number
.
isNaN
(
value
)
?
wrongParameters
:
toExecute
.
bind
(
null
,
value
)
);
}
function
displayMessage
(
message
)
{
console
.
log
(
message
);
return
0
;
}
function
exit
()
{
running
=
false
;
return
0
;
}
function
getInput
()
{
let
undefined_cmd
;
let
altitude
;
let
cmd
;
let
latitude
;
let
longitude
;
let
s
;
let
speed
;
const
help
=
`
land
goto(point)
gotoCoord(latitude, longitude)
altitude(altitude)
speed(speed)
positions
reboot
exit
help
`
;
const
f
=
std
.
fdopen
(
std
.
in
,
"
r
"
);
running
=
true
;
while
(
running
)
{
std
.
printf
(
"
>
"
);
s
=
f
.
getline
();
undefined_cmd
=
false
;
switch
(
s
)
{
case
"
altitude
"
:
std
.
printf
(
"
Altitude:
"
);
altitude
=
parseFloat
(
f
.
getline
());
cmd
=
checkNumber
(
altitude
,
setAltitude
);
break
;
case
"
exit
"
:
cmd
=
exit
;
break
;
/* case "gotoCoord":
std.printf("Latitude: ");
latitude = parseFloat(f.getline());
std.printf("Longitude: ");
longitude = parseFloat(f.getline());
cmd = checkNumber(longitude, checkNumber(latitude, setTargetLatLong));
break;*/
case
"
help
"
:
cmd
=
displayMessage
.
bind
(
null
,
help
);
break
;
case
"
land
"
:
cmd
=
land
;
break
;
case
"
loiter
"
:
cmd
=
loiter
;
break
;
case
"
positions
"
:
cmd
=
displayDronePositions
;
break
;
case
"
reboot
"
:
cmd
=
reboot
;
break
;
case
"
speed
"
:
std
.
printf
(
"
Speed:
"
);
speed
=
parseFloat
(
f
.
getline
());
cmd
=
checkNumber
(
speed
,
setAirspeed
);
break
;
default
:
undefined_cmd
=
true
;
cmd
=
displayMessage
.
bind
(
null
,
"
Undefined command
"
);
}
let
ret
=
cmd
();
if
(
ret
)
{
console
.
log
(
"
[ERROR] function:
\n
"
,
cmd
,
"
\n
return value:
"
,
ret
);
}
else
if
(
s
!==
"
help
"
&&
!
undefined_cmd
)
{
console
.
log
(
"
Command successful
"
);
}
};
f
.
close
();
}
me
.
onUpdate
=
function
()
{
getInput
();
};
/*jslint nomen: true, indent: 2, maxerr: 3, maxlen: 80 */
/*global console, me*/
(
function
(
console
,
me
)
{
"
use strict
"
;
function
displayMessage
(
message
)
{
console
.
log
(
message
);
return
0
;
}
var
help
=
[
"
altitude(altitude)
"
,
"
exit
"
,
"
goto(latitude, longitude, altitude)
"
,
"
help
"
,
"
land
"
,
"
loiter
"
,
"
positions
"
,
"
speed(speed)
"
].
join
(
"
\n
"
),
wrongParameters
=
displayMessage
.
bind
(
null
,
"
Wrong parameters
"
);
function
checkNumber
(
value
,
toExecute
)
{
return
(
Number
.
isNaN
(
value
)
?
wrongParameters
:
toExecute
.
bind
(
null
,
value
)
);
}
function
displayDronePositions
()
{
Object
.
entries
(
me
.
droneDict
).
forEach
(
function
([
id
,
drone
])
{
console
.
log
(
id
,
drone
.
latitude
,
drone
.
longitude
,
drone
.
altitudeAbs
,
drone
.
altitudeRel
);
});
return
0
;
}
function
exit
()
{
try
{
me
.
f
.
close
();
}
catch
(
error
)
{
console
.
error
(
error
);
}
me
.
exit
(
0
);
}
me
.
onStart
=
function
()
{
me
.
f
=
me
.
fdopen
(
me
.
in
,
"
r
"
);
console
.
log
(
help
);
};
me
.
onUpdate
=
function
()
{
var
altitude
,
latitude
,
longitude
,
speed
,
user_input
,
undefined_cmd
=
false
,
cmd
,
ret
;
console
.
log
(
"
>
"
);
user_input
=
me
.
f
.
getline
();
switch
(
user_input
)
{
case
"
altitude
"
:
console
.
log
(
"
Altitude:
"
);
altitude
=
parseFloat
(
me
.
f
.
getline
());
cmd
=
checkNumber
(
altitude
,
me
.
setAltitude
);
break
;
case
"
exit
"
:
cmd
=
exit
;
break
;
case
"
goto
"
:
console
.
log
(
"
Latitude:
"
);
latitude
=
parseFloat
(
me
.
f
.
getline
());
console
.
log
(
"
Longitude:
"
);
longitude
=
parseFloat
(
me
.
f
.
getline
());
console
.
log
(
"
Altitude:
"
);
altitude
=
parseFloat
(
me
.
f
.
getline
());
cmd
=
checkNumber
(
altitude
,
checkNumber
(
longitude
,
checkNumber
(
latitude
,
me
.
setTargetCoordinates
))
);
break
;
case
"
help
"
:
cmd
=
displayMessage
.
bind
(
null
,
help
);
break
;
case
"
land
"
:
cmd
=
me
.
triggerParachute
;
break
;
case
"
loiter
"
:
cmd
=
me
.
loiter
;
break
;
case
"
positions
"
:
cmd
=
displayDronePositions
;
break
;
case
"
speed
"
:
console
.
log
(
"
Speed:
"
);
speed
=
parseFloat
(
me
.
f
.
getline
());
cmd
=
checkNumber
(
speed
,
me
.
setAirspeed
);
break
;
default
:
undefined_cmd
=
true
;
cmd
=
displayMessage
.
bind
(
null
,
"
Undefined command
"
);
}
ret
=
cmd
();
if
(
ret
)
{
console
.
log
(
"
[ERROR] function:
\n
"
,
cmd
,
"
\n
return value:
"
,
ret
);
}
else
if
(
user_input
!==
"
help
"
&&
!
undefined_cmd
)
{
console
.
log
(
"
Command successful
"
);
}
};
}(
console
,
me
));
\ No newline at end of file
demo.js
View file @
5e57abdf
This diff is collapsed.
Click to expand it.
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