{'fraction_non_alphanumeric': 0.028559018351612554, 'fraction_numerical': 0.007058312520360517, 'mean_word_length': 4.840653242429047, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
NMPC trajectory planner for urban autonomous driving

This paper presents a trajectory planner for autonomous driving based on a Nonlinear Model Predictive Control (NMPC) algorithm that accounts for Pacejka's nonlinear lateral tyre dynamics as well as for zero speed conditions through a novel slip angles calculation. In the NMPC framework, road boundaries and obstacles (both static and moving) are taken into account thanks to soft and hard constraints implementation. The numerical solution of the NMPC problem is carried out using ACADO toolkit coupled with the quadratic programming solver qpOASES. The effectiveness of the proposed NMPC trajectory planner has been tested using CarMaker multibody models. Time analysis results provided by the simulations shown, state that the proposed algorithm can be implemented on the real-time control framework of an autonomous vehicle under the assumption of data coming from an upstream estimation block.

I. INTRODUCTION Autonomous driving is considered one of the most disruptive technologies of the near future that will completely reshape transportation systems as well as, hopefully, its impact on safety and environment [1], [2].
According to [3] and [4], a typical control architecture for AVs is composed by four hierarchical control layers called: route planning layer, behavioural layer, trajectory planning layer, local feedback layer.
Focusing on the trajectory planning task, different algorithms can be found in literature. Potential field algorithms consider the ego-vehicle as an electric charge that moves inside a potential field [5]. The final desired configuration is represented by an attractive field, while obstacles are represented by repulsive fields. Extensions of this method are the virtual force fields [6] and the vector field histogram algorithms [7]. The implementation is simple but the solution usually gets trapped in local minima [8].
Graph search based algorithms perform a global search on a graph generated by discretization of the path configuration space.These methods do not explicitly enforce dynamic constraints, but explore the reachable and free configuration space using some discretization strategy, while checking for steering and collision constraints. In order to obtain smooth paths, several sampling-based discretization strategies are available in literature, such as cubic splines [9] or clothoids [10]. The main drawback of these methods is related to the discretization process itself that prevents to obtain a true optimal path in the configuration space.
Incremental search techniques, such as the Rapidlyexploring Random Tree (RRT) algorithm [11] and its successful asymptotically optimal adaptation, the RRT* algorithm [12], try to overcome the limitations of graph search methods by incrementally producing an increasingly finer discretization of the configuration space. The use of RRT algorithms in combination with dynamic vehicle models and in presence of dynamic obstacles while maintaining real-time performances remains an active research area [13], [14].
Recently, particular attention has been devoted to pathvelocity decomposition techniques. The trajectory planning task is decomposed into two sub-tasks: path planning and velocity planning. Various methods are available to generate kinematically feasible paths, such as cubic curvature polynomials [15], Bezier curves [16], clothoid tentacles [17], [18] methods. The velocity planning, instead, can be performed either assuming a speed profile with a certain predefined shape or using other techniques, such as MPC, to obtain the optimal velocity profile along the chosen path [19]. The main drawback in path-velocity decomposition approaches lies in the handling of dynamic obstacles: due to the separation of path and velocity planning tasks, it is difficult to account for the time-dependent position of dynamic obstacles [19].
In the last decades, progress in theory and algorithms allowed to expand the use of real-time LMPC and NMPC to the area of autonomous vehicles for tracking tasks [20], [21] and, more recently, for trajectory generation tasks [22], [23]. The use of LMPC and NMPC for trajectory generation and path tracking has been particularly successful due to its ability to handle Multi-Input Multi-Output (MIMO) systems, while considering vehicle dynamics and constraints on state and input variables. The various approaches available in literature differ mainly for the complexity of the vehicle model, the presence of static and/or dynamic obstacles and the optimization method used to solve each MPC iteration.
A common approach to reduce the computational burden of trajectory generation and tracking tasks is to decompose the problem into two subsequent hierarchical MPCs: the higher level controller adopts a simple vehicle model in order to plan a trajectory over a long time horizon while the lower level controller tracks such trajectory using a more complex vehicle model over a shorter horizon.
The main risk is that, due to unmodelled dynamics, the high level controller can generate trajectories that cannot be tracked by the low level controller. A possible solution has been presented in [24] where the high level NMPC is based on precomputed primitive trajectories that results advantageous especially in structured environments. The drawback is that the high level controller is allowed to choose the (sub-)optimal "manoeuvre" only from a finite set of precomputed primitive trajectories. Furthermore, the real-time implementation results challenging due to the necessity of solving an on-line mixedinteger optimization problem or of managing a large precomputed look-up table.
In [25] a two-level NMPC that uses a nonlinear dynamic single-track vehicle model for the high level trajectory generation and a more complex four wheel vehicle model for the low level trajectory tracking is proposed. The single-track vehicle model uses a simplified Pacejka's tyre model and exploits a spatial reformulation to speed up calculations and defines constraints as a function of the spatial coordinates. The controller is able to avoid static obstacles and the use of a dynamic model greatly improves the ability of the low level controller to follow the prescribed trajectory.
The same spatial reformulation has been implemented in [23] where the tracking infeasibility issue of two-levels schemes has been solved by adopting a single level NMPC based on a complex model to merge the trajectory generation and tracking tasks.
The spatial reformulation adopted in [25] and [23] implies some important limitations, i.e. the vehicle's velocity must always be different from zero and the integration is performed in space. Furthermore, the advantages of the spatial reformulation are greatly reduced when dynamic obstacles are considered.
In [22] the trajectory planning is performed using a single stage NMPC. In this case a single-track vehicle model with Pacejka's lateral tyre model is adopted and the model is linearized at each step around the current configuration to speed up calculations. Moving obstacles are considered as fixed within each MPC step, thus reducing the prediction capability of the controller.
A single layer linear time-varying MPC based on a kinematic vehicle model is implemented in [26]. Static and moving obstacles are considered, and the optimal control problem (OCP) is solved by using a slack formulation and applying a quadratic programming (QP) routine.
The use of kinematic and dynamic single-track vehicle models for MPC applications is investigated in [27]. On one hand, kinematic models have the advantage of a lower computational cost and do not suffer from the slip going to infinity at zero velocity. On the other hand, kinematic models are not able to consider friction limits at tyre-road interaction. Hence, the paper concludes suggesting the use of dynamic models when moderate driving speeds are involved.
As previously proposed in [28]- [30] by the authors, this paper presents a single stage NMPC trajectory planning algorithm that can deal with multiple static and moving obstacles. The vehicle model is implemented as a single-track vehicle model in which lateral tyre dynamics is modelled through Pacejka's simplified Magic Formula model [31]. A novel modified slip calculation is introduced allowing to avoid the need of switching to a different model in low speeds and stop-and-go scenarios that are common in urban driving. The algorithm is implemented using ACADO toolkit [32] coupled with the QP solver qpOASES [33]. For validation purposes, the proposed trajectory planner has been tested on two relevant urban driving scenarios in Simulink and CarMaker [34] cosimulation environment.

II. THE NMPC FRAMEWORK
The aim of the modelling phase is to find the best tradeoff between model complexity, accuracy and computational cost. On one hand, the implementation of a good mathematical model ensures accurate predictions of the system's behavior. On the other hand, if the computational effort raises too much, real-time applicability is not achievable. Moreover, higher levels of detail usually entail an often-difficult parameter estimation step that can lead to a lower overall robustness.

A. Road Map Model
A reliable local road map is fundamental for the navigation of AVs and for the prediction of their position with respect to obstacles and to road boundaries along the optimization horizon. Therefore, a local road map based has been developed in the local reference framework s-y (curvilinear abscissa and lateral displacement) as depicted in Fig. 1). This framework is particularly convenient when describing road boundaries and obstacles' motion along the prediction horizon. Starting from a road map defined in the Cartesian global reference system X-Y , the local road map is generated by fitting third-order polynomials that locally approximate the road centreline angle ϑ c as a function of the curvilinear abscissa s.
Throughout this work, the complete knowledge of the road map is assumed. Thus, all the polynomial coefficients are available to the trajectory planner as a function of the vehicle's current position along the map. As stated in [35], considering the availability of a detailed road map is a reasonable assumption when dealing with the control of autonomous vehicles.This information can, for example, be obtained as the of an on-line environment mapping process based on vehicle mounted sensors such as cameras, lidars and radars [36], [37].

