Simulate lane-keeping assistance using adaptive model predictive controller
Model Predictive Control Toolbox / Automated Driving
TheLane Keeping Assist Systemblock simulates a lane keeping assist (LKA) system that keeps an ego vehicle traveling along the center of a straight or curved road by adjusting the front steering angle. The controller reduces the lateral deviation and relative yaw angle of the ego vehicle with respect to the lane centerline. The block computes optimal control actions while satisfying steering angle constraints using adaptive model predictive control (MPC).
To customize your controller, for example to use advanced MPC features or modify controller initial conditions, clickCreate LKA subsystem.
Curvature
— Road curvatureRoad curvature, specified as1/R, whereRis the radius of the curve in meters.
The road curvature is:
Positive when the road curves toward the positive Y axis of the global coordinate system.
Negative when the road curves toward the negative Y axis of the global coordinate system.
Zero for a straight road.
的controller models the road curvature as a measured disturbance with previewing. You can specify the curvature as a:
Scalar signal — Specify the curvature for the current control interval. The controller uses this curvature value across the prediction horizon.
Vector signal with length less than or equal to thePrediction Horizon——指定当前和预测的曲率价值es across the prediction horizon. If the length of the vector is less than the prediction horizon, then the controller uses the final curvature value in the vector for the remainder of the prediction horizon.
Longitudinal velocity
— Ego vehicle velocityEgo vehicle velocity in m/s.
Lateral deviation
— Ego vehicle lateral deviationEgo vehicle lateral deviation in meters from the centerline of the lane.
Relative yaw angle
— Angle from lane centerlineEgo vehicle longitudinal axis angle in radians from the centerline of the lane.
Minimum steering angle
— Minimum front steering angleMinimum front steering angle constraint in radians. Use this input port when the minimum steering angle varies at run time.
To enable this port, selectUse external sourcefor theMinimum steering angleparameter.
Maximum steering angle
— Maximum front steering angleMaximum front steering angle constraint in radians. Use this input port when the maximum steering angle varies at run time.
To enable this port, selectUse external sourcefor theMaximum steering angleparameter.
Enable optimization
— Controller optimization enable signalController optimization enable signal. When this signal is:
Nonzero, the controller performs optimization calculations and generates aSteering anglecontrol signal.
Zero, the controller does not perform optimization calculations. In this case, theSteering angleoutput signal remains at the value it had when the optimization was disabled. The controller continues to update its internal state estimates.
To enable this port, select theUse external signal to enable or disable optimizationparameter.
External control signal
— Steering angle applied to ego vehicleActual steering angle in radians applied to the ego vehicle. The controller uses this signal to estimate the ego vehicle model states. Use this input port when the control signal applied to the ego vehicle does not match the optimal control signal computed by the model predictive controller. This mismatch can occur when, for example:
TheLane Keeping Assist Systemis not the active controller. Maintaining an accurate state estimate when the controller is not active prevents bumps in the control signal when the controller becomes active.
The steering actuator fails and does not provide the correct control signal to the ego vehicle.
To enable this port, select theUse external control signal for bumpless transfer between PFC and other controllersparameter.
Vehicle dynamics matrix A
— State matrix of ego vehicle predictive modelState matrix of ego vehicle predictive model. The number of rows in the state matrix corresponds to the number of states in the predictive model. This matrix must be square.
The ego vehicle predictive model defined byVehicle dynamics matrix A,Vehicle dynamics matrix B, andVehicle dynamics matrix Cmust be minimal.
To enable this port, select theUse vehicle modelparameter.
Vehicle dynamics matrix B
— Input-to-state matrix of ego vehicle predictive modelInput-to-state matrix of ego vehicle predictive model. The number of rows in this signal must match the number of rows inVehicle dynamics matrix A.
The ego vehicle predictive model defined byVehicle dynamics matrix A,Vehicle dynamics matrix B, andVehicle dynamics matrix Cmust be minimal.
To enable this port, select theUse vehicle modelparameter.
Vehicle dynamics matrix C
— State-to-output matrix of ego vehicle predictive modelState-to-output matrix of ego vehicle predictive model. The number of columns in this signal must match the number of rows inVehicle dynamics matrix A.
The ego vehicle predictive model defined byVehicle dynamics matrix A,Vehicle dynamics matrix B, andVehicle dynamics matrix Cmust be minimal.
To enable this port, select theUse vehicle modelparameter.
Steering angle
— Front steering angle control signalFront steering angle control signal in radians generated by the controller. The front steering angle is the angle of the front tires from the longitudinal axis of the vehicle. The steering angle is positive towards the positive lateral axis of the ego vehicle.
使用车辆参数s
— Define ego vehicle model using vehicle propertieson
(default) |off
Select this parameter to define the ego vehicle model used by the MPC controller by specifying properties of the ego vehicle. The ego vehicle model is the linear model from the front steering angle to the lateral velocity and yaw angle rate. For more information, see自我车辆预测模型.
定义车辆模型,specify the following block parameters:
Total mass
Yaw moment of inertia
Longitudinal distance from center of gravity to front tires
Longitudinal distance from center of gravity to rear tires
Cornering stiffness of front tires
Cornering stiffness of rear tires
For more information on the ego vehicle model, see自我车辆预测模型.
Selecting this parameter clears theUse vehicle modelparameter.
Block Parameter:ModelType |
Type:string, character vector |
Default:"Use vehicle parameters" |
Use vehicle model
— Define ego vehicle model using state-space matricesoff
(default) |on
Select this parameter to define the state-space matrices of the ego vehicle model used by the MPC controller. This model is the linear model from the front steering angle in radians to the lateral velocity in meters per second and yaw angle rate in radians per second. For more information on the ego vehicle model, see自我车辆预测模型.
To define the initial internal model, specify theA,B, andCstate-space matrices. The internal model must be a minimal realization with no direct feedthrough, and the dimensions ofA,B, andCmust be consistent.
Typically, the ego vehicle steering model is velocity-dependent, and therefore, it varies over time. To update the internal model at run time, use theVehicle dynamics A,Vehicle dynamics B, andVehicle dynamics Cinput ports.
Selecting this parameter clears the使用车辆参数sparameter.
Block Parameter:ModelType |
Type:string, character vector |
Default:"Use vehicle parameters" |
Total mass
— Ego vehicle mass1575
(default) | positive scalarEgo vehicle mass in kg.
To enable this parameter, select the使用车辆参数sparameter.
Block Parameter:VehicleMass |
Type:string, character vector |
Default:"1575" |
Yaw moment of inertia
— Moment of inertia about the ego vehicle vertical axis2875
(default) | positive scalarMoment of inertia about the ego vehicle vertical axis in Kg·m2.
To enable this parameter, select the使用车辆参数sparameter.
Block Parameter:VehicleYawInertia |
Type:string, character vector |
Default:"2875" |
Longitudinal distance from center of gravity to front tires
— Distance from the ego vehicle center of mass to its front tires1.2
(default) | positive scalarDistance from the ego vehicle center of mass to its front tires in meters, measured along the longitudinal axis of the vehicle.
To enable this parameter, select the使用车辆参数sparameter.
Block Parameter:LengthToFront |
Type:string, character vector |
Default:"1.2" |
Longitudinal distance from center of gravity to rear tires
— Distance from the ego vehicle center of mass to its rear tires1.6
(default) | positive scalarDistance from the ego vehicle center of mass to its rear tires in meters, measured along the longitudinal axis of the vehicle.
To enable this parameter, select the使用车辆参数sparameter.
Block Parameter:LengthToRear |
Type:string, character vector |
Default:"1.6" |
Cornering stiffness of front tires
— Front tire stiffness19000
(default) | positive scalarFront tire stiffness in N/rad, defined as the relationship between the side force on the front tires and the angle of the tires to the longitudinal axis of the vehicle.
To enable this parameter, select the使用车辆参数sparameter.
Block Parameter:FrontTireStiffness |
Type:string, character vector |
Default:"19000" |
Cornering stiffness of rear tires
— Rear tire stiffness33000
(default) | positive scalarRear tire stiffness in N/rad, defined as the relationship between the side force on the rear tires and the angle of the tires to the longitudinal axis of the vehicle.
To enable this parameter, select the使用车辆参数sparameter.
Block Parameter:RearTireStiffness |
Type:string, character vector |
Default:"33000" |
A
— Initial state matrix of ego vehicle predictive modelInitial state matrix of ego vehicle predictive model. The number of rows in the state matrix corresponds to the number of states in the predictive model. This matrix must be square.
The initial ego vehicle predictive model defined byA,B, andCmust be minimal.
Typically, the ego vehicle model varies over time. To update the state matrix at run time, use theVehicle dynamics Ainput port.
To enable this parameter, select theUse vehicle modelparameter.
Block Parameter:EgoModelMatrixA |
Type:string, character vector |
Default:"[-4.4021 ,-12.4603;1.3913,-5.1868]" |
B
— Initial input-to-state matrix of ego vehicle predictive modelInitial input-to-state matrix of ego vehicle predictive model. The number of rows in this parameter must match the number of rows inA.
The initial ego vehicle predictive model defined byA,B, andCmust be minimal.
Typically, the ego vehicle model varies over time. To update the input-to-state matrix at run time, use theVehicle dynamics Binput port.
To enable this parameter, select theUse vehicle modelparameter.
Block Parameter:EgoModelMatrixB |
Type:string, character vector |
Default:"[24.1270;15.8609]" |
C
— Initial state-to-output matrix of ego vehicle predictive modelInitial state-to-output matrix of ego vehicle predictive model. The number of columns in this parameter must match the number of rows inA.
The initial ego vehicle predictive model defined byA,B, andCmust be minimal.
Typically, the ego vehicle model varies over time. To update the state-to-output matrix at run time, use theVehicle dynamics Cinput port.
To enable this parameter, select theUse vehicle modelparameter.
Block Parameter:EgoModelMatrixC |
Type:string, character vector |
Default:"[1,0;0,1]" |
Initial longitudinal velocity
— Initial velocity of the ego vehicle15
(default) | positive scalarInitial velocity of the ego vehicle model when the lane-keeping assist is enabled in m/s. This velocity can differ from the actual ego vehicle initial velocity.
Note
A very small initial velocity, for exampleeps
, can produce a nonminimal realization for the controller plant model, causing an error. To prevent this error, set the initial velocity to a larger value, for example1e-3
.
Block Parameter:InitialLongVel |
Type:string, character vector |
Default:"15" |
Transport lag between model inputs and outputs
— Total transport lag in ego vehicle model0
(default) | nonnegative scalarTotal transport lag,τ, in the ego vehicle model in seconds. This lag includes actuator, sensor, and communication lags. For each input-output channel, the transport lag is approximated by:
Block Parameter:TransportLag |
Type:string, character vector |
Default:"0" |
Minimum steering angle
— Minimum front steering angle-0.26
(default) | scalar between-pi/2
andpi/2
Minimum front steering angle constraint in radians.
If the minimum steering angle varies over time, add theMinimum steering angleinput port to the block by selectingUse external source.
This parameter must be less than theMaximum steering angleparameter.
Block Parameter:MinSteering |
Type:string, character vector |
Default:"-0.26" |
Maximum steering angle
— Maximum front steering angle0.26
(default) | scalar between-pi/2
andpi/2
Maximum front steering angle constraint in radians.
If the maximum steering angle varies over time, add theMaximum steering angleinput port to the block by selectingUse external source.
This parameter must be greater than theMinimum steering angleparameter.
Block Parameter:MaxSteering |
Type:string, character vector |
Default:“0.26” |
Sample time
— Controller sample time0.1
(default) | positive scalarController sample time in seconds.
Block Parameter:Ts |
Type:string, character vector |
Default:"0.1" |
Prediction horizon
— Controller prediction horizon10
(default) | positive integer控制器预测地平线的步骤。的controller prediction time is the product of the sample time and the prediction horizon.
Block Parameter:PredictionHorizon |
Type:string, character vector |
Default:"30" |
Controller behavior
— Closed-loop controller performance0.5
(default) | scalar between0
and1
Closed-loop controller performance. The default parameter value provides a balanced controller design. Specifying a:
Smaller value produces a more robust controller with smoother control actions.
Larger value produces a more aggressive controller with a faster response time.
When you modify this parameter, the change is applied to the controller immediately.
Block Parameter:ControllerBehavior |
Type:string, character vector |
Default:"0.5" |
Use suboptimal solution
— Apply suboptimal solution after specified number of iterationsoff
(default) |on
Configure the controller to apply a suboptimal solution after a specified maximum number of iterations, which guarantees the worst-case execution time for your controller.
For more information, seeSuboptimal QP Solution.
After selecting this parameter, specify theMaximum iteration numberparameter.
Block Parameter:suboptimal |
Type:string, character vector |
Default:"off" |
Maximum iteration number
— Maximum optimization iterations10
(default) | positive integerMaximum number of controller optimization iterations.
To enable this parameter, select theUse suboptimal solutionparameter.
Block Parameter:maxiter |
Type:string, character vector |
Default:"10" |
Use external signal to enable or disable optimization
— Add port for enabling optimizationoff
(default) |on
To add theEnable optimizationinput port to the block, select this parameter.
Block Parameter:optmode |
Type:string, character vector |
Default:"off" |
Use external signal for bumpless transfer between LKA and other controllers
— Add external control signal input portoff
(default) |on
To add theExternal control signalinput port to the block, select this parameter.
Block Parameter:trackmode |
Type:string, character vector |
Default:"off" |
Create LKA subsystem
— Create custom controllerGenerate a custom LKA subsystem, which you can modify for your application. The controller configuration data for the custom controller is exported to the MATLAB®workspace as a structure.
You can modify the custom controller subsystem to:
Modify default MPC settings or use advanced MPC features.
Modify the default controller initial conditions.
The default ego vehicle predictive model is the following state-space model:
Here:
VXis the longitudinal velocity of the car. At the start of the simulation, this velocity is equal to theInitial condition for longitudinal velocityparameter. At run time, this velocity is equal to theLongitudinal velocityinput signal.
mis theTotal massparameter.
IZis theYaw moment of inertiaparameter.
LFis theLongitudinal distance from center of gravity to front tiresparameter.
LRis theLongitudinal distance from center of gravity to rear tiresparameter.
CFis theCornering stiffness of front tiresparameter.
CRis theCornering stiffness of rear tiresparameter.
The input to this model is the steering angle in radians, and the outputs are the lateral velocity in meters per second and yaw angle rate in radians per second.
To define a different ego vehicle predictive model, select theUse vehicle modelparameter, and specify the initial state-space model. Then, specify the run-time values of the state-space matrices using theVehicle dynamics A,Vehicle dynamics B, andVehicle dynamics Cinput signals.
的controller creates its internal predictive model by augmenting the ego vehicle dynamic model. The augmented model includes the road curvature as a measured disturbance input signal.
By default, the model predictive controller assumes the following initial conditions for the ego vehicle:
Longitudinal velocity is equal to theInitial longitudinal velocityparameter.
Lateral velocity is zero.
Steering angle is zero.
Yaw angle rate is zero.
If the initial conditions in your model do not match these conditions, theSteering angleoutput can exhibit an initial bump at the start of the simulation.
To modify the controller initial conditions to match your simulation, create a custom lane-keeping control system by, on theBlocktab, clickingCreate LKA subsystem.
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select:.
Selectweb siteYou can also select a web site from the following list:
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.