M

DC Motor

Continuous
运行在线示例 免费 · 无需注册 · 直接在浏览器中运行

DCMotor 模块对机电直流(DC)电机对象进行建模。它描述电枢电路(电阻 RR、电感 LL、反电动势 ebe_b)与转子力学平衡(转动惯量 JJ、粘性摩擦 bb、负载转矩 TLT_L)之间的动态相互作用。模块提供统一的模型阶次选择,适用于教学与工业仿真:

  1. 一阶(仅机械):忽略电感(L=0L = 0),电枢电流按代数关系瞬时计算,转速呈指数收敛。
  2. 二阶(转速与电流)[标准]:完整的机电耦合,包含电气和机械时间常数。
  3. 三阶(位置、转速与电流):在机电模型上增加转子角位置(θ\theta)积分,用于伺服定位和运动控制。

模块分别输出转子角速度(ω\omega)、电枢电流(iai_a)、电磁转矩(TeT_e)和角位置(θ\theta),并对退化参数内置除零保护。

视频教程

数学模型

永磁直流电机的电枢电路遵循基尔霍夫电压定律,转子轴遵循牛顿-欧拉转动动力学:

电枢电路

Va(t)−eb(t)=R⋅ia(t)+L⋅dia(t)dtV_a(t) - e_b(t) = R \cdot i_a(t) + L \cdot \frac{di_a(t)}{dt}

反电动势与轴角速度成正比:

eb(t)=Ke⋅ω(t)e_b(t) = K_e \cdot \omega(t)

整理得电流导数:

dia(t)dt=1L(Va(t)−R⋅ia(t)−Ke⋅ω(t))\frac{di_a(t)}{dt} = \frac{1}{L} \left( V_a(t) - R \cdot i_a(t) - K_e \cdot \omega(t) \right)

转子力学平衡

Te(t)−TL(t)=J⋅dω(t)dt+b⋅ω(t)T_e(t) - T_L(t) = J \cdot \frac{d\omega(t)}{dt} + b \cdot \omega(t)

电磁转矩与电枢电流成正比:

Te(t)=Kt⋅ia(t)T_e(t) = K_t \cdot i_a(t)

整理得角加速度:

dω(t)dt=1J(Kt⋅ia(t)−b⋅ω(t)−TL(t))\frac{d\omega(t)}{dt} = \frac{1}{J} \left( K_t \cdot i_a(t) - b \cdot \omega(t) - T_L(t) \right)

转子位置动态

dθ(t)dt=ω(t)\frac{d\theta(t)}{dt} = \omega(t)

稳态解析解

稳态时(diadt=0\frac{di_a}{dt} = 0,dωdt=0\frac{d\omega}{dt} = 0),电机精确收敛到:

ωss=KtVa−RTLRb+KtKe,ia,ss=bVa+KeTLRb+KtKe,Te,ss=Ktia,ss\omega_{ss} = \frac{K_t V_a - R T_L}{R b + K_t K_e}, \quad i_{a,ss} = \frac{b V_a + K_e T_L}{R b + K_t K_e}, \quad T_{e,ss} = K_t i_{a,ss}

在国际单位制下,转矩常数与反电动势常数数值相等(Kt=KeK_t = K_e)。当 L≤10−6 HL \le 10^{-6}\text{ H} 或 dynamicsMode 设为 firstOrder 时,电气时间常数消失(τe→0\tau_e \to 0),系统平滑过渡到精确的指数型机械响应。

输入与输出

Direction ID Label 类型 Status
→ In voltage Voltage (Va) number Optional
→ In loadTorque Load Torque (TL) number Optional
→ In p + number Optional
→ In n - number Optional
→ In flange_a Shaft number Optional
→ In flange_b Case number Optional
→ In H H number Optional
← Out speed Speed (ω) number Output
← Out current Current (ia) number Output
← Out torque Torque (Te) number Output
← Out position Position (θ) number Output

参数