B. Vehicle Model
The vehicle model adopted in this work is a single-track dynamic model in which the lateral tyres forces are calculated through a simplified Pacejika's model based on a modified slip calculation procedure. This vehicle model represents a trade-off between the high complexity of 14 (or more) dofs models [38], [39] and single-track kinematic models [27], [40], allowing to reduce the number of state variables while capturing the relevant nonlinearities associated to lateral tyre dynamics.
The model considers two translational dofs in the X-Y plane and one rotational dof around the Z axis as shown in Fig. 1. The translation along the Z direction and the roll and pitch rotations are neglected. The system's equations of motion in state-space formẋ(t) = f (x(t), u(t)), expressed in the local reference system s-y (see [41] and [42]) are reported in (1), where x(t) ∈ R 8 is the state vector and u(t) ∈ R 2 is the input vector. Fig. 1. Representation of the vehicle model framework. X-Y represents the global reference system, while s-y denotes the curvilinear abscissa reference system. Vx-Vy are oriented according to the chassis' reference system.
with s is the curvilinear abscissa, y is the distance between the vehicle's centre of mass (C.o.M.) and the centreline, ξ is the error between the heading angle of the vehicle and the angle of the tangent to the road centreline in the global reference system (ξ = ψ − ϑ c ), V x , V y and ω are the vehicle's velocity components in the local reference system centred in the C.o.M., δ and T r are the steering angle at the front wheels and the torque applied to the rear axle and are obtained by integrating the inputs u 1 and u 2 . The longitudinal force F rl at the rear axle is equal to F rl = T r /R r , with T r being the total applied torque and R r the nominal rear wheels radius. This assumption is acceptable in (relatively) low speed urban scenarios and avoids introducing additional dofs to describe the wheels' rotation.
The lateral forces F f c and F rc at the front and rear tyres are calculated using the well-known Pacejka's semi-empirical tyre model [31], also known as "Magic Formula", considering steady-state pure lateral slip conditions: where the pre-multiplication by 2 is used to take into account that there are two tyres for each axle, B, C, D, E are the Pacejka's coefficients and α * is the slip angle of the front or rear tyres that are calculated as: The coupling of the lateral and longitudinal tyre-road contact forces is indirectly accounted for by considering the coupling of the lateral and longitudinal accelerations through the equivalent friction ellipse constraint [43]: where coefficients a * and b * are fitted to approximate the ellipse-shaped envelope as a function of the estimated friction coefficient and road surface conditions. Through (3) the maximum longitudinal acceleration (i.e. torque applied to the tyres) is a function of the lateral acceleration of the vehicle's C.o.M. This approach is acceptable in urban driving conditions (not in limit handling conditions) which in fact is the target for the proposed trajectory planner. Moreover, this approach allows to easily enforce safety: as proposed in [44], the friction ellipse approximation can be artificially reduced with respect to the real tyre-road friction limit to always maintain a safety margin. It is important to point out that equations (2) can be difficult to handle when V x → 0 m/s. In fact, as V x approaches zero, the slips tend to infinity for non-vanishing V y or ω. This causes model instability even for small numerical or estimation errors.
Since the intent is to develop a trajectory planner for urban environment, it is necessary to have a model that is robust and stable also at low or zero velocities. A velocity dependent switch to a kinematic vehicle model would introduce additional computational costs and should therefore be avoided. Thus, the slip angle calculation has been modified as where κ and 0 allow to shape the transition toward a kinematic-like behaviour at low velocities while preserving the Pacejka's model slip calculation at medium-high speeds as shown in Fig. 2.
To assess the effectiveness of the modified slip calculation at low velocities, the dynamic vehicle model behaviour at different velocities is compared to the single-track kinematic vehicle model [27], [40]. In Fig. 3  The single-track vehicle model with modified slip angle calculation has been also compared with an 18 dofs multibody vehicle model implemented in CarMaker environment. The results of the simulations are shown in Fig. 4 where both models are subjected to a constant steering input δ = 0.15 rad at the front wheels and constant longitudinal velocities V x = {1, 5, 8, 11} m/s for 3 s. At low velocities, the simplified 3 dofs model moves on trajectories that are very close to the ones of the more complex CarMaker model. As velocity increases, the single-track vehicle model predicts tighter curvature radii. This is due to the fact that the 3 dofs model does not account for the load transfers that cause a reduction of the tyre cornering stiffness [45]. The singletrack vehicle trajectory at 11 m/s has a curvature radius of 16.4 m, while a radius of 17.0 m is obtained using the CarMaker model. It should be noted that this represents a pretty tough manoeuvre, that exploits approximately 73% of the tyre friction limit. Since the trajectory planner has been designed for low to medium velocities in urban driving scenarios, the singletrack vehicle model (1) with the modified slip calculation (4) represents a good approximation of the complex CarMaker model. Furthermore, differences between the estimated and the actual vehicle trajectories can be addressed by the feedback provided by the NMPC logic that, at each step, re-plans the optimal trajectory, compensating for small modelling errors and external disturbances.

