public LevelCrossingDetector(CompositeEntity container, String name)
throws IllegalActionException, NameDuplicationException {
super(container, name);
output = new TypedIOPort(this, "output", false, true);
new Parameter(output, "signalType", new StringToken("DISCRETE"));
trigger = new TypedIOPort(this, "trigger", true, false);
trigger.setMultiport(false);
trigger.setTypeEquals(BaseType.DOUBLE);
new Parameter(trigger, "signalType", new StringToken("CONTINUOUS"));
level = new Parameter(this, "level", new DoubleToken(0.0));
level.setTypeEquals(BaseType.DOUBLE);
// By default, this director detects both directions of leve crossings.
direction = new StringParameter(this, "direction");
direction.setExpression("both");
_detectRisingCrossing = true;
_detectFallingCrossing = true;
direction.addChoice("both");
direction.addChoice("falling");
direction.addChoice("rising");
defaultEventValue = new Parameter(this, "defaultEventValue",
new DoubleToken(0.0));
// FIXME: If usingDefaultEventValue is false, the output
// type should be constrained to match the trigger input type.
output.setTypeAtLeast(defaultEventValue);
useDefaultEventValue = new Parameter(this, "useDefaultEventValue");
useDefaultEventValue.setTypeEquals(BaseType.BOOLEAN);
useDefaultEventValue.setToken(BooleanToken.FALSE);
_errorTolerance = 1e-4;
errorTolerance = new Parameter(this, "errorTolerance", new DoubleToken(
_errorTolerance));
errorTolerance.setTypeEquals(BaseType.DOUBLE);
}