### UAV motor-primitive expression

In this paper, motor primitives are defined as follows. In Eq. (1), the *i*th observed and measured motor primitive *m*
_{
i
} is defined in terms of its consecutive movements with execution time *t*
_{
i
}
*'*. We assume that all motor primitives have the same number of movements. Therefore, *p* is the total number of measured motor primitives, and *q* is the number of movements in a motor primitive.

$$m_{i} = \, \{ m_{i,1} , \, m_{i,2} , \ldots , \, m_{i,j} , \ldots , \, m_{i,q} ,\,\,t_{i}^{\prime } \} ,$$

(1)

where the *j*th movement of the *i*th motor primitive is *m*
_{
i,j
}. The movement *m*
_{
i,j
} is defined as shown in Eq. (2). Each movement is expressed by *x* properties and *y* commands. *p*
_{
i,j,x
} and *c*
_{
i,j,y
} is the *x*th property and *y*th command. A property can be not only UAV values, but also any external values. The motor primitive *m*
_{
i,j
} is executed by considering the properties and then sending commands at execution time *t'*
_{
i
}.

$$m_{i,j} = \, \left[ {p_{i,j,1} , \, p_{i,j,2} , \ldots , \, p_{i,j,x} , \, c_{i,j,1} , \, c_{i,j,2} , \ldots , \, c_{i,j,y} } \right]$$

(2)

The movement properties are utilized as the conditions required to send movement commands. When the difference between the movement properties and the UAV properties is smaller than α, the command is sent by the UAV. A graph-based motor primitive *G* is defined as shown in Eq. (3).

$$G \, = \, \left\{ {J, \, M} \right\},$$

(3)

where *J* is the joint-ordered set and *M* is the movement-ordered set. *j*
_{
i
} is the joint of the *i*th movements and an element of joint-ordered set *J*. The movement-ordered set *M* contains the sets of movements. Each set of movements contains movements that occur at the same time.

### UAV motor-primitive generation

The proposed method generates motor primitives in three stages: Operation-collection stage, time-adjustment stage, and motor-primitive generation stage. In the operation-collection stage, an operator uses a controller to make the UAV fly along a predefined path. Given that motor primitives are generated through demonstration-based learning, the UAV should fly the same path repeatedly. Therefore, the path should be defined in advance.

The operator usually guides the UAV on the same path three to five times. Flying fewer than three times cannot make motor primitives with the flexibility needed for a dynamic environment; more than five times results in complicated motor primitives. While the UAV is controlled, it measures and records its properties (such as pitch, roll, and yaw) and its command signals. Figure 1 shows the measured motor primitives. At this time, the properties of the UAV are measured and the commands of the UAV are obtained. The time *t*
_{
i,j
} is the measured time of *m*
_{
i,j
}.

Then, the movements and motor primitives of the UAV are defined, based on the properties and the commands. When a UAV faces an intermediate pinpoint to adjust its location, a new movement is defined and added to the motor primitive. The order of the visited pinpoints of motor primitives should be the same during the demonstration-based learning. A single motor primitive is generated based on a single flight.

During the time-adjustment stage, the movement times of all the motor primitives are adjusted. In the proposed method, the executed movements need not depend on a certain motor primitive. For example, movement *m*
_{2,2} in motor primitive *m*
_{2} can be executed after executing *m*
_{1,1} in *m*
_{1}, if movement *m*
_{2,2} is more appropriate than movement *m*
_{1,1}, considering the current properties of the UAV. To execute the movements as above, the ordered movements should have the same time, as shown in Fig. 2.

*t*
_{1}′ is assigned by *t*
_{1}, which is 0. From *t*
_{2}′, the time of movements is calculated by Eq. (4).

$${\it {\text{t}}_{\text{j}}^{\prime } = {\text{ t}}_{{{\text{j}} - 1}}^{\prime } + {\text{ MAX }}\left( {{\text{d}}_{{ 1,{\text{j}}}} ,{\text{ d}}_{{ 2,{\text{j}}}} , \ldots ,{\text{ d}}_{{{\text{p}},{\text{j}}}} } \right),}$$

(4)

where *d*
_{
i,j
} is the duration of *m*
_{
i,j
}.

The motor-primitive generation stage merges all motor primitives into a single graph-based motor primitive by connecting the movements in order, as shown in Fig. 3. The graph-based motor primitive of Fig. 3 is defined as {{*j*
_{1}, *j*
_{2}, …, *j*
_{
j
}}, {{*m*
_{1,1}, *m*
_{2,1},…, *m*
_{
p,i
}}, {*m*
_{1,2}, *m*
_{2,2},…, *m*
_{
p,2
}},…, {*m*
_{1,j
}, *m*
_{2,j
},…, *m*
_{
p,j
}}}}.

### UAV motor-primitive execution

If a graph-based motor primitive *G* is executed, all joins in the joint-ordered set *J* are selected in order. If the *i*th join *j*
_{
i
} is selected, then one of the corresponding linked movements is selected, by considering the movement properties, and executed. Given that the UAV selects its movements based on the changed properties, it can consider changes in the environment.