Skip to content
Snippets Groups Projects
Commit 392b4706 authored by Arnaud Taffanel's avatar Arnaud Taffanel
Browse files

Fix synchrounousSequence flake8/style

parent 84859f55
No related branches found
No related tags found
No related merge requests found
......@@ -23,7 +23,8 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
"""
Simple example of a synchronized swarm choreography using the High level commander.
Simple example of a synchronized swarm choreography using the High level
commander.
The swarm takes off and flies a synchronous choreography before landing.
The take-of is relative to the start position but the Goto are absolute.
......@@ -33,7 +34,10 @@ This example is intended to work with any absolute positioning system.
It aims at documenting how to use the High Level Commander together with
the Swarm class to achieve synchronous sequences.
"""
import threading
import time
from collections import namedtuple
from queue import Queue
import cflib.crtp
from cflib.crazyflie.log import LogConfig
......@@ -41,19 +45,17 @@ from cflib.crazyflie.swarm import CachedCfFactory
from cflib.crazyflie.swarm import Swarm
from cflib.crazyflie.syncLogger import SyncLogger
from collections import namedtuple
import threading
from queue import Queue
# Time for one step in second
STEP_TIME = 1
# Possible commands, all times are in seconds
Takeoff = namedtuple('Takeoff', ['height', 'time'])
Land = namedtuple("Land", ['time'])
Land = namedtuple('Land', ['time'])
Goto = namedtuple('Goto', ['x', 'y', 'z', 'time'])
Ring = namedtuple('Ring', ['r', 'g', 'b', 'intensity', 'time']) # RGB [0-255], Intensity [0.0-1.0]
Quit = namedtuple('Quit', []) # Reserved for the control loop, do not use in sequence
# RGB [0-255], Intensity [0.0-1.0]
Ring = namedtuple('Ring', ['r', 'g', 'b', 'intensity', 'time'])
# Reserved for the control loop, do not use in sequence
Quit = namedtuple('Quit', [])
uris = [
'radio://0/10/2M/E7E7E7E701', # cf_id 0, startup position [-0.5, -0.5]
......@@ -99,6 +101,7 @@ sequence = [
(15, 2, Ring(0, 0, 0, 0, 5)),
]
def wait_for_position_estimator(scf):
print('Waiting for estimator to find position...')
......@@ -198,26 +201,27 @@ def crazyflie_control(scf):
command.intensity, command.time)
pass
else:
print("Warning! unknown command {} for uri {}".format(command,
print('Warning! unknown command {} for uri {}'.format(command,
cf.uri))
def control_thread():
pointer = 0
step = 0
stop = False
while not stop:
print("Step {}:".format(step))
print('Step {}:'.format(step))
while sequence[pointer][0] <= step:
cf_id = sequence[pointer][1]
command = sequence[pointer][2]
print(" - Running: {} on {}".format(command, cf_id))
print(' - Running: {} on {}'.format(command, cf_id))
controlQueues[cf_id].put(command)
pointer += 1
if pointer >= len(sequence):
print("Reaching the end of the sequence, stopping!")
print('Reaching the end of the sequence, stopping!')
stop = True
break
......@@ -227,6 +231,7 @@ def control_thread():
for ctrl in controlQueues:
ctrl.put(Quit())
if __name__ == '__main__':
controlQueues = [Queue() for _ in range(len(uris))]
......@@ -236,7 +241,7 @@ if __name__ == '__main__':
swarm.parallel_safe(activate_high_level_commander)
swarm.parallel_safe(reset_estimator)
print("Starting sequence!")
print('Starting sequence!')
threading.Thread(target=control_thread).start()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment