main content

lane keeping assist with lane detection -凯发k8网页登录

this example shows how to simulate and generate code for an automotive lane keeping assist (lka) controller.

in this example, you:

  1. review a control algorithm that combines data processing from lane detections and a lane keeping controller from the model predictive control toolbox™.

  2. test the control system in a closed-loop simulink® model using synthetic data generated by the automated driving toolbox™.

  3. configure the code generation settings for software-in-the-loop simulation and automatically generate code for the control algorithm.

introduction

a lane keeping assist (lka) system is a control system that aids a driver in maintaining safe travel within a marked lane of a highway. the lka system detects when the vehicle deviates from a lane and automatically adjusts the steering to restore proper travel inside the lane without additional input from the driver. in this example, the lka system switches between the driver steering command and lane keeping controller. this approach is sufficient to introduce a modeling architecture for an lka system, however a real system would also provide haptic feedback to the steering wheel and enable the driver to override the lka system by applying sufficient counter-torque.

for the lka to work correctly, the ego vehicle must determine the lane boundaries and how the lane in front of it curves. idealized lka designs rely mostly on the previewed curvature, the lateral deviation, and relative yaw angle between the centerline of the lane and the ego vehicle. an example of such a system is given in (model predictive control toolbox). moving from advanced drive-assistance system (adas) designs to more autonomous systems, the lka must be robust to missing, incomplete, or inaccurate measurement readings from real-world lane detectors.

this example demonstrates a robust approach to the controller design when the data from lane detections may not be accurate. to do so, it uses data from a synthetic lane detector that simulates the impairments introduced by a wide-angle monocular vision camera. the controller makes decisions when the data from the sensor is invalid or outside a range. this provides a safety guard when the sensor measurement is false due to conditions in the environment, such as a sharp curve on the road.

get a list of systems that are open now so any systems opened during this example can be closed at the end.

startingopensystems = find_system('matchfilter', @simulink.match.allvariants);

open test bench model

to open the simulink test bench model, use the following command.

open_system('lkatestbenchexample')

the model contains two main subsystems:

  1. lane keeping assist, which controls the front steering angle of the vehicle

  2. vehicle and environment subsystem, which models the motion of the ego vehicle and models the environment

opening this model also runs the helperlkasetup script, which initializes data used by the model. the script loads certain constants needed by the simulink model, such as the vehicle model parameters, controller design parameters, road scenario, and driver path. you can plot the road and the path that the driver model will follow.

plotlkainputs(scenario,driverpath)

simulate assisting a distracted driver

you can explore the behavior of the algorithm by enabling lane-keeping assistance and setting the safe lateral distance. in the simulink model, in the user controls section, switch the toggle to on, and set the safe lateral distance to 1 meter. alternatively, enable the lane-keeping assist and set the safe lateral distance.

set_param('lkatestbenchexample/enable','value','1')
set_param('lkatestbenchexample/safe lateral offset','value','1')

to plot the results of the simulation, use the . the bird's-eye scope is a model-level visualization tool that you can open from the simulink toolstrip. on the simulation tab, under review results, click bird's-eye scope. after opening the scope, click find signals to set up the signals. then run the simulation for 15 seconds, and explore the contents of the bird's-eye scope.

sim('lkatestbenchexample','stoptime','15') % simulate 15 seconds
   assuming no disturbance added to measured output #1.
-->assuming output disturbance added to measured output #2 is integrated white noise.
-->"model.noise" is empty. assuming white noise on each measured output.
ans = 
  simulink.simulationoutput:
                logsout: [1x1 simulink.simulationdata.dataset] 
                   tout: [4682x1 double] 
     simulationmetadata: [1x1 simulink.simulationmetadata] 
           errormessage: [0x0 char] 

the bird's-eye scope shows a symbolic representation of the road from the perspective of the ego vehicle. in this example, the bird's-eye scope renders the coverage area of the synthetic vision detector as a shaded area. the ideal lane markings are additionally shown, as well as the synthetically detected left and right lane boundaries (shown here in red).

