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
d6f89db3
Commit
d6f89db3
authored
Jun 20, 2024
by
Léo-Paul Géneau
👾
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update bouncy-flight.js
parent
a0de0e00
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
111 deletions
+34
-111
bouncy-flight.js
bouncy-flight.js
+34
-111
No files found.
bouncy-flight.js
View file @
d6f89db3
...
@@ -10,94 +10,46 @@
...
@@ -10,94 +10,46 @@
(
function
(
console
,
me
)
{
(
function
(
console
,
me
)
{
"
use strict
"
;
"
use strict
"
;
var
EPSILON
=
42
,
var
ALTITUDE
=
100
,
FLIGH_ALTITUDE
=
100
,
EPSILON
=
9
,
CHECKPOINT_LIST
=
[
CHECKPOINT_LIST
=
[
{
{
"
altitude
"
:
604
,
latitude
:
45.64492790560583
,
"
latitude
"
:
45.641
,
longitude
:
14.25334942966329
"
longitude
"
:
14.26472
},
},
{
{
"
altitude
"
:
642
,
latitude
:
45.64316335436476
,
"
latitude
"
:
45.6463889
,
longitude
:
14.26332880184475
"
longitude
"
:
14.2516
},
},
{
{
"
altitude
"
:
596
,
latitude
:
45.64911917196595
,
"
latitude
"
:
45.656
,
longitude
:
14.26214792790128
"
longitude
"
:
14.2516
},
},
{
{
"
altitude
"
:
634
,
latitude
:
45.64122685351364
,
"
latitude
"
:
45.65916
,
longitude
:
14.26590493128597
"
longitude
"
:
14.255
},
},
{
{
"
altitude
"
:
676
,
latitude
:
45.64543355564817
,
"
latitude
"
:
45.6527
,
longitude
:
14.27242391207985
"
longitude
"
:
14.2775
},
},
{
{
"
altitude
"
:
589
,
latitude
:
45.6372792927328
,
"
latitude
"
:
45.6427
,
longitude
:
14.27533492411138
"
longitude
"
:
14.2519
},
},
{
{
"
altitude
"
:
582
,
latitude
:
45.64061299543953
,
"
latitude
"
:
45.641
,
longitude
:
14.26161958465814
"
longitude
"
:
14.254
},
},
{
{
"
altitude
"
:
686
,
latitude
:
45.64032340702919
,
"
latitude
"
:
45.6558
,
longitude
:
14.2682896662383
"
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
)
{
function
distance
(
lat1
,
lon1
,
lat2
,
lon2
)
{
var
R
=
6371
e3
,
// meters
var
R
=
6371
e3
,
// meters
la1
=
lat1
*
Math
.
PI
/
180
,
// la
, lo
in radians
la1
=
lat1
*
Math
.
PI
/
180
,
// la
t, lon
in radians
la2
=
lat2
*
Math
.
PI
/
180
,
la2
=
lat2
*
Math
.
PI
/
180
,
lo1
=
lon1
*
Math
.
PI
/
180
,
lo1
=
lon1
*
Math
.
PI
/
180
,
lo2
=
lon2
*
Math
.
PI
/
180
,
lo2
=
lon2
*
Math
.
PI
/
180
,
...
@@ -107,72 +59,43 @@
...
@@ -107,72 +59,43 @@
return
2
*
R
*
Math
.
asin
(
Math
.
sqrt
(
h
));
return
2
*
R
*
Math
.
asin
(
Math
.
sqrt
(
h
));
}
}
function
exit_on_fail
(
ret
,
msg
)
{
me
.
onStart
=
function
(
timestamp
)
{
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
;
}
me
.
onStart
=
function
()
{
me
.
direction_set
=
false
;
me
.
direction_set
=
false
;
me
.
next_checkpoint
=
0
;
me
.
next_checkpoint
=
0
;
me
.
takeOff
();
};
};
me
.
onUpdate
=
function
(
timestamp
)
{
me
.
onUpdate
=
function
(
timestamp
)
{
if
(
me
.
must_wait
>
0
)
{
if
(
!
me
.
isReadyToFly
())
{
return
;
}
if
(
!
mustWait
(
timestamp
))
{
me
.
must_wait
=
0
;
me
.
timestamp
=
0
;
}
return
;
}
if
(
!
me
.
direction_set
)
{
if
(
!
me
.
direction_set
)
{
if
(
me
.
next_checkpoint
<
CHECKPOINT_LIST
.
length
)
{
if
(
me
.
next_checkpoint
<
CHECKPOINT_LIST
.
length
)
{
exit_on_fail
(
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
+
FLIGH_ALTITUDE
ALTITUDE
+
ALTITUDE
*
me
.
id
,
),
5
"
Failed to set checkpoint coordinates
"
);
);
console
.
log
(
"
[DEMO] Going to Checkpoint
"
+
me
.
next_checkpoint
+
"
\n
"
);
console
.
log
(
"
[DEMO] Going to Checkpoint
%d
"
,
me
.
next_checkpoint
);
}
}
me
.
direction_set
=
true
;
me
.
direction_set
=
true
;
return
;
return
;
}
}
if
(
me
.
next_checkpoint
<
CHECKPOINT_LIST
.
length
)
{
if
(
me
.
next_checkpoint
<
CHECKPOINT_LIST
.
length
)
{
me
.
current_position
=
me
.
getCurrentPosition
();
me
.
current_position
=
me
.
getCurrentPosition
();
me
.
distance
=
distance
(
me
.
distance
=
distance
(
me
.
current_position
.
x
,
me
.
current_position
.
latitude
,
me
.
current_position
.
y
,
me
.
current_position
.
longitude
,
CHECKPOINT_LIST
[
me
.
next_checkpoint
].
latitude
,
CHECKPOINT_LIST
[
me
.
next_checkpoint
].
latitude
,
CHECKPOINT_LIST
[
me
.
next_checkpoint
].
longitude
CHECKPOINT_LIST
[
me
.
next_checkpoint
].
longitude
);
);
if
(
me
.
distance
>
EPSILON
)
{
if
(
me
.
distance
<=
EPSILON
)
{
console
.
log
(
console
.
log
(
"
[DEMO] Reached Checkpoint %d
"
,
me
.
next_checkpoint
);
"
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
.
next_checkpoint
+=
1
;
me
.
direction_set
=
false
;
me
.
direction_set
=
false
;
}
}
return
;
return
;
}
}
if
(
!
me
.
isLanding
())
{
me
.
land
();
}
console
.
log
(
"
[DEMO] Deploying parachute...
"
);
if
(
me
.
getCurrentPosition
().
altitude
<=
0
)
{
me
.
exit
(
0
);
}
exit_on_fail
(
me
.
triggerParachute
(),
"
Failed to deploy parachute
"
);
me
.
exit
(
0
);
};
};
}(
console
,
me
));
}(
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