Skip to content
LIBRARY
Examples.LaneChangeMPCExample.md

Examples.LaneChangeMPCExample ​

Autonomous lane change with ACADOSMPC, translated from the DyadControlSystems lane-change tutorial: the car follows a smooth lateral reference (a point-to-point profile with bounded lateral velocity and acceleration, in place of the tutorial's trajectory limiter) from one lane to the next while accelerating from 30 to 50 km/h, with the tutorial's weights on the state, the controls and the control increments and its bounds on the lateral position, speed, heading, acceleration and steering angle. The reference is held constant over the horizon (no preview) and the tutorial's terminal equality constraint is not imposed. Verified in test/test_acados_tutorials.jl.

Usage ​

MPCComponents.Examples.LaneChangeMPCExample()

Variables ​

NameDescriptionUnits
yLateral position–
rLateral reference–
vSpeed–
psiHeading (degrees)–
aAcceleration–
deltaSteering angle (degrees)–
flagacados status–

Behavior ​

Behavior of this component cannot be rendered because it includes path variables.

Source ​

dyad
"""
Autonomous lane change with `ACADOSMPC`, translated from the DyadControlSystems lane-change tutorial:
the car follows a smooth lateral reference (a point-to-point profile with bounded lateral velocity and
acceleration, in place of the tutorial's trajectory limiter) from one lane to the next while
accelerating from 30 to 50 km/h, with the tutorial's weights on the state, the controls and the control
increments and its bounds on the lateral position, speed, heading, acceleration and steering angle.
The reference is held constant over the horizon (no preview) and the tutorial's terminal equality
constraint is not imposed. Verified in `test/test_acados_tutorials.jl`.
"""
example component LaneChangeMPCExample
  periodicclock = DiscreteComponents.PeriodicClock(dt = 0.1) {}
  plant = MPCComponents.Examples.LaneChangeCarPlant() {}
  "Samplers of the three state variables"
  s = [DiscreteComponents.Sampler() for i in 1:3] {}
  "Reference samplers"
  sr = [DiscreteComponents.Sampler() for i in 1:3] {}
  "Holds of the acceleration and the steering angle"
  zoh = [DiscreteComponents.ZeroOrderHold() for i in 1:2] {}
  "Lateral reference: one lane over, with bounded lateral velocity and acceleration"
  yref = BlockComponents.Sources.KinematicPTP(q0 = [0.0], q1 = [1.5], qd_max = [1.5], qdd_max = [0.4], startTime = 1.0) {}
  "Speed reference, 50 km/h"
  vref = BlockComponents.Sources.Constant(k = 13.88888888888889) {}
  "Heading reference"
  psiref = BlockComponents.Sources.Constant(k = 0.0) {}
  mpc = MPCComponents.ACADOSMPC(dynamics = plant, inputs = ["a", "delta"], state_variables = ["y", "v", "psi"], outputs = ["y", "v", "psi"], Ts = 0.1, Np = 30, Q1 = diagonal([1.0, 0.02, 0.01]), Q2 = diagonal([0.01, 1e-5]), penalize_increments = true, Q3 = diagonal([1.0, 0.001]), umin = [-10.0, -25.0], umax = [1.96, 25.0], constrained = ["y", "v", "psi"], constrained_min = [-1.53, 0.0, -6.0], constrained_max = [1.53, 33.333333333333336, 6.0], integrator = ACADOSIntegrator.IRK(), integrator_stages = 3) {}
  "Lateral position"
  variable y::Real
  "Lateral reference"
  variable r::Real
  "Speed"
  variable v::Real
  "Heading (degrees)"
  variable psi::Real
  "Acceleration"
  variable a::Real
  "Steering angle (degrees)"
  variable delta::Real
  "acados status"
  variable flag::Real
relations
  y = plant.y
  r = yref.q[1]
  v = plant.v
  psi = plant.psi
  a = mpc.u[1]
  delta = mpc.u[2]
  flag = mpc.exitflag
  connect(plant.y_out, s[1].u)
  connect(plant.v_out, s[2].u)
  connect(plant.psi_out, s[3].u)
  connect(yref.q[1], sr[1].u)
  connect(vref.y, sr[2].u)
  connect(psiref.y, sr[3].u)
  connect(s[1].y, mpc.x[1], periodicclock.y)
  for i in 2:3
    connect(s[i].y, mpc.x[i])
  end
  for i in 1:3
    connect(sr[i].y, mpc.r[i])
  end
  for i in 1:2
    connect(mpc.u[i], zoh[i].u)
  end
  connect(zoh[1].y, plant.a)
  connect(zoh[2].y, plant.delta)
metadata {"Dyad": {"doc": {"behavior": false}}}
end
Flattened Source
dyad
"""
Autonomous lane change with `ACADOSMPC`, translated from the DyadControlSystems lane-change tutorial:
the car follows a smooth lateral reference (a point-to-point profile with bounded lateral velocity and
acceleration, in place of the tutorial's trajectory limiter) from one lane to the next while
accelerating from 30 to 50 km/h, with the tutorial's weights on the state, the controls and the control
increments and its bounds on the lateral position, speed, heading, acceleration and steering angle.
The reference is held constant over the horizon (no preview) and the tutorial's terminal equality
constraint is not imposed. Verified in `test/test_acados_tutorials.jl`.
"""
example component LaneChangeMPCExample
  periodicclock = DiscreteComponents.PeriodicClock(dt = 0.1) {}
  plant = MPCComponents.Examples.LaneChangeCarPlant() {}
  "Samplers of the three state variables"
  s = [DiscreteComponents.Sampler() for i in 1:3] {}
  "Reference samplers"
  sr = [DiscreteComponents.Sampler() for i in 1:3] {}
  "Holds of the acceleration and the steering angle"
  zoh = [DiscreteComponents.ZeroOrderHold() for i in 1:2] {}
  "Lateral reference: one lane over, with bounded lateral velocity and acceleration"
  yref = BlockComponents.Sources.KinematicPTP(q0 = [0.0], q1 = [1.5], qd_max = [1.5], qdd_max = [0.4], startTime = 1.0) {}
  "Speed reference, 50 km/h"
  vref = BlockComponents.Sources.Constant(k = 13.88888888888889) {}
  "Heading reference"
  psiref = BlockComponents.Sources.Constant(k = 0.0) {}
  mpc = MPCComponents.ACADOSMPC(dynamics = plant, inputs = ["a", "delta"], state_variables = ["y", "v", "psi"], outputs = ["y", "v", "psi"], Ts = 0.1, Np = 30, Q1 = diagonal([1.0, 0.02, 0.01]), Q2 = diagonal([0.01, 1e-5]), penalize_increments = true, Q3 = diagonal([1.0, 0.001]), umin = [-10.0, -25.0], umax = [1.96, 25.0], constrained = ["y", "v", "psi"], constrained_min = [-1.53, 0.0, -6.0], constrained_max = [1.53, 33.333333333333336, 6.0], integrator = ACADOSIntegrator.IRK(), integrator_stages = 3) {}
  "Lateral position"
  variable y::Real
  "Lateral reference"
  variable r::Real
  "Speed"
  variable v::Real
  "Heading (degrees)"
  variable psi::Real
  "Acceleration"
  variable a::Real
  "Steering angle (degrees)"
  variable delta::Real
  "acados status"
  variable flag::Real
relations
  y = plant.y
  r = yref.q[1]
  v = plant.v
  psi = plant.psi
  a = mpc.u[1]
  delta = mpc.u[2]
  flag = mpc.exitflag
  connect(plant.y_out, s[1].u)
  connect(plant.v_out, s[2].u)
  connect(plant.psi_out, s[3].u)
  connect(yref.q[1], sr[1].u)
  connect(vref.y, sr[2].u)
  connect(psiref.y, sr[3].u)
  connect(s[1].y, mpc.x[1], periodicclock.y)
  for i in 2:3
    connect(s[i].y, mpc.x[i])
  end
  for i in 1:3
    connect(sr[i].y, mpc.r[i])
  end
  for i in 1:2
    connect(mpc.u[i], zoh[i].u)
  end
  connect(zoh[1].y, plant.a)
  connect(zoh[2].y, plant.delta)
metadata {"Dyad": {"doc": {"behavior": false}}}
end


Test Cases ​

No test cases defined.

  • Examples

  • Experiments

  • Analyses