Project

General

Profile

Defining new aircraft using plugins » History » Version 2

Rafael Bailon-Ruiz, 2020-08-28 18:19

1 2 Rafael Bailon-Ruiz
h1. Defining new aircraft using plugins
2 1 Rafael Bailon-Ruiz
3
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.
4
5
h2. Aircraft abstraction
6
7
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.
8
An example from the Aircraft class of nephelae_base repository:
9
<pre><code class="python">def start(self): # Called at initialization
10
   """
11
   Sets the running attribute to true, then fetches all mandatory
12
   informations by requesting messages via the socket.
13
   """                                                                                                                                                                              
14
   self.running = True
15
   self.set_config()
16
   self.binds.append(self.harmonizer.subscribe_to(
17
        self.flight_param_callback, 'status')) # Subscribing to status messages
18
&nbsp;
19
def flight_param_callback(self, status): # Callback
20
   """
21
   Calls the set_status method of the status attribute, then sends a copy 
22
   of the current status on the add_status notification method
23
&nbsp;
24
   Parameters
25
   ----------
26
   status : dict
27
      Contains the new informations about the status of the uav (name of
28
      parameter : new value)
29
   """
30
   self.status.set_status(status)
31
   self.add_status(self.status.copy()) #Updating the aircraft abstraction status
32
</code></pre>
33
34
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.
35
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. 
36
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.
37
It is also by these means that Aircraft abstractions can retrieve the measurements of sensors.
38
39
Aircraft class is Pluginable, which means that this class and its specifications can use plugins.
40
41
h2. Plugins
42
43
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.
44
An example of how a function can be added :
45
<pre><code class="python">def __pluginmethods__():
46
    """
47
    Returns the list of methods that needs to be attached to the Pluginable
48
    class that uses it.
49
    Each element of the list is a dict, containing :
50
    - Name of the function to decorate (if it does exist) or to create
51
    (if it does not) inside the Pluginable object
52
    - Method used to decorate (the one defined inside the Plugin object)
53
    - How it decorates the method.
54
&nbsp;
55
    Returns
56
    -------
57
    list[dict]
58
        List of methods to decorate
59
    """
60
    return [{'name'         : 'energy_callback', # The name of the function we want to decorate
61
             'method'       : Energy.energy_callback, # The function that is written inside the plugin
62
             'conflictMode' : 'append'}, # How the class is aggregated (here, after the normal behavior)
63
            {'name'         : 'add_sensor_observer',
64
             'method'       : Energy.add_sensor_observer,
65
             'conflictMode' : 'abort'}, # In this case, the function is not created if already existing
66
            {'name'         : 'remove_sensor_observer',
67
             'method'       : Energy.remove_sensor_observer,
68
             'conflictMode' : 'abort'}
69
           ]
70
</code></pre>
71
Attributes can be added as well as functions.
72
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.