Skip to content

Commit

Permalink
Reformatting
Browse files Browse the repository at this point in the history
  • Loading branch information
duembgen committed Apr 28, 2021
1 parent ecddb39 commit 04b7c1b
Show file tree
Hide file tree
Showing 23 changed files with 1,142 additions and 623 deletions.
23 changes: 12 additions & 11 deletions flight_contol/fly_forward_turn_forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from cflib.positioning.motion_commander import MotionCommander


URI = 'radio://0/80/2M/E7E7E7E7E7'
URI = "radio://0/80/2M/E7E7E7E7E7"
DEFAULT_HEIGHT = 0.5

is_deck_attached = False
Expand All @@ -19,15 +19,15 @@ def move_linear_simple(scf):
with MotionCommander(scf, default_height=DEFAULT_HEIGHT) as mc:
print("Take off")
time.sleep(1)

print("Forward")
mc.forward(0.25)
time.sleep(1)

print("Turn left")
mc.turn_left(180)
time.sleep(1)

print("Forward")
mc.forward(0.25)
time.sleep(1)
Expand All @@ -42,21 +42,22 @@ def param_deck_flow(name, value):

print(type(value))

if value == '1':
if value == "1":
is_deck_attached = True
print('Deck is attached!')
print("Deck is attached!")
else:
is_deck_attached = False
print('Deck is NOT attached!')
print("Deck is NOT attached!")


if __name__ == '__main__':
if __name__ == "__main__":
cflib.crtp.init_drivers(enable_debug_driver=False)

with SyncCrazyflie(URI, cf=Crazyflie(rw_cache='./cache')) as scf:
with SyncCrazyflie(URI, cf=Crazyflie(rw_cache="./cache")) as scf:

scf.cf.param.add_update_callback(group='deck', name='bcFlow2',
cb=param_deck_flow)
scf.cf.param.add_update_callback(
group="deck", name="bcFlow2", cb=param_deck_flow
)
time.sleep(1)

if is_deck_attached:
Expand Down
18 changes: 10 additions & 8 deletions flight_contol/fly_hover_land.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
z_filtered_logs = np.empty(1)
vz_logs = np.empty(1)


def initialization(scf):
cf = scf.cf
activate_high_level_commander(cf)
Expand All @@ -34,6 +35,7 @@ def initialization(scf):
time.sleep(2)
return cf.high_level_commander


def low_pass(z, z_old, dt, fc):
tau = 1 / (2 * np.pi * fc)
alpha = dt / tau
Expand Down Expand Up @@ -67,7 +69,7 @@ def log_func(scf):
vz = (z - z_filtered_logs[-1]) / dt
vz_logs = np.append(vz_logs, vz)
z_filtered_logs = np.append(z_filtered_logs, z)
print('thrust', data["stabilizer.thrust"])
print("thrust", data["stabilizer.thrust"])


def take_off(commander):
Expand All @@ -76,13 +78,14 @@ def take_off(commander):
commander.takeoff(height, 0.5)
time.sleep(1.0)


def param_update_callback(name, value):
print('The crazyflie has parameter ' + name + ' set at number: ' + value)
print("The crazyflie has parameter " + name + " set at number: " + value)


if __name__ == "__main__":
#cf_id = "E7E7E7E7E8"
#id = f"radio://0/80/2M/{cf_id}"
# cf_id = "E7E7E7E7E8"
# id = f"radio://0/80/2M/{cf_id}"

cf_id = "E7E7E7E7E7"
id = f"radio://0/70/2M/{cf_id}"
Expand All @@ -95,7 +98,7 @@ def param_update_callback(name, value):
time_start = time.process_time()

take_off(commander)

try:
Thread(target=log_func, args=[scf]).start()

Expand All @@ -105,17 +108,16 @@ def param_update_callback(name, value):
commander.land(0.0, 1.0)
time.sleep(2)
commander.stop()

print("flying")
time.sleep(2)

print("landing")
commander.land(0.0, 1.0)
commander.stop()

time.sleep(2)


if PLOTTING:
fig, axs = plt.subplots(2)
axs[0].plot(z_ranger_logs)
Expand Down
33 changes: 17 additions & 16 deletions flight_contol/fly_hover_land_buzz.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
id = "radio://0/80/2M"
is_deck_attached = False