to run the full simulation and explore the results, use the following commands.

sim('lkatestbenchexample')                  % simulate to end of scenario
plotlkaresults(scenario,logsout,driverpath)
   assuming no disturbance added to measured output #1.
-->assuming output disturbance added to measured output #2 is integrated white noise.
-->"model.noise" is empty. assuming white noise on each measured output.

the blue curve for the driver path shows that the distracted driver may drive the ego vehicle to another lane when the road curvature changes. the red curve for the driver with lane keeping assist shows that the ego vehicle remains in its lane when the road curvature changes.

to plot the controller performance, use the following command.

plotlkaperformance(logsout)

  • top plot shows the lateral deviation relative to ego vehicle. the lateral deviation with lka is within [-0.5,0.5] m.

  • middle plot shows the relative yaw angle. the relative yaw angle with lka is within [-0.15,0.15] rad.

  • bottom plot shows the steering angle of the ego vehicle. the steering angle with lka is within [-0.5,0.5] rad.

to view the controller status, use the following command.

plotlkastatus(logsout)

  • top plot shows the left and right lane offset. around 5.5 s, 19 s, 31 s, and 33 s, the lateral offset is within the distance set by the lane keeping assist. when this happens, the lane departure is detected.

  • middle plot shows the lka status and the detection of lane departure. the departure detected status is consistent with the top plot. the lka is turned on when the lane departure is detected, but the control is returned to the driver later when the driver can steer the ego vehicle correctly.

  • bottom plot shows the steering angle from driver and lka. when the difference between the steering angle from driver and lka is small, the lka releases control to driver (for example, between 9 s to 17 s).

simulate lane following

you can modify the value of safe lateral offset for lka to ignore the driver input, putting the controller into a pure lane following mode. by increasing this threshold, the lateral offset is always within the distance set by the lane keeping assist. thus, the status for lane departure is on and the lane keeping assist takes control all the time.

set_param('lkatestbenchexample/safe lateral offset','value','2')
sim('lkatestbenchexample')                                     % simulate to end of scenario
   assuming no disturbance added to measured output #1.
-->assuming output disturbance added to measured output #2 is integrated white noise.
-->"model.noise" is empty. assuming white noise on each measured output.

you can explore the results of the simulation using the following commands.

plotlkaresults(scenario,logsout)

the red curve shows that the lane keeping assist on its own can keep the ego vehicle travelling along the centerline of its lane.

use the following command to depict the controller performance.

plotlkaperformance(logsout)

  • top plot shows the lateral deviation relative to ego vehicle. the lateral deviation with lka is within [-0.1,0.1] m.

  • middle plot shows the relative yaw angle. the relative yaw angle with lka is within [-0.02,0.02] rad.

  • bottom plot shows the steering angle of the ego vehicle. the steering angle with lka is within [-0.04,0.04] rad.

to view the controller status, use the following command.

plotlkastatus(logsout)

  • top plot shows the left and right lane offset. since the lateral offset is never within the distance set by the lane keeping assist, the lane departure is not detected.

  • middle plot shows that the lka status is always one, that is, the lane keeping assist takes control all the time.

  • bottom plot shows the steering angle from driver and lka. the steering angle from driver negotiating with the curved road is too aggressive. the small steering angle from lka is sufficient for the curved road in this example.

explore lane keeping assist algorithm

the lane keeping assist model contains four main parts: 1) estimate lane center 2) lane keeping controller 3) detect lane departure, and 4) apply assist.

open_system('lkatestbenchexample/lane keeping assist')

the detect lane departure subsystem outputs a signal that is true when the vehicle is too close to a detected lane. you detect a departure when the offset between the vehicle and lane boundary from the lane sensor is less than the lane assist offset input.

