Source code for commands

import time
import random
from abc import ABC, abstractmethod

[docs] class Command(ABC): """Abstract base class for all drone command types. :param related_task: ID of parent task :type related_task: int :param id: Unique command identifier :type id: int :param command_type: Command category (e.g., 'NAVIGATION', 'CAMERA') :type command_type: str :param start_time: Unix timestamp of command initiation :type start_time: int :param command_status: Current execution state ('Pending'|'Running'|'Completed') :type command_status: str .. note:: All concrete commands must implement execute() and result() methods """
[docs] def __init__(self, related_task: int, id: int, command_type: str, start_time: int, command_status: str): self.related_task = related_task self.id = id self.command_type = command_type self.start_time = start_time self.command_status = command_status
[docs] @abstractmethod def execute(self): """Execute command logic. Must be implemented by subclasses.""" pass
[docs] @abstractmethod def result(self): """Return command outcome. Must be implemented by subclasses. :return: Tuple containing (command_id, status_message, lat, lon) :rtype: tuple """ pass
[docs] class Camera_Image(Command): """Image capture command implementation. :param params: Camera parameters in order: [0] yaw_angle (float): Camera heading (degrees) [1] pitch_angle (float): Camera tilt angle (degrees) [2] photo_count (int): Number of images to capture [3] time_interval (float): Time between captures (seconds) """
[docs] def __init__(self, related_task, id, command_type, start_time, command_status, params): super().__init__(related_task, id, command_type, start_time, command_status) self.yaw_angle = params[0] self.pitch_angle = params[1] self.photo_count = params[2] self.time_interval = params[3]
[docs] def execute(self): """Simulate photo capture with 1s delay.""" print("Taking picture...") time.sleep(10)
[docs] def result(self): """Return image capture confirmation. :return: (command_id, status, None, None) """ return self.id, "Picture taken", None, None
[docs] class Analyze_Image(Command): """Image analysis command implementation. :param params: Analysis parameters in order: [0] product (str): Target detection product [1] latitude (float): Image location latitude [2] longitude (float): Image location longitude """
[docs] def __init__(self, related_task, id, command_type, start_time, command_status, params): super().__init__(related_task, id, command_type, start_time, command_status) self.product = params[0] self.latitude = params[1] self.longitude = params[2]
[docs] def execute(self): """Simulate analysis with random result and 10s delay.""" print("Analyzing image...") self.product_amount = random.randint(0, 3) time.sleep(10)
[docs] def result(self): """Return analysis results with location. :return: (command_id, [product, amount], lat, lon) """ return self.id, [self.product, self.product_amount], self.latitude, self.longitude
[docs] class Spray(Command): """Spray treatment command implementation. :param params: Spray parameters in order: [0] product (str): Treatment product name [1] product_amount (float): Quantity to dispense (liters) [2] latitude (float): Application latitude [3] longitude (float): Application longitude """
[docs] def __init__(self, related_task, id, command_type, start_time, command_status, params): super().__init__(related_task, id, command_type, start_time, command_status) self.product = params[0] self.product_amount = params[1] self.latitude = params[2] self.longitude = params[3]
[docs] def execute(self): """Simulate spraying operation with 5s delay.""" print("Spraying...") time.sleep(10)
[docs] def result(self): """Return spray operation confirmation. :return: (command_id, [product, amount], lat, lon) """ return self.id, [self.product, self.product_amount], self.latitude, self.longitude