Index: applications/pmsm/pmsm.h
===================================================================
--- applications/pmsm/pmsm.h (revision 1327)
+++ applications/pmsm/pmsm.h (revision 1341)
@@ -29,5 +29,5 @@
 	bool cutoff;
 public:
-	IMpmsm() :diffbifn ( ) {dimy=4; dimx = 4; dimu=2; dimc=6;compensate=true;cutoff=true;};
+	IMpmsm() :diffbifn ( ) {dimy=4; dimx = 4; dimu=2; dimc=6;compensate=false;cutoff=true;};
 	//! Set mechanical and electrical variables
 	virtual void set_parameters ( double Rs0, double Ls0, double dt0, double Ypm0, double kp0, double p0, double J0, double Mz0 ) {Rs=Rs0; Ls=Ls0; dt=dt0; Ypm=Ypm0; kp=kp0; p=p0; J=J0; Mz=Mz0;}
@@ -134,5 +134,5 @@
 	bool cutoff;
 public:
-	IMpmsmOT() :diffbifn ( ) {dimy=2; dimx = 2; dimu=4; dimc=6;compensate=true;cutoff=true;};
+	IMpmsmOT() :diffbifn ( ) {dimy=2; dimx = 2; dimu=4; dimc=6;compensate=false;cutoff=true;};
 	//! Set mechanical and electrical variables
 	virtual void set_parameters ( double Rs0, double Ls0, double dt0, double Ypm0, double kp0, double p0, double J0, double Mz0 ) {Rs=Rs0; Ls=Ls0; dt=dt0; Ypm=Ypm0; kp=kp0; p=p0; J=J0; Mz=Mz0;}