the estimate lane center subsystem outputs the data from lane sensors to the lane keeping controller. the detector in this example is configured to report the left and right lane boundaries of the current lane in the current field-of-view of the camera. each boundary is modeled as a length of a curve whose curvature varies linearly with distance (clothoid curve). to feed this data to a controller, offset both of the detected curves toward the center of the lane by the width of the car and a small margin (1.8 m total). weight each of the resulting centered curves by the strength of the detection and pass the averaged result to the controller. also, the estimate lane center subsystem provides finite values for inputs to the lane keeping controller subsystem. the previewed curvature provides the centerline of lane curvature ahead of the ego vehicle. in this example, the ego vehicle can look ahead for three seconds, which is the product of the prediction horizon and sample time. this look-ahead time enables the controller to use previewed information for calculating steering angle for the ego vehicle, which improves the mpc controller performance.

the goal for the lane keeping controller block is to keep the vehicle in its lane and follow the curved road by controlling the front steering angle . this goal is achieved by driving the lateral deviation and the relative yaw angle to be small (see the following figure).

the lka controller calculates a steering angle for the ego vehicle based on the following inputs:

  • previewed curvature (derived from lane detections)

  • ego vehicle longitudinal velocity

  • lateral deviation (derived from lane detections)

  • relative yaw angle (derived from lane detections)

considering physical limitations of the ego vehicle, the steering angle is constrained to be within [-0.5,0.5] rad. you can change the prediction horizon or move the controller behavior slider to adjust the performance of the controller.

the apply assist subsystem decides if the lane keeping controller or the driver takes control of the ego vehicle. the subsystem switches between the driver commanded steering and the assisted steering from the lane keeping controller. the switch to assisted steering is initiated when a lane departure is detected. control is returned to the driver when the driver begins steering within the lane again.

explore vehicle and environment

the vehicle and environment subsystem enables closed loop simulation of the lane keeping assist controller.

open_system('lkatestbenchexample/vehicle and environment')

the vehicle dynamics subsystem models the vehicle dynamics with vehicle body 3dof single track block from vehicle dynamics blockset™.

the block generates the ideal left and right lane boundaries based on the position of the vehicle with respect to the scenario read from scenario file lkatestbenchscenario.mat.

the vision detection generator block takes the ideal lane boundaries from the scenario reader block. the detection generator models the field of view of a monocular camera and determines the heading angle, curvature, curvature derivative, and valid length of each road boundary, accounting for any other obstacles.

the driver subsystem generates the driver steering angle based on the driver path which was created in helperlkasetup.

generate code for the control algorithm

the lkarefmdl model is configured to support generating c code using embedded coder® software. to check if you have access to embedded coder, run:

hasembeddedcoderlicense = license('checkout','rtw_embedded_coder')

you can generate a c function for the model and explore the code generation report by running:

if hasembeddedcoderlicense
    slbuild('lkarefmdl')
end

you can verify that the compiled c code behaves as expected using software-in-the-loop (sil) simulation. to simulate the lkarefmdl referenced model in sil mode, use:

if hasembeddedcoderlicense
    set_param('lkatestbenchexample/lane keeping assist',...
        'simulationmode','software-in-the-loop (sil)')
end

when you run the lkatestbenchexample model, code is generated, compiled, and executed for the lkarefmdl model. this allows you to test the behavior of the compiled code through simulation.

conclusions

this example shows how to implement an integrated lane keeping assist (lka) controller on a curved road with lane detection. it also shows how to test the controller in simulink using synthetic data generated by the automated driving toolbox, componentize it, and automatically generate code for it.

% close any systems opened during execution of this example.
endingopensystems = find_system('matchfilter', @simulink.match.allvariants);
bdclose(setdiff(endingopensystems,startingopensystems))

see also

apps

blocks

  • (vehicle dynamics blockset) |

related topics

  • (model predictive control toolbox)
  • (model predictive control toolbox)
网站地图