C. Constraints
The OCP is subjected to both hard and soft constraints. In fact, soft constraints allow to obtain a smoother driving behaviour while improving the convergence of the solver and reducing the risk of hard constraints violations in presence of modelling errors, external disturbances and uncertainties (eventually coming from sensors) related to obstacles' current and future estimated positions.
Constraints on state and input variables: this set of constraints includes the physical limits of the vehicle model: Physical limits have been derived from the experimental vehicle presented in [46], [47] and they have been applied to both the simulated and the CarMaker multibody vehicle models as constraints. In this way, simulation results are already fitted on the real vehicle that, in a next phase of this work, will become the prototype on which this planner will be implemented. The steering angle δ is limited by the geometry of the steering system while torque T r is bounded by the friction limit and the maximum torque that can be generated by the powertrain. The steering angular velocityδ and the torque derivativeṪ r are limited according to the saturation limits of the actuators installed on the prototype vehicle. These constraints are handled by the active-set routine of the QP solver qpOASES [33].
Presence of obstacles: both static or moving obstacles (such as cars, trucks and motorcycles driving along the road as well as pedestrians crossing the road, vehicles parked on the road side, etc.) are taken into account. In case of moving obstacles, it is fundamental to estimate not only the obstacle's current position, but also its future trajectory. The future obstacle's positions are approximately obtained in the local reference frame s-y assuming constant velocities V obs s and V obs y in s and y directions (simplest possible assumption) as in (6). The adoption of the local s-y reference frame greatly simplifies the description of the obstacles' motion with respect to a more standard Cartesian reference system: two parameters are sufficient to reasonably approximate obstacles' motion even along twisty roads.
Since equations (6) are time dependent, the equationṫ = 1 has been added to (1) to integrate time along the prediction horizon. Note that the trajectory planner requires the knowledge of the obstacles' positions and velocities at each time sample. This information could be obtained from sensors installed on the vehicle (such as cameras, lidars and radars) [36], [37].
One of the simplest yet effective ways to model the egovehicle and the obstacles is by means of multiple circles [26]. In this way, the relative distance calculation can be approximated by an Euclidean norm in the s-y space. If the egovehicle and the obstacle are both modelled through two circles, as shown in Fig. 5, a total of four distance computations is required to evaluate each obstacle constraint.
Each constraint is implemented both as a hard (7) and as a soft (8) constraint: This constraint is shaped as an ellipse in the s-y reference frame to guarantee the safety distance also during curves. The ellipse is centred with respect to the obstacle while its dimensions (i.e. parameters d s and d y ) are set by a higher level behavioural layer as a function of the ego-vehicle velocity, traffic conditions and maximum braking capability that usually depends on weather and road surface conditions. Thanks to equation (9), also the uncertainty related to the obstacles' predicted velocities can be accounted for. In fact, while the obstacles' actual initial position estimation can be considered as being highly accurate (depending on the reliability of the sensors and of the estimation algorithms), the reliability of the prediction of future obstacles' positions relies on the assumption of constant velocities V obs s and V obs y . This uncertainty can be accounted for by reducing the weights d s and d y in equation (9), thus increasing the ellipse dimensions (e.g. as a function of time).
Road boundaries: the distance y of the road boundaries from the centreline as a function of the curvilinear abscissa s is described through third order polynomials that are considered to be known as explained in Section II-A. Similarly as discussed in the previous paragraph , the vehicle can be approximated with two circles of radius ρ ego . Therefore, the constraints of the left and right road boundaries can be written as: with = {1, 2} and K L(i) and K R(i) , the 4 coefficients of the third order left and right polynomials respectively. Soft constraints are also implemented using an exponential function: The resulting penalty terms C lef t, and C right, are accounted for in the cost function.

