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