Coding Project 1 / FOC Frequency Sweep

What is frequency sweep actually measuring in motor control? 电机控制中的“扫频”,到底在测什么?

This project asks you to go beyond simply “running a script.” You should use simulation, plotting, tuning, and explanation to determine what speed-loop sweep, current-loop sweep, and load-torque sweep really mean in a multi-loop motor-control system. 这次作业不是让你只会“跑脚本”。你需要通过仿真、作图、调参和解释,真正弄清楚在多闭环电机控制中,速度环扫频、电流环扫频和负载转矩扫频到底测到了什么。

Core scripts核心脚本
simulation/tuner.py
simulation/tutorials_ep6_svpwm.py
Keywords关键词
speed loop / current loop / disturbance / bandwidth
Expected output建议产出
figures + analysis + tuning notes图 + 分析解释 + 调参说明
Report format报告形式
PDF

The key question is not “how to sweep,” but “what the sweep result means.”真正的问题不是“怎么扫频”,而是“扫出来的结果代表什么”。

A frequency sweep injects a sinusoidal signal near an operating point and observes how the output changes with frequency. So the result is a frequency-domain view of a specific input-output path.扫频本质上是在某个工作点附近注入正弦信号,并观察输出如何随频率变化。因此你测到的是某条输入—输出通道的频域特性。

$$G(j\omega)=\frac{Y(j\omega)}{U(j\omega)}$$

In motor control, the result depends on where you inject the signal, which variable you observe, whether the mechanical subsystem is allowed to move, and how fast the inner current loop is.在电机控制里,结果取决于你把信号注入在哪一层、观测哪一个量、机械系统是否允许运动,以及电流内环是否足够快。

Minimum standard最低要求 Do not submit only screenshots. You must explicitly state the input, the output, the injection point, the observed variable, and which dynamics are intentionally included or avoided. 不要只提交截图。你必须明确说明输入、输出、注入点、观测量,以及哪些动态是你故意包含或故意避免的。

Layer 1: observe层次 1:观察

Run the simulation and inspect speed, i_q, i_d, and load torque.先跑通仿真,观察速度、i_qi_d 和负载转矩。

Layer 2: interpret层次 2:解释

Explain whether you are measuring tracking, disturbance rejection, or a coupled electro-mechanical response.解释你测到的是跟踪、抗扰,还是电气与机械耦合后的响应。

Layer 3: tune层次 3:调参

Change controller bandwidth and show how the sweep results change.改变控制器带宽,并说明扫频结果如何变化。

Code entry points and setup references代码入口与环境参考

Recommended repository推荐参考仓库
git clone https://github.com/horychen/ee275.git

simulation/tutorials_ep6_svpwm.py

  • Search for bool_apply_sweeping_frequency_excitation.先搜索 bool_apply_sweeping_frequency_excitation
  • Find CMD_SPEED_SINE_RPM, CMD_CURRENT_SINE_AMPERE.找到 CMD_SPEED_SINE_RPMCMD_CURRENT_SINE_AMPERE
  • Find cmd_rpm, cmd_idq[1], and ACM.TLoad.找到 cmd_rpmcmd_idq[1]ACM.TLoad
  • Locate where speed and current PI controllers are initialized.定位速度环和电流环 PI 初始化的位置。

simulation/tuner.py

  • Read get_coeffs_dc_motor_current_regulator().get_coeffs_dc_motor_current_regulator()
  • Read get_coeffs_dc_motor_SPEED_regulator().get_coeffs_dc_motor_SPEED_regulator()
  • Read iterate_for_desired_bandwidth().iterate_for_desired_bandwidth()
  • Understand FOC_delta and FOC_desired_VLBW_HZ.理解 FOC_deltaFOC_desired_VLBW_HZ 的作用。

Variables you should know至少要熟悉这些变量

CTRL.bool_apply_speed_closed_loop_control CTRL.bool_apply_sweeping_frequency_excitation CTRL.bool_overwrite_speed_commands CMD_SPEED_SINE_HZ CMD_SPEED_SINE_STEP_SIZE CMD_SPEED_SINE_HZ_CEILING CMD_CURRENT_SINE_AMPERE CL_SERIES_KP / KI VL_SERIES_KP / KI FOC_delta FOC_desired_VLBW_HZ

Your report must answer Q1–Q7你的报告必须围绕 Q1–Q7 展开

Q1

What does a sweep actually measure?扫频到底在测什么?

State the input, output, injection point, and observation point.明确输入、输出、注入点和观测点。

Q2

What do speed-loop sweep and current-loop sweep measure, respectively?扫速度环和扫电流环分别在测什么?

