123487

Dependencies:   mbed-dev-f303 FastPWM3

Revision:
55:14ac00a5f43d
Parent:
51:6cd89bd6fcaa
--- a/FOC/foc.cpp	Thu Aug 29 08:48:20 2019 +0000
+++ b/FOC/foc.cpp	Tue Nov 19 08:54:35 2019 +0000
@@ -133,8 +133,31 @@
         double e = observer->temperature - observer->temperature2;
         observer->temperature -= .001*e;
         //printf("%.3f\n\r", e);
+        /*
+        // Integrate the thermal model //
+        delta_t = observer.temperature - T_AMBIENT;
+        observer.qd_in = R_NOMINAL**(1.0f + .00393f*delta_t)*controller.i*controller.i;
+        observer.qd_out = delta_t*R_TH;
+        observer.temperature += DT*(observer.qd_in-observer.qd_out)/C_TH;
+            
+        // Estimate Resistance //
+        observer.resistance = (controller.v_q - controller.omega*(L_D*controller.i_d + WB))/(controller.i_q);
         
-
+        // Estimate Temperature from temp-co //
+        observer.t_measured = ((T_AMBIENT + ((observer.resistance/R_NOMINAL) - 1.0f)*254.5f));
+        
+        // Update Observer with measured temperature //
+        e = (float)observer.temperature - observer.temp_measured;
+        //observer.temperature -= .0001f*e;
+        // Calculate "trust" based on state //
+        observer.trust = (1.0f - .004f*fminf(abs(controller.dtheta_elec), 250.0f)) * (.01f*(fminf(controller.current^2, 100.0f)));
+        
+        // Scale observer gain by "trust" //
+        // .0001 is the default observer gain //
+        observer.temperature -= observer.trust*.0001f*e;
+        
+        
+        */    
        /// Commutation Loop ///
        controller->loop_count ++;   
        if(PHASE_ORDER){                                                                          // Check current sensor ordering