modelSecondOrderSystem"A second order rotational system"typeAngle=Real(unit="rad");typeAngularVelocity=Real(unit="rad/s");typeInertia=Real(unit="kg.m2");typeStiffness=Real(unit="N.m/rad");typeDamping=Real(unit="N.m.s/rad");parameterInertiaJ1=0.4"Moment of inertia for inertia 1";parameterInertiaJ2=1.0"Moment of inertia for inertia 2";parameterStiffnessc1=11"Spring constant for spring 1";parameterStiffnessc2=5"Spring constant for spring 2";parameterDampingd1=0.2"Damping for damper 1";parameterDampingd2=1.0"Damping for damper 2";Anglephi1"Angle for inertia 1";Anglephi2"Angle for inertia 2";AngularVelocityomega1"Velocity of inertia 1";AngularVelocityomega2"Velocity of inertia 2";initialequationphi1=0;phi2=1;omega1=0;omega2=0;equation// Equations for inertia 1omega1=der(phi1);J1*der(omega1)=c1*(phi2-phi1)+d1*der(phi2-phi1);// Equations for inertia 2omega2=der(phi2);J2*der(omega2)=c1*(phi1-phi2)+d1*der(phi1-phi2)-c2*phi2-d2*der(phi2);endSecondOrderSystem;
modelSampleAndHold"Measure speed and hold"extendsBasicEquations.RotationalSMD.SecondOrderSystem;parameterRealsample_time(unit="s")=0.125;discreteRealomega1_measured;equationwhensample(0,sample_time)thenomega1_measured=omega1;endwhen;endSampleAndHold;
modelIntervalMeasure"Measure interval between teeth"extendsBasicEquations.RotationalSMD.SecondOrderSystem;parameterIntegerteeth=200;parameterRealtooth_angle(unit="rad")=2*3.14159/teeth;Realnext_phi,prev_phi;Reallast_time;Realomega1_measured;initialequationnext_phi=phi1+tooth_angle;prev_phi=phi1-tooth_angle;last_time=time;equationwhen{phi1>=pre(next_phi),phi1<=pre(prev_phi)}thenomega1_measured=tooth_angle/(time-pre(last_time));next_phi=phi1+tooth_angle;prev_phi=phi1-tooth_angle;last_time=time;endwhen;endIntervalMeasure;
modelCounter"Count teeth in a given interval"extendsBasicEquations.RotationalSMD.SecondOrderSystem;parameterRealsample_time(unit="s")=0.125;parameterIntegerteeth=200;parameterRealtooth_angle(unit="rad")=2*3.14159/teeth;Realnext_phi,prev_phi;Integercount;Realomega1_measured;initialequationnext_phi=phi1+tooth_angle;prev_phi=phi1-tooth_angle;count=0;equationwhen{phi1>=pre(next_phi),phi1<=pre(prev_phi)}thennext_phi=phi1+tooth_angle;prev_phi=phi1-tooth_angle;count=pre(count)+1;endwhen;whensample(0,sample_time)thenomega1_measured=pre(count)*tooth_angle/sample_time;count=0"Another equation for count?";endwhen;endCounter;
modelCounterWithAlgorithm"Count teeth in a given interval using an algorithm"extendsBasicEquations.RotationalSMD.SecondOrderSystem;parameterRealsample_time(unit="s")=0.125;parameterIntegerteeth=200;parameterRealtooth_angle(unit="rad")=2*3.14159/teeth;Realnext_phi,prev_phi;Integercount;Realomega1_measured;initialequationnext_phi=phi1+tooth_angle;prev_phi=phi1-tooth_angle;count=0;algorithmwhen{phi1>=pre(next_phi),phi1<=pre(prev_phi)}thennext_phi:=phi1+tooth_angle;prev_phi:=phi1-tooth_angle;count:=pre(count)+1;endwhen;whensample(0,sample_time)thenomega1_measured:=pre(count)*tooth_angle/sample_time;count:=0;endwhen;endCounterWithAlgorithm;