+ All Categories
Home > Documents > Optimal Racing Line Control - mit.edushayegan/files/omidshafiei_optimal_racing_line_control14.pdfThe...

Optimal Racing Line Control - mit.edushayegan/files/omidshafiei_optimal_racing_line_control14.pdfThe...

Date post: 23-Mar-2020
Category:
Upload: others
View: 2 times
Download: 0 times
Share this document with a friend
20
Optimal Racing Line Control Shayegan Omidshafiei May 9, 2014 Abstract Analysis of race car dynamics and control is conducted. A kinematic race car system is constructed for preliminary construction of optimal racing lines. An extension to a 6-state dynamical system is then made using a half-car model. Performance is analyzed on a variety of race track types, using the MATLAB GPOPS library. A brief analysis of code optimization techniques is presented, motivated by the computational complexity of calculating the optimal trajectory for the dynamical model. Finally, performance on a complex track comprised of 18 phases is analyzed. 1 Introduction Optimal control of car racing lines has been of interest for researchers in the last several years. The problem of designing optimal trajectories for race cars and high performance vehicles has been analyzed using a wide range of kinematic and dynamical models [5][2][7]. The optimal racing line problem can be considered a dual problem of the optimal vehicle control problem, and solving it in an efficient manner can be extremely useful in future autonomous vehicle systems. This paper aims to investigate optimal control of vehicles on a race track, using the GPOPS MATLAB toolbox, starting with a relatively simple kinematic system model. Additional extensions are made to a dynamical model including tire friction forces, allowing more accurate trajectories to be obtained. Following this, an improved method of initial guessing is implemented to allow for problems up to 18 phases to be solved in GPOPS. The paper concludes with a brief discussion and analysis of improving performance in GPOPS, as the complexity of the problem requires significant effort to be spent on code optimization to allow solutions to be obtained in reasonable time. 2 Kinematic Model Initial analysis is performed using a kinematic single-track model for the vehicle, following the derivation outlined in [5]. This formulation is similar to the well-known Dubins car model. This Figure 1: Single-track kinematic model. is used as a means of validating track design and initial optimal control results without considering the complications of a dynamical model. In this model, the front and rear wheels of the car are paired together, essentially treating the car as a bicycle (Figure 1). Define the inertial frame of reference as x, y. Let V be the constant speed of the vehicle, ψ the vehicle yaw, and δ the steering angle. Given a vehicle body length of L b , the kinematic equations are summarized as, ˙ x = V cos(ψ) (1) ˙ y = V sin(ψ) (2) ˙ ψ = V tan(δ) L b (3) 3 Dynamical Model A variety of dynamical models are considered for the vehicle. A 10-state full car model is presented in [10], including an engine torque map as well as 1
Transcript
Page 1: Optimal Racing Line Control - mit.edushayegan/files/omidshafiei_optimal_racing_line_control14.pdfThe optimal racing line problem can be considered a dual problem of the optimal vehicle

Optimal Racing Line Control

Shayegan Omidshafiei

May 9, 2014

Abstract

Analysis of race car dynamics and control is conducted. A kinematic race car system is constructed forpreliminary construction of optimal racing lines. An extension to a 6-state dynamical system is then madeusing a half-car model. Performance is analyzed on a variety of race track types, using the MATLAB GPOPSlibrary. A brief analysis of code optimization techniques is presented, motivated by the computationalcomplexity of calculating the optimal trajectory for the dynamical model. Finally, performance on acomplex track comprised of 18 phases is analyzed.

1 Introduction

Optimal control of car racing lines has been ofinterest for researchers in the last several years.The problem of designing optimal trajectories forrace cars and high performance vehicles has beenanalyzed using a wide range of kinematic anddynamical models [5][2][7]. The optimal racing lineproblem can be considered a dual problem of theoptimal vehicle control problem, and solving it inan efficient manner can be extremely useful in futureautonomous vehicle systems.

This paper aims to investigate optimal controlof vehicles on a race track, using the GPOPSMATLAB toolbox, starting with a relatively simplekinematic system model. Additional extensions aremade to a dynamical model including tire frictionforces, allowing more accurate trajectories to beobtained. Following this, an improved methodof initial guessing is implemented to allow forproblems up to 18 phases to be solved in GPOPS.The paper concludes with a brief discussion andanalysis of improving performance in GPOPS, asthe complexity of the problem requires significanteffort to be spent on code optimization to allowsolutions to be obtained in reasonable time.

2 Kinematic Model

Initial analysis is performed using a kinematicsingle-track model for the vehicle, following thederivation outlined in [5]. This formulation issimilar to the well-known Dubins car model. This

Figure 1: Single-track kinematic model.

is used as a means of validating track design andinitial optimal control results without consideringthe complications of a dynamical model.

In this model, the front and rear wheels of thecar are paired together, essentially treating the caras a bicycle (Figure 1). Define the inertial frame ofreference as x, y. Let V be the constant speed of thevehicle, ψ the vehicle yaw, and δ the steering angle.Given a vehicle body length of Lb, the kinematicequations are summarized as,

x = V cos(ψ) (1)

y = V sin(ψ) (2)

ψ =V tan(δ)

Lb(3)

3 Dynamical Model

A variety of dynamical models are considered forthe vehicle. A 10-state full car model is presentedin [10], including an engine torque map as well as

1

Page 2: Optimal Racing Line Control - mit.edushayegan/files/omidshafiei_optimal_racing_line_control14.pdfThe optimal racing line problem can be considered a dual problem of the optimal vehicle

xI

yI

CG.

yB

V

fRy fRx

R

F

fFx

fFy

xB

TR

TF

β

ψδ

Figure 2: Single-track, half-car dynamical model [1].