Distinguish speed-reference-to-speed, current-reference-to-current, and disturbance-to-speed.区分速度参考到速度、电流参考到电流、扰动到速度这几条通道。

Q3

When sweeping the current loop, should rotor speed change or stay fixed?扫电流环时,转速应变化还是保持不变?

Discuss d-axis and q-axis separately, including back-EMF and torque production.请分开讨论 d 轴和 q 轴,并说明反电势与转矩耦合的影响。

Q4

Why does i_q amplitude often grow as speed-sweep frequency increases?为什么速度指令扫频时,i_q 幅值通常会随频率升高而变大?

Answer from the mechanical equation, not only from control intuition.请从机械方程出发解释,而不是只说“控制器更努力了”。

Q5

How is load-torque sweep at constant speed related to, and different from, speed-reference sweep?恒速时对负载转矩扫频,与对速度参考扫频,有什么联系与区别?

Explain using transfer-path or block-diagram language.请用传递路径或框图语言解释。

Q6

How does the current loop affect load-torque sweep results?电流环会怎样影响负载转矩扫频结果?

Explain why a slower inner loop worsens disturbance rejection and adds phase lag.说明为什么更慢的内环会降低抗扰并更早带来相位滞后。

Q7

How do you change bandwidth? Which parameters matter, and why?如何改变带宽?涉及哪些参数?原理是什么?

Connect the formulas in tuner.py with your experimental results.请把 tuner.py 中的公式和你的实验结果对应起来。

Suggested workflow建议实验流程

Stage阶段 What to do要做什么 What to answer要回答什么
Task A Run tutorials_ep6_svpwm.py with a valid configuration and inspect the default waveforms.先跑通 tutorials_ep6_svpwm.py,确认默认波形能正常显示。 Identify commands, feedback signals, states, and disturbances.先分清哪些是命令量、反馈量、状态量和扰动量。
Task B Sweep the speed reference while keeping the speed loop closed.保持速度环闭环,对速度参考进行扫频。 Describe the tracking path and how speed and i_q vary with frequency.分析闭环跟踪通道,并说明速度和 i_q 随频率如何变化。
Task C Sweep d-axis and q-axis current separately.分别对 d 轴和 q 轴电流做扫频。 Explain whether you are measuring a pure current loop or a current-mechanics coupled response.说明你测到的是纯电流环,还是与机械环耦合后的响应。
Task D Keep the speed command constant and inject a sinusoidal disturbance into ACM.TLoad.保持速度给定恒定,对 ACM.TLoad 注入正弦扰动。 Explain the disturbance-rejection path and compare it with speed-reference sweep.分析抗扰通道,并与速度参考扫频进行比较。
Task E Use tuner.py to generate at least two different bandwidth settings and repeat the experiments.tuner.py 生成至少两组不同带宽参数,并重复实验。 Show how bandwidth changes the results and explain why.说明带宽变化后结果如何变化,以及原因。
Programming minimum编程最低要求 Add at least one small function or script that extracts useful summary values from each sweep segment, such as frequency, amplitude, peak-to-peak value, or a simple phase estimate. 至少补一个自动整理结果的小功能,例如提取每段扫频的频率、响应幅值、峰峰值或简单相位估计。

Hints that should push you in the right direction足以把你推向正确方向的提示

Hint 1: A sweep measures the frequency response of a path提示 1:扫频测的是某条通道的频率响应

Speed-reference sweep is mainly about tracking. Load-torque sweep is mainly about disturbance rejection. Current-reference sweep targets the current loop only if mechanical effects are intentionally suppressed.速度参考扫频主要对应跟踪;负载转矩扫频主要对应抗扰;电流参考扫频只有在机械影响被刻意压制时,才更接近纯电流环测量。

Hint 2: Think carefully about d-axis vs q-axis sweep提示 2:认真区分 d 轴和 q 轴扫频

d-axis sweepd 轴扫频

Sweeping d-axis current typically does not create average torque in the basic PMSM setting, so it is often cleaner for observing electrical dynamics.在基本 PMSM 场景下,扫 d 轴电流通常不会直接产生平均电磁转矩,因此更适合较干净地观察电气动态。

q-axis sweepq 轴扫频

Sweeping q-axis current creates torque. If the rotor is free to accelerate, you are exciting both the current loop and the mechanical subsystem.q 轴电流会产生转矩。如果转子可以自由加减速,你激发的就不只是电流环,还包括机械系统。

