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
7568df53
Commit
7568df53
authored
Mar 02, 2023
by
Léo-Paul Géneau
👾
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add bouncy flight script
parent
5e57abdf
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
201 additions
and
0 deletions
+201
-0
bouncy-flight.js
bouncy-flight.js
+201
-0
No files found.
bouncy-flight.js
0 → 100644
View file @
7568df53
/*jslint nomen: true, indent: 2, maxerr: 3, maxlen: 80 */
/*global console, me*/
(
function
(
console
,
me
)
{
"
use strict
"
;
var
EPSILON
=
9
,
FLIGH_ALTITUDE
=
100
,
PARACHUTE_ALTITUDE
=
35
,
CHECKPOINT_LIST
=
[
{
"
altitude
"
:
604
,
"
latitude
"
:
45.641
,
"
longitude
"
:
14.26472
},
{
"
altitude
"
:
642
,
"
latitude
"
:
45.6463889
,
"
longitude
"
:
14.2516
},
{
"
altitude
"
:
596
,
"
latitude
"
:
45.656
,
"
longitude
"
:
14.2516
},
{
"
altitude
"
:
634
,
"
latitude
"
:
45.65916
,
"
longitude
"
:
14.255
},
{
"
altitude
"
:
676
,
"
latitude
"
:
45.6527
,
"
longitude
"
:
14.2775
},
{
"
altitude
"
:
589
,
"
latitude
"
:
45.6427
,
"
longitude
"
:
14.2519
},
{
"
altitude
"
:
582
,
"
latitude
"
:
45.641
,
"
longitude
"
:
14.254
},
{
"
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
}
];
function
distance
(
lat1
,
lon1
,
lat2
,
lon2
)
{
var
R
=
6371
e3
,
// meters
la1
=
lat1
*
Math
.
PI
/
180
,
// la, lo in radians
la2
=
lat2
*
Math
.
PI
/
180
,
lo1
=
lon1
*
Math
.
PI
/
180
,
lo2
=
lon2
*
Math
.
PI
/
180
,
haversine_phi
=
Math
.
pow
(
Math
.
sin
((
la2
-
la1
)
/
2
),
2
),
sin_lon
=
Math
.
sin
((
lo2
-
lo1
)
/
2
),
h
=
haversine_phi
+
Math
.
cos
(
la1
)
*
Math
.
cos
(
la2
)
*
sin_lon
*
sin_lon
;
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
;
}
function
groundLevel
(
drone
)
{
return
drone
.
getAltitudeAbs
()
-
drone
.
getCurrentPosition
().
z
;
}
me
.
onStart
=
function
()
{
me
.
direction_set
=
false
;
me
.
landing_alt_reached
=
false
;
me
.
next_checkpoint
=
0
;
me
.
parachute_triggered
=
false
;
};
me
.
onUpdate
=
function
(
timestamp
)
{
if
(
me
.
must_wait
>
0
)
{
if
(
!
mustWait
(
timestamp
))
{
me
.
must_wait
=
0
;
me
.
timestamp
=
0
;
}
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
"
);
console
.
log
(
`[DEMO] Going to Checkpoint
${
me
.
next_checkpoint
}
\n`
);
}
else
{
me
.
loiter
();
console
.
log
(
"
[DEMO] Going to landing altitude...
\n
"
);
me
.
landing_altitude
=
groundLevel
(
me
)
+
PARACHUTE_ALTITUDE
;
exit_on_fail
(
me
.
setAltitude
(
me
.
landing_altitude
),
"
Failed to set landing altitude
"
);
}
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
,
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`
);
me
.
next_checkpoint
+=
1
;
me
.
direction_set
=
false
;
}
return
;
}
if
(
!
me
.
landing_alt_reached
)
{
me
.
landing_alt_reached
=
altitudeReached
(
me
.
getAltitudeAbs
(),
me
.
landing_altitude
);
return
;
}
if
(
!
me
.
parachute_triggered
)
{
console
.
log
(
"
[DEMO] Deploying parachute...
"
);
exit_on_fail
(
me
.
triggerParachute
(),
"
Failed to deploy parachute
"
);
me
.
parachute_triggered
=
true
;
}
if
(
me
.
landed
())
{
me
.
exit
(
0
);
}
};
}(
console
,
me
));
\ No newline at end of file
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