diff --git a/src/api_communication/api_communication/api_listener.py b/src/api_communication/api_communication/api_listener.py index ff25675f..7842874f 100644 --- a/src/api_communication/api_communication/api_listener.py +++ b/src/api_communication/api_communication/api_listener.py @@ -124,17 +124,20 @@ class ApiListener(Node): self.get_logger().info('Calling take picture service') future = self.take_picture_client.call_async(self.take_picture_request) future.add_done_callback(partial(self.image_request_callback)) - + + def image_request_callback(self, future): try: result_filename = future.result().filename - result_filename = result_filename.replace("/home/ubuntu/ros2_ws/api/public", "") self.get_logger().info("Received result filename: " + result_filename) - self.message_queue.append(json.dumps( - {'type': ResponseMessage.IMAGE.name, 'image': result_filename})) + with open(result_filename, 'rb') as f: + self.get_logger().info('Reading image') + self.message_queue.append(json.dumps( + {'type': ResponseMessage.IMAGE.name, 'image': image_data})) + image_data = f.read() except Exception as e: - self.get_logger().error( - 'Something went wrong while sending a take picture request and waiting for the response: %r' % (e)) + self.get_logger().error('Something went wrong while sending a take picture request and waiting for the response: %r' % (e)) + def send_available_commands(self): print('Sending available commands') @@ -231,12 +234,10 @@ class ApiListener(Node): self.get_logger().info('Emergency stop command received') # emergency stop: set to attitude mode and stop, also disarm else: - self.get_logger().error('Received unknown command ' + - str(message_json['command'])) + self.get_logger().error('Received unknown command ' + str(message_json['command']) ) self.send_available_commands() except TypeError: - self.get_logger().error('Received unknown type: ' + - str(type(message)) + " " + str(message)) + self.get_logger().error('Received unknown type: ' +str(type(message)) + " " + str(message)) self.send_available_commands() except json.JSONDecodeError: self.get_logger().error('Received invalid JSON') diff --git a/src/camera/camera/camera_controller.py b/src/camera/camera/camera_controller.py index 6f1fde70..a70b37de 100644 --- a/src/camera/camera/camera_controller.py +++ b/src/camera/camera/camera_controller.py @@ -21,7 +21,7 @@ class CameraController(Node): if (request.input_name == "default"): self.get_logger().info("Taking picture with default filename") now = datetime.now().strftime("droneimage_%Y-%m-%d_%H-%M-%S") - imagename = "/home/ubuntu/ros2_ws/api/public/img/" + now + ".jpg" + imagename = "/home/ubuntu/drone_img/" + now + ".jpg" response.filename = imagename else: response.filename = request.input_name