DiscreteObserver.java

/*
 * $Id: DiscreteObserver.java,v 1.6 2008/07/16 04:58:04 koga Exp $
 *
 * Copyright (C) 2004 Koga Laboratory. All rights reserved.
 *
 */
package org.mklab.tool.control.system.controller;

import org.mklab.nfc.matrix.ComplexNumericalMatrix;
import org.mklab.nfc.matrix.RealNumericalMatrix;
import org.mklab.nfc.scalar.ComplexNumericalScalar;
import org.mklab.nfc.scalar.RealNumericalScalar;
import org.mklab.tool.control.LinearSystem;
import org.mklab.tool.control.system.LinearSystemOperator;
import org.mklab.tool.control.system.discrete.DiscreteLinearDynamicSystem;
import org.mklab.tool.control.system.parameter.Parameter;
import org.mklab.tool.control.system.parameter.ParameterUpdator;


/**
 * 離散時間オブザーバを表すクラスです。
 * 
 * @author koga
 * @version $Revision: 1.6 $, 2004/06/04
 * @param <RS> type of real scalar
 * @param <RM> type of real matrix
 * @param <CS> type of complex scalar
 * @param <CM> type of complex matrix
 */
public class DiscreteObserver<RS extends RealNumericalScalar<RS, RM, CS, CM>, RM extends RealNumericalMatrix<RS, RM, CS, CM>, CS extends ComplexNumericalScalar<RS, RM, CS, CM>, CM extends ComplexNumericalMatrix<RS, RM, CS, CM>> extends DiscreteLinearDynamicSystem<RS,RM,CS,CM> implements ParameterUpdator {

  /** 連続時間オブザーバーの極 */
  @Parameter(name = "continuousObserverPoles", description = "連続時間オブザーバーの極", update = true)
  private CM continuousObserverPoles;

  /** 離散時間オブザーバーの設計器 */
  private DiscreteObserverDesigner<RS,RM,CS,CM> designer;

  /**
   * コンストラクター
   * 
   * @param plant 状態推定の対象(連続時間線形システム)
   * @param sunit unit of scalar
   */
  public DiscreteObserver(final LinearSystemOperator<RS,RM,CS,CM> plant, RS sunit) {
    super(sunit);
    
    RS[][] rp = sunit.createArray(2,1);
    RS[][] ip = sunit.createArray(2,1);
    rp[0][0] = sunit.create(-1);
    rp[1][0] = sunit.create(-1);
    ip[0][0] = sunit.create(0);
    ip[1][0] = sunit.create(0);
    RM rr = sunit.createGrid(rp);
    RM ii = sunit.createGrid(ip);
    this.continuousObserverPoles = rr.createComplex(rr, ii);
    
    this.designer = new DiscreteObserverDesigner<>(plant);
  }

  /**
   * {@inheritDoc}
   */
  @Override
  public void setSamplingInterval(final RS samplingInterval) {
    super.setSamplingInterval(samplingInterval);
    this.designer.setSamplingInterval(samplingInterval);
    setObserverLinearSystem();
  }

  /**
   * 連続時間オブザーバーの極を設定します。
   * 
   * @param continuousObserverPoles 連続時間オブザーバーの極
   */
  public void setContinuousObserverPoles(final CM continuousObserverPoles) {
    this.continuousObserverPoles = continuousObserverPoles.createClone();
    this.designer.setContinuousObserverPoles(continuousObserverPoles);
    setObserverLinearSystem();
  }

  /**
   * オブザーバーの線形システムとしての値を設定します。
   */
  private void setObserverLinearSystem() {
    if (this.designer.isAvailable()) {
      final LinearSystem<RS,RM,CS,CM> linearSystem = this.designer.getObserver().getLinearSystem();
      setLinearSystem(linearSystem);
      setInputSize(linearSystem.getInputSize());
      setOutputSize(linearSystem.getOutputSize());
      setStateSize(linearSystem.getStateSize());
      setInitialState(this.sunit.createZeroGrid(linearSystem.getStateSize(), 1));
      setState(this.sunit.createZeroGrid(linearSystem.getStateSize(), 1));
    }
  }

  /**
   * @see org.mklab.tool.control.system.parameter.ParameterUpdator#updateWith(java.lang.String)
   */
  public boolean updateWith(final String parameter) {
    if (parameter.equals("continuousObserverPoles")) { //$NON-NLS-1$
      setContinuousObserverPoles(this.continuousObserverPoles);
      return true;
    }
    return false;
  }
}