def initialization(scf):
cf = scf.cf
activate_high_level_commander(cf)
Expand All @@ -36,15 +37,17 @@ def initialization(scf):
time.sleep(2)
return cf.high_level_commander


def param_deck_flow(name, value):
global is_deck_attached
print(value)
if value:
is_deck_attached = True
print('Deck is attached!')
print("Deck is attached!")
else:
is_deck_attached = False
print('Deck is NOT attached!')
print("Deck is NOT attached!")


def low_pass(z, z_old, dt, fc):
tau = 1 / (2 * np.pi * fc)
Expand Down Expand Up @@ -88,17 +91,17 @@ def take_off(commander):
commander.takeoff(height, 0.5)
time.sleep(1.0)


def param_update_callback(name, value):
print('The crazyflie has parameter ' + name + ' set at number: ' + value)
print("The crazyflie has parameter " + name + " set at number: " + value)


def simple_param_async(scf, groupstr, namestr, value):
cf = scf.cf
full_name = groupstr + '.' + namestr
full_name = groupstr + "." + namestr

cf.param.add_update_callback(group=groupstr, name=namestr,
cb=param_update_callback)
#time.sleep(1)
cf.param.add_update_callback(group=groupstr, name=namestr, cb=param_update_callback)
# time.sleep(1)
cf.param.set_value(full_name, value)


Expand All @@ -112,7 +115,7 @@ def simple_param_async(scf, groupstr, namestr, value):
time_start = time.process_time()

take_off(commander)

try:
Thread(target=log_func, args=[scf]).start()

Expand All @@ -122,23 +125,21 @@ def simple_param_async(scf, groupstr, namestr, value):
commander.land(0.0, 1.0)
time.sleep(2)
commander.stop()


simple_param_async(scf, 'sound', 'effect', 12)
simple_param_async(scf, 'sound', 'freq', 600)
simple_param_async(scf, 'sound', 'ratio', 0)
simple_param_async(scf, "sound", "effect", 12)
simple_param_async(scf, "sound", "freq", 600)
simple_param_async(scf, "sound", "ratio", 0)

print("Flying")
time.sleep(2)

print("Landing")
commander.land(0.0, 1.0)
commander.stop()

simple_param_async(scf, 'sound', 'effect', 0)
simple_param_async(scf, "sound", "effect", 0)
time.sleep(2)


if PLOTTING:

fig, axs = plt.subplots(2)
Expand Down
81 changes: 37 additions & 44 deletions flight_contol/test_buzzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,28 @@
from cflib.crazyflie.syncLogger import SyncLogger

# URI to the Crazyflie to connect to
uri = 'radio://0/80/2M/E7E7E7E7E7'
uri = "radio://0/80/2M/E7E7E7E7E7"

# Only output errors from the logging framework
logging.basicConfig(level=logging.ERROR)


def param_update_callback(name, value):
print('The crazyflie has parameter ' + name + ' set at number: ' + value)
print("The crazyflie has parameter " + name + " set at number: " + value)


def simple_param_async(scf, groupstr, namestr, value):
cf = scf.cf
full_name = groupstr + '.' + namestr
full_name = groupstr + "." + namestr

cf.param.add_update_callback(group=groupstr, name=namestr,
cb=param_update_callback)
#time.sleep(1)
cf.param.add_update_callback(group=groupstr, name=namestr, cb=param_update_callback)
# time.sleep(1)
cf.param.set_value(full_name, value)



def log_stab_callback(timestamp, data, logconf):
print('[%d][%s]: %s' % (timestamp, logconf.name, data))
print("[%d][%s]: %s" % (timestamp, logconf.name, data))


def simple_log_async(scf, logconf):
cf = scf.cf
Expand All @@ -39,6 +38,8 @@ def simple_log_async(scf, logconf):
logconf.start()
time.sleep(5)
logconf.stop()


def simple_log(scf, logconf):

with SyncLogger(scf, lg_stab) as logger:
Expand All @@ -49,62 +50,54 @@ def simple_log(scf, logconf):
data = log_entry[1]
logconf_name = log_entry[2]

print('[%d][%s]: %s' % (timestamp, logconf_name, data))
print("[%d][%s]: %s" % (timestamp, logconf_name, data))

break


def simple_connect():

print("Yeah, I'm connected! :D")
time.sleep(3)
print("Now I will disconnect :'(")

