Skip to content

Connectivity module description

Qubaef edited this page Apr 14, 2021 · 2 revisions

Scope of the module

Connectivity module should enable connection with the drone. It should provide a way to instruct the device from within the code so that it can be moved freely. It should also provide some sort of emergency mode to prevent damage to the device.

Moreover, it should deliver error-handling functionalities and provide low-level decision making during critical situations. It shall provide error-handling at the connection level and at the level of execution of instructions on the device. Unexpected results should be analyzed and followed with proper internal decisions - either another attempt to perform operation, or emergency landing in possibly safest manner (the decision should be proper to the error level).

The number of instructions sent to the drone should be minimized, to ensure the lowest possible traffic load.

Concept of instruction

Drone operates on its own internal instructions defined by its API. Example instructions below:

However, the module operates on custom format of instruction (MovementInstruction) which is defined externally and will be used by other modules. Custom format is described on other wiki page TODO: here.

MovementInstruction should deliver a translation method, which will transcript our movement instruction to series of drone instructions which need to be completed.

Entrypoints

It should publish following entrypoints:

  • initialize - opens separate threads, which are supposed to communicate with the drone. It should open UDP connection following the documentation instructions. This connection should be maintained in the newly opened threads, which should collect and send proper data to the drone. Returns true if connection was established properly. Returns false otherwise.

  • send_instruction - receives properly formatted instruction, which describes expected drone movement. This instruction should be executed on the drone as soon as possible, overwriting previously passed instructions, even if they were not finished. Instructions received by this entrypoint should be of type MovementInstruction. Received instruction should be translated to series of drone instructions, which should be further placed on drone_instruction_stack. Returns true if instruction was received properly by the module (not by the drone!). Returns false otherwise.

  • get_instruction - returns last instruction sent to the module - doesn't matter if was finalized or not. Returns last_instruction value.

  • get_state - returns current drone state as DroneState object. The translation from Returns last_instruction value.

  • if_idle - checks if drone's instruction stack is empty, what means that the drone is idle and waiting for new input Returns true if instruction stack is empty. Returns false otherwise.

  • close - closes established connection with the drone and clears connectivity thread. If drone is in the air, proper landing procedure should be executed beforehand. It might take a while to finish this entrypoint execution, but it must provide safe connection closure. Returns no value, as it has to land properly and close the connection.

  • halt - interrupts currently performed task and attempts to stop as quickly as it is possible (might try to perform few previous instructions to move to safety). Used in order to prevent drone damage - called manually by the user. Returns no value, as it has to stop the drone.

  • TODO: there is also some kind of get_stream function which needs to be defined, but it requires further discussion, so it will be described later on

Imports

This module should also import following dataclasses (import, because they will be also used in other modules, so they have to be independent):

  • MovementInstruction - used in send_instruction
  • DroneState - used in get_state

Internal fields

This module should also contain following internal fields:

  • response_thread - the response thread should read the drone state and save the string to drone_state; it should also collect drone responses to save and log them Responsibilities:
    • actively collecting and saving the drone state data
    • logging every drone's response
  • sender_thread - the sender thread should send queued instructions when drone is ready to collect them Responsibilities:
    • sending instructions and waiting for their finalization
    • logging every drone's input
    • reacting on errors and deciding how to handle them dynamically
  • last_instruction - last received (through send_instruction) MovementInstruction instruction
  • drone_instruction_stack - stack of drone instructions to complete. Next instruction should be placed on the top. Performed instruction should be placed to drone_finished_stack.
  • drone_finished_stack - contains previously performed drone instructions. Last performed instruction should be placed on the top. It may be limited of size. Might be used during halt or close procedures to perform safer landing procedure.
  • drone_state - string containing recent drone state. Used in get_state to create DroneState object and return it.

Clone this wiki locally