*3.2. Route Segmentation*

The routes travelled by the users through the exercise plan have a high number of GPS localizations. First, it is necessary to identify each of the segments that make up a given route. To this end, the route is segmented into independent sections of different lengths that are connected to each other. The aim of performing this segmentation is to be able to make an individual analysis of each section; reducing its complexity and establishing the assist level required for that route. As described previously, electric bicycles are operated through a series of assist levels, where each one corresponds to a particular amount of power that is provided by the engine. The higher the assist level, the greater the power generated by the engine. Thus, the higher is the assist level, the lesser is the effort of the user. *Sensors* **2018**, *18*, 220 8 of 21 section; reducing its complexity and establishing the assist level required for that route. As described previously, electric bicycles are operated through a series of assist levels, where each one corresponds to a particular amount of power that is provided by the engine. The higher the assist level, the greater the power generated by the engine. Thus, the higher is the assist level, the lesser is the effort of the user. The second criterion for making this division is based on the difference of slopes at the different

The second criterion for making this division is based on the difference of slopes at the different points of the route. Slopes are obtained for each of the GPS points *p*, therefore it is possible to group the adjacent route points which have similar magnitude of slope *g<sup>i</sup>* , in the same segment *S<sup>i</sup>* . The segments obtained can have different lengths *l<sup>i</sup>* . Thus, a route with origin **O** and destination **D** is divided into a series of *i* = 1, . . . , *N* segments *S<sup>i</sup>* , which are connected one to another, as shown in Figure 5. points of the route. Slopes are obtained for each of the GPS points *p*, therefore it is possible to group the adjacent route points which have similar magnitude of slope , in the same segment .The segments obtained can have different lengths . Thus, a route with origin and destination **D** is divided into a series of = 1, … , segments , which are connected one to another, as shown in Figure 5.

**Figure 5.** Example of route segmentation. The bottom side and the upper side of the route is segmented according to its profile. **Figure 5.** Example of route segmentation. The bottom side and the upper side of the route is segmented according to its profile.

By grouping the points *p* according to the magnitude of the slope, the profile of the route is reconstructed with the set of segments , as can be seen in Figure 5. Thanks to this grouping, it is possible to establish a single assist level for each segment; this level will be adapted to its slope. When calculating the starting and ending waypoints of a segment, not only the magnitudes of these points should be considered but also the magnitudes of the adjacent points. The algorithm used to perform this segmentation is based on the previous work of the same By grouping the points *p* according to the magnitude of the slope, the profile of the route is reconstructed with the set of segments *S<sup>i</sup>* , as can be seen in Figure 5. Thanks to this grouping, it is possible to establish a single assist level for each segment; this level will be adapted to its slope. When calculating the starting and ending waypoints of a segment, not only the magnitudes of these points should be considered but also the magnitudes of the adjacent points.

authors [60]. In the segmentation algorithm, does not only consider whether the slope is positive or negative, its magnitude is also considered. In this way, within segments with slopes of the same signs, different segments can be grouped according to their magnitude. As for segments of 0% slope, they are considered to be positive or negative, according to the adjacent slopes. The algorithm used to perform this segmentation is based on the previous work of the same authors [60]. In the segmentation algorithm, does not only consider whether the slope is positive or negative, its magnitude is also considered. In this way, within segments with slopes of the same signs, different segments can be grouped according to their magnitude. As for segments of 0% slope, they are considered to be positive or negative, according to the adjacent slopes.

#### *3.3. Calculation of Assist Level 3.3. Calculation of Assist Level*

each segment of a route.

described in [61].

