Advertisement
Rubics

Take off Bitcraze

Feb 24th, 2022
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. import logging
  2. import sys
  3. import time
  4. from threading import Event
  5.  
  6. import cflib.crtp
  7. from cflib.crazyflie import Crazyflie
  8. from cflib.crazyflie.syncCrazyflie import SyncCrazyflie
  9. from cflib.positioning.motion_commander import MotionCommander
  10. from cflib.utils import uri_helper
  11.  
  12. URI = uri_helper.uri_from_env(default='radio://0/80/2M/E7E7E7E7E7')
  13.  
  14. DEFAULT_HEIGHT = 1.0
  15.  
  16. deck_attached_event = Event()
  17.  
  18. logging.basicConfig(level=logging.ERROR)
  19.  
  20. def take_off_simple(scf):
  21. with MotionCommander(scf, default_height=DEFAULT_HEIGHT) as mc:
  22. time.sleep(1)
  23. mc.stop()
  24.  
  25.  
  26. def param_deck_flow(_, value_str):
  27. value = int(value_str)
  28. print(value)
  29. if value:
  30. deck_attached_event.set()
  31. print('Deck is attached!')
  32. else:
  33. print('Deck is NOT attached!')
  34.  
  35.  
  36. if __name__ == '__main__':
  37. cflib.crtp.init_drivers()
  38.  
  39. with SyncCrazyflie(URI, cf=Crazyflie(rw_cache='./cache')) as scf:
  40.  
  41. scf.cf.param.add_update_callback(group='deck', name='bcDWM1000',cb=param_deck_flow)
  42. scf.cf.param.request_param_update('deck.bcDWM1000')
  43.  
  44.  
  45. if not deck_attached_event.wait(timeout=5):
  46. print('No flow deck detected!')
  47. sys.exit(1)
  48.  
  49. take_off_simple(scf)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement