Mission Manager

This module implements the central mission management system featuring: - Multi-threaded mission execution - Vehicle communication coordination - Plan processing and validation - Feedback handling and status updates - Cross-service integration (REST, MQTT, Database)

Classes

MissionManagerThread

Core mission execution thread

CommandsActionServer

ROS 2 action server implementation (external)

Functions

create_mission_manager

Mission thread factory function

create_logger

Concurrent-safe logging configuration

create_queues

Inter-service communication setup

Note

Requires concurrent access protection for: - Queue operations - Plan modifications - Status updates

Warning

Maintain strict synchronization between: - Vehicle command sequences - Task status updates - Dependency resolutions

class mission_manager.MissionManagerThread(mission_id, mission_json, send_vehicle_queue, receive_vehicle_queue, send_db_queue, receive_db_queue, send_mqtt_queue, send_rest_queue, mission_logger)[source]

Bases: Thread

Central mission execution thread managing vehicle coordination and task processing.

Parameters:
  • mission_id (int) – Unique mission identifier

  • mission_json (dict) – Complete mission specification

  • send_vehicle_queue (queue.Queue) – Outbound vehicle command queue (producer)

  • receive_vehicle_queue (queue.Queue) – Inbound vehicle feedback queue (consumer)

  • send_db_queue (queue.Queue) – Database write queue (unimplemented)

  • receive_db_queue (queue.Queue) – Database read queue (unimplemented)

  • send_mqtt_queue (queue.Queue) – MQTT telemetry publication queue

  • send_rest_queue (queue.Queue) – REST API communication queue

  • mission_logger (logging.Logger) – Configured mission logger instance

Variables:
  • plans (dict) – Current vehicle task configurations (vehicle_id → plan)

  • results (dict) – Vehicle completion status tracking (vehicle_id → bool)

  • start_plan (dict) – Mission timing metadata (vehicle_id → timestamp)

__init__(mission_id, mission_json, send_vehicle_queue, receive_vehicle_queue, send_db_queue, receive_db_queue, send_mqtt_queue, send_rest_queue, mission_logger)[source]

This constructor should always be called with keyword arguments. Arguments are:

group should be None; reserved for future extension when a ThreadGroup class is implemented.

target is the callable object to be invoked by the run() method. Defaults to None, meaning nothing is called.

name is the thread name. By default, a unique name is constructed of the form “Thread-N” where N is a small decimal number.

args is a list or tuple of arguments for the target invocation. Defaults to ().

kwargs is a dictionary of keyword arguments for the target invocation. Defaults to {}.

context is the contextvars.Context value to use for the thread. The default value is None, which means to check sys.flags.thread_inherit_context. If that flag is true, use a copy of the context of the caller. If false, use an empty context. To explicitly start with an empty context, pass a new instance of contextvars.Context(). To explicitly start with a copy of the current context, pass the value from contextvars.copy_context().

If a subclass overrides the constructor, it must make sure to invoke the base class constructor (Thread.__init__()) before doing anything else to the thread.

run()[source]

Executes the mission by managing plans, processing feedback, and communicating with vehicles.

Note

Lifecycle phases: 1. Mission data persistence 2. Plan generation & validation 3. Vehicle command distribution 4. Feedback processing loop 5. Mission termination & cleanup

proccess_plans()[source]

Processes the mission plans and sends initial commands to vehicles.

Parameters:
  • plans (dict) – The mission plans.

  • results (dict) – A dictionary to track the completion status of vehicles.

process_vehicle_feedback()[source]

Processes incoming vehicle feedback and updates mission plans.

Note

Handles message types: 0: Plan initiation confirmation 1: Command execution feedback 2: Plan completion notice

handle_plan_started(vehicle_id: int)[source]

Handles the event when a vehicle starts its plan.

Parameters:

vehicle_id (int) – Target vehicle identifier

handle_command_feedback(vehicle_id: int, drone_result: list)[source]

Handles command feedback from a vehicle

Parameters:
  • vehicle_id (int) – The ID of the vehicle.

  • drone_result (list) – The feedback data from the vehicle.

update_status(vehicle_id: int, task_id: int, cmd_id: int)[source]

Progresses task and command states based on completion.

Parameters:
  • vehicle_id (int) – Target vehicle identifier

  • task_id (int) – Current task identifier

  • cmd_id (int) – Completed command identifier

mission_telemetry()[source]

Modifies the telemetry data to include mission-specific information.

Parameters:

telemetry (dict) – The telemetry data to modify.

feedback_telemetry(task, command, vehicle_id, result)[source]

Modifies the telemetry data to include mission-specific information.

Parameters:

telemetry (dict) – The telemetry data to modify.

set_fields()[source]
update_field()[source]

Updates the state of the fields based on the command type.

send_plan(vehicle_id: int, plan: dict)[source]

Sends a plan to a vehicle.

Parameters:
  • vehicle_id (int) – The ID of the vehicle.

  • plan (dict) – The plan to send.

send_queue(service: str, **kwargs)[source]

Routes messages through appropriate service channels.

Parameters:

service – Target service identifier

Note

Supported services: - REST: Mission status updates - Vehicle: Command distributions - MQTT: Thingsboard data - DB: (Implementation pending)

receive_queue(service: str) list[source]

Retrieves and parses incoming service messages.

Parameters:

service – Source service identifier

Returns:

Parsed message content

Note

Supported services: - Vehicle: Command feedback - DB: (Implementation pending)

save_to_file(file_path: str, data: dict)[source]

Persists mission data to JSON files.

Parameters:
  • file_path (str) – Target file path

  • data (dict) – Data structure to persist

mission_manager.create_mission_manager(mission_json: list, send_vehicle_queue: <module 'queue' from '/opt/hostedtoolcache/Python/3.14.3/x64/lib/python3.14/queue.py'>, receive_vehicle_queue: <module 'queue' from '/opt/hostedtoolcache/Python/3.14.3/x64/lib/python3.14/queue.py'>, send_db_queue: <module 'queue' from '/opt/hostedtoolcache/Python/3.14.3/x64/lib/python3.14/queue.py'>, receive_db_queue: <module 'queue' from '/opt/hostedtoolcache/Python/3.14.3/x64/lib/python3.14/queue.py'>, send_mqtt_queue: <module 'queue' from '/opt/hostedtoolcache/Python/3.14.3/x64/lib/python3.14/queue.py'>, send_rest_queue: <module 'queue' from '/opt/hostedtoolcache/Python/3.14.3/x64/lib/python3.14/queue.py'>, mission_logger: ~logging.Logger) int[source]

Creates and starts a MissionManagerThread.

Parameters:
  • mission_json (dict) – The JSON data of the mission.

  • send_vehicle_queue (queue) – Queue for sending data to vehicles.

  • receive_vehicle_queue (queue) – Queue for receiving data from vehicles.

  • send_db_queue (queue) – Queue for sending data to the database.

  • receive_db_queue (queue) – Queue for receiving data from the database.

  • send_mqtt_queue (queue) – Queue for sending data via MQTT.

  • send_rest_queue (queue) – Queue for sending data via REST.

  • mission_logger (logging.Logger) – Logger for logging mission manager activities.

Returns:

The ID of the created mission.

Return type:

int

mission_manager.create_logger(logger_name: str, log_file: str) Logger[source]

Configures concurrent-safe logging infrastructure.

Returns:

Configured logger instance

mission_manager.create_queues() tuple[source]

Generates communication queue set.

Returns:

Tuple of configured queues in order: (send_vehicle, receive_vehicle, send_db, receive_db, send_mqtt, send_rest)