Part 6: How to Design an MPC Controller with Simulink and Model Predictive Control Toolbox

In this video, we’ll use the MPC Designer app to design an MPC controller that autonomously steers a car in a lane change maneuver scenario. Let’s start by looking at the parameters of this system. The car’s global position is represented with respect to the X and Y axis. These vectors show the car’s longitudinal and lateral velocities. In this control problem, we want the car to follow a reference trajectory. So, what we need to control here is the lateral position and the yaw angle. And we’re going to do so by adjusting the steering angle. The reference values for the lateral position and yaw angle are calculated with respect to the horizontal axis. In this example, we’ll assume a constant longitudinal speed of 15 m/s and use a linearized car model representing the lateral vehicle dynamics. For more information, check out the link given in the video description, which will take you to this Model Predictive Control Toolbox example.

在本视频中,我们将使用MPC Designer应用程序设计一个MPC控制器,在换道机动场景中自动驾驶汽车。让我们先看看这个系统的参数。汽车的全局位置是相对于X轴和Y轴表示的。这些矢量表示汽车的纵向和横向速度。在这个控制问题中,我们希望汽车遵循一个参考轨迹。所以,我们需要控制的是横向位置和偏航角。我们将通过调整转向角来实现这一点。横向位置和偏航角的参考值是相对于水平轴计算的。在本例中,我们将假设15 m/s的恒定纵向速度,并使用表示横向车辆动力学的线性化车辆模型。有关更多信息,请查看视频描述中提供的链接,该链接将带您访问此模型预测控制工具箱示例。

Let’s switch to Simulink to build the autonomous steering control system. This is the standard MPC control diagram that we want to build. We’ll start by adding the plant to our model. Here, I have a custom library, which includes the blocks I’ve previously created. The plant is one of them and has been developed as a state space model representing the lateral vehicle dynamics. The input to the plant is the steering angle, and the two outputs are the lateral position and the yaw angle. Now, we’re going to connect the MPC controller that you can find under Model Predictive Control Toolbox. The first input to this block is the measured outputs. So, we connect the outputs here. And the second input is the reference. In this example, we want to simulate a car changing lanes. To create a custom reference trajectory for such a scenario, I’m going to use the Driving Scenario Designer that is part of Automated Driving Toolbox. Using this app, I create a road with two lanes that are 4 meters wide, then add a car and add waypoints to generate the lane-change maneuver. You can adjust the waypoints manually from the side panel if needed. The car’s speed is set to 15 m/s. If I now simulate this scenario step by step, the app shows me how the yaw angle changes. I exported this scenario as a MATLAB function and created a block that outputs the reference lateral position and yaw angle values. I add this custom reference to my model and connect it to the controller. Here, we assume there are no measured disturbances, so we’ll remove the third input. Now that we connected all system components, we’ll continue designing the MPC controller. For this, we open the MPC block and click on “Design,” which opens up the MPC Designer. The MPC Designer is an interactive tool that lets you design MPC controllers and is shipped as part of Model Predictive Control Toolbox. Remember in the previous videos we talked about MPC design parameters such as sample time, prediction and control horizons, and constraints and weights. You can specify all these parameters in the MPC Designer, tune the controller, and then evaluate the controller’s performance. Now, we’ll go back to the MPC Designer and start by defining the MPC structure. We’ll enter the number of manipulated variables and measured outputs, and set the controller sample time to 0.1s. Then we click “define and linearize.” Remember that MPC uses an internal plant model to make predictions and an optimizer to find the optimal control action. Now, when we click “define and linearize,” the app imports and linearizes the plant from the Simulink model and uses it as the internal plant model. It also runs the default simulation scenario and displays the input and output responses. Next, we click on the I/O Attributes to type in the signal labels and units. Note that if these signals differ too much in magnitude, for example, say one is around 1 and the other one is around 1000, then you can use scale factors to bring them to similar scale. We’ll keep the default values for this example as the magnitude difference is not too much. Next, we’ll edit the default scenario. We can choose different types of reference signals from these options. The closest to our lane change scenario would be a ramp input for the lateral position reference and a constant reference of zero for the yaw angle to minimize it. We click OK and this updates the responses. Next, we’ll switch to the tuning tab where we can specify MPC design parameters. These are the default values for prediction and control horizons. Let’s see how the system behavior changes for a larger prediction horizon. For 15 and 20, the response looks more sluggish, so we will set it back to 10. Next, we’ll play with the control horizon. Increasing it to 3 provides a better control of the lateral position. If we increase it further, it doesn’t affect the response significantly, so we settle on a control horizon of 3.