aerodynamic drag and downforce effects. Givencomputational limitations, however, comprehensivemodels including downforce and air drag effectsare not considered. A three-dimensional vehiclemodel is used in [8] for analyzing performance onbanked turns. Single-track, constant speed modelsare considered in [5], but are deemed inappropriatefor this application due to the severe assumptionsmade.

The dynamical model used in this paper is asingle-track, half-car model, with tire friction forcestaken into consideration [1]. Figure 2 illustrates thebody diagram of the system. Suspension dynamicsare not modeled, due to an addition of verticalvehicle dynamics which increase the state-space size,making the problem infeasible to solve in GPOPS.Aerodynamic forces as well as engine dynamics areneglected for the same reason.

Additional assumptions include lack of rear wheelsteering and a center of gravity (CG) centeredlaterally on the vehicle (with varying longitudinalposition). It is assumed that both the front andrear wheels can apply acceleration and decelerationindependently, making this system a four-wheeldrive car.

To derive the vehicle dynamical equations, let x, yrepresent the coordinates of the vehicle CG in aninertial frame of reference, m the mass of the vehicle,ψ the yaw angle, δ the steering angle, lF and lRthe distance of the CG from the front and rear ofthe vehicle, respectively. Then, the dynamics are

summarized,

mx = fFxcos(ψ + δ)− fFy

sin(ψ + δ)+

fRxcos(ψ)− fRy

sin(ψ) (4)

my = fFxsin(ψ + δ) + fFy

cos(ψ + δ)+

fRxsin(ψ) + fRy

cos(ψ) (5)

Izψ = (fFycos(δ) + fFx

sin(δ))lF − fRylR (6)

Note that the problem, as posed, has a 6-dimensional state space (the first order differentialequations for x, y, ψ can be trivially computed). Thecontrol inputs can be considered the friction forcesin addition to the vehicle steering angle δ.

The longitudinal and lateral friction forces of thevehicle can be calculated using the so-called “Pace-jka’s Magic Formula” [11], which offers accuratemodeling of tire dynamics with low computationaloverhead,

fij = −sijsiFi(s), i = F,R, j = x, y (7)

Fi(si) = fizDsin(Catan(Bsi)), i = F,R (8)

The constants B,C,D appearing in the aboveformula are found empirically and can be usedto model friction forces for various tires androad conditions. Pacejka’s Magic Formula linkslongitudinal and lateral slip, sij , i = F,R, j = x, yto the longitudinal and lateral friction forces. Thenormal force on the front and rear axles can becalculated using,

fRz= mg

lFlF + lR

(9)

fFz= mg

lRlF + lR

(10)

The longitudinal and lateral slip quantities can beindividually calculated as follows,

sRy=vsin(β)− ψlR

vcosβ(11)

sFy=vsin(β − δ) + ψlF cos(δ)

vcos(β − δ) + ψlF sin(δ)(12)

sRx =