When the system calculates the assist level for each segment, two elements are taken into account. On the one hand, the user's ability level (calculated with the scores obtained on the routes they travelled previously in the "training" mode). On the other hand, the average slope of the segment within the route. The objective is to apportion the power required, according to the level of assist for each of the segments. The power provided by the engine must be complemented with the power derived from the user's physical effort. Thus, the sum of the power to be supplied by the engine and the power that is to be provided by the user in each of the segments, is the total power required to travel the route, as shown in Equation (2). When the system calculates the assist level for each segment, two elements are taken into account. On the one hand, the user's ability level (calculated with the scores obtained on the routes they travelled previously in the "training" mode). On the other hand, the average slope of the segment within the route. The objective is to apportion the power required, according to the level of assist for each of the segments. The power provided by the engine must be complemented with the power derived from the user's physical effort. Thus, the sum of the power to be supplied by the engine and the power that is to be provided by the user in each of the segments, is the total power required to travel the route, as shown in Equation (2).

To calculate the power required to cycle a bike route, it is necessary to apply Equation (3) as

= (2)

∑( + )

=0

$$\sum\_{i=0}^{n} (p\_{\mathcal{S}} + p\_u) = \text{Total power to travel a route} \tag{2}$$

where *p<sup>g</sup>* represents the power supplied by the engine and *p<sup>u</sup>* the power supplied by the user, in each segment *n* of a route.

To calculate the power required to cycle a bike route, it is necessary to apply Equation (3) as described in [61].

$$P = k\_rMs + k\_aAsv^2d + \text{gjMs} \tag{3}$$

where


Equation (3) can be divided into three different parts. In the first part (*krMs*) calculates the power necessary to overcome the resistance produced by the friction between the wheel and the ground. For this part, it is necessary to add the power required to overcome wind resistance (*kaAsv*2*d*) and finally the power required to overcome the resistance of the slope of the road (*giMs*).

To calculate the total mass (sum of the mass of the user and the mass of the bicycle), the user's profile with their data is accessed. The weight of the bicycle is also known since the system registers the bicycle that the user is using to cycle a route. Likewise, knowing the user's height and the size of the bicycle, makes it possible to obtain the user's frontal area.

For the system designed in this work, speed is considered to be a key factor. From the user's overall score (which is the sum of the points obtained at previous routes), the average speed that is to be maintained constant by the user during the completion of a new route is determined. The goal of the "training" mode is to maintain a constant average speed throughout the route, regardless of its profile, and to increase that speed progressively at new routes. In this way, the user gradually observes progress in his training, as the average speed at the routes they cycle is increased and the power supplied by the engine is reduced. Table 2 shows the ability levels established in the system and the score necessary to reach each one of them. The table also indicates the average speed at each of the levels which is used to calculate the power. These power estimates are defined, in ideal conditions, for a person of 75 kg and a bicycle of 8 kg (a total of 83 kg).

Each route is divided into a set of segments, as shown in Figure 5 and Equation (4).

$$\mathcal{F} = \{\mathcal{S}\_1, \dots, \mathcal{S}\_n\} \tag{4}$$

The slope of each segment within a route is calculated, thus obtaining a set of values for each of the segments (Equation (5)).

$$I = \{h\_1, \dots, h\_n\} \tag{5}$$

For each segment *S<sup>i</sup>* , the automatic assist level is calculated. First, the power that is to be generated by the user is established. The power *p* is kept constant for each of the intervals and the speed of the user is determined using the formula indicated in Equation (3). The speed calculated for each interval is shown in Equation (6).

$$V = \{v\_1, \dots, v\_n\} \tag{6}$$

At this point, the tentative speed *v*' that is to be maintained is considered and the power that should be generated to maintain that speed *v*' is calculated for each interval (Equation (7)).

$$P = \{p\_1, \dots, p\_n\} \tag{7}$$

The power supplied by the battery will be the difference between the power required to maintain the speed constant at each interval and the *p* value maintained by the user (Equation (8)).

$$P\ell = \left\{p\_1' = p\_1 - p\_\prime \dots \, , \, p\_n' = p\_n - p\right\} \tag{8}$$

Once the *p* 0 *i* values are obtained, the level of assist is calculated. Each assist level *r* is associated with a power *p l r* , whereby the possible power values are as given in Equation (9).

$$p^l = \left\{o, p\_1^l, \dots, p\_r^l\right\} \tag{9}$$

Based on the power values defined in Equation (9), the power intervals are established Equation (10).