D. Cost Function
The cost function to be minimized is in the form of Bolza problem. Thus, it includes a quadratic integral term and a quadratic terminal term: where || • || 2 Q,R,P denotes the Euclidean norm weighted with diagonal matrices Q, R or P . The input vector u(t) ∈ R 2 accounts for the control actions, while h (t) = [x (t), C sof t (t)] is a time-dependent vector that contains the states x(t) ∈ R 8 and the cost penalties C sof t (t) ∈ R N sof t , and h ref (t) is the corresponding reference vector.
The elements of matrix Q that refer to the states are used to normalize the state error with respect to the maximum desired deviation ∆x imax = x imax −h ref,i : In this way, the cost variation associated to an error equal to ∆x imax is the same for all state variables. The remaining N sof t elements of the weight matrix Q are related to soft constraints. Recalling the definitions of soft constraints (8) and (11), the values of the weights Q i,i for i = N x +1, ..., N sof t represent the cost penalty associated to soft constraints with exponents equal to zero, i.e. the cost penalty associated to the activation of the corresponding hard constraints (7) and (10). This holds also for soft constraints that are not coupled with a hard constraint such as (9).
The reference vector h ref is, in general, time dependent. All reference values related to soft constraints are set to zero. The reference for ξ, V y , ω, δ, T r and all reference values related to soft constraints are set to zero. Instead, the reference value of y can be different from zero in case of roads with multiple lanes. Similarly, the reference value of V x is set to be equal to a desired speed profile while the reference value of the curvilinear position s is set to be equal to the time integral of the velocity or to an arbitrary value if the associated weight in matrix Q is null.
The weight matrix R can be chosen in the same way as done for the matrix Q considering that the references for both control actions is zero.
Finally, matrix P can be, for example, obtained as the solution of Riccati equation for the infinite time LQR problem considering the system's equations linearized around the steady state condition x = 0 and weight matrices Q and R.

