From b300db8601e12601cdc1da8f9458e9c010c8154a Mon Sep 17 00:00:00 2001 From: Artem30801 Date: Sun, 20 Jan 2019 12:07:27 +0300 Subject: [PATCH] Leds off + takeoff fix --- Drone/client.py | 10 +++++++--- Drone/client_config.ini | 3 ++- Drone/play_animation.py | 21 +++++++++++++-------- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/Drone/client.py b/Drone/client.py index e7f30eb..bf94fdd 100644 --- a/Drone/client.py +++ b/Drone/client.py @@ -102,7 +102,7 @@ def animation_player(running_event, stop_event): print("Animation thread activated") rate = rospy.Rate(1000 / 100) play_animation.takeoff(TAKEOFF_HEIGHT) - for current_frame in play_animation.frame(): + for current_frame in play_animation.get_frames(): running_event.wait() if stop_event.is_set(): break @@ -165,6 +165,9 @@ if COPTER_ID == 'default': TAKEOFF_HEIGHT = float(config.get('COPTER', 'takeoff_height')) +USE_LEDS = bool(config.get('COPTER', 'use_leds')) +play_animation.USE_LEDS = USE_LEDS + print("Client started on copter:", COPTER_ID) print("NTP time:", time.ctime(get_ntp_time(NTP_HOST, NTP_PORT))) print("System time", time.ctime(time.time())) @@ -200,8 +203,9 @@ try: send_all(bytes(form_command("response", response))) print("Request responded with:", response) - except socket.error: - print("Connection lost... reconnecting") + except socket.error as e: + print("Connection lost due error:", e) + print("Reconnecting...") reconnect() print("Re-connection successful") except KeyboardInterrupt: diff --git a/Drone/client_config.ini b/Drone/client_config.ini index 71439a9..c121f7c 100644 --- a/Drone/client_config.ini +++ b/Drone/client_config.ini @@ -11,7 +11,8 @@ host = ntp1.stratum2.ru port = 123 [COPTER] -id = copter6349 +id = default takeoff_height = 1.75 takeoff_timeout = 7 +use_leds = True animation_file = animation.csv diff --git a/Drone/play_animation.py b/Drone/play_animation.py index dcc3838..62adbb9 100644 --- a/Drone/play_animation.py +++ b/Drone/play_animation.py @@ -6,17 +6,21 @@ from FlightLib.FlightLib import LedLib animation_file_path = 'drone.csv' frames = [] +USE_LEDS = True def takeoff(h=1.75): - LedLib.wipe_to(0, 255, 0) - FlightLib.takeoff(h) + if USE_LEDS: + LedLib.wipe_to(0, 255, 0) + FlightLib.takeoff(h, fixed_delay=True) def land(): - LedLib.rainbow() + if USE_LEDS: + LedLib.blink(0, 255, 0) FlightLib.land() - LedLib.off() + if USE_LEDS: + LedLib.off() def do_next_animation(current_frame): @@ -24,9 +28,10 @@ def do_next_animation(current_frame): round(float(current_frame['x']), 4), round(float(current_frame['y']), 4), round(float(current_frame['z']), 4), round(float(current_frame['yaw']), 4), speed=round(float(current_frame['speed']), 4) ) - LedLib.fill( - int(current_frame['green']), int(current_frame['red']), int(current_frame['blue']) - ) + if USE_LEDS: + LedLib.fill( + int(current_frame['green']), int(current_frame['red']), int(current_frame['blue']) + ) def read_animation_file(filepath=animation_file_path): @@ -49,7 +54,7 @@ def read_animation_file(filepath=animation_file_path): }) -def frame(): +def get_frames(): global frames return frames