让我们切换到Simulink来构建自动转向控制系统。这是我们想要构建的标准MPC控制图。我们将首先将植物添加到模型中。在这里,我有一个自定义库,其中包括我以前创建的块。该装置是其中之一,已开发为代表横向车辆动力学的状态空间模型。设备的输入为转向角,两个输出为横向位置和偏航角。现在,我们将连接MPC控制器,您可以在模型预测控制工具箱中找到它。该模块的第一个输入是测量输出。所以,我们在这里连接输出。第二个输入是参考。在本例中,我们希望模拟汽车变换车道。要为这样的场景创建自定义参考轨迹,我将使用自动驾驶工具箱中的驾驶场景设计器。使用这个应用程序,我创建了一条有两条4米宽的车道的道路,然后添加一辆车并添加航路点,以生成换道动作。如果需要,您可以从侧面板手动调整航路点。汽车的速度设置为15米/秒。如果我现在一步一步地模拟这个场景,应用程序会显示偏航角是如何变化的。我将此场景导出为一个MATLAB函数,并创建了一个输出参考横向位置和偏航角值的块。我将此自定义引用添加到模型并将其连接到控制器。这里,我们假设没有测量到的干扰,所以我们将删除第三个输入。现在我们连接了所有系统组件,我们将继续设计MPC控制器。为此,我们打开MPC块并单击“设计”,这将打开MPC设计器。MPC设计器是一个交互式工具,可用于设计MPC控制器,并作为模型预测控制工具箱的一部分提供。还记得在之前的视频中,我们讨论过MPC设计参数,如采样时间、预测和控制范围以及约束和权重。您可以在MPC设计器中指定所有这些参数,调整控制器,然后评估控制器的性能。现在,我们将回到MPC设计器,从定义MPC结构开始。我们将输入操纵变量和测量输出的数量,并将控制器采样时间设置为0.1s。然后单击“定义并线性化”。记住,MPC使用内部电厂模型进行预测,并使用优化器找到最佳控制措施。现在,当我们单击“定义并线性化”时,应用程序将从Simulink模型导入植物并线性化,并将其用作内部植物模型。它还运行默认的模拟场景,并显示输入和输出响应。接下来,单击I/O属性以输入信号标签和单位。请注意,如果这些信号的大小差异过大,例如,一个约为1,另一个约为1000,则可以使用比例因子将它们调整为类似的比例。对于本例,我们将保留默认值,因为幅值差异不会太大。接下来,我们将编辑默认场景。我们可以从这些选项中选择不同类型的参考信号。最接近我们车道变换场景的是横向位置参考的坡道输入和偏航角的恒定参考零,以使其最小化。我们单击OK,这将更新响应。接下来,我们将切换到tuning选项卡,在那里可以指定MPC设计参数。这些是预测和控制范围的默认值。让我们看看在更大的预测范围内系统行为是如何变化的。对于15和20,响应看起来更缓慢,因此我们将其设置回10。接下来,我们将使用控制地平线。将其增加到3可以更好地控制横向位置。如果我们进一步增加它,它不会显著影响响应,因此我们将控制范围定为3。

