# 机械示例¶

$J \dot{\omega} = \sum_i \tau_i$

$\tau = k \Delta \varphi$

$\tau = d \Delta \dot{\varphi}$

$\begin{split}\omega_1 &= \dot{\varphi}_1 \\ J_1 \dot{\omega}_1 &= k_1 (\varphi_2-\varphi_1) + d_1 \frac{\mathrm{d} (\varphi_2-\varphi_1)}{\mathrm{d}t} \\ \omega_2 &= \dot{\varphi}_2 \\ J_2 \dot{\omega}_2 &= k_1 (\varphi_1-\varphi_2) + d_1 \frac{\mathrm{d} (\varphi_1-\varphi_2)}{\mathrm{d}t} - k_2 \varphi_2 - d_2 \dot{\varphi}_2\end{split}$

$\begin{split}\varphi_1 &= 0 \\ \omega_1 &= 0 \\ \varphi_2 &= 1 \\ \omega_2 &= 0\end{split}$

model SecondOrderSystem "A second order rotational system"
type Inertia=Real(unit="kg.m2");
parameter Inertia J1=0.4 "Moment of inertia for inertia 1";
parameter Inertia J2=1.0 "Moment of inertia for inertia 2";
parameter Stiffness k1=11 "Spring constant for spring 1";
parameter Stiffness k2=5 "Spring constant for spring 2";
parameter Damping d1=0.2 "Damping for damper 1";
parameter Damping d2=1.0 "Damping for damper 2";
Angle phi1 "Angle for inertia 1";
Angle phi2 "Angle for inertia 2";
AngularVelocity omega1 "Velocity of inertia 1";
AngularVelocity omega2 "Velocity of inertia 2";
initial equation
phi1 = 0;
phi2 = 1;
omega1 = 0;
omega2 = 0;
equation
// Equations for inertia 1
omega1 = der(phi1);
J1*der(omega1) = k1*(phi2-phi1)+d1*der(phi2-phi1);
// Equations for inertia 2
omega2 = der(phi2);
J2*der(omega2) = k1*(phi1-phi2)+d1*der(phi1-phi2)-k2*phi2-d2*der(phi2);
end SecondOrderSystem;


model SecondOrderSystem "A second order rotational system"


  type Angle=Real(unit="rad");
type Inertia=Real(unit="kg.m2");


  parameter Inertia J1=0.4 "Moment of inertia for inertia 1";
parameter Inertia J2=1.0 "Moment of inertia for inertia 2";
parameter Stiffness k1=11 "Spring constant for spring 1";
parameter Stiffness k2=5 "Spring constant for spring 2";
parameter Damping d1=0.2 "Damping for damper 1";
parameter Damping d2=1.0 "Damping for damper 2";


  Angle phi1 "Angle for inertia 1";
Angle phi2 "Angle for inertia 2";
AngularVelocity omega1 "Velocity of inertia 1";
AngularVelocity omega2 "Velocity of inertia 2";


initial equation
phi1 = 0;
phi2 = 1;
omega1 = 0;
omega2 = 0;


equation
// Equations for inertia 1
omega1 = der(phi1);
J1*der(omega1) = k1*(phi2-phi1)+d1*der(phi2-phi1);
// Equations for inertia 2
omega2 = der(phi2);
J2*der(omega2) = k1*(phi1-phi2)+d1*der(phi1-phi2)-k2*phi2-d2*der(phi2);


end SecondOrderSystem;


model SecondOrderSystemInitParams
"A second order rotational system with initialization parameters"
type Inertia=Real(unit="kg.m2");
parameter Angle phi1_init = 0;
parameter Angle phi2_init = 1;
parameter AngularVelocity omega1_init = 0;
parameter AngularVelocity omega2_init = 0;
parameter Inertia J1=0.4 "Moment of inertia for inertia 1";
parameter Inertia J2=1.0 "Moment of inertia for inertia 2";
parameter Stiffness k1=11 "Spring constant for spring 1";
parameter Stiffness k2=5 "Spring constant for spring 2";
parameter Damping d1=0.2 "Damping for damper 1";
parameter Damping d2=1.0 "Damping for damper 2";
Angle phi1 "Angle for inertia 1";
Angle phi2 "Angle for inertia 2";
AngularVelocity omega1 "Velocity of inertia 1";
AngularVelocity omega2 "Velocity of inertia 2";
initial equation
phi1 = phi1_init;
phi2 = phi2_init;
omega1 = omega1_init;
omega2 = omega2_init;
equation
omega1 = der(phi1);
omega2 = der(phi2);
J1*der(omega1) = k1*(phi2-phi1)+d1*der(phi2-phi1);
J2*der(omega2) = k1*(phi1-phi2)+d1*der(phi1-phi2)-k2*phi2-d2*der(phi2);
end SecondOrderSystemInitParams;