Technical Articles and Newsletters

使用MATLAB实时脚本来教授最佳控制和动态编程在线

Eindhoven技术大学Duarte J. Antunes


When my course最佳控制和动态编程在COVID-19大流行期间过渡到在线模型MATLAB®live scripts proved invaluable. They enabled me to teach complex concepts in a way that was interactive, engaging, and better suited to online learning than a traditional lecture-with-slides approach.

With live scripts I can combine formatted text, images, hyperlinks, equations, and code (Figure 1). Because the scripts are live, students can tune parameters or modify the code and immediately see how their changes affect the output. The process engages students in active learning and encourages exploration of the material. In a post-course student survey, 97% of the respondents reported that live scripts either “helped” or were “very useful” in completing assignments.

图1.使用的实时脚本最佳控制和动态编程。

图1.使用的实时脚本最佳控制和动态编程。

演讲的局限性,并滑行

当我教最佳控制和动态编程过去,我的讲座合并了我引入一个新概念的幻灯片,描述了如何实现,然后显示一些样本输出。例如,在有关线性季度调节器(LQRS)的课程中,我将从讨论相关方程以及特殊情况和假设开始,显示MATLAB实现,然后显示各种参数值的代码输出(图2)。后来,我将分配练习,要求学生使用MATLAB解决一组最佳控制问题。练习包括带有MATLAB代码快照的示例解决方案。

图2. LQR上的幻灯片系列。顺时针从左上方:简介,示例应用程序,相应的MATLAB代码以及结果的图。

图2. LQR上的幻灯片系列。顺时针从左上方:简介,示例应用程序,相应的MATLAB代码以及结果的图。

I always felt that this approach was a clumsy way of presenting material. The code on the slide was just a snapshot of the implementation, and I had to include numerous plots to show the effect of different parameter values on the output. Motivated by these issues, I decided to convert all the course material involving MATLAB to live scripts.

从幻灯片到实时脚本

我总共转换了16个讲座,30个MATLAB示例,30个MATLAB练习和10个分级作业。对于每个课程主题,我将介绍性的讨论文本复制到实时脚本中,并将其与标题,项目符号和超链接到背景材料结构。我使用Live编辑器在将方程式放置在实时脚本中之前(图3),然后在将方程式放置之前预览相应的方程式。

Figure 3. Inserting a LaTeX equation into a Live Script and previewing the output.

Figure 3. Inserting a LaTeX equation into a Live Script and previewing the output.

在某些情况下,方程式很长,我没有乳胶代码。在这些情况下,我使用了Mathpix OCR software扫描书面或打印方程并为我生成乳胶。

创建实时脚本后,我通过MATLAB驱动器cloud-based storage. Students downloaded the scripts for each lecture and ran them either on their laptops or in a browser usingMATLAB在线(图4)。使用MATLAB Online,学生可以从任何计算机或平板电脑中运行和编辑脚本,甚至没有安装MATLAB的机器。

图4.使用MATLAB Online在浏览器中运行的LQR控制课程的实时脚本。

图4.使用MATLAB Online在浏览器中运行的LQR控制课程的实时脚本。学生可以使用第29行上的滑块更改参数值,并在右侧查看图中的产生效果。

实时脚本分配和自动分级

During lectures, students often experiment with the corresponding live scripts, varying parameter values and checking the results. I encourage this kind of experimentation because it helps them to absorb the new material.

实时脚本对于帮助学生进行作业同样有价值。例如,一个任务涉及为流行线游戏开发控制算法。在游戏的真实版本中,目标是沿着弯曲的电线传递环,而不会在任何时候让戒指触摸电线。For the assignment, I reduced it to a two-dimensional problem in which the algorithm must control the ring’s trajectory by calculating the offset and angle of the ring for each time step as it moved down the wire (Figure 5) so that it reaches the end of the wire in a minimum time.

Figure 5. A visualization of the buzz wire assignment in which a ring (blue lines) must pass along a wire (red curve) without touching it.

Figure 5. A visualization of the buzz wire assignment in which a ring (blue lines) must pass along a wire (red curve) without touching it.

当我解释这项任务时,学生往往会有很多问题。当我向他们提供示例实施的实时脚本时,他们可以自己回答许多此类问题。他们可以离线运行脚本,更改控制参数,准确查看是什么构成与电线接触的环,依此类推。

To simplify grading, I show the students exactly the function they needed to develop within the live script to complete the assignment, with clearly defined inputs and outputs. I then use this specific function to automatically grade the students’ solution withMATLAB分级机,它与我们的学习管理系统Canvas集成在一起。

实时脚本的计划改进和其他用途

I continue to add enhancements as I develop new live scripts for my courses. These enhancements include incorporating more animations. I did this for an assignment in which the students had to develop an optimal control policy for the ghosts chasing a Pac-Man™-like character in a pursuit-evasion game (Figure 6). I found that the animation helped the students understand the assignment much better than my textual description could do.

图6.追求逃避游戏,学生为幽灵(红色)开发最佳控制算法以追求主角(黄色)。

图6.追求逃避游戏,学生为幽灵(红色)开发最佳控制算法以追求主角(黄色)。

In response to student feedback, I’m also adding more in-line comments to the MATLAB code. I’ve noticed that today’s students depend on seeing the code, and code comments, to cement their understanding. In the past, I tended to de-emphasize implementation details, but more and more students understand the language of programming and find it easier to grasp certain concepts when they are expressed in commented code rather than in our natural language. One student noted, “It really helps to see how a problem/solution changes when you decide to change a certain parameter or piece of code. Normally, examples are limited by the one variation that is shown. Besides that, the actual implementation of some of the theory is hard to imagine sometimes, while such a piece of code can help that process immensely.”

实时脚本的主要优点之一是它们易于学习和使用。我发现,大约五分钟的文档后,大多数学生都在启动和跑步。在我在信号和系统上教授的另一门课程中,我要求学生提交有关他们项目的报告。许多人决定自己创建最终报告作为实时脚本,并使用实时脚本来解释他们的项目through a video

About the Author

Duarte Antunes是Eindhoven Technology(TU/E)机械工程系的助理教授,他是Control Systems Technology Group的成员。他的教学和研究活动集中于控制理论。

Published 2021

View Articles for Related Capabilities