new DoubleToken(0.02));
feedbackGain = new Parameter(this, "feedbackGain", new DoubleToken(
-20.0));
// CT subsystem
TypedCompositeActor ctsub = new TypedCompositeActor(this, "CTSubsystem");
Parameter ctSamplePeriod = new Parameter(ctsub, "samplePeriod");
ctSamplePeriod.setExpression("samplePeriod");
Parameter ctFeedbackGain = new Parameter(ctsub, "feedbackGain");
ctFeedbackGain.setExpression("feedbackGain");
TypedIOPort subin = new TypedIOPort(ctsub, "Pin");
subin.setInput(true);
TypedIOPort subout = new TypedIOPort(ctsub, "Pout");
subout.setOutput(true);
CTMixedSignalDirector ctdir = new CTMixedSignalDirector(ctsub,
"CTEmbDir");
//ctdir.addDebugListener(new StreamListener());
// ---------------------------------
// Create the actors.
// ---------------------------------
// CTActors
CurrentTime time = new CurrentTime(ctsub, "CurTime");
TrigFunction trigFunction = new TrigFunction(ctsub, "TrigFunction");
ZeroOrderHold hold = new ZeroOrderHold(ctsub, "Hold");
AddSubtract add1 = new AddSubtract(ctsub, "Add1");
Integrator intgl1 = new Integrator(ctsub, "Integrator1");
Integrator intgl2 = new Integrator(ctsub, "Integrator2");
Scale scale0 = new Scale(ctsub, "Scale0");
Scale scale1 = new Scale(ctsub, "Scale1");
Scale scale2 = new Scale(ctsub, "Scale2");
Scale scale3 = new Scale(ctsub, "Scale3");
Scale scale4 = new Scale(ctsub, "Scale4");
scale4.factor.setExpression("feedbackGain");
TimedPlotter ctPlot = new TimedPlotter(ctsub, "CTPlot");
ctPlot.plot = new Plot();
ctPlot.plot.setGrid(true);
ctPlot.plot.setXRange(0.0, stopT);
ctPlot.plot.setYRange(-1.0, 1.0);
ctPlot.plot.setSize(500, 180);
ctPlot.plot.addLegend(0, "Position");
ctPlot.plot.addLegend(1, "Input");
ctPlot.plot.addLegend(2, "Control");
CTPeriodicSampler ctSampler = new CTPeriodicSampler(ctsub,
"PeriodicSampler");
ctSampler.samplePeriod.setExpression("samplePeriod");
// CT Connections
ctsub.connect(time.output, scale3.input);
ctsub.connect(scale3.output, trigFunction.input);
Relation cr0 = ctsub.connect(trigFunction.output, scale0.input, "CR0");
ctsub.connect(scale0.output, add1.plus, "CR1");
ctsub.connect(add1.output, intgl1.input, "CR2");
Relation cr3 = ctsub.connect(intgl1.output, intgl2.input, "CR3");
Relation cr4 = ctsub.connect(intgl2.output, ctPlot.input, "CR4");
scale1.input.link(cr3);
scale2.input.link(cr4);
ctSampler.input.link(cr4);
TypedIORelation cr5 = new TypedIORelation(ctsub, "CR5");
ctSampler.output.link(cr5);
subout.link(cr5);
ctsub.connect(scale1.output, add1.plus, "CR6");
ctsub.connect(scale2.output, add1.plus, "CR7");
ctsub.connect(scale4.output, add1.plus, "CR8");
TypedIORelation cr9 = new TypedIORelation(ctsub, "CR9");
hold.input.link(cr9);
subin.link(cr9);
Relation cr10 = ctsub.connect(hold.output, scale4.input, "CR10");
ctPlot.input.link(cr0);
ctPlot.input.link(cr10);
// DE System
ptolemy.domains.de.lib.TimedDelay delay = new ptolemy.domains.de.lib.TimedDelay(