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
a1853c84
Commit
a1853c84
authored
Apr 25, 2024
by
Léo-Paul Géneau
👾
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update state management
parent
34bf391d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
59 additions
and
58 deletions
+59
-58
multicopter_swarm.js
multicopter_swarm.js
+59
-58
No files found.
multicopter_swarm.js
View file @
a1853c84
...
...
@@ -75,19 +75,6 @@
}
}
function
sendLandingMessage
(
drone
)
{
console
.
log
(
"
Landing
"
);
drone
.
sendMsg
(
JSON
.
stringify
(
{
id
:
drone
.
id
,
inAir
:
false
,
state
:
"
Landed
"
,
type
:
"
state
"
}
));
}
function
land
(
drone
)
{
console
.
log
(
"
Landing
"
);
sendLandingMessage
(
drone
);
exitOnFail
(
drone
.
land
(),
"
Failed to land
"
);
}
function
toRad
(
angle
)
{
return
Math
.
PI
*
angle
/
180
;
}
...
...
@@ -137,7 +124,8 @@
me
.
flightAltitude
=
BASE_ALTITUDE
+
me
.
id
*
ALTITUDE_DIFF
;
me
.
following
=
false
;
me
.
going_to_parachute
=
false
;
me
.
id_list
=
Object
.
keys
(
me
.
getDroneDict
()).
map
((
x
)
=>
Number
(
x
));
me
.
id_list
=
[
me
.
id
];
me
.
timestamp_list
=
[
0
];
me
.
id_list
.
sort
();
me
.
landing
=
false
;
me
.
last_cmd_timestamp
=
0
;
...
...
@@ -145,10 +133,6 @@
me
.
started
=
false
;
me
.
stopped
=
false
;
me
.
reverse
=
false
;
me
.
sendMsg
(
JSON
.
stringify
(
{
id
:
me
.
id
,
inAir
:
true
,
state
:
"
Ready
"
,
type
:
"
state
"
}
));
};
me
.
onUpdate
=
function
(
timestamp
)
{
...
...
@@ -174,40 +158,49 @@
position
.
timestamp
-
neighbor_position
.
timestamp
);
}
return
;
return
me
.
sendMsg
(
JSON
.
stringify
(
{
id
:
me
.
id
,
okState
:
true
,
state
:
"
Ready
"
}
));
}
if
(
me
.
landing
&&
me
.
isLanding
())
{
return
sendLandingMessage
(
me
);
return
me
.
sendMsg
(
JSON
.
stringify
(
{
id
:
drone
.
id
,
okState
:
false
,
state
:
"
Landing
"
}
));
}
if
(
!
me
.
started
)
{
if
(
me
.
isReadyToFly
())
{
me
.
started
=
true
;
}
else
{
console
.
log
(
"
Taking off
"
);
return
me
.
sendMsg
(
JSON
.
stringify
({
id
:
me
.
id
,
timestamp
:
Date
.
now
()}));
return
me
.
sendMsg
(
JSON
.
stringify
(
{
id
:
me
.
id
,
okState
:
true
,
state
:
"
Taking Off
"
,
timestamp
:
Date
.
now
()}
));
}
}
if
(
!
me
.
landing
)
{
if
(
!
me
.
isReadyToFly
())
{
return
console
.
log
(
"
emergency state
"
);
return
me
.
sendMsg
(
JSON
.
stringify
(
{
id
:
me
.
id
,
okState
:
false
,
state
:
"
Emergency
"
}
));
}
me
.
timestamp_list
.
forEach
(
function
(
last_timestamp
,
id
)
{
if
(
me
.
id_list
[
id
]
!==
me
.
id
&&
Math
.
abs
(
timestamp
-
last_timestamp
)
>=
TIMEOUT
)
{
console
.
log
(
"
Lost drone
"
,
me
.
id_list
[
id
],
"
timestamp difference
"
,
timestamp
-
last_timestamp
);
me
.
id_list
.
splice
(
me
.
id_list
.
indexOf
(
id
),
1
);
me
.
timestamp_list
.
splice
(
me
.
id_list
.
indexOf
(
id
),
1
);
return
;
JSON
.
parse
(
JSON
.
stringify
(
me
.
timestamp_list
)).
forEach
(
function
(
last_timestamp
,
id
)
{
if
(
me
.
id_list
[
id
]
!==
me
.
id
&&
Math
.
abs
(
timestamp
-
last_timestamp
)
>=
TIMEOUT
)
{
console
.
log
(
"
Lost drone
"
,
me
.
id_list
[
id
],
"
timestamp difference
"
,
timestamp
-
last_timestamp
);
me
.
id_list
.
splice
(
me
.
id_list
.
indexOf
(
id
),
1
);
me
.
timestamp_list
.
splice
(
me
.
id_list
.
indexOf
(
id
),
1
);
}
}
}
);
);
console
.
log
(
"
leader id
"
,
leader_id
,
"
me id
"
,
me
.
id
);
if
(
leader_id
!==
me
.
id
)
{
...
...
@@ -230,12 +223,11 @@
distanceToTakeOffPoint
);
if
(
distanceToTakeOffPoint
<
2
*
TARGETED_DISTANCE
)
{
return
me
.
sendMsg
(
JSON
.
stringify
({
id
:
me
.
id
,
timestamp
:
Date
.
now
()}));
return
me
.
sendMsg
(
JSON
.
stringify
(
{
id
:
me
.
id
,
okState
:
true
,
state
:
"
Waiting
"
,
timestamp
:
Date
.
now
()}
));
}
me
.
following
=
true
;
return
me
.
sendMsg
(
JSON
.
stringify
(
{
id
:
me
.
id
,
inAir
:
true
,
state
:
"
Flying
"
,
timestamp
:
Date
.
now
(),
type
:
"
state
"
}
));
}
distanceDiff
=
distance2d
-
TARGETED_DISTANCE
;
...
...
@@ -253,7 +245,9 @@
);
console
.
log
(
"
distance to leader
"
,
distance2d
);
return
me
.
sendMsg
(
JSON
.
stringify
({
id
:
me
.
id
,
timestamp
:
Date
.
now
()}));
return
me
.
sendMsg
(
JSON
.
stringify
(
{
id
:
me
.
id
,
okState
:
true
,
state
:
"
Flying
"
,
timestamp
:
Date
.
now
()}
));
}
checkpointIndex
=
(
!
me
.
reverse
)
?
me
.
next_checkpoint
...
...
@@ -276,8 +270,9 @@
me
.
direction_set
=
false
;
return
me
.
sendMsg
(
JSON
.
stringify
({
id
:
me
.
id
,
type
:
"
checkpoint
"
,
okState
:
true
,
next_checkpoint
:
me
.
next_checkpoint
,
state
:
"
Flying
"
,
timestamp
:
Date
.
now
()
}));
}
...
...
@@ -286,7 +281,7 @@
if
(
me
.
going_to_parachute
&&
pointReached
(
me
,
PARACHUTE_POINT_ARRAY
[
me
.
id
],
EPSILON
))
{
me
.
going_to_parachute
=
false
;
return
land
(
me
);
return
exitOnFail
(
drone
.
land
(),
"
Failed to land
"
);
}
if
(
!
me
.
landing
||
me
.
going_to_parachute
)
{
...
...
@@ -298,7 +293,9 @@
Date
.
now
()
);
}
return
me
.
sendMsg
(
JSON
.
stringify
({
id
:
me
.
id
,
timestamp
:
Date
.
now
()}));
return
me
.
sendMsg
(
JSON
.
stringify
(
{
id
:
me
.
id
,
okState
:
true
,
state
:
"
Flying
"
,
timestamp
:
Date
.
now
()}
));
};
me
.
onGetMsg
=
function
(
msg
)
{
...
...
@@ -306,18 +303,11 @@
me
.
path_planning
=
true
;
console
.
log
(
"
running
"
);
me
.
timestamp_list
=
Array
.
apply
(
null
,
Array
(
me
.
id_list
.
length
)).
map
(
function
()
{
return
Date
.
now
()
});
me
.
takeOff
();
return
me
.
sendMsg
(
JSON
.
stringify
(
{
id
:
me
.
id
,
inAir
:
true
,
state
:
"
Flying
"
,
type
:
"
state
"
}
));
return
me
.
takeOff
();
}
var
msgDict
=
JSON
.
parse
(
msg
);
if
(
msgDict
.
hasOwnProperty
(
"
id
"
)
&&
msgDict
.
hasOwnProperty
(
"
timestamp
"
))
{
me
.
timestamp_list
[
msgDict
.
id
]
=
msgDict
.
timestamp
;
}
if
(
msgDict
.
hasOwnProperty
(
"
status
"
))
{
switch
(
msgDict
.
status
)
{
...
...
@@ -345,15 +335,18 @@
return
;
}
if
(
msgDict
.
hasOwnProperty
(
"
typ
e
"
))
{
switch
(
msgDict
.
typ
e
)
{
if
(
msgDict
.
hasOwnProperty
(
"
stat
e
"
))
{
switch
(
msgDict
.
stat
e
)
{
case
"
checkpoint
"
:
me
.
next_checkpoint
=
msgDict
.
next_checkpoint
;
case
"
Ready
"
:
if
(
!
me
.
id_list
.
includes
(
msgDict
.
id
))
{
me
.
id_list
[
me
.
id_list
.
length
-
1
]
=
msgDict
.
id
;
me
.
id_list
.
sort
();
}
break
;
case
"
state
"
:
if
(
m
sgDict
.
state
===
"
Landed
"
&&
m
e
.
id_list
.
includes
(
msgDict
.
id
))
{
case
"
Landing
"
:
if
(
me
.
id_list
.
includes
(
msgDict
.
id
))
{
me
.
id_list
.
splice
(
me
.
id_list
.
indexOf
(
msgDict
.
id
),
1
);
me
.
timestamp_list
.
splice
(
me
.
id_list
.
indexOf
(
id
),
1
);
if
(
me
.
stopped
&&
me
.
id
===
(
!
me
.
reverse
?
me
.
id_list
[
me
.
id_list
.
length
-
1
]
:
me
.
id_list
[
0
]))
{
...
...
@@ -368,8 +361,16 @@
break
;
default
:
console
.
log
(
"
Unknown message type:
"
+
msgDict
.
type
)
;
break
;
}
}
if
(
msgDict
.
hasOwnProperty
(
"
timestamp
"
))
{
me
.
timestamp_list
[
msgDict
.
id
]
=
msgDict
.
timestamp
;
}
if
(
msgDict
.
hasOwnProperty
(
"
next_checkpoint
"
))
{
me
.
next_checkpoint
=
msgDict
.
next_checkpoint
;
}
};
}(
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