III. ALGORITHM IMPLEMENTATION A. Perceived and Simulated Spatial Horizons
While developing a trajectory planner for autonomous driving, it is important to consider the difference between the horizon perceived by the sensors and the one simulated within the NMPC. In particular, the former depends on the range of the sensors (such as cameras, lidars and radars) while the latter is defined by two parameters: the time span of the optimization horizon, which is generally fixed a priori, and the vehicle velocity, which is not known beforehand being a consequence of the optimization process itself. It is clear that, for safety reasons, the simulated spatial horizon should be shorter than the perceived one, thus allowing to plan trajectories only within the "known" environment.
This issue can be addressed by transforming the OCP into a spatial dependent one as in [23] and [25]. As already pointed out, this approach implies strong assumptions on the velocity profile of the vehicle.
In order not to switch to a spatial OCP, the simulated spatial horizon is limited by imposing an extra inequality constraint on the velocity V x as a function of the curvilinear abscissa s as in (14). The velocity profile constraint enforces a deceleration that achieves zero velocity at the perceived spatial horizon limit.
The reference velocity V x ref is set by the behavioural layer as the maximum allowed speed considering road rules and estimated tyre-road friction coefficient. The parameter κ vel is used to limit the resulting maximum deceleration imposed by the velocity profile within comfort limits. In Fig. 6 examples of spatial and temporal velocity profiles for V x ref = 8 m/s and s max = 20 m are shown. Differently from a constant deceleration, this profile provides a much smoother deceleration, especially toward the end of the braking phase, reducing harshness and improving passengers' comfort.
A similar effect could have been achieved by imposing a constraint on the maximum distance s at the final time t N . However, exploiting the velocity profile constraints, a smoother deceleration is obtained.

B. Driving Modes
Two driving modes have been implemented: the DRIVE and the OVERTAKE modes. The DRIVE mode is used to drive along the road, keeping the current lane and reducing the vehicle's velocity if a slower preceding vehicle is detected. The OVERTAKE mode, instead, is used to overtake slower preceding vehicles if possible. The switching between these two modes (and eventually between other modes) is demanded to the behavioural layer that considers road rules, traffic conditions and visibility range. The switch is accomplished by gradually shifting the weighting matrices of one mode to the matrices of the other mode. In this way the homotopy between subsequent solutions is ensured and sharp discontinuities are avoided, resulting in a more natural and comfortable driving behaviour.
Regarding stop-and-go manoeuvres, these are managed by the DRIVE mode, applying a spatial velocity profile that is gradually shifted to impose zero velocity at the desired stopping point. An extra hard inequality constraint on the maximum distance s can also be applied.

