root/applications/doprava/aimsun_bdm/aimsun_ds.h @ 814

Revision 814, 3.0 kB (checked in by smidl, 14 years ago)

AimsunDS

Line 
1/*!
2  \file
3  \brief DataSource for experiments with Aimsun
4  \author Jan prikryl.
5
6*/
7
8#include <base/loggers.h>
9
10using namespace bdm;
11
12//! Simulator of traffic - AIMSUN
13class AimsunDS : public DS
14{
15
16protected:
17    //! indeces of logged variables
18    int L_x, L_ou, L_oy, L_iu, L_optu;
19    //! Setpoints of omega in timespans given by dt_prof
20    vec profileWw;
21    //! Setpoints of Mz in timespans given by dt_prof
22    vec profileMz;
23    //! time-step for profiles
24    double dt_prof;
25    //! Number of miliseconds per discrete time step
26    int Dt;
27    //! options for logging, - log predictions of 'true' voltage
28    bool opt_modu;
29    //! options for logging, -
30public:
31    //! Constructor with fixed sampling period
32    AimsunDS () : DS()
33    {
34        Dt=125;
35        Yrv=RV ( "{o_ua o_ub o_ia o_ib t_ua t_ub o_om o_th Mz }" );
36                ytsize = Yrv._dsize();
37                Drv = Yrv;
38    }
39    void set_parameters ( double Rs0, double Ls0, double Fmag0, double Bf0, double p0, double kp0, double J0, double Uc0, double DT0, double dt0 )
40    {
41        pmsmsim_set_parameters ( Rs0, Ls0, Fmag0, Bf0, p0, kp0, J0, Uc0, DT0, dt0 );
42    }
43    //! parse options: "modelu" => opt_modu=true;
44    void set_options ( string &opt )
45    {
46        opt_modu = ( opt.find ( "modelu" ) !=string::npos );
47    }
48    void getdata ( vec &dt ) const
49    {
50        dt.set_subvector(0,vec ( KalmanObs,6 ));
51        dt(6)=x[2];
52        dt(7)=x[3];
53        dt(8)=x[8];
54    }
55    void write ( vec &ut ) {}
56
57    void step()
58    {
59        static int ind=0;
60        static double dW; // increase of W
61        static double Ww; // W
62        static double Mz; // W
63        if ( t>=dt_prof*ind )
64        {
65            ind++;
66            // check omega profile and set dW
67                        if ( ind <2 && profileWw.length() ==1 )
68                        {
69                                Ww=profileWw ( 0 );
70                                dW=0.0;
71                        }
72                        if ( ind<profileWw.length() )
73            {
74                    dW = profileWw ( ind )-profileWw ( ind-1 );
75                    dW *=125e-6/dt_prof;
76            }
77            else
78            {
79                dW = 0;
80            }
81            // Check Mz profile and set Mz
82            if ( ind<profileMz.length() )
83            {
84                //sudden increase
85                Mz = profileMz(ind);
86            }
87            else
88            {
89                Mz = 0;
90            }
91        }
92        Ww += dW;
93        //Simulate Dt seconds!
94        for ( int i=0; i<Dt; i++ )
95        {
96            pmsmsim_step ( Ww , Mz);
97        }
98//              for ( int i=0;i<Dt;i++ ) {      pmsmsim_noreg_step ( Ww , Mz);}
99
100        //discretization
101        double ustep=1.2;
102        KalmanObs [ 0 ] = ustep*itpp::round( KalmanObs [ 0 ]/ ustep) ;
103        KalmanObs [ 1 ] = ustep*itpp::round(KalmanObs [ 1 ]/ ustep);
104        double istep=0.085;
105        KalmanObs [ 2 ] = istep*itpp::round( KalmanObs [ 2 ]/ istep) ;
106        KalmanObs [ 3 ] = istep*itpp::round(KalmanObs [ 3 ]/ istep);
107
108    };
109
110 
111
112    // TODO dodelat void to_setting( Setting &root ) const;
113};
Note: See TracBrowser for help on using the browser.