mirror of
https://github.com/CopterExpress/clever-show.git
synced 2026-05-30 00:39:32 +00:00
Improvements in client-side
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
[SERVER]
|
||||
port = 25000
|
||||
broadcast_port = 8181
|
||||
host = 192.168.1.104
|
||||
host = 192.168.43.168
|
||||
buffer_size = 1024
|
||||
|
||||
[FILETRANSFER]
|
||||
@@ -27,3 +27,4 @@ id = /hostname
|
||||
use_leds = True
|
||||
x0 = 0
|
||||
y0 = 0
|
||||
|
||||
|
||||
@@ -9,16 +9,17 @@ import client
|
||||
import messaging_lib as messaging
|
||||
import play_animation
|
||||
|
||||
def
|
||||
|
||||
class CopterClient(client.Client):
|
||||
def load_config(self):
|
||||
super(CopterClient, self).load_config()
|
||||
self.FRAME_ID = self.config.get('COPTERS', 'frame_id') # TODO in play_animation
|
||||
self.FRAME_ID = self.config.get('COPTERS', 'frame_id')
|
||||
play_animation.FRAME_ID = self.FRAME_ID
|
||||
self.TAKEOFF_HEIGHT = self.config.getfloat('COPTERS', 'takeoff_height')
|
||||
self.TAKEOFF_TIME = self.config.getfloat('COPTERS', 'takeoff_time')
|
||||
self.RFP_TIME = self.config.getfloat('COPTERS', 'reach_first_point_time')
|
||||
self.SAFE_TAKEOFF = self.config.getboolean('COPTERS', 'safe_takeoff')
|
||||
self.RFP_TIME = self.config.getfloat('COPTERS', 'reach_first_point_time')
|
||||
|
||||
|
||||
self.X0_COMMON = self.config.getfloat('COPTERS', 'x0_common')
|
||||
self.Y0_COMMON = self.config.getfloat('COPTERS', 'y0_common')
|
||||
@@ -34,23 +35,26 @@ class CopterClient(client.Client):
|
||||
if self.USE_LEDS:
|
||||
LedLib.init_led()
|
||||
|
||||
|
||||
@messaging.request_callback("selfcheck")
|
||||
def _response_selfcheck():
|
||||
return FlightLib.selfcheck()
|
||||
|
||||
|
||||
@messaging.request_callback("batt_voltage")
|
||||
def _response_batt():
|
||||
return FlightLib.get_telemetry('body').voltage
|
||||
|
||||
|
||||
@messaging.request_callback("cell_voltage")
|
||||
def _response_cell():
|
||||
return FlightLib.get_telemetry('body').cell_voltage
|
||||
|
||||
|
||||
@messaging.message_callback("service_restart")
|
||||
def _message_service_restart(*args, **kwargs):
|
||||
def _command_service_restart(*args, **kwargs):
|
||||
os.system("systemctl restart"+kwargs["name"])
|
||||
|
||||
|
||||
@messaging.message_callback("led_test")
|
||||
def _command_config_write(*args, **kwargs):
|
||||
LedLib.chase(255, 255, 255)
|
||||
@@ -58,6 +62,13 @@ def _command_config_write(*args, **kwargs):
|
||||
LedLib.off()
|
||||
|
||||
|
||||
@messaging.message_callback("takeoff")
|
||||
def _command_takeoff(*args, **kwargs):
|
||||
play_animation.takeoff(z=client.active_client.TAKEOFF_HEIGHT,
|
||||
timeout=client.active_client.TAKEOFF_TIME,
|
||||
safe_takeoff=client.active_client.SAFE_TAKEOFF,
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
copter_client = CopterClient()
|
||||
|
||||
@@ -10,13 +10,13 @@ module_logger = logging.getLogger("Animation player")
|
||||
|
||||
animation_file_path = 'animation.csv'
|
||||
USE_LEDS = True
|
||||
FRAME_ID = 'aruco_map'
|
||||
|
||||
|
||||
def takeoff(z=1.5, safe_takeoff=True, timeout=5000):
|
||||
if USE_LEDS:
|
||||
LedLib.wipe_to(255, 0, 0)
|
||||
if safe_takeoff:
|
||||
FlightLib.takeoff(z=z, wait=True, timeout_takeoff=timeout, emergency_land=safe_takeoff)
|
||||
FlightLib.takeoff(z=z, wait=True, timeout_takeoff=timeout, emergency_land=safe_takeoff,)
|
||||
LedLib.blink(0, 255, 0)
|
||||
|
||||
|
||||
@@ -28,14 +28,16 @@ def land(descend=False):
|
||||
LedLib.off()
|
||||
|
||||
|
||||
def animate_frame(current_frame, x0=0.0, y0=0.0):
|
||||
FlightLib.navto(current_frame['x']+x0, current_frame['y']+y0, current_frame['z'], yaw=1.57) # TODO yaw
|
||||
def animate_frame(current_frame, x0=0.0, y0=0.0, copter_frame_id=FRAME_ID):
|
||||
FlightLib.navto(current_frame['x']+x0, current_frame['y']+y0, current_frame['z'],
|
||||
yaw=1.57, frame_id=copter_frame_id) # TODO yaw
|
||||
if USE_LEDS:
|
||||
LedLib.fill(current_frame['red'], current_frame['green'], current_frame['blue'])
|
||||
|
||||
|
||||
def reach_frame(current_frame, x0=0.0, y0=0.0, timeout=5000):
|
||||
FlightLib.reach_point(current_frame['x']+x0, current_frame['y']+y0, current_frame['z'], yaw=1.57, timeout=timeout) # TODO yaw
|
||||
def reach_frame(current_frame, x0=0.0, y0=0.0, timeout=5000, copter_frame_id=FRAME_ID):
|
||||
FlightLib.reach_point(current_frame['x']+x0, current_frame['y']+y0, current_frame['z'],
|
||||
yaw=1.57, timeout=timeout, frame_id=copter_frame_id) # TODO yaw
|
||||
if USE_LEDS:
|
||||
LedLib.fill(current_frame['red'], current_frame['green'], current_frame['blue'])
|
||||
|
||||
|
||||
@@ -14,7 +14,6 @@ except ImportError:
|
||||
|
||||
PendingRequest = collections.namedtuple("PendingRequest", ["value", "requested_value", # "expires_on",
|
||||
"callback", "callback_args", "callback_kwargs",
|
||||
# "obj",
|
||||
])
|
||||
|
||||
|
||||
@@ -323,14 +322,14 @@ class ConnectionManager(object):
|
||||
else:
|
||||
logging.warning("Unexpected response!")
|
||||
|
||||
def _process_filetransfer(self, message):
|
||||
def _process_filetransfer(self, message): # TODO path?
|
||||
if message.jsonheader["content-type"] == "binary":
|
||||
filepath = message.jsonheader["filepath"]
|
||||
try:
|
||||
with open(filepath, 'wb') as f:
|
||||
f.write(message.content)
|
||||
except OSError as error:
|
||||
logging.warning("File can not be written due error: ".format(error))
|
||||
logging.error("File {} can not be written due error: {}".format(filepath, error))
|
||||
else:
|
||||
logging.info("File {} successfully received ".format(filepath))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user