Motor2ObserverSampledDataRKFSimulation.java
01 /*
02  * $Id: Motor2ObserverSampledDataRKFSimulation.java,v 1.3 2008/02/02 03:06:25 koga Exp $
03  *
04  * Copyright (C) 2004 Koga Laboratory. All rights reserved.
05  *
06  */
07 package matxbook.chap21;
08 
09 import java.io.IOException;
10 
11 import org.mklab.nfc.matrix.DoubleMatrix;
12 import org.mklab.nfc.matrix.Matrix;
13 import org.mklab.nfc.ode.DifferentialEquationSolver;
14 import org.mklab.nfc.ode.RungeKuttaFehlberg;
15 import org.mklab.nfc.ode.SolverStopException;
16 import org.mklab.nfc.util.Pause;
17 import org.mklab.tool.control.system.SystemSolver;
18 import org.mklab.tool.graph.gnuplot.Canvas;
19 import org.mklab.tool.graph.gnuplot.Gnuplot;
20 
21 
22 /**
23  @author koga
24  @version $Revision: 1.3 $, 2004/04/23
25  */
26 public class Motor2ObserverSampledDataRKFSimulation {
27 
28   /**
29    * メインメソッド
30    
31    @param args コマンドライン引数
32    @throws InterruptedException 強制終了された場合
33    @throws IOException キーボードから入力できない場合
34    @throws SolverStopException ソルバーが停止された場合
35    */
36   @SuppressWarnings("nls")
37   public static void main(String[] argsthrows InterruptedException, IOException, SolverStopException {
38     Motor2DiscreteObserver system = new Motor2DiscreteObserver();
39     Matrix xc0 = new DoubleMatrix(new double[] {10}).transpose();
40     Matrix xd0 = new DoubleMatrix(new double[] {0}).transpose();
41     system.setContinuousInitialState(xc0);
42     system.setDiscreteInitialState(xd0);
43     system.setSamplingInterval(0.5);
44 
45     DifferentialEquationSolver solver = new RungeKuttaFehlberg();
46     solver.setTimeStep(0.1);
47     solver.setSaveAtSamplingPoint(true);
48     new SystemSolver(solver).solve(system, 010);
49     DoubleMatrix tt = solver.getTimeSeries();
50     DoubleMatrix xc = solver.getContinuousStateSeries();
51     DoubleMatrix xd = solver.getDiscreteStateSeries();
52     // Matrix uy = ans[3];
53 
54     Gnuplot gnuplot = new Gnuplot();
55     Canvas canvas = gnuplot.createCanvas();
56     canvas.setHolding(true);
57     canvas.plot(tt, xc, new String[] {"x1""x2"});
58     canvas.plot(tt, xd, new String[] {"xd"});
59     // canvas.plot(tt, uy, new String[] {"u", "y"});
60     canvas.setHolding(false);
61     Pause.pause();
62     gnuplot.close();
63   }
64 }