$$I = \{ \left[ 0, \frac{0 + p\_1^l}{2} \right), \left[ \frac{p\_1^l + p\_2^l}{2}, \frac{p\_2^l + p\_3^l}{2} \right), \dots, \left[ \frac{p\_{r-1}^l + p\_r^l}{2}, p\_r^l \right) \} \tag{10}$$

Therefore, the assistance for segment *q* defined as *p e q* , is represented by Equation (11).

$$p\_q^e = p\_j^l / \left[ \frac{p\_{j-1}^l + p\_j^l}{2}, \frac{p\_j^l + p\_{j+1}^l}{2} \right) \tag{11}$$

As shown in Figure 6, after establishing the assist levels for each segment, the amount of power that the user must provide and the power that the bicycle must supply is determined. The total sum of the powers must be equal to the power required to travel the segment at a constant speed.

**Table 2.** Ability levels, average speed and the score required for each level.


each interval is shown in Equation (6).

Once the

with a power

For each segment *Si*, the automatic assist level is calculated. First, the power that is to be generated by the user is established. The power *p* is kept constant for each of the intervals and the speed of the user is determined using the formula indicated in Equation (3). The speed calculated for

At this point, the tentative speed *v*' that is to be maintained is considered and the power that

The power supplied by the battery will be the difference between the power required to maintain

Based on the power values defined in Equation (9), the power intervals are established Equation (10).

2 , + +1 2

of the powers must be equal to the power required to travel the segment at a constant speed.

′ values are obtained, the level of assist is calculated. Each assist level *r* is associated

) , … ,[ −1 + 

2

,

, is represented by Equation (11).

, . . , } (6)

, . . , } (7)

′ = − } (8)

} (9)

)} (10)

) (11)

= {<sup>1</sup>

= {<sup>1</sup>

′ = <sup>1</sup> − , . . ,

, whereby the possible power values are as given in Equation (9).

should be generated to maintain that speed *v*' is calculated for each interval (Equation (7)).

the speed constant at each interval and the *p* value maintained by the user (Equation (8)).

 = {, <sup>1</sup> , . . , 

′ = {<sup>1</sup>

= {[0,

Therefore, the assistance for segment *q* defined as

0 + <sup>1</sup> 2 ) ,[ 1 + <sup>2</sup> 2 , 2 + <sup>3</sup> 2

> = / [ −1 +

**Figure 6.** Example of how power is distributed for each of the segments of a route. **Figure 6.** Example of how power is distributed for each of the segments of a route.

#### An important aspect is the evaluation of the user's performance on the routes cycled. However, *3.4. Evaluation of the Final Route*

*3.4. Evaluation of the Final Route*

to be able to make a fair evaluation of these routes it must be taken into account that the profile of each route is different. Thus, a procedure has been designed to make a fair comparison. The power generated by the user over the course of the route is the aspect that is considered in the evaluation; An important aspect is the evaluation of the user's performance on the routes cycled. However, to be able to make a fair evaluation of these routes it must be taken into account that the profile of each route is different. Thus, a procedure has been designed to make a fair comparison. The power generated by the user over the course of the route is the aspect that is considered in the evaluation; as it can be seen in Equation (3), the calculation of this power depends on a number of factors. The power generated by the user is defined in Equation (12).

$$p\_{\mu} = \sum\_{i=1}^{n} (p\_i - p\_i^{\varepsilon}) \tag{12}$$

Once the power generated by the user has been calculated, the system determines the final score that is to be awarded for the route represented by *s<sup>r</sup>* . This score will accrue to the one already obtained by the user. The score is therefore calculated as Equation (13):

$$s\_r = \begin{cases} \begin{array}{cc} p\_{\mu} & p\_{\mu} < 600 \\ 600 & eoc \end{array} \end{cases} \tag{13}$$

The value of 600 W is considered as the energy required to maintain an average speed of 50 km/h for one hour on a flat surface, considering a user of 75 kg and a bicycle of 8 kg and with average parameters for the coefficients of friction, resistance etc. Considering the records registered by International Cyclist Union [62], the 600 W value is the maximum limit for a person.