@@ -188,5 +188,5 @@
 	
 	void dfdx_cond ( const vec &x0, const vec &u0, mat &A, bool full=true ) {
-		const double &omm = x0 ( 0 );
+//		const double &omm = x0 ( 0 );
 		const double &thm = x0 ( 1 );
 
@@ -223,4 +223,112 @@
 
 UIREGISTER ( IMpmsmOT );
+
+//! Evolution model of \f$ \omega, \vartheta\f$ for a PMSM drive and its derivative with respect to \f$x\f$
+class IMpmsmOTM : public diffbifn {
+protected:
+	double Rs, Ls, dt, Ypm, kp, p,  J, Mz;
+	
+	bool compensate;
+	bool cutoff;
+public:
+	IMpmsmOTM() :diffbifn ( ) {dimy=2; dimx = 3; dimu=4; dimc=6;compensate=false;cutoff=true;};
+	//! Set mechanical and electrical variables
+	virtual void set_parameters ( double Rs0, double Ls0, double dt0, double Ypm0, double kp0, double p0, double J0, double Mz0 ) {Rs=Rs0; Ls=Ls0; dt=dt0; Ypm=Ypm0; kp=kp0; p=p0; J=J0; Mz=Mz0;}
+	
+	void modelpwm(const vec &x0, const vec u0, double &ua, double &ub){
+		/*		ua=u0[0];
+		 *		ub=u0[1];
+		 *		return;*/
+		double sq3=sqrt ( 3.0 );
+		double i1=x0(0);
+		double i2=0.5* ( -i1+sq3*x0[1] );
+		double i3=0.5* ( -i1-sq3*x0[1] );
+		double u1=u0(0);
+		double u2=0.5* ( -u1+sq3*u0(1) );
+		double u3=0.5* ( -u1-sq3*u0(1) );
+		
+		double du1=1.4* ( double ( i1>0.3 ) - double ( i1<-0.3 ) ) +0.2*i1;
+		double du2=1.4* ( double ( i2>0.3 ) - double ( i2<-0.3 ) ) +0.2*i2;
+		double du3=1.4* ( double ( i3>0.3 ) - double ( i3<-0.3 ) ) +0.2*i3;
+		ua = ( 2.0* ( u1-du1 )- ( u2-du2 )- ( u3-du3 ) ) /3.0;
+		ub = ( ( u2-du2 )- ( u3-du3 ) ) /sq3;
+	}
+	
+	vec eval ( const vec &x0, const vec &u0 ) {
+		// last state
+		const double &omm = x0 ( 0 );
+		const double &thm = x0 ( 1 );
+		const double &Mm  = x0 ( 2 );
+		double uam;
+		double ubm;
+		
+		if (compensate){
+			modelpwm(x0,u0,uam,ubm);
+		} else {
+			uam = u0(0);
+			ubm = u0(1);
+		}
+		
+		const double &iam = u0 ( 2 );
+		const double &ibm = u0 ( 3 );
+		
+		vec xk( 3 );
+		//ia
+		//om
+		xk ( 0 ) = omm + kp*p*p * Ypm/J*dt* ( ibm * cos ( thm )-iam * sin ( thm ) ) - p/J*dt*Mm;
+		//th
+		xk ( 1 ) = thm + omm*dt; // <0..2pi>
+		xk (2) = Mm;
+		
+		if (cutoff) {
+			if ( xk ( 1 ) >pi ) xk ( 1 )-=2*pi;
+			if ( xk ( 1 ) <-pi ) xk ( 1 ) +=2*pi;
+		}
+		return xk;
+	}
+	
+	void dfdx_cond ( const vec &x0, const vec &u0, mat &A, bool full=true ) {
+//		const double &omm = x0 ( 0 );
+		const double &thm = x0 ( 1 );
+//		const double &Mm  = x0 ( 2 );
+		
+		const double &iam = u0 ( 2 );
+		const double &ibm = u0 ( 3 );
+		
+		// d ia
+		// d om
+		A ( 0,0 ) = 1.0;
+		A ( 0,1 ) = kp*p*p * Ypm/J*dt* ( -ibm * sin ( thm )-iam * cos ( thm ) );
+		A ( 0,2 ) = -p/J*dt;
+		// d th
+		A ( 1,0 ) = dt; 
+		A ( 1,1 ) = 1.0;
+		A ( 1,2 ) = 0.0;
+		// d M
+		A ( 2,0 ) = 0.0;
+		A ( 2,1 ) = 0.0;
+		A ( 2,2 ) = 1.0;
+	}
+	
+	void dfdu_cond ( const vec &x0, const vec &u0, mat &A, bool full=true ) {it_error ( "not needed" );};
+	
+	void from_setting( const Setting &root )
+	{	
+		
+		const SettingResolver& params_b=root["params"];
+		const Setting& params=params_b.result;
+		
+		set_parameters ( params["Rs"], params["Ls"], 125e-6, params["Fmag"], \
+		params["kp"], params["p"], params["J"], 0.0);
+		int comp=0;
+		if (UI::get(comp,root,"compensate",UI::optional)){compensate=(comp==1);}
+		int cuto=0;
+		if (UI::get(cuto,root,"cutoff",UI::optional)){cutoff=(cuto==1);}
+	};
+	
+	// TODO dodelat void to_setting( Setting &root ) const;
+};
+
+UIREGISTER ( IMpmsmOTM );
 
 //! Evolution model of \f$ \omega, \vartheta\f$ for a PMSM drive and its derivative with respect to \f$x\f$ -- Scaled to [-1,1]
@@ -766,4 +874,60 @@
 UIREGISTER ( OMpmsmOT );
 
+//! Observation model for PMSM drive in reduced form coordinates
+class OMpmsmOTM: public diffbifn {
+public:
+	double Rs, Ls, dt, Ypm, kp, p,  J, Mz;
+	
+	virtual void set_parameters ( double Rs0, double Ls0, double dt0, double Ypm0, double kp0, double p0, double J0, double Mz0 ) {Rs=Rs0; Ls=Ls0; dt=dt0; Ypm=Ypm0; kp=kp0; p=p0; J=J0; Mz=Mz0;}
+	
+	OMpmsmOTM() :diffbifn () {dimy=2;dimx=2;dimu=4;};
+	
+	vec eval ( const vec &x0, const vec &u0 ) {
+		vec y ( 2 );
+		const double &omm = x0(0);
+		const double &thm = x0(1);
+		
+		const double &uam = u0 ( 0 );
+		const double &ubm = u0 ( 1 );
+		const double &iam = u0 ( 2 );
+		const double &ibm = u0 ( 3 );
+		
+		y ( 0 ) = ( 1.0- Rs/Ls*dt ) * iam + Ypm/Ls*dt*omm * sin ( thm ) + uam*dt/Ls;
+		//ib
+		y ( 1 ) = ( 1.0- Rs/Ls*dt ) * ibm - Ypm/Ls*dt*omm * cos ( thm ) + ubm*dt/Ls;
+		
+		return y;
+	}
+	
+	void dfdx_cond ( const vec &x0, const vec &u0, mat &A, bool full=true ) {
+		const double &omm = x0(0);
+		const double &thm = x0(1);
+		
+		A ( 0,0 ) = Ypm/Ls*dt* sin ( thm ); 
+		A ( 0,1 ) = Ypm/Ls*dt*omm * ( cos ( thm ) );
+		A( 0,2) = 0.0;
+		// d ib
+		A ( 1,0 ) = -Ypm/Ls*dt* cos ( thm ); 
+		A ( 1,1 ) = Ypm/Ls*dt*omm * ( sin ( thm ) );
+		A(1,2) = 0.0;
+		
+	}
+	
+	void from_setting( const Setting &root )
+	{	
+		
+		const SettingResolver& params_b=root["params"];
+		const Setting& params=params_b.result;
+		
+		set_parameters ( params["Rs"], params["Ls"], 125e-6, params["Fmag"], \
+		params["kp"], params["p"], params["J"], 0.0);
+	};
+	
+};
+
+UIREGISTER ( OMpmsmOTM );
+
+
+
 //! Observation model for PMSM drive in reduced form coordinates -- scaled to [-1,1]
 class OMpmsmOTsc: public diffbifn {
