Opened 18 years ago
Last modified 12 years ago
#108 closed defect
OMC crashes when plotting — at Initial Version
Reported by: | miguel.prada.sarasola | Owned by: | miguel.prada.sarasola |
---|---|---|---|
Priority: | critical | Milestone: | |
Component: | OMNotebook | Version: | |
Keywords: | Cc: | miguel.prada.sarasola, Adrian Pop |
Description
{{{package MediaPath
package Interfaces
connector PaperCut
Modelica.SIunits.Position pos;
flow Modelica.SIunits.Force F;
end PaperCut;
partial model Paper
PaperCut cut_a,cut_b;
Modelica.SIunits.Force F;
Modelica.SIunits.Length pos_rel;
equation
pos_rel=cut_a.pos - cut_b.pos;
cut_a.F=F;
cut_b.F=-F;
end Paper;
partial model Roller
extends Modelica.Mechanics.Rotational.Interfaces.Rigid(phi(start=0));
parameter Modelica.SIunits.Inertia J=1;
parameter Modelica.SIunits.Radius r=1;
Modelica.SIunits.AngularVelocity w(start=0);
Modelica.SIunits.AngularAcceleration a;
Modelica.SIunits.Position tanPos;
Modelica.SIunits.Velocity tanVel;
equation
w=der(phi);
a=der(w);
tanPos=phi*r;
tanVel=w*r;
end Roller;
end Interfaces;
model DriveRoller
extends Interfaces.Roller;
Interfaces.PaperCut cut_a,cut_b;
equation
cut_a.pos=phi*r;
cut_b.pos=phi*r;
J*a=flange_a.tau + flange_b.tau + cut_a.F*r + cut_b.F*r;
end DriveRoller;
model PaperRoll
extends Interfaces.Roller;
Interfaces.PaperCut cut_b;
equation
cut_b.pos=phi*r;
J*a=flange_a.tau + flange_b.tau + cut_b.F*r;
end PaperRoll;
model Cardboard
extends Interfaces.Paper;
equation
pos_rel=0;
end Cardboard;
model RealPaper
extends Interfaces.Paper;
parameter Real k=1;
equation
F=if pos_rel > 0 then 0 else pos_rel*k;
end RealPaper;
end MediaPath;
package Control
block PID
extends Modelica.Blocks.Interfaces.SISO;
parameter Real Kp=1,Kd=1;
Modelica.Blocks.Math.Gain proportional(k=Kp),derivative(k=Kd);
Modelica.Blocks.Continuous.Der derivator;
Modelica.Blocks.Math.Add sum;
equation
connect(u,derivator.u);
connect(u,proportional.u);
connect(derivator.y,derivative.u);
connect(proportional.y,sum.u1);
connect(derivative.y,sum.u2);
connect(sum.y,y);
end PID;
block DiscretePID
extends Modelica.Blocks.Interfaces.DiscreteSISO;
parameter Real Kp=1,Kd=1;
Real verr;
equation
verr=der(u);
when {sampleTrigger,initial()} then
y=(Kp*u + Kd*verr)/128;
end when;
end DiscretePID;
model PWMGenerator
Modelica.Blocks.Interfaces.RealInput u;
Modelica.Electrical.Analog.Interfaces.Pin p,n;
parameter Real gain=1;
equation
p.v - n.v=u*gain;
p.i + n.i=0;
end PWMGenerator;
model PWMSaturation
Modelica.Blocks.Interfaces.RealInput u;
Modelica.Electrical.Analog.Interfaces.Pin p,n;
parameter Real gain=1;
parameter Real saturation=42;
equation
p.v - n.v=if u*gain > saturation then saturation else if u*gain < -saturation then -saturation else u*gain;
p.i + n.i=0;
end PWMSaturation;
model LowPassFilter
parameter Real T=1;
Modelica.Blocks.Interfaces.RealInput u;
Modelica.Blocks.Interfaces.RealOutput y;
equation
T*der(y) + y=u;
end LowPassFilter;
model Servo
parameter Real KP=1800,KD=6000;
parameter Real MotorJ=0.0001,MotorTorqueK=0.078,MotorResistance=7.1,MotorInductance=0.1;
Modelica.Mechanics.Rotational.Interfaces.Flange_b flange_b;
Modelica.Blocks.Interfaces.RealInput u;
Modelica.Blocks.Math.Add comparator(k2=-1);
PID pid(Kp=KP,Kd=KD);
PWMSaturation pwm;
Modelica.Electrical.Analog.Basic.Ground ground;
DCMotor motor(load.J=MotorJ,emf1.k=MotorTorqueK,r1.R=MotorResistance,i1.L=MotorInductance);
Modelica.Mechanics.Rotational.Sensors.AngleSensor encoder;
equation
connect(u,comparator.u1);
connect(comparator.y,pid.u);
connect(pid.y,pwm.u);
connect(pwm.p,motor.p);
connect(pwm.n,motor.n);
connect(motor.n,ground.p);
connect(motor.flange_b,encoder.flange_a);
connect(encoder.phi,comparator.u2);
connect(motor.flange_b,flange_b);
end Servo;
model ServoWithIdealGear
parameter Real KP=1800,KD=6000;
parameter Real MotorJ=0.0001,MotorTorqueK=0.078,MotorResistance=7.1,MotorInductance=0.1;
parameter Real GearRatio=40;
Modelica.Mechanics.Rotational.Interfaces.Flange_b flange_b;
Modelica.Blocks.Interfaces.RealInput u;
Modelica.Blocks.Math.Add comparator(k2=-1);
PID pid(Kp=KP,Kd=KD);
PWMSaturation pwm;
Modelica.Electrical.Analog.Basic.Ground ground;
DCMotor motor(load.J=MotorJ,emf1.k=MotorTorqueK,r1.R=MotorResistance,i1.L=MotorInductance);
Modelica.Mechanics.Rotational.IdealGear gear(ratio=GearRatio);
Modelica.Mechanics.Rotational.Sensors.AngleSensor encoder;
equation
connect(u,comparator.u1);
connect(comparator.y,pid.u);
connect(pid.y,pwm.u);
connect(pwm.p,motor.p);
connect(pwm.n,motor.n);
connect(motor.n,ground.p);
connect(motor.flange_b,gear.flange_a);
connect(gear.flange_b,encoder.flange_a);
connect(encoder.phi,comparator.u2);
connect(gear.flange_b,flange_b);
end ServoWithIdealGear;
model ServoWithGear
parameter Real KP=1800,KD=6000;
parameter Real MotorJ=0.0001,MotorTorqueK=0.078,MotorResistance=7.1,MotorInductance=0.1;
parameter Real GearRatio=40;
parameter Real BacklashAmplitude=0.01,BacklashDamping=10;
Modelica.Mechanics.Rotational.Interfaces.Flange_b flange_b;
Modelica.Blocks.Interfaces.RealInput u;
Modelica.Blocks.Math.Add comparator(k2=-1);
PID pid(Kp=KP,Kd=KD);
PWMSaturation pwm;
Modelica.Electrical.Analog.Basic.Ground ground;
DCMotor motor(load.J=MotorJ,emf1.k=MotorTorqueK,r1.R=MotorResistance,i1.L=MotorInductance);
Modelica.Mechanics.Rotational.IdealGear gear(ratio=GearRatio);
Modelica.Mechanics.Rotational.ElastoBacklash backlash(b=BacklashAmplitude,d=BacklashDamping);
Modelica.Mechanics.Rotational.Sensors.AngleSensor encoder;
equation
connect(u,comparator.u1);
connect(comparator.y,pid.u);
connect(pid.y,pwm.u);
connect(pwm.p,motor.p);
connect(pwm.n,motor.n);
connect(motor.n,ground.p);
connect(motor.flange_b,gear.flange_a);
connect(gear.flange_b,backlash.flange_a);
connect(backlash.flange_b,encoder.flange_a);
connect(encoder.phi,comparator.u2);
connect(backlash.flange_b,flange_b);
end ServoWithGear;
model DiscreteServoWithGear
parameter Real KP=1800,KD=6000;
parameter Real MotorJ=0.0001,MotorTorqueK=0.078,MotorResistance=7.1,MotorInductance=0.1;
parameter Real GearRatio=40;
parameter Real BacklashAmplitude=0.01,BacklashDamping=10;
parameter Real SamplerPeriod=0.0012;
Modelica.Mechanics.Rotational.Interfaces.Flange_b flange_b;
Modelica.Blocks.Interfaces.RealInput u;
Modelica.Blocks.Math.Add comparator(k2=-1);
DiscretePID pid(Kp=KP,Kd=KD,samplePeriod=SamplerPeriod);
PWMSaturation pwm;
Modelica.Electrical.Analog.Basic.Ground ground;
DCMotor motor(load.J=MotorJ,emf1.k=MotorTorqueK,r1.R=MotorResistance,i1.L=MotorInductance);
Modelica.Mechanics.Rotational.IdealGear gear(ratio=GearRatio);
Modelica.Mechanics.Rotational.ElastoBacklash backlash(b=BacklashAmplitude,d=BacklashDamping);
Modelica.Mechanics.Rotational.Sensors.AngleSensor encoder;
equation
connect(u,comparator.u1);
connect(comparator.y,pid.u);
connect(pid.y,pwm.u);
connect(pwm.p,motor.p);
connect(pwm.n,motor.n);
connect(motor.n,ground.p);
connect(motor.flange_b,gear.flange_a);
connect(gear.flange_b,backlash.flange_a);
connect(backlash.flange_b,encoder.flange_a);
connect(encoder.phi,comparator.u2);
connect(backlash.flange_b,flange_b);
end DiscreteServoWithGear;
model ServoWithFilter
parameter Real KP=1800,KD=6000;
parameter Real MotorJ=0.0001,MotorTorqueK=0.078,MotorResistance=7.1,MotorInductance=0.1;
Modelica.Mechanics.Rotational.Interfaces.Flange_b flange_b;
Modelica.Blocks.Interfaces.RealInput u;
Modelica.Blocks.Math.Add comparator(k2=-1);
PID pid(Kp=KP,Kd=KD);
LowPassFilter filter;
PWMSaturation pwm;
Modelica.Electrical.Analog.Basic.Ground ground;
DCMotor motor(load.J=MotorJ,emf1.k=MotorTorqueK,r1.R=MotorResistance,i1.L=MotorInductance);
Modelica.Mechanics.Rotational.Sensors.AngleSensor encoder;
equation
connect(u,comparator.u1);
connect(comparator.y,pid.u);
connect(pid.y,filter.u);
connect(filter.y,pwm.u);
connect(pwm.p,motor.p);
connect(pwm.n,motor.n);
connect(motor.n,ground.p);
connect(motor.flange_b,encoder.flange_a);
connect(encoder.phi,comparator.u2);
connect(motor.flange_b,flange_b);
end ServoWithFilter;
model SpeedTrapezium
import SI = Modelica.SIunits;
extends Modelica.Blocks.Interfaces.SO;
parameter Real acc=1,dec=1;
parameter SI.Length adv=1;
parameter SI.Velocity vel=1;
parameter SI.Time startTime=0;
SI.Time tAcc,tSlew,tDec;
equation
tAcc=vel/acc;
tDec=vel/dec;
tSlew=if ((tAcc + tDec)*vel)/2 >= adv then 0 else (adv - ((tAcc + tDec)*vel)/2)/vel;
y=if time <= startTime then 0 else if time <= startTime + tAcc then (time - startTime)*acc else if time <= startTime + tAcc + tSlew then vel else if time <= startTime + tAcc + tSlew + tDec then vel - (time - startTime - tAcc + tSlew)*dec else 0;
end SpeedTrapezium;
end Control;
model DCMotor
Modelica.Electrical.Analog.Interfaces.Pin p,n;
Modelica.Mechanics.Rotational.Interfaces.Flange_b flange_b;
Modelica.Electrical.Analog.Basic.Resistor r1(R=10);
Modelica.Electrical.Analog.Basic.Inductor i1;
Modelica.Electrical.Analog.Basic.EMF emf1;
Modelica.Mechanics.Rotational.Inertia load;
equation
connect(p,r1.p);
connect(r1.n,i1.p);
connect(i1.n,emf1.p);
connect(emf1.n,n);
connect(emf1.flange_b,load.flange_a);
connect(load.flange_b,flange_b);
end DCMotor;
model Test1
Control.SpeedTrapezium trapezium(adv=0.1016,vel=0.100228);
Control.DiscreteServoWithGear servo(KD=1000);
MediaPath.DriveRoller driveRoller(J=0.00365);
equation
connect(trapezium.y,servo.u);
connect(servo.flange_b,driveRoller.flange_a);
end Test1;}}}