{+1− vcos(β)−ψlR

ωF r

−1 + ωF r

vcos(β)−ψlR

(13)

2

Page 3: Optimal Racing Line Control - mit.edushayegan/files/omidshafiei_optimal_racing_line_control14.pdfThe optimal racing line problem can be considered a dual problem of the optimal vehicle

sFx=

{+1− vcos(β−δ)+ψlF cos(δ)

ωF r

−1 + ωF r

vcos(β−δ)+ψlF cos(δ)(14)

where the total slip si in a given tire can becalculated as,

si =√s2ix + s2iy, i = F,R (15)

Finally, the vehicle speed and slip angle arecalculated as,

v =√x2 + y2 (16)

β = tan−1(y/x)− ψ (17)

The above collection of equations can be used toreasonably model vehicle dynamics, with suspen-sion, aerodynamic forces, and engine dynamics ne-glected. The control inputs are considered as theslip quantities sij and the steering angle δ.

3.1 Problem Initialization and Bounds

The cost function for the optimal control problemis simply the total travel time for the vehicle, witha free final time,

J =

∫ tf

0

dt (18)

The racetrack is constructed in piecewise fashion,using phases. Let (xCoordsi, yCoordsi) define thecenter-line of the track, with i ∈ [1, finalPhase+1].Let arclengthsi define the arclength of the track upto phase i. In a given phase, the initial time is fixedat 0, with the maximum allowable final time definedheuristically as follows,

tfmax,i =arclengthsi+1 − arclengthsi

topSpeed/3+ tfmax,const

(19)where topSpeed is the predefined top speed of thecar, and tfmax,const is a buffer time allotted to ensurecompletion of the phase is possible.

Vehicle parameters are defined in Table 1.Note that road condition specifications (captured

in Pacejka parameters B,C,D) are obtained from[1], and approximate a dry tarmac surface.

Bounds are placed on the car’s x, y coordinates ina given phase i using the minimum and maximumvalues of the track’s coordinates that phase,

xmin,i = min([xEdge1,i, xEdge1,i+1,

xEdge2,i, xEdge2,i+1]); (20)

Parameter Valuevmax varies per track, average 15 ms−1

g 9.81 ms−2

m 600 kgIzz 1000 kgm2

lR 0.8 mlF 0.7 mB 7C 1.6D 0.7

Table 1: Vehicle parameters

xmax,i = max([xEdge1,i, xEdge1,i+1,

xEdge2,i, xEdge2,i+1]); (21)

ymin,i = min([yEdge1,i, yEdge1,i+1,

yEdge2,i, yEdge2,i+1]); (22)

ymax,i = max([yEdge1,i, yEdge1,i+1,

yEdge2,i, yEdge2,i+1]); (23)

Initial conditions for the car (in phase 1) aresummarized as follows,

x0 = xCoords1 (24)

y0 = yCoords1 (25)

x0 = 5dx

dL(26)

y0 = 5dy

dL(27)

ψ0 = atan2(dy, dx) (28)

ψ0 = 0 (29)

where dydx is the slope of the track in the given

phase, and dL is the arclength. The above equationsindicate that the vehicle is initialized moving downthe centerline of the track in the first phase, with aspeed of 5ms−1.

Initial conditions for subsequent phases are boundedas follows,

x0 ∈ [xmin,i, xmax,i] (30)

y0 ∈ [ymin,i, ymax,i] (31)

x0 ∈ [−vmax, vmax] (32)

y0 ∈ [−vmax, vmax] (33)

ψ0 ∈ [0, 2π] (34)

ψ0 ∈ [−π, π] (35)

3

Page 4: Optimal Racing Line Control - mit.edushayegan/files/omidshafiei_optimal_racing_line_control14.pdfThe optimal racing line problem can be considered a dual problem of the optimal vehicle

3.2 Constraints

The above initial condition constraints allow thevehicle to start off in any position and orientation ina given phase. Thus, state constraints are equivalentto the above equations as well.

Control input bounds are based on several as-sumptions. A primary assumption is that both thefront and rear wheels can apply throttle and brak-ing. Hence, the control input bounds on slip quan-tities are,

si ∈ [−1, 1] (36)

The car wheels are assumed to be bounded asfollows, slightly less constrained than a typicalracing vehicle steering angle of 20− 23◦,

δ ∈ [−30◦, 30◦] (37)

To ensure the vehicle stays within the trackthroughput all phases, two varieties of constraintswere considered.

The first was a path constraint, derived by consid-ering the problem of identifying whether a point (ve-hicle) lies within a convex quadrilateral. Considerthe cross product of a vector ((xi+1, yi+1)− (xi, yi))connecting two adjacent vertices of the quadrilat-eral, and vector (p − (xi, yi)) connecting the point(vehicle) to vertex i (see Figure 3). Given vehicleposition p = (x, y), the process is repeated for allfour combinations of adjacent vertices. If the Z-component of the resulting cross products all havethe same sign, then the point (vehicle) resides in thequadrilateral. However, such a path constraint canbe costly to evaluate. To save computational effort,it can be noted from Figure 3 that the cross productneeds only be checked for edges ((x2, y2)− (x1, y1))and ((x4, y4) − (x3, y3)), since the same path con-straints from the next phase of the track will en-sure that the car never leaves the track, making itredundant to perform the cross product check onthe two additional edges ((x3, y3) − (x2, y2)) and((x1, y1)− (x4, y4)).

Using the above information, it can be shown thatthe region of transition for a given vehicle betweentwo phases is a quadrilateral Q (indicated in Figure3). This makes the use of manifold constraintsredundant as well, as the vehicle will naturally tendtowards the end of the current phase.

Despite the novel nature of the track constraintposed as above, initial experiments indicated thatthe use of such a path constraint was still highlyexpensive computationally, making it extremely

difficult for GPOPS to solve the problem oninteresting tracks.

Therefore, a simpler, computationally inexpen-sive phase manifold constraint was utilized in thefinal implementation. Let (xi,tf , yi,tf ) be the finalposition of the vehicle in a given track phase i. Thenthree distance metrics can be defined using this po-sition as well as the coordinates of the left and rightside of the track at the end of the phase (see Figure4),

d1 =[(ytf − yEdge1,i+1)2

+ (xtf − xEdge1,i+1)2]1/2

d2 =[(ytf − yEdge2,i+1)2

+ (xtf − xEdge2,i+1)2]1/2

d3 =[(yEdge2,i+1 − yEdge1,i+1)2

+ (xEdge2,i+1 − xEdge1,i+1)2]1/2

Then a constraint ensuring that the vehiclefinishes on the terminal manifold of the track phaseis,

d1 + d2 ≤ d3 + ε (38)

Upon closer inspection, this is the equation of aregion bounded by an ellipse, with its foci on theleft side and right side of the track’s terminalmanifold. Initial experiments reveal that the squareroot function involved in all the distance metricsimposes heavy computational burden, due to theconstraint being checked several thousand times ineach run of GPOPS. To reduce this burden, it isnoted that the distance metrics are all positive.Therefore, squaring both sides of the equation,

(d1 + d2)2 ≤ (d3 + ε)2 (39)

and expanding,

d21 + 2d1d2 + d22 ≤ d23 + 2d3ε+ ε2 (40)

Reorganzing the equation,

d21 + d22 ≤ d23 + 2(d3ε− d1d2) + ε2 (41)

it is clear that ε can be chosen to be arbitrarilylarge enough that 2(d3ε−d1d2) is a positive quantity.Hence, defining ε2 = 2(d3ε−d1d2)+ε2, the equationcan be re-written as,

d21 + d22 ≤ d23 + ε2 (42)

4

Page 5: Optimal Racing Line Control - mit.edushayegan/files/omidshafiei_optimal_racing_line_control14.pdfThe optimal racing line problem can be considered a dual problem of the optimal vehicle

Q

x1,y1

x2,y2

x3,y3

x4,y4

p

Figure 3: Track constraints can be describedusing a cross product rule, which allows manifoldconstraints to be avoided.

This new track constraint utilizes only the squaresof the distance metrics, avoiding the square rootsand lessening the computational complexity of theconstraint checks. The value of ε2 was determinedempirically. For the given track sizes, a value of0.025 was found to be suitable in ensuring the carfinishes near the manifold of each track phase.

State constraints across phases were also imposedusing eventgroups. For most of the tracks consid-ered, each element of the 6-D state vector was al-lowed to vary across a phase within a tolerance of1e− 3.

d1

d2d3

Figure 4: Manifold constraints can be imposed usingan ellipse with its foci centered on the endpoints ofeach track phase.

Additionally, the vehicle top speed is imposedas a path constraint, as it cannot be exceededthroughout the entire track. The speed is obtainedfrom the vehicle as,

v =√x2 + y2 (43)

with the lower and upper bounds being 0 and vmax,respectively.

3.3 Initial Guesses

The initial guess in a given phase i is constructed byaligning the vehicle with the track at the beginningand end of the phase, with v = vmax/2. Thefollowing equations summarize the initial guess,

xguess,i,start = xCoordsi (44)

yguess,i,start = yCoordsi (45)

xguess,i,start =vmax

2

dxidLi

(46)

yguess,i,start =vmax

2

dyidLi

(47)

ψguess,i,start = atan2(dyi, dxi) (48)

ψguess,i,start = 0 (49)

xguess,i,end = xCoordsi+1 (50)

yguess,i,end = yCoordsi+1 (51)

xguess,i,end =vmax

2

dxi+1

dLi+1(52)

yguess,i,end =vmax

2

dyi+1

dLi+1(53)

ψguess,i,end = atan2(dyi+1, dxi+1) (54)

ψguess,i,end = 0 (55)

The control guess is constructed in a simplermanner, by assuming that the car is slightlyaccelerating in all phases. The steering angle isassumed to be 0, since the curvature of the trackis not explicitly calculated. The following equationssummarize the initial guess for control,

six = [0.1; 0.1], i = F,R (56)

δ = [0; 0] (57)

5

Page 6: Optimal Racing Line Control - mit.edushayegan/files/omidshafiei_optimal_racing_line_control14.pdfThe optimal racing line problem can be considered a dual problem of the optimal vehicle

3.4 Refined Initial Guessing

Using the above initial guessing scheme, GPOPSis able to compute the optimal control for a trackconsisting of 5-6 phases. With more phases, GPOPStypically reports that the problem is “infeasible”, orsimply runs out of iterations before mesh tolerancesare met.

A refined guessing scheme is constructed byincrementally building up the total number ofphases, using past solutions as initial guesses forthe earlier phases. For the latest phase, however,the guess is constructed as in the previous guessingscheme. The pseudo-code is presented in Algorithm1.

Data: track, numPhasesTotalResult: uoptnumPhasess← 1;solution← racinglineMainDyn(numPhases);for numPhases = 1 to numPhasesTotal do

for iphase = 1 to numPhases-1 doguess(iphase)← solution(iphase);

endsolution← racinglineMainDyn(numPhases,guess);

enduopt ← solution(:).control(:, :);Algorithm 1: Refined guessing algorithm

4 Kinematic Model Results

Initial trials with GPOPS were conducted using thekinematic model in order to ascertain computationalperformance and correct problem setup in MAT-LAB, prior to converting to a full dynamical model.The kinematic, constant-speed model was tested ona single-phase straight track, along with a multi-phase U-turn track. The resulting trajectory for theU-turn track is visualized in Figure 5, with the car’sinitial position indicated as a red circle. Note thatthe car behaves as expected, steering left in orderto hit the turn’s apex.

Additionally, the car hits an early apex, andleaves the final phase going straight. The early apexbehavior is as expected, as it allows the car to takethe shortest straight-line distance to the next phase.The late apex behavior is, at first, counter-intuitiveas it appears that a shorter total time might havebeen possible if the vehicle continued to hug the

turn. However, once consideration for the ellipsemanifold terminal constraint (Figure 4) is made,the trajectory makes sense. The ellipse manifold isnotably larger in the middle of the track rather thanthe sides. Therefore, at the final phase, the car willprefer to finish in the middle of the track rather thanon the sides. Note that this is also a consequence ofthe constant-speed kinematic model.

In the dynamical model, more interesting trajec-tories are obtained as the vehicle has the opportu-nity to accelerate out of the turn. This concludesanalysis of the kinematic model, as it was simplya means of evaluating initial GPOPS performance.More detailed control analysis is performed for thedynamical model.

Figure 5: Kinematic model optimal trajectory fora U-turn. The car’s initial position is indicated inred.

5 Dynamical Model Results

Full dynamical model trials were conducted on astraight track, a U-turn track, an S-curve track, aswell as a track based on the Formula 1 AustralianGP circuit.

5.1 Friction Ellipse

Slip quantities sij , i = F,R j = x, y corresponddirectly to longitudinal and lateral friction forces,as shown in Equation 3. Thus, for a range of slipquantities, the corresponding friction force can becalculated directly. This result is plotted in Figure 6for the longitudinal direction. As shown on the plot,

6

Page 7: Optimal Racing Line Control - mit.edushayegan/files/omidshafiei_optimal_racing_line_control14.pdfThe optimal racing line problem can be considered a dual problem of the optimal vehicle

a maximum friction force can be calculated, whichcorresponds to the point of maximum accelerationfor the car. If the slip quantity increases abovethis point, the car loses traction and accelerationreduces. If the slip quantity decreases, then thedriver is not exerting maximum control input andthe overall track time will be sup-optimal.

For a given set of vehicle dynamical parame-ters and road/tire friction characteristics (capturedthrough Pacejka’s Magic Formula), the maximumpossible friction force leads to the concept of thefriction ellipse. Using Pontryagin’s Minimum Prin-ciple, it can be concluded that for a car to be opti-mally on a track, the total friction force must lie onthe friction ellipse. More comments on this behav-ior will be made for the specific tracks consideredbelow.

0 0.2 0.4 0.6 0.8 10

500

1000

1500

2000

2500

sx

Fx

(0.21443,2231.7698)

(1,1684.5506)

Figure 6: Longitudinal friction force vs. longitudi-nal slip quantity. The maximum friction value isalso indicated, corresponding to the radius of thefriction circle.

5.2 Straight Track Results

The optimal racing line for the straight track isshown in Figure 7. More detailed results, includingvehicle velocity, control inputs, and friction ellipseplots are shown in Figure 8.

Note that the vehicle speed is indicated by thecolor of the racing line (with red hues indicatinga slower speed, and green hues indicating speedsnear vmax). Intuitively, the vehicle accelerates on astraight line along the track. As Figure 8(b) reveals,y = 0 for the entire duration of the track. On theother hand, x increases until top speed is hit.

Figure 7: Straight track optimal trajectory andspeed. Red marker indicates starting position.

The control input plots reveal that while thecar is accelerating, both the front and rear wheelshave a slip quantity which lead the vehicle to havemaximal friction force (the same maximum forceindicated in Figure 6). This control input continuesuntil the vehicle accelerates to vmax, at whichpoint oscillations between maximum braking andmaximum acceleration occur in order to maintainspeed at vmax.

Additionally, at a large number of instancesin Figure 8(d), the slip quantities reach theirmaximum and minimum allowable values, +1 and-1. It is hypothesized that this issue is causedby the numerical methods used by GPOPS tosolve the problem. It is likely that reducingthe convergence tolerances in GPOPS will helpremove these discontinuities. However, at thesame time, these have minimal impact on the cartrajectory as slip quantities of +1 or -1 correspondto zero traction, meaning that the vehicle does notaccelerate or decelerate.

Figure 8(e) indicates the longitudinal and lateralfriction forces of the front and rear tires, respec-tively. Note that for the majority of the track, thecar is applying maximum longitudinal friction (topof the friction ellipse). Once top speed is reached,the input oscillates between the top and bottom ofthe friction ellipse, in order to satisfy the velocityconstraint. The friction data appearing inside theellipse is due to the discontinuous control inputsmentioned earlier, which are a result of the numer-ical approximations used by GPOPS.

7

Page 8: Optimal Racing Line Control - mit.edushayegan/files/omidshafiei_optimal_racing_line_control14.pdfThe optimal racing line problem can be considered a dual problem of the optimal vehicle

(a) Optimal trajectory and input SRx.

0 0.5 1 1.5 2 2.5 3−2

0

2

4

6

8

10

12

t [s]

v [m

s−1 ]

v

x

vy

|v|v

max

(b) Speed profile.

0 0.5 1 1.5 2 2.5 3−25

−20

−15

−10

−5

0

5

10

15

20

25

t [s]

δ [d

egre

es]

(c) Steering control input history.

0 0.5 1 1.5 2 2.5 3−1

−0.5

0

0.5

1

t [s]

s

0 0.5 1 1.5 2 2.5 3−0.5

0

0.5

t [s]

s

sF

x

sR

x

sF

y

sR

y

(d) Throttle control input history.

−2000 0 2000

−2000

−1000

0

1000

2000

Front wheels

fy [N]

f x [N]

−2000 0 2000

−2000

−1000

0

1000

2000

Rear wheels

fy [N]

f x [N]

(e) Friction ellipse and slip quantities.

0 0.5 1 1.5 2 2.5 3−150

−100

−50

0

50

100

150

t [s]

Tur

ning

rad

ius

[m]

(f) Turning radius.

Figure 8: Straight track results

8

Page 9: Optimal Racing Line Control - mit.edushayegan/files/omidshafiei_optimal_racing_line_control14.pdfThe optimal racing line problem can be considered a dual problem of the optimal vehicle

5.3 U-Turn Track Results

Figure 9 shows the optimal trajectory for the U-Turn track. Figure 10 shows detailed optimalsolution plots for the track. The behavior of thevehicle on this track is much more interesting. Forinstance, note in Figure 9 that the vehicle smoothlyhits the apex of the turn upon entry, and leaves witha near straight line motion in order to maximizeacceleration. This behavior is also seen in the speedplot (Figure 10(b)). At around t = 5s, the vehicleclears the turn and starts accelerating towards thefinish line.

Figure 9: U-Turn track optimal trajectory andspeed. Red marker indicates starting position.

Additionally, the speed profile in Figure 10indicates that the vehicle slows into the turn early,at around t = 2.1s, in order to decrease corneringradius and hug the inside of the curve tightly. Dueto the discretized nature of the track, as well asthe nature of the terminal constraint manifolds foreach phase, the vehicle trajectory hits the jaggededges of the track. This phenomenon is explainedeasily when consideration is made for the dynamicalnature of the vehicle model.

For the vehicle to perfectly hug the inside of thetrack, including at the corner points, the velocitymust be drastically reduced in order to allow fora nearly infinite trajectory curvature. However,this is infeasible as it tremendously increases theoverall time objective. Hence, unlike the kinematicmodel (which does indeed hug the track perfectly),the dynamical model instead takes the approach ofbalancing vehicle speed with distance from the inneredge of the track.

As Figure 10(d) indicates, the U-Turn track does

not exhibit the same oscillatory slip quantity inputbetween +1 and -1 which the straight track did.Looking at the velocity plot 10(b) in conjunction, itis concluded that since the vehicle does not reach topspeed, the same discontinuous behaviors exhibitedin the straight track are disallowed. The controleffort is fully dedicated to balancing longitudinalacceleration or decreasing cornering (lateral) radiuson this track. This also explains why the controleffort is fully located on the perimeter of the frictionellipse plots in Figure 10(e).

Figure 10(f) reveals that the vehicle has infiniteturning radius until approximately t = 10s, at whichpoint the steering input (Figure 10(c)) turns awayfrom the curve and then back towards the curve inorder to lead the car into the U-Turn. At this point,the lateral slip quantities siy (i = F,R) increasenearly to their maximal limits, in order to performa hard turn to the left. The turning radius thenapproache 20m, the radius of the U-Turn, afterwhich it drops off to infinity again due to the trackstraightening out. The lateral slip quantities alsoreveal that early into the turn, the front wheel hasa slightly larger slip than the rear wheel. On theother hand, when the turn concludes, the rear wheelhas a larger slip quantity. These results correspondto the dynamical model used, since the vehicle hasnon-negligible length and the behavior of the frontwheels tends to lead the behavior of the rear wheels.

5.4 S-Curve Track Results

Figure 11 shows the optimal trajectory for the S-Curve track. Figure 12 shows detailed optimalsolution plots for the track. This trajectory is fairlysimilar to the U-Turn trajectory, with the exceptionthat the vehicle is able to retain its longitudinalvelocity much more efficiently as it does not haveto turn excessively. In fact, as Figure 12(b) shows,the vehicle is able to hit top speed at the end of thetrack.

In addition, the friction ellipse plots in Figure12(e) are more symmetrical than those for the U-Turn track, due to the presence of two oppositeturns in the S-Curve. Another interesting behavioris the “leading in” that the steering angle performswhenever the car approaches the turn. For instance,at t = 10s in Figure 12(c), the car steers right,before taking a hard left into the first turn. Aconjugate behavior is repeated when coming out ofthe S-Curve, at t = 12s.

9

Page 10: Optimal Racing Line Control - mit.edushayegan/files/omidshafiei_optimal_racing_line_control14.pdfThe optimal racing line problem can be considered a dual problem of the optimal vehicle

(a) Optimal trajectory and input SRx.

0 1 2 3 4 5 6 7 8 9−30

−20

−10

0

10

20

30

40

t [s]

v [m

s−1 ]

v

x

vy

|v|v

max

(b) Speed profile.

0 1 2 3 4 5 6 7 8 9−6

−4

−2

0

2

4

6

8

10

12

t [s]

δ [d

egre

es]

(c) Steering control input history.

0 1 2 3 4 5 6 7 8 9−1

−0.5

0

0.5

t [s]

s

0 1 2 3 4 5 6 7 8 9−0.1

0

0.1

0.2

0.3

t [s]

s

sF

x

sR

x

sF

y

sR

y

(d) Throttle control input history.

−2000 0 2000

−2000

−1000

0

1000

2000

Front wheels

fy [N]

f x [N]

−2000 0 2000

−2000

−1000

0

1000

2000

Rear wheels

fy [N]

f x [N]

(e) Friction ellipse and slip quantities.

0 1 2 3 4 5 6 7 8 9−150

−100

−50

0

50

100

150

t [s]

Tur

ning

rad

ius

[m]

(f) Turning radius

Figure 10: U-Turn track results

10

Page 11: Optimal Racing Line Control - mit.edushayegan/files/omidshafiei_optimal_racing_line_control14.pdfThe optimal racing line problem can be considered a dual problem of the optimal vehicle

Figure 11: S-Curve track optimal trajectory andspeed. Red marker indicates starting position.

Another interesting note is that the friction plots(Figure 12(e)) reveal the rear wheels to be doingmore braking than the front wheels. This behavioris also observed for the U-Turn track, and resemblesthe behavior of race car driving using the frontthrottle and rear brake simultaneously in order todrift the car around a turn.

5.5 Formula 1 Australian GP TrackResults - Dry Track

To ascertain vehicle performance in the real world,the Formula 1 Melbourne Grand Prix Circuit wasmodeled, with the vehicle placed at the usualstarting line of the track for F1 vehicles. The F1track was constructed by utilizing longitude andlatitude coordinates from Google Maps, along withMATLAB’s mapping toolbox for changing from amercator to a cartesian coordinate system.

However, vehicle dynamics were not tuned tomatch F1 vehicles, as aerodynamic forces (down-force and drag) have considerable impact on F1performance, but were not modeled in this report.

The F1 track model consisted of 80 phases intotal. However, solving for optimal trajectories onsuch a large number of phases was determined tobe infeasible in MATLAB, even after redesigningthe initial guessing scheme in order to use previousphases’ results. Instead, the code was redesigned toallow cutoff at any given phase, meaning that theprogram could be run for several hours and simplyterminated, with the results for the most up-to-datenumber of phases saved.

Figure 17 shows the optimal trajectory of thevehicle on the F1 track. This behavior is consistentwith those observed in the U-Turn and S-Curvetracks, with the car veering to the opposite directionof a corner before turning back in order to hit theapex.

Additionally, the slip control inputs in Figure18(c) appear much noisier than on the othertracks. This is due to the significant length ofstraightaways on this track, allowing the vehicle tohit top speed, at which point the control oscillatesbetween maximum and minimum bounds (as wellas maximum and minimum traction limits) to holdthe vehicle speed at vmax.

A final note is the presence of an apparent “inner”friction ellipse in Figure 18(d). These lower frictionforces correspond to instances where the optimalslip control is +1 or -1, as mentioned earlier, andare indicated in Figure 18(e).

5.6 Formula 1 Australian GP TrackResults - Wet Track

The effects of changing tire/road interaction param-eters (or traction limits) were also considered. In-stead of using the Pacejka tire parameters shownin Table 1, the parameters in Table 2 were uti-lized, which correspond to a wet road. Note thatthe top speed was also increased to 29ms−1. Thecorresponding friction limit graph is shown in Fig-ure 20(e), with a maximum friction force value of2040N, compared to the dry road’s maximum fric-tion force of 2231N.

Figure 21 shows a comparison of racing lines fordry and wet conditions. Note that the turningradius is, on average, notably larger on the wet trackthan the dry track. This makes intuitive sense, as awet tarmac makes for a more difficult car to control,with the lack of friction reducing the total amountof lateral acceleration the car can obtain during aturn.

Parameter ValueB 7C 1.6D 0.60

Table 2: Pacejka parameters for a wet road

11

Page 12: Optimal Racing Line Control - mit.edushayegan/files/omidshafiei_optimal_racing_line_control14.pdfThe optimal racing line problem can be considered a dual problem of the optimal vehicle

(a) Optimal trajectory and input SRx.

0 1 2 3 4 5 6 7 8−5

0

5

10

15

20

t [s]

v [m

s−1 ]

v

x

vy

|v|v

max

(b) Speed profile.

0 1 2 3 4 5 6 7 8−10

−5

0

5

10

15

20

t [s]

δ [d

egre

es]

(c) Steering control input history.

0 1 2 3 4 5 6 7 8−1

−0.5

0

0.5

t [s]

s

0 1 2 3 4 5 6 7 8−0.4

−0.2

0

0.2

0.4

t [s]

s

sF

x

sR

x

sF

y

sR

y

(d) Throttle control input history.

−2000 0 2000

−2000

−1000

0

1000

2000

Front wheels

fy [N]

f x [N]

−2000 0 2000

−2000

−1000

0

1000

2000

Rear wheels

fy [N]

f x [N]

(e) Friction ellipse and slip quantities.

0 1 2 3 4 5 6 7 8−150

−100

−50

0

50

100

150

t [s]

Tur

ning

rad

ius

[m]

(f) Turning radius.

Figure 12: S-Curve track results

12

Page 13: Optimal Racing Line Control - mit.edushayegan/files/omidshafiei_optimal_racing_line_control14.pdfThe optimal racing line problem can be considered a dual problem of the optimal vehicle

6 Constraint Satisfaction

The minimum time racing line problem, as posed,imposes several constraints. Dynamical and stateconstraints are verified to be met through GPOPSoutput log for all tracks, which indicates satisfactionof these constraints. A more interesting constraintis that on the top speed, vmax, which is verified tobe met in the speed plots (see Figures 8(b), 10(b),12(b), 18(b)).

Control input constraints are also verified to bemet, although in some cases (especially in longertracks) GPOPS sets control inputs to maximum orminimum limits. It is conjectured that these discon-tinuities are caused by slightly loose convergence tol-erances set in the problem configuration. The trackconstraint was posed in the form of a terminal ellip-tical manifold for each phase, as shown in Figure 4.As trajectory Figures 8(a), 10(a), 12(a), and 18(a)indicate, the vehicle always passes inside the termi-nal manifold of each phase. Note that the phasescan be visually seen as discontinuities in the track,as the track was discretized.

7 Computational Optimization

Due to the large state space considered in theproblem, as well as the large number of phases inthe tracks, a variety of methods were used to allowthe code to converge faster. These computationaloptimization techniques were deemed noteworthyand of possible use to future students.

The MATLAB profiler (Figure 13) was extremelyuseful in determining code bottlenecks and avoidingmicro-optimization. Initial trials revealed thatsignificant time was spent in both the continuous.mand endpoint.m functions in GPOPS, despite thefunctions’ relative simplicity. This was determinedto be due to GPOPS calling each function up toseveral hundred thousand times, as seen in Figure13. Efforts were placed in optimizing the code inseveral ways, outlined in Table 3.

Optimization Level 1 involved using the “@doubleclass” MATLAB toolbox, obtained from [12]. Thistoolbox offers improvements in runtime for elemen-tary functions in MATLAB, such as sqrt() and trigfunctions, which appear to be a major bottleneck inthe code based on the profiler. A full plot of var-ious elementary function runtime improvements ispresented in Figure 14. On average, runtimes de-crease by factors of 2 to 7. For a 4 phase track, this

Figure 13: MATLAB code profiler

Opt. Level Description Runtime [s]0 No optimization 60.011 MATLAB @double toolbox 55.982 Struct initialization 50.913 Improved initial guesses 28.64

Table 3: Optimization methods, details, andruntimes for 4 phase track. Note that each levelbuilds on top of previous levels.

results in a runtime improvement of 5 seconds, orapproximately 9%.

After implementation of the @double class, itwas noted that a significant amount of time wasspent initializing the phaseout struct in GPOPS’continuous.m function. This can be seen on line 63in Figure 15. By instead pre-allocating the struct(Figure 16), an additional 5 second improvementwas obtained in Optimization Level 2.

Optimization Level 3 involved implementing theimproved initial guessing method discussed earlier,by using previous results as guesses for longer phasetracks. This resulted in a significant improvement,seen in Table 3.

Overall, computational optimization of the codeled to runtime improvements of more than 50% for a4 phase track. For longer tracks, this improvementwas even more pronounced.

It is concluded that simple optimization tech-niques for a dynamically-typed language such asMATLAB can still yield significant runtime im-provements. For future work, an investigation ofporting the continuous.m and endpoint.m func-tions to a compiled language (or MEX files) can be

13

Page 14: Optimal Racing Line Control - mit.edushayegan/files/omidshafiei_optimal_racing_line_control14.pdfThe optimal racing line problem can be considered a dual problem of the optimal vehicle

conducted.

Figure 14: MATLAB @double class elementaryfunction improvements [12].

Figure 15: MATLAB code profiler results beforeOptimization Level 2. Note that th struct on line 63has not been initialized, and is more red (indicatinglonger relative time spent on it)

8 Conclusion

Optimal control of a vehicle dynamical model wasperformed in order to minimize total race time. Thechosen vehicle model was a single-track dynamicalmodel, including tire friction forces as governedby Pacejka’s Magic Formula. Two forms of thetrack constraint were considered, one being a pathconstraint ensuring that the vehicle never leaves the

Figure 16: MATLAB code profiler results afterOptimization Level 2. Line 66 (the same struct setin Line 63 of Figure 15) has its runtime significantlyreduced due to struct pre-allocation.

track boundaries in a given phase. The second wasa less constraining manifold constriant (for eachphase), treating the track similar to a series ofslalom gates. The latter constraint was chosen in thefinal implementation in order to allow for extremelylong tracks, up to 18 phases, to be solved.

It was noted that the control inputs of thevehicle typically stay on the perimeter of the frictionellipse. However, due to top speed constraints,inputs within the friction ellipse were occasionallyoccurred as well. These were determined to be dueto loose convergence tolerances set in GPOPS, dueto the level of complexity of the problem.

Future work includes an extension of the dynami-cal model to include simple notions of aerodynamicforces, such as downforce and drag, in addition toinvestigation of further computational performanceimprovements by implementing the code in a com-piled language such as C or C++.

References

[1] Velenis, E., “Analysis and Control of High-SpeedWheeled Vehicles”. PhD Thesis, 2006.

[2] Jeon, J., “Optimal Motion Planning with theHalf-Car Dynamical Model for AutonomousHigh-Speed Driving”. ACC, 2013.

[3] Pepy, R., “Path Planning using a DynamicVehicle Model”. ACC, 2013.

14

Page 15: Optimal Racing Line Control - mit.edushayegan/files/omidshafiei_optimal_racing_line_control14.pdfThe optimal racing line problem can be considered a dual problem of the optimal vehicle

[4] Velenis, E., “Optimality Properties and DriverInput Parameterization for Trail-braking Cor-nering”. EUCA, 2008.

[5] Campbell, S., “Steering Control of an Au-tonomous Ground Vehicle with Application tothe DARPA Urban Challenge”. Master of Sci-ence Thesis, 2007.

[6] Rucco, A., “Computing Minimum Lap-timeTrajectories for a Single-Track Car with LoadTransfer”. 51st IEEE Conference on Decisionand Control, 2012.

[7] Perantoni, G., “Optimal Control for a FormulaOne Car With Variable Parameters”. VehicleSystem Dynamics 2014, 2014.

[8] Xiong, Y., “Racing Line Optimization”. Masterof Science Thesis, 2010.

[9] Beltman, F., “Optimization of Ideal RacingLine”. BMI Paper, 2008.

[10] Gustafsson, T., “Computing the Ideal RacingLine Using Optimal Control”. Thesis, 2008.

[11] Pacejka, H., “Tyre modelling for use in vehicledynamics studies”. SAE Paper No. 870421,1987.

[12] Leutenegger, M., “MATLAB Toolbox: doubleclass”. Available at http://documents.

epfl.ch/users/l/le/leuteneg/www/

MATLABToolbox/DoubleClass.html, 2014.

15

Page 16: Optimal Racing Line Control - mit.edushayegan/files/omidshafiei_optimal_racing_line_control14.pdfThe optimal racing line problem can be considered a dual problem of the optimal vehicle

Figure 17: Formula 1 Australian GP track sector, calculated optimal trajectory and speed. Dry conditions.

16

Page 17: Optimal Racing Line Control - mit.edushayegan/files/omidshafiei_optimal_racing_line_control14.pdfThe optimal racing line problem can be considered a dual problem of the optimal vehicle

0 20 40 60 80 100−15

−10

−5

0

5

10

15

20

25

t [s]

v [m

s−1 ]

v

x

vy

|v|v

max

(a) Speed profile.

0 20 40 60 80 100−30

−20

−10

0

10

20

30

t [s]

δ [d

egre

es]

(b) Steering control input history.

0 20 40 60 80 100−2

−1

0

1

2

t [s]

s

0 20 40 60 80 100−1.5

−1

−0.5

0

0.5

1

t [s]

s

sF

x

sR

x

sF

y

sR

y

(c) Throttle control input history.

−2000 0 2000

−2000

−1000

0

1000

2000

Front wheels

fy [N]

f x [N]

−2000 0 2000

−2000

−1000

0

1000

2000

Rear wheels

fy [N]

f x [N]

(d) Friction ellipse and slip quantities.

0 0.2 0.4 0.6 0.8 10

500

1000

1500

2000

2500

sx

Fx

(0.21443,2231.7698)

(1,1684.5506)

(e) Longitudinal friction force vs. longitudinal slip quantity.

0 20 40 60 80 100−150

−100

−50

0

50

100

150

t [s]

Tur

ning

rad

ius

[m]

(f) Turning radius.

Figure 18: Formula 1 Australian GP track results. Dry conditions.

17

Page 18: Optimal Racing Line Control - mit.edushayegan/files/omidshafiei_optimal_racing_line_control14.pdfThe optimal racing line problem can be considered a dual problem of the optimal vehicle

Figure 19: Formula 1 Australian GP track sector, calculated optimal trajectory and speed. Wet conditions.

18

Page 19: Optimal Racing Line Control - mit.edushayegan/files/omidshafiei_optimal_racing_line_control14.pdfThe optimal racing line problem can be considered a dual problem of the optimal vehicle

0 5 10 15 20 25 30 35 40−30

−20

−10

0

10

20

30

t [s]

v [m

s−1 ]

v

x

vy

|v|v

max

(a) Speed profile.

0 5 10 15 20 25 30 35 40−30

−20

−10

0

10

20

30

t [s]

δ [d

egre

es]

(b) Steering control input history.

0 5 10 15 20 25 30 35 40−1.5

−1

−0.5

0

0.5

1

t [s]

s

0 5 10 15 20 25 30 35 40−0.5

0

0.5

1

t [s]

s

sF

x

sR

x

sF

y

sR

y

(c) Throttle control input history.

−2000 0 2000

−2000

−1000

0

1000

2000

Front wheels

fy [N]

f x [N]

−2000 0 2000

−2000

−1000

0

1000

2000

Rear wheels

fy [N]

f x [N]

(d) Friction ellipse and slip quantities.

0 0.2 0.4 0.6 0.8 10

500

1000

1500

2000

2500

sx

Fx

(0.21443,2040.4752)

(1,1540.1605)

(e) Longitudinal friction force vs. longitudinal slip quantity.

0 5 10 15 20 25 30 35 40−150

−100

−50

0

50

100

150

t [s]

Tur

ning

rad

ius

[m]

(f) Turning radius.

Figure 20: Formula 1 Australian GP track results. Wet conditions.

19

Page 20: Optimal Racing Line Control - mit.edushayegan/files/omidshafiei_optimal_racing_line_control14.pdfThe optimal racing line problem can be considered a dual problem of the optimal vehicle

Figure 21: Formula 1 Australian GP track sector, calculated optimal trajectory. Comparison of dry and wetconditions.

20


Recommended