Next, we’ll set the constraints. The input constraints are dictated by the physical limitations of the vehicle. In this example, we’ll assume that the steering can turn a maximum of 30 degrees, so we’ll input pi/6 radians for the input constraints. And for driver comfort, we’ll limit the rate of change of the steering angle to 15 degrees/sec. Note that all the input constraints are hard and the output constraints are soft by default. We’ll try to keep the outputs between these values. Next, we’ll specify the weights. If we want the inputs and outputs have a target, we need to set the weights to a nonzero value. For steering angle, we’ll keep the default weight of zero, as it doesn’t need to track a target. We’ll also keep the default weight for the input rate. You can increase this weight if you want to have even smaller input increments. And for the outputs, we’ll set the weight for the lateral position to 1 and the yaw angle weight to 0.1, as position tracking is our primary objective. After setting all these parameters, you can fine tune your controller by using this slider. We’ll slide it right for a more aggressive control. And the response looks good.

接下来,我们将设置约束。输入约束由车辆的物理限制决定。在本例中,我们将假设转向最多可以转动30度,因此我们将输入pi/6弧度作为输入约束。为了让驾驶员舒适,我们将转向角的变化率限制在15度/秒。请注意,默认情况下,所有输入约束都是硬约束,而输出约束都是软约束。我们将尝试将输出保持在这些值之间。接下来,我们将指定权重。如果我们希望输入和输出有一个目标,我们需要将权重设置为非零值。对于转向角,我们将保持默认权重为零,因为它不需要跟踪目标。我们还将保留输入速率的默认权重。如果希望输入增量更小,可以增加此权重。对于输出,我们将横向位置的权重设置为1,偏航角权重设置为0.1,因为位置跟踪是我们的主要目标。设置所有这些参数后,可以使用此滑块微调控制器。我们会将其向右滑动,以实现更具攻击性的控制。反应看起来不错。

Now that we’re satisfied with the controller performance, we click on “export controller,” which updates the MPC controller block and runs the simulation. Note that in our Simulink model, we use the custom reference that we’ve designed before for the lane change scenario. Now we can look at the simulation results. We get satisfactory tracking for both outputs. And the steering angle is kept within the limits by the controller.

现在,我们对控制器的性能感到满意,我们单击“导出控制器”,它将更新MPC控制器块并运行模拟。请注意,在我们的Simulink模型中,我们使用了之前为车道更改场景设计的自定义参考。现在我们可以看看模拟结果。我们得到了满意的跟踪两个输出。控制器将转向角保持在限制范围内。

In this video, we’ve walked through the design process of an MPC controller but let me also mention that in Release 2018a there’s a Lane Keep Assist System block that effectively simplifies the design process. Check out the links in the video description to find out more on this.

在本视频中,我们已经介绍了MPC控制器的设计过程,但我还要提到,在2018a版中,有一个车道保持辅助系统块,可以有效简化设计过程。查看视频描述中的链接,了解更多有关此的信息。

We showed that the designed controller performs well, but note that the car dynamics we’ve used work for a specific operating condition, which is when we have a longitudinal speed of 15 m/s. If, however, the longitudinal speed of the car changes as it travels, the dynamics of the car will change, too. So, if we now change the speed to 35 m/s, this will cause the controller to degrade. In order to deal with this, we need to design an adaptive MPC controller that will update the internal plant model for changing operating conditions. And this is what we’re going to discuss in the next video.

我们展示了设计的控制器性能良好,但请注意,我们使用的汽车动力学适用于特定的操作条件,即当纵向速度为15 m/s时。然而,如果汽车的纵向速度在行驶过程中发生变化,汽车的动力学也会发生变化。因此,如果我们现在将速度更改为35 m/s,这将导致控制器性能下降。为了解决这个问题,我们需要设计一个自适应MPC控制器,该控制器将根据不断变化的运行条件更新内部电厂模型。这就是我们将在下一个视频中讨论的内容。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值