Key idea关键点 If your goal is to measure something close to the pure current loop, you usually want rotor speed to stay fixed, so that speed-dependent back-EMF and mechanical dynamics do not contaminate the result too much. 如果你的目标是尽量测到“纯电流环”,通常更希望转速保持不变,这样速度相关的反电势和机械动态就不至于过多污染结果。

Hint 3: Why does i_q grow with speed-sweep frequency?提示 3:为什么速度扫频时 i_q 往往随频率增大?

$$J\frac{d\omega_m}{dt}=T_e-T_L,\qquad T_e=\frac{3}{2}n_{pp}K_A i_q$$
$$\omega_m^\ast(t)=A\sin(2\pi f t)\Rightarrow \frac{d\omega_m^\ast}{dt}=2\pi f A\cos(2\pi f t)$$

For fixed speed amplitude A, higher frequency means larger acceleration amplitude, which requires larger torque amplitude, which in turn requires larger i_q.在速度幅值 A 固定时,频率越高,加速度幅值越大;更大的加速度需要更大的转矩,而更大的转矩又需要更大的 i_q

Hint 4: Reference sweep and load-torque sweep are related but not identical提示 4:速度参考扫频和负载转矩扫频既相关又不同

They pass through the same closed-loop system and may share a similar closed-loop denominator, but they are injected at different points, so they do not represent the same transfer function.它们都经过同一个闭环系统,因此可能共享相近的闭环分母;但注入点不同,所以不是同一条传递函数。

$$\frac{\omega_m}{\omega_m^\ast}\sim \frac{C_vG_iG_m}{1+C_vG_iG_m},\qquad \frac{\omega_m}{T_L}\sim -\frac{G_d}{1+C_vG_iG_m}$$

Hint 5: The current loop is the torque actuator seen by the speed loop提示 5:从速度环角度看,电流环就是“转矩执行器”

The speed loop outputs i_q^*, but only the current loop can turn it into actual i_q. So a slower current loop makes the speed loop more sluggish and weaker against disturbances.速度环输出的是 i_q^*,真正把它变成实际 i_q 的是电流环。因此更慢的电流环会让速度环更迟钝、抗扰更差。

Hint 6: Bandwidth design is explicitly coded in tuner.py提示 6:带宽设计在 tuner.py 里写得很明确

$$K_{p,i}=2\pi L\,\mathrm{BW}_c,\qquad K_{i,i}=\frac{R}{L}$$
$$K_{i,\omega}=\frac{\omega_{ci}}{\delta^2},\qquad K_{p,\omega}=\frac{J_s/n_{pp}}{1.5\,n_{pp}K_A}\,\delta K_{i,\omega}$$

Connect these formulas with code variables and with your own sweep results.请把这些公式、代码变量和你自己的扫频结果对应起来。

bool_apply_sweeping_frequency_excitation
CMD_SPEED_SINE_RPM
CMD_CURRENT_SINE_AMPERE
cmd_rpm
cmd_idq[1]
ACM.TLoad
get_coeffs_dc_motor_current_regulator
get_coeffs_dc_motor_SPEED_regulator
iterate_for_desired_bandwidth

Required content of the final PDF report最终 PDF 报告要求

The final PDF must contain these 4 core figures最终 PDF 必须包含这 4 张核心图
  1. d-axis current-loop sweep — sweep the d-axis current loop alone.d 轴电流环扫频图——单独对 d 轴进行扫频。
  2. q-axis current-loop sweep — sweep the q-axis current loop alone.q 轴电流环扫频图——单独对 q 轴进行扫频。
  3. Speed-loop sweep — sweep the speed reference.速度环扫频图——对速度参考进行扫频。
  4. Load-torque sweep at constant speed — keep the speed command constant and sweep TLoad.恒速下的负载转矩扫频图——保持速度参考恒定,对 TLoad 进行扫频。

Mandatory必须包含

A clear description of what code you changed and why.明确说明你改了哪些代码,以及为什么。
All 4 required figures in the final PDF.最终 PDF 中必须出现上述 4 张图。
At least 2 different bandwidth settings for comparison.至少比较 2 组不同带宽参数。
Direct answers to Q1–Q7, not figures without explanation.逐条回答 Q1–Q7,不能只放图不解释。

Suggested report structure建议结构

  1. Objective and measured path实验目的与测量通道
  2. Code entry points and modifications代码入口与修改点
  3. Experimental settings实验设置
  4. The 4 core figures first先放 4 张核心图
  5. Q1–Q7 analysisQ1–Q7 分析
  6. Conclusion结论

Online submission is currently disabled.当前暂不支持在线提交。 Please prepare your report as a PDF. The upload form is intentionally hidden for now. 请先准备 PDF 报告。上传区域目前已隐藏。