Cart.java

/*
 * $Id: Cart.java,v 1.3 2008/06/26 10:10:34 koga Exp $
 *
 * Copyright (C) 2005 Koga Laboratory. All rights reserved.
 *
 */

package org.mklab.tool.control.model.pendulum;

import org.mklab.nfc.matrix.DoubleMatrix;
import org.mklab.tool.control.system.continuous.DoubleBaseContinuousExplicitDynamicSystem;
import org.mklab.tool.control.system.parameter.Parameter;
import org.mklab.tool.control.system.parameter.SIunit;


/**
 * 台車を表すクラスです。
 * 
 * @author koga
 * @version $Revision: 1.3 $, 2005/06/15
 */
public class Cart extends DoubleBaseContinuousExplicitDynamicSystem {

  /** 台車の質量 */
  @Parameter(name = "M", unit = SIunit.kg, description = "台車の質量")
  protected double m1 = 0.16;

  /** 台車の摩擦係数 */
  @Parameter(name = "Fr", unit = {SIunit.N, SIunit.s, SIunit.m_1}, description = "台車の摩擦係数")
  protected double fr = 2.6;

  /** 入力電圧と発生する力の変換係数 */
  @Parameter(name = "a", unit = {SIunit.N, SIunit.V_1}, description = "電圧・力変換係数")
  protected double a0 = 0.1;

  /** センサの出力と台車の位置の変換係数 */
  @Parameter(name = "cc1", unit = {SIunit.m, SIunit.V_1}, description = "台車の位置センサーの変換係数")
  protected double cc1 = 1.0;

  /** 重力係数 */
  final protected double g = 9.8;

  /**
   * コンストラクタ
   */
  public Cart() {
    super(1, 1, 2); // 1入力、1出力、2状態
    setHasDirectFeedthrough(false); // 直達項がない
  }
  
  /**
   * {@inheritDoc}
   */
  public DoubleMatrix stateEquation( final double t, final DoubleMatrix x, final DoubleMatrix u) {
    final double dr = x.getDoubleElement(2);
    final double u1 = u.getDoubleElement(1);

    final DoubleMatrix dx = new DoubleMatrix(2, 1);
    dx.setElement(1, dr);
    dx.setElement(2, -this.fr * dr + this.a0 * u1);
    return dx;
  }

  /**
   * {@inheritDoc}
   */
  @Override
  public DoubleMatrix outputEquation( final double t, final DoubleMatrix x) {
    final double r = x.getDoubleElement(1);
    final DoubleMatrix y = new DoubleMatrix(1, 1);
    y.setElement(1, this.cc1 * r);
    return y;
  }
}