Project

General

Profile

Actions

Defining new aircraft using plugins

In this page, we will talk about the aircraft abstraction of autopilots. These are representations of flying UAVs (or simulated ones) that are flying. These aircraft abstractions can be plugged with other classes that are made for this. These classes are called plugins.

Aircraft abstraction

The aircraft abstraction class, named Aircraft, is a class that is meant to represent the UAV status and retrieve information from autopilots / registered data. To do so, the class uses mainly callbacks to listen to messages (or topics in a more ROS view), and to update its status. At initialization, it first register all the callbacks needed, then every time a message is received corresponding to one of the callbacks, status are updated with new information.
An example from the Aircraft class of nephelae_base repository:

def start(self): # Called at initialization
   """ 
   Sets the running attribute to true, then fetches all mandatory
   informations by requesting messages via the socket.
   """                                                                                                                                                                              
   self.running = True
   self.set_config()
   self.binds.append(self.harmonizer.subscribe_to(
        self.flight_param_callback, 'status')) # Subscribing to status messages
 
def flight_param_callback(self, status): # Callback
   """ 
   Calls the set_status method of the status attribute, then sends a copy 
   of the current status on the add_status notification method
 
   Parameters
   ----------
   status : dict
      Contains the new informations about the status of the uav (name of
      parameter : new value)
   """ 
   self.status.set_status(status)
   self.add_status(self.status.copy()) #Updating the aircraft abstraction status

The messages must come at a medium-high frequency (2 messages per second is enough) to keep a good track of the position of the UAV.
Aircraft are also capable to interact with the database by notifying them with new samples or status, and use them to monitor UAV for instance.
Subscriptions are done by using the harmonizer class. This class is purely meant to compose / decompose messages over the middleware used (python sockets for instance). See this page for further informations.
It is also by these means that Aircraft abstractions can retrieve the measurements of sensors.

Aircraft class is Pluginable, which means that this class and its specifications can use plugins.

Plugins

Plugins are special classes that are not meant to be used alone. Plugins classes are designed to be attached to a certain class, decorating a class during runtime. It can add functionalities to an existing function of the plugged class (before or after its normal behavior), or adding new functions to the class. The choice of plugins is made inside the configuration file.
An example of how a function can be added :

def __pluginmethods__():
    """ 
    Returns the list of methods that needs to be attached to the Pluginable
    class that uses it.
    Each element of the list is a dict, containing :
    - Name of the function to decorate (if it does exist) or to create
    (if it does not) inside the Pluginable object
    - Method used to decorate (the one defined inside the Plugin object)
    - How it decorates the method.
 
    Returns
    -------
    list[dict]
        List of methods to decorate
    """ 
    return [{'name'         : 'energy_callback', # The name of the function we want to decorate
             'method'       : Energy.energy_callback, # The function that is written inside the plugin
             'conflictMode' : 'append'}, # How the class is aggregated (here, after the normal behavior)
            {'name'         : 'add_sensor_observer',
             'method'       : Energy.add_sensor_observer,
             'conflictMode' : 'abort'}, # In this case, the function is not created if already existing
            {'name'         : 'remove_sensor_observer',
             'method'       : Energy.remove_sensor_observer,
             'conflictMode' : 'abort'}
           ]

Attributes can be added as well as functions.
This way, we can tailor our Aircraft abstractions instances to our needs, subscribing only on topics we are interested in or using only features adapted to the Aircraft.

Updated by Rafael Bailon-Ruiz about 4 years ago · 2 revisions