/**
   * Initialize particle filter parameters.
   *
   * @exception IllegalActionException
   * @exception NameDuplicationException
   */
  private void _init() throws IllegalActionException, NameDuplicationException {

    StringToken[] stateNames = new StringToken[2];
    stateNames[0] = new StringToken("x");
    stateNames[1] = new StringToken("y");
    stateVariableNames.setToken(new ArrayToken(BaseType.STRING, stateNames));
    stateVariableNames.setVisibility(Settable.EXPERT);

    observerPosition = new PortParameter(this, "observerPosition");
    observerPosition.setExpression("{0.0,0.0}");
    SingletonParameter showName =
        (SingletonParameter) observerPosition.getPort().getAttribute("_showName");
    if (showName == null) {
      showName = new SingletonParameter(observerPosition.getPort(), "_showName");
      showName.setToken("true");
    } else {
      showName.setToken("true");
    }

    // The input port for range measurements.
    z_m = new TypedIOPort(this, "z_m", true, false);
    z_m.setTypeEquals(BaseType.DOUBLE);
    showName = (SingletonParameter) z_m.getAttribute("_showName");
    z_m.setDisplayName("rangeMeasurement");
    if (showName == null) {
      showName = new SingletonParameter(z_m, "_showName");
      showName.setToken("true");
    } else {
      showName.setToken("true");
    }

    // The parameter that contains the measurement expression.
    z = new Parameter(this, "z");
    z.setExpression("sqrt((x-observerPosition(0))^2 + (y-observerPosition(1))^2)");
    z.setVisibility(Settable.EXPERT);

    x_update = new Parameter(this, "x_update");
    x_update.setExpression("x");

    y_update = new Parameter(this, "y_update");
    y_update.setExpression("y");

    measurementCovariance.setExpression("[2.0]");
    prior.setExpression("{random()*200-100,random()*200-100}");

    processNoise.setExpression("multivariateGaussian({0.0,0.0},[3.0,0.0;0.0,3.0])");

    particleCount.setExpression("2000");

    bootstrap.setVisibility(Settable.EXPERT);
    lowVarianceSampler.setVisibility(Settable.EXPERT);
  }
Ejemplo n.º 2
0
  /**
   * Override the base class to set type constraints between the output ports and parameters of this
   * actor whose name matches the output port. If there is no such parameter, then create an
   * instance of Variable with a matching name and set up the type constraints to that instance. The
   * type of the output port is constrained to be at least that of the parameter or variable.
   *
   * @exception IllegalActionException If there is no director, or if the director's preinitialize()
   *     method throws it, or if this actor is not opaque.
   */
  public void preinitialize() throws IllegalActionException {
    super.preinitialize();

    Iterator ports = outputPortList().iterator();

    while (ports.hasNext()) {
      TypedIOPort port = (TypedIOPort) ports.next();

      // Ensure that the production rate is one.
      // FIXME: This may not be right if there is no
      // actual source of data for this port (e.g. no
      // SetVariable actor).
      Variable rate = (Variable) port.getAttribute("tokenProductionRate");

      if (rate == null) {
        try {
          rate = new Variable(port, "tokenProductionRate");
        } catch (NameDuplicationException e) {
          throw new InternalErrorException(e);
        }
      }

      rate.setToken(new IntToken(1));

      String portName = port.getName();
      Attribute attribute = getAttribute(portName);

      if (attribute == null) {
        try {
          workspace().getWriteAccess();
          attribute = new Variable(this, portName);
        } catch (NameDuplicationException ex) {
          throw new InternalErrorException(ex);
        } finally {
          workspace().doneWriting();
        }
      }

      // attribute is now assured to be non-null.
      if (attribute instanceof Variable) {
        port.setTypeAtLeast((Variable) attribute);
      } else {
        // Assume the port type must be a string.
        port.setTypeEquals(BaseType.STRING);
      }
    }
  }