C. Numerical Solution
The resulting finite horizon OCP that has to be solved at each NMPC iteration is the following: The OCP is iteratively solved in a MPC framework using the open source ACADO toolkit software that implements Bock's multiple shooting method [48] coupled with Real-Time Iteration (RTI) scheme [49]- [51].
The RTI scheme is based on a sequential quadratic programming (SQP) method that performs only one iteration per sampling time, reinitializing the trajectory by shifting the old prediction. In particular, each RTI iteration is divided into a preparation and a feedback phase. The preparation phase is performed before the new sample is available and takes care of computationally expensive tasks, such as sensitivities generation and matrix condensation. The feedback phase is performed, as soon as the new sample is available, by solving the updated small-scale parametric QP problem. In this case, the small-scale QP problem has been solved with the QP solver qpOASES [33], an open source C++ implementation of an online active-set strategy based on a parametric quadratic programming approach [52].
The ACADO Code Generation tool produces a selfcontained C-code. The computational speed is increased exploiting automatic differentiation and avoiding dynamic memory allocation by hard-coding all problem dimensions [32].

D. Improved Robustness
The presence of hard constraints and the nonlinearity of the problem may induce an infeasibility, causing a solver error, if an obstacle suddenly appears within the simulated spatial horizon, e.g. a pedestrian suddenly crosses the street or another vehicle performs a hazardous overtaking manoeuvre. For these reasons, it is necessary to set up a backup policy that allows, if possible, to find a solution to the planning task, while guaranteeing feasibility.
A possible solution could be to reinitialize all the solver steps at each iteration with the current state estimation. This method can be successfully applied for low speed manoeuvres with short simulated spatial horizons in particularly crowded environments, such as a restart after a traffic stop light. Unfortunately, as the spatial horizon and the longitudinal velocity increase (V x 2 m/s), this method would require too many QP iterations to converge to a locally optimal solution.
An alternative way is to have two or more identical sub-planners with different simulated spatial horizon lengths that work in parallel. Let's consider sub-planners A and B having decreasing horizon lengths: sub-planner A has the longest simulated spatial horizon; sub-planner B, instead, has a simulated spatial horizon length that corresponds to the minimum stopping distance calculated considering the current vehicle's velocity and maximum admissible deceleration. The sub-planners are run in parallel, with a limited number of working set recalculations to account for the limited available computation time of the overall optimization. The solution adopted is the one given by the sub-planner with the longer spatial horizon that obtained a feasible trajectory.

IV. SIMULATION RESULTS
The NMPC described in previous sections is implemented considering a time horizon length of 3 s discretized in N = 60 steps (thus ∆t = 0.05s). The temporal horizon length is a design parameter that should be chosen considering the range of the sensors and the stopping distance of the vehicle (a function of tyre-road friction coefficient and velocity). The forward integration of the system's dynamics is accomplished by second order implicit Runge-Kutta method and two full sequential quadratic programming (SQP) iterations are performed per NMPC step. Thus, the vehicle's inputs are updated with a frequency of 20 Hz, applying the first of the 60 calculated optimal control actions. All closed-loop simulations are performed considering a detailed 18 dofs CarMaker model. Ego-vehicle state and obstacles positions and velocities are directly computed by the simulator and assumed as known. In [53] a real implementation of and estimator for these quantities based on a kalman filter algorithm that combines lidars and radars data is presented. Simulations are performed on a laptop featuring an Intel i7-3610QM CPU and 8 GB of RAM.
In the following, two relevant driving scenarios are considered.

A. Overtaking of a single moving obstacle
In this first scenario the ego-vehicle is required to overtake a moving obstacle positioned at a distance ∆s = 25 m, in the same lane as the ego-vehicle, with constant longitudinal velocity V s obs = 10 m/s and zero lateral velocity. The reference longitudinal velocity of ego-vehicle is set to V x ref = 13 m/s and a straight road is considered for the sake of representation clarity.
The weight matrix of the OVERTAKE mode and a sufficiently long perceived spatial horizon allow a safe overtaking manoeuvre, during which the safety distance from the obstacle is always maintained. The ego-vehicle and obstacle trajectories, together with the predictions along the optimization horizon, are displayed in Fig. 7.
The velocities V x and V y , the steering angle δ and the applied torque T r as functions of time are presented in Fig. 8. It should be noted that the velocity of the ego-vehicle decreases by approximately 0.5 m/s in the first part of the manoeuvre and successively increases to the reference value with a small overshoot. The lateral displacement is increased up to y = 3.4 m to keep the appropriate safety distance from the obstacle during the overtaking manoeuvre. The computational time required to solve each OCP is, on average, lower than 8 ms. Therefore, the real-time feasibility of the proposed trajectory planner can be stated.