if __name__ == '__main__':

if __name__ == "__main__":
# Initialize the low-level drivers (don't list the debug drivers)
cflib.crtp.init_drivers(enable_debug_driver=False)

lg_stab = LogConfig(name='Stabilizer', period_in_ms=10)
lg_stab.add_variable('stabilizer.roll', 'float')
lg_stab.add_variable('stabilizer.pitch', 'float')
lg_stab.add_variable('stabilizer.yaw', 'float')
lg_stab = LogConfig(name="Stabilizer", period_in_ms=10)
lg_stab.add_variable("stabilizer.roll", "float")
lg_stab.add_variable("stabilizer.pitch", "float")
lg_stab.add_variable("stabilizer.yaw", "float")

group = 'sound'
name = 'effect'
group = "sound"
name = "effect"

with SyncCrazyflie(uri, cf=Crazyflie(rw_cache='./cache')) as scf:
simple_param_async(scf, 'sound', 'effect', 0)
with SyncCrazyflie(uri, cf=Crazyflie(rw_cache="./cache")) as scf:
simple_param_async(scf, "sound", "effect", 0)
time.sleep(2)


simple_param_async(scf, 'sound', 'effect', 12)
simple_param_async(scf, 'sound', 'freq', 2000)
simple_param_async(scf, 'sound', 'ratio', 1)

simple_param_async(scf, "sound", "effect", 12)
simple_param_async(scf, "sound", "freq", 2000)
simple_param_async(scf, "sound", "ratio", 1)
time.sleep(5)

simple_param_async(scf, 'sound', 'effect', 12)
simple_param_async(scf, 'sound', 'freq', 600)
simple_param_async(scf, 'sound', 'ratio', 0)
simple_param_async(scf, "sound", "effect", 12)
simple_param_async(scf, "sound", "freq", 600)
simple_param_async(scf, "sound", "ratio", 0)
time.sleep(5)
simple_param_async(scf, 'sound', 'effect', 0)
simple_param_async(scf, "sound", "effect", 0)
time.sleep(2)

simple_param_async(scf, 'sound', 'effect', 12)
simple_param_async(scf, 'sound', 'freq', 600)
simple_param_async(scf, 'sound', 'ratio', 10)
simple_param_async(scf, "sound", "effect", 12)
simple_param_async(scf, "sound", "freq", 600)
simple_param_async(scf, "sound", "ratio", 10)
time.sleep(5)

simple_param_async(scf, 'sound', 'effect', 12)
simple_param_async(scf, 'sound', 'freq', 600)
simple_param_async(scf, 'sound', 'ratio', 0)
simple_param_async(scf, "sound", "effect", 12)
simple_param_async(scf, "sound", "freq", 600)
simple_param_async(scf, "sound", "ratio", 0)
time.sleep(5)
simple_param_async(scf, 'sound', 'effect', 0)
simple_param_async(scf, "sound", "effect", 0)
time.sleep(2)










16 changes: 9 additions & 7 deletions flight_contol/test_flow_detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,30 @@
from cflib.crazyflie.syncCrazyflie import SyncCrazyflie
from cflib.positioning.motion_commander import MotionCommander

URI = 'radio://0/80/2M/E7E7E7E7E7'
URI = "radio://0/80/2M/E7E7E7E7E7"

is_deck_attached = False

logging.basicConfig(level=logging.ERROR)


def param_deck_flow(name, value):
global is_deck_attached
print(value)
if value:
is_deck_attached = True
print('Deck is attached!')
print("Deck is attached!")
else:
is_deck_attached = False
print('Deck is NOT attached!')
print("Deck is NOT attached!")


if __name__ == '__main__':
if __name__ == "__main__":
cflib.crtp.init_drivers(enable_debug_driver=False)

with SyncCrazyflie(URI, cf=Crazyflie(rw_cache='./cache')) as scf:
with SyncCrazyflie(URI, cf=Crazyflie(rw_cache="./cache")) as scf:

scf.cf.param.add_update_callback(group='deck', name='bcFlow2',
cb=param_deck_flow)
scf.cf.param.add_update_callback(
group="deck", name="bcFlow2", cb=param_deck_flow
)
time.sleep(1)
Loading

0 comments on commit 04b7c1b

Please sign in to comment.