# 基本旋转组件¶

## 组件模型¶

### 坐标系¶

$\omega = \dot{\varphi}$

$\alpha = \dot{\omega}$

$J \frac{\mathrm{d}\omega}{\mathrm{d}t} = \tau$

### 转动惯量元件¶

within ModelicaByExample.Components.Rotational.VerboseApproach;
model Inertia "Rotational inertia without inheritance"
parameter Modelica.SIunits.Inertia J;
Modelica.Mechanics.Rotational.Interfaces.Flange_a flange_a
annotation (Placement(transformation(extent={{-110,-10},{-90,10}})));
Modelica.Mechanics.Rotational.Interfaces.Flange_b flange_b
annotation (Placement(transformation(extent={{90,-10},{110,10}})));
protected
Modelica.SIunits.Angle phi_rel;
Modelica.SIunits.Torque tau;
Modelica.SIunits.AngularVelocity w;
equation
// Variables
phi_rel = flange_a.phi-flange_b.phi;
tau = flange_a.tau;
w = der(flange_a.phi);

// Conserviation of angular momentum (includes storage)
J*der(w) = flange_a.tau + flange_b.tau;

// Kinematic constraint (inertia is rigid)
phi_rel = 0;
annotation ( Icon(graphics={
extent={{-100,90},{100,50}},


Inertia模型包括两个“法兰”，两端各一个。这些法兰的意义是可以更清楚地从Inertia模型的图标看出：

  J*der(w) = flange_a.tau + flange_b.tau;


### 弹簧模型¶

within ModelicaByExample.Components.Rotational.VerboseApproach;
model Spring "Rotational spring without inheritance"
parameter Modelica.SIunits.RotationalSpringConstant c;
Modelica.Mechanics.Rotational.Interfaces.Flange_a flange_a
annotation (Placement(transformation(extent={{-110,-10},{-90,10}})));
Modelica.Mechanics.Rotational.Interfaces.Flange_b flange_b
annotation (Placement(transformation(extent={{90,-10},{110,10}})));
protected
Modelica.SIunits.Angle phi_rel;
Modelica.SIunits.Torque tau;
equation
// Variables
phi_rel = flange_a.phi-flange_b.phi;
tau = flange_a.tau;

// No storage of angular momentum
flange_a.tau + flange_b.tau = 0;

// Hooke's law
tau = c*phi_rel;
end Spring;


Inertia模型一样，Spring模型有两个连接器，一端各一个。模型还定义了许多相同的内部变量。最终，弹簧的行为可以总结为如下公式：

  // Hooke's law
tau = c*phi_rel;
end Spring;


### 阻尼器模型¶

Damper模型也和Spring模型非常相似。同样，主要区别是参数（这里是d），以及一个方程：

within ModelicaByExample.Components.Rotational.VerboseApproach;
model Damper "Rotational damper without inheritance"
parameter Modelica.SIunits.RotationalDampingConstant d;
Modelica.Mechanics.Rotational.Interfaces.Flange_a flange_a
annotation (Placement(transformation(extent={{-110,-10},{-90,10}})));
Modelica.Mechanics.Rotational.Interfaces.Flange_b flange_b
annotation (Placement(transformation(extent={{90,-10},{110,10}})));
protected
Modelica.SIunits.Angle phi_rel;
Modelica.SIunits.Torque tau;
equation
// Variables
phi_rel = flange_a.phi-flange_b.phi;
tau = flange_a.tau;

// No storage of angular momentum
flange_a.tau + flange_b.tau = 0;

// Damping relationship
tau = d*der(phi_rel);
end Damper;


Damper模型的图标如下所示：

## DRY组件模型¶

### 共同代码¶

within ModelicaByExample.Components.Rotational.Interfaces;
partial model TwoFlange
"Definition of a partial rotational component with two flanges"

Modelica.Mechanics.Rotational.Interfaces.Flange_a flange_a
annotation (Placement(transformation(extent={{-110,-10},{-90,10}})));
Modelica.Mechanics.Rotational.Interfaces.Flange_b flange_b
annotation (Placement(transformation(extent={{90,-10},{110,10}})));
protected
Modelica.SIunits.Angle phi_rel;
equation
phi_rel = flange_a.phi-flange_b.phi;
end TwoFlange;


within ModelicaByExample.Components.Rotational.Interfaces;
partial model Compliant "A compliant rotational component"
extends ModelicaByExample.Components.Rotational.Interfaces.TwoFlange;
protected
Modelica.SIunits.Torque tau;
equation
tau = flange_a.tau;
flange_a.tau + flange_b.tau = 0
"Conservation of angular momentum (no storage)";
end Compliant;


Compliant模型加上额外的内部变量（以代表从flange_a进入该组件然后传递到flange_b的转矩）。另外，模型也加入了方程，以表示组件不会存储任何角动量。

### 转动惯量元件¶

within ModelicaByExample.Components.Rotational.Components;
model Inertia "A rotational inertia model"
parameter Modelica.SIunits.Inertia J;
extends ModelicaByExample.Components.Rotational.Interfaces.TwoFlange;
Modelica.SIunits.AngularVelocity w "Angular Velocity"
annotation(Dialog(group="Initialization", showStartAttribute=true));
Modelica.SIunits.Angle phi "Angle"
annotation(Dialog(group="Initialization", showStartAttribute=true));
equation
phi = flange_a.phi;
w = der(flange_a.phi) "velocity of inertia";
phi_rel = 0 "inertia is rigid";
J*der(w) = flange_a.tau + flange_b.tau
"Conservation of angular momentum with storage";
end Inertia;


### 弹簧模型¶

within ModelicaByExample.Components.Rotational.Components;
model Spring "A rotational spring component"
parameter Modelica.SIunits.RotationalSpringConstant c;
extends ModelicaByExample.Components.Rotational.Interfaces.Compliant;
equation
tau = c*phi_rel "Hooke's Law";
end Spring;


### 阻尼器模型¶

within ModelicaByExample.Components.Rotational.Components;
model Damper "A rotational damper"
parameter Modelica.SIunits.RotationalDampingConstant d;
extends ModelicaByExample.Components.Rotational.Interfaces.Compliant;
equation
tau = d*der(phi_rel) "Damping relationship";
end Damper;


### 机械地面¶

within ModelicaByExample.Components.Rotational.Components;
model Damper "A rotational damper"
parameter Modelica.SIunits.RotationalDampingConstant d;
extends ModelicaByExample.Components.Rotational.Interfaces.Compliant;
equation
tau = d*der(phi_rel) "Damping relationship";
annotation (Icon(graphics={


### 双弹簧质量阻尼系统¶

within ModelicaByExample.Components.Rotational.Examples;
model SMD
Components.Ground ground annotation (Placement(transformation(
extent={{-10,-10},{10,10}},
rotation=90,
origin={76,0})));
Components.Damper damper2(d=1)
annotation (Placement(transformation(extent={{30,10},{50,30}})));
Components.Spring spring2(c=5)
annotation (Placement(transformation(extent={{28,-30},{48,-10}})));
Components.Inertia inertia2(
J=1,
phi(fixed=true, start=1),
w(fixed=true, start=0))
annotation (Placement(transformation(extent={{-10,-10},{10,10}})));
Components.Damper damper1(d=0.2)
annotation (Placement(transformation(extent={{-50,10},{-30,30}})));
Components.Spring spring1(c=11)
annotation (Placement(transformation(extent={{-50,-30},{-30,-10}})));
Components.Inertia inertia1(
J=0.4,
phi(fixed=true, start=0),
w(fixed=true, start=0))
annotation (Placement(transformation(extent={{-90,-10},{-70,10}})));
equation
connect(ground.flange_a, damper2.flange_b) annotation (Line(
points={{70,0},{66,0},{66,0},{60,0},{60,20},{50,20}},
color={0,0,0},
smooth=Smooth.None));

connect(ground.flange_a, spring2.flange_b) annotation (Line(
points={{70,0},{60,0},{60,-20},{48,-20}},
color={0,0,0},
smooth=Smooth.None));
connect(damper2.flange_a, inertia2.flange_b) annotation (Line(
points={{30,20},{20,20},{20,0},{10,0}},
color={0,0,0},
smooth=Smooth.None));
connect(spring2.flange_a, inertia2.flange_b) annotation (Line(
points={{28,-20},{20,-20},{20,0},{10,0}},
color={0,0,0},
smooth=Smooth.None));
connect(inertia2.flange_a, damper1.flange_b) annotation (Line(
points={{-10,0},{-20,0},{-20,20},{-30,20}},
color={0,0,0},
smooth=Smooth.None));
connect(inertia2.flange_a, spring1.flange_b) annotation (Line(
points={{-10,0},{-20,0},{-20,-20},{-30,-20}},
color={0,0,0},
smooth=Smooth.None));
connect(damper1.flange_a, inertia1.flange_b) annotation (Line(
points={{-50,20},{-60,20},{-60,0},{-70,0}},
color={0,0,0},
smooth=Smooth.None));
connect(spring1.flange_a, inertia1.flange_b) annotation (Line(
points={{-50,-20},{-60,-20},{-60,0},{-70,0}},
color={0,0,0},
smooth=Smooth.None));
end SMD;