B. Car suddenly exiting from a blind spot
The parallel sub-planners structure proposed in Section III-D is now assessed considering three sub-planners, A, B and C, with decreasing spatial horizon lengths. The simulation test is performed on a straight road along which the ego-vehicle is running at a speed equal to V x = 8 m/s. An obstacle suddenly appears from the right side of the road at a distance ∆s = 20 m. The obstacle travels at 3 m/s and enters the egovehicle lane without observing the right of way prescribed by the yield sign. Due to the presence of a building, the field of view of the ego-vehicle is obstructed and the other vehicle is detected only at t = 1.2 s. Hence, an infeasibility may occur in sub-planners characterized by long spatial horizons. This is shown in Fig.11, where a sudden growth in computational time affects sub-planner A: in these conditions, sub-planners B and C can provide feasible manoeuvres. In particular, at time t = 1.2 s, sub-planner A cannot find a feasible solution within the prescribed number of iterations or CPU-time. Thus, the solution of sub-planner B is adopted. At the next iteration, sub-planned B becomes the leading planner and its simulated spatial horizon is extended to the perceived spatial horizon length while sub-planner A is reinitialized with a simulated spatial horizon equal to that of B at the previous step.
The ego-vehicle and obstacle trajectories, together with their prediction along the optimization horizon, are displayed in Fig. 9. Note that, as explained in Section II, the obstacle trajectory is approximated at each step with constant velocities in both longitudinal and lateral directions. Fig. 10, instead, shows the velocities V x and V y , the steering angle δ and the applied torque T r during the braking manoeuvre. The longitudinal velocity is reduced to match the speed of the merging vehicle, generating a longitudinal deceleration of approximately 6.5 m/s 2 , which is still within the adhesion limit of the tyres.
The trajectory planner with three parallel sub-planners shows improved robustness and guarantees feasibility in a broader range of scenarios, while achieving an overall smooth manoeuvre that does not present discontinuities. Aiming at reducing the computational burden of this configuration, only the sub-planner with the longest simulated spatial horizon performs two full SQP iterations, while the other two implement only one SQP iteration. The loop times required by the three sub-planners are shown in Fig. 11. It is possible to notice that, at t = 1.2 s, sub-planner A reaches the maximum allowed CPU-time of 10 ms. Thus, the solution calculated by sub-planner B is considered while sub-planner A is reinitialized. In the next step, sub-planner B takes the role of sub-planner A, acquiring the longer spatial horizon and performing two SQP iterations. Even without considering possible computation parallelization, the total computational time, even in this configuration, is lower than 20 ms, thus well below the total available time of 50 ms.

V. CONCLUSIONS
In this paper a NMPC trajectory planner for autonomous vehicles based on a direct approach has been presented. Thanks to the proposed modified slip calculation, the dynamic  Fig. 11. sub-planner A, sub-planner B, sub-planner C and total trajectory planner CPU-time.
single-track vehicle model can be employed at both high and low velocities. This allows to have one single model that presents a kinematic-like behaviour at low velocities while keeping the standard dynamic single-track vehicle model behaviour at higher speeds. Obstacles' uncertainties have been taken into account through the implementation of coupled soft and hard constraints. The correlation between the simulated and perceived spatial horizon lengths has been enforced with a spatial dependent velocity profile that has been imposed as an extra inequality constraint. The numerical solution is carried out using ACADO toolkit, coupled with the QP solver qpOASES. The trajectory planner performances have been checked in simulation, applying the controller to a nonlinear multibody model in CarMaker environment. The results coming from the simulations carried on two significant driving scenarios have been reported to highlight the effectiveness of the calculated trajectories. The analysis of the computational times has confirmed that the proposed trajectory planner can be implemented within the real-time control routine of an autonomous vehicle.