参数 Label 类型 默认值 描述
preset Motor Preset select custom Select a pre-calibrated physical motor model or configure custom parameters
dynamicsMode Model Dynamics select secondOrder Select dynamical model order and complexity
resistance Resistance (R) number 1 Armature winding resistance [Ω]
inductance Inductance (L) number 0.5 Armature winding inductance [H]
torqueConstant Torque Constant (Kt) number 0.1 Motor torque constant [N·m/A]
backEmfConstant Back-EMF Constant (Ke) number 0.1 Back-EMF constant [V/(rad/s)]
inertia Rotor Inertia (J) number 0.02 Rotor moment of inertia [kg·m²]
damping Viscous Friction (b) number 0.05 Viscous damping coefficient [N·m·s/rad]
brushDrop Brush Voltage Drop (Vbrush) number 0 Total contact voltage drop across carbon brushes [V]. Sets effective voltage to 0 when |Va| <= Vbrush.
currentLimit Current Limit (Imax) number 0 Armature peak current limit [A]. Clamps armature current to ±Imax. 0 = unlimited.
coulombFriction Coulomb Friction / Stiction (Tc) number 0 Breakaway Coulomb friction torque opposing motion [N·m]. Prevents rotation until net torque exceeds Tc.
initialSpeed Initial Speed (ω0) number 0 Initial angular velocity at t=0 [rad/s]
initialCurrent Initial Current (ia0) number 0 Initial armature current at t=0 [A]
initialPosition Initial Position (θ0) number 0 Initial rotor position at t=0 [rad]
coggingTorque Cogging Torque (Tcog) number 0 Peak reluctance cogging torque amplitude due to stator slotting [N·m]. 0 = neglected.
coggingSlots Cogging Slots / Poles number 12 Number of cogging torque periods per mechanical revolution.

使用示例

示例 1:转速阶跃响应与负载抑制

一台 12 V 永磁直流电机从静止空载加速,在 t=2.0 st = 2.0\text{ s} 时突加 0.5 N⋅m0.5\text{ N}\cdot\text{m} 的负载转矩。使用默认参数(R=1.0 Ω,L=0.5 H,Kt=0.1 N⋅m/A,Ke=0.1 V/(rad/s),J=0.02 kg⋅m2,b=0.05 N⋅m⋅s/radR = 1.0\ \Omega, L = 0.5\text{ H}, K_t = 0.1\text{ N}\cdot\text{m/A}, K_e = 0.1\text{ V}/(\text{rad/s}), J = 0.02\text{ kg}\cdot\text{m}^2, b = 0.05\text{ N}\cdot\text{m}\cdot\text{s/rad}),开环电机平稳加速到稳态转速 ωss=20.0 rad/s\omega_{ss} = 20.0\text{ rad/s}(191 rpm191\text{ rpm}),电枢电流为 10.0 A10.0\text{ A}。负载接入后,转速降至 11.67 rad/s11.67\text{ rad/s},电流升至 10.83 A10.83\text{ A}。

示例 2:闭环 PID 位置控制

将 thirdOrder 模式的 DCMotor 模块与 PIDController 相连进行角位置调节。用方波设定值(θref=±π rad\theta_{ref} = \pm \pi\text{ rad})减去位置输出 position(θ\theta)后送入控制器。将 PID 参数整定为 Kp=15.0,Ki=2.0,Kd=1.2K_p = 15.0, K_i = 2.0, K_d = 1.2,可在 0.35 s0.35\text{ s} 内实现快速、临界阻尼且无超调的定位。

说明与最佳实践

  • 数值稳定性与步长:默认参数给出条件良好的时间常数(τe=L/R=0.5 s\tau_e = L/R = 0.5\text{ s},τm=J/b=0.4 s\tau_m = J/b = 0.4\text{ s}),在默认步长 Δt=0.01 s\Delta t = 0.01\text{ s} 和四阶龙格-库塔积分下稳定。
  • 代数一阶回退:当 L≤10−6 HL \le 10^{-6}\text{ H} 时不再除以 LL,而是直接计算平衡电流 ia=(Va−Keω)/Ri_a = (V_a - K_e \omega) / R,避免显式求解器常见的刚性不稳定。
  • 端口灵活:loadTorque 输入未连接时默认为零,便于只用一个输入做转速实验。

常见工程问题解答 (FAQ)

Q: Why does my DC Motor simulation oscillate or become unstable with very small inductance L?

When the electrical time constant τe=L/R\tau_e = L / R is significantly smaller than the simulation step size (Δt=0.01 s\Delta t = 0.01\text{ s}), the differential equation for armature current becomes numerically stiff. If you wish to neglect inductance without changing the simulation step size, select 1st Order in the dynamicsMode dropdown or set L=0L = 0. The block will automatically switch to an exact algebraic calculation of armature current ia=(Va−Keω)/Ri_a = (V_a - K_e \omega) / R, guaranteeing numerical stability.

相关模块