Package ptolemy.actor

Examples of ptolemy.actor.TypedCompositeActor


import ptolemy.kernel.util.NamedObj;
import ptolemy.kernel.util.Workspace;

public class TutorialApplet2 extends PtolemyApplet {
    public NamedObj _createModel(Workspace workspace) throws Exception {
        TypedCompositeActor toplevel = new TypedCompositeActor(workspace);

        // Create the director.
        DEDirector director = new DEDirector(toplevel, "director");
        director.stopTime.setExpression("10.0");

        // Create two actors.
        Clock clock = new Clock(toplevel, "clock");
        TimedPlotter plotter = new TimedPlotter(toplevel, "plotter");

        // Connect them.
        toplevel.connect(clock.output, plotter.input);
        return toplevel;
    }
View Full Code Here


                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(
View Full Code Here

                    // requests, but more importantly, we need to execute
                    // any change requests that may have been queued
                    // during cloning. The following call does that.
                    newModel.setDeferringChangeRequests(false);
                } else {
                    newModel = new TypedCompositeActor(new Workspace());
                }

                // The model should have a parser associated with it
                // so that undo works.
                // Checking to see if there already is a _parser attribute
View Full Code Here

        // FIXME: It is inefficient to calculate and set the inside DT
        // director's period value at every call to this function
        Token periodToken;
        double periodValue = 0.0;
        Director outsideDirector;
        TypedCompositeActor container = (TypedCompositeActor) getContainer();
        boolean shouldUpdatePeriod = false;

        outsideDirector = _getOutsideDirector();

        if (outsideDirector instanceof DTDirector) {
View Full Code Here

     *   output port.
     *  @param port The port to transfer tokens from.
     *  @return True if data are transferred.
     */
    public boolean transferOutputs(IOPort port) throws IllegalActionException {
        TypedCompositeActor container = (TypedCompositeActor) getContainer();
        Boolean flag = (Boolean) _shouldTransferOutputs.get(port);

        if (_shouldDoInternalTransferOutputs && flag.booleanValue()) {
            if (container.getExecutiveDirector() instanceof DTDirector) {
                // If we have dt inside dt, then transfer all of the
                // tokens that were created.  The containing director
                // will figure out what time they should appear.
                return super.transferOutputs(port);
            } else {
View Full Code Here

     *  that are completing invocation at the end of this cycle.
     *  @exception IllegalActionException If this director does not have a
     *   container.
     */
    public void fire() throws IllegalActionException {
        TypedCompositeActor container = (TypedCompositeActor) getContainer();

        if (container == null) {
            throw new IllegalActionException(this, "Has no container!");
        }

View Full Code Here

    /** Build the internal cache of all the ports directed by this director
     *
     *  @exception IllegalActionException If methods called throw it.
     */
    private void _buildOutputPortTable() throws IllegalActionException {
        TypedCompositeActor container = (TypedCompositeActor) getContainer();

        _shouldTransferOutputs = new HashMap();

        Iterator outports = container.outputPortList().iterator();

        while (outports.hasNext()) {
            IOPort port = (IOPort) outports.next();

            _shouldTransferOutputs.put(port, Boolean.TRUE);
View Full Code Here

     *
     *  @exception IllegalActionException If methods called throw it.
     */
    private final void _checkValidTimeIntervals() throws IllegalActionException {
        //  -checkValidTimeIntervals-
        TypedCompositeActor container = (TypedCompositeActor) getContainer();
        Director outsideDirector = _getOutsideDirector();
        _debug("shouldIgnoreFire subroutine called");

        // No need to check if this director is in the top level.
        if (outsideDirector == null) {
            _formerValidTimeFired = getModelTime();
            return;
        }

        // No need to check if the executive director is also a DTDirector
        if (outsideDirector instanceof DTDirector) {
            _formerValidTimeFired = getModelTime();
            return;
        }

        Time currentTime = outsideDirector.getModelTime();
        Time currentPeriod = new Time(this, getPeriod());
        Time timeElapsed = currentTime.subtract(_formerValidTimeFired);

        _debug("DT Director just started fire----------------"
                + _formerValidTimeFired + " " + currentTime);

        if ((currentTime.getDoubleValue() != 0) && (!_inputTokensAvailable)
                && (currentTime.compareTo(_formerTimeFired) == 0)) {
            //  duplicate firings at the same time should be ignored
            //  unless there are input tokens
            _debug("duplicate firing");
            _isFiringAllowed = false;
            _shouldDoInternalTransferOutputs = false;
            _makeTokensUnavailable();
            return;
        } else {
            _formerTimeFired = currentTime;
        }

        // this occurs during startup
        if (currentTime.getDoubleValue() == 0) {
            _debug("first firing");
            _shouldDoInternalTransferOutputs = true;
            _formerValidTimeFired = currentTime;
            _issuePseudoFire(currentTime);
            _isFiringAllowed = true;
            return;
        }

        Time timeRemaining = currentPeriod.subtract(timeElapsed);
        _debug("timeElapsed = " + timeElapsed);
        _debug("timeRemaining = " + timeRemaining);
        _debug("tolerance = " + _TOLERANCE);

        if (timeRemaining.getDoubleValue() < 0) {
            // this case should not occur
            _debug("InternalErrorException time: " + _formerValidTimeFired
                    + " " + currentTime);
            throw new InternalErrorException("unexpected time rollback");
        }

        if ((timeRemaining.getDoubleValue() > 0)
                && (timeElapsed.getDoubleValue() > 0)) {
            Iterator outputPorts = container.outputPortList().iterator();
            _isFiringAllowed = false;

            while (outputPorts.hasNext()) {
                Receiver[][] insideReceivers;
                TypedIOPort port = (TypedIOPort) outputPorts.next();
View Full Code Here

     *  holds this director.  If this director is inside a toplevel
     *  container, then the returned value is null.
     *  @return The executive director
     */
    private Director _getOutsideDirector() {
        TypedCompositeActor container = (TypedCompositeActor) getContainer();
        Director outsideDirector = container.getExecutiveDirector();

        return outsideDirector;
    }
View Full Code Here

     @param time The time when this director's container should be fired
     *  @exception IllegalActionException If getting the container or
     *  executive director fails
     */
    private void _requestRefireAt(Time time) throws IllegalActionException {
        TypedCompositeActor container = (TypedCompositeActor) getContainer();
        Director outsideDirector = container.getExecutiveDirector();

        if (outsideDirector != null) {
            outsideDirector.fireAt(container, time);
        }
    }
View Full Code Here

TOP

Related Classes of ptolemy.actor.TypedCompositeActor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.