1

Dependencies:   mbed-dev-f303 FastPWM3

Files at this revision

API Documentation at this revision

Comitter:
shaorui
Date:
Fri Oct 16 09:08:47 2020 +0000
Parent:
56:fe5056ac6740
Commit message:
1

Changed in this revision

CAN/CAN_com.cpp Show annotated file Show diff for this revision Revisions of this file
Config/motor_config.h Show annotated file Show diff for this revision Revisions of this file
PositionSensor/PositionSensor.cpp Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
structs.h Show annotated file Show diff for this revision Revisions of this file
--- a/CAN/CAN_com.cpp	Thu Oct 10 15:03:12 2019 +0000
+++ b/CAN/CAN_com.cpp	Fri Oct 16 09:08:47 2020 +0000
@@ -3,8 +3,12 @@
 
  #define P_MIN -12.5f
  #define P_MAX 12.5f
- #define V_MIN -65.0f
- #define V_MAX 65.0f
+ /*shaorui modify matching to relative gear ration***/
+ //#define V_MIN -65.0f   //GR=6
+ //#define V_MAX 65.0f    //GR=6
+ #define V_MIN -45.0f   
+ #define V_MAX 45.0f    
+/*shaorui modify matching to relative gear ration***/
  #define KP_MIN 0.0f
  #define KP_MAX 500.0f
  #define KD_MIN 0.0f
--- a/Config/motor_config.h	Thu Oct 10 15:03:12 2019 +0000
+++ b/Config/motor_config.h	Fri Oct 16 09:08:47 2020 +0000
@@ -6,7 +6,8 @@
 #define L_Q 0.00008f            //Henries
 #define KT .075f                 //N-m per peak phase amp, = WB*NPP*3/2
 #define NPP 21                  //Number of pole pairs
-#define GR 6.0f                 //Gear ratio
+//#define GR 6.0f                 //Gear ratio
+#define GR 49.0f                 //Gear ratio
 #define KT_OUT 0.45f            //KT*GR
 #define WB 0.00287f              //Flux linkage, Webers.  
 #define R_TH 1.25f              //Kelvin per watt
--- a/PositionSensor/PositionSensor.cpp	Thu Oct 10 15:03:12 2019 +0000
+++ b/PositionSensor/PositionSensor.cpp	Fri Oct 16 09:08:47 2020 +0000
@@ -34,10 +34,10 @@
     
 void PositionSensorAM5147::Sample(float dt){
     GPIOA->ODR &= ~(1 << 15);
-    //raw = spi->write(readAngleCmd);
-    //raw &= 0x3FFF;   
-    raw = spi->write(0);
-    raw = raw>>2;                                                             //Extract last 14 bits
+    raw = spi->write(readAngleCmd);
+    raw &= 0x3FFF;   
+    //raw = spi->write(0);
+    //raw = raw>>2;                                                             //Extract last 14 bits
     GPIOA->ODR |= (1 << 15);
     int off_1 = offset_lut[raw>>7];
     int off_2 = offset_lut[((raw>>7)+1)%128];
--- a/main.cpp	Thu Oct 10 15:03:12 2019 +0000
+++ b/main.cpp	Fri Oct 16 09:08:47 2020 +0000
@@ -236,7 +236,8 @@
                     state = REST_MODE;
                     state_change = 1;
                     gpio.led->write(0);
-                    observer.temperature = (double)(T_AMBIENT + ((observer.resistance/R_NOMINAL) - 1.0f)*254.5f);
+                    //observer.temperature = (double)(T_AMBIENT + ((observer.resistance/R_NOMINAL) - 1.0f)*254.5f);
+                    observer.temperature = (float)(T_AMBIENT + ((observer.resistance/R_NOMINAL) - 1.0f)*254.5f);
                     printf("Winding Resistance:  %f\n\r", observer.resistance);
                     printf("Winding Temperature:  %f\n\r", observer.temperature);
                     
@@ -427,6 +428,7 @@
                 case 'd':
                     controller.i_q_ref = 0;
                     controller.i_d_ref = 0;
+                    //printf("id_ref=iq_ref=0\n\r");
                 }
             }
             
@@ -500,7 +502,8 @@
     init_controller_params(&controller);
     
 
-    pc.baud(921600);                                                            // set serial baud rate
+    //pc.baud(921600); 
+    pc.baud(460800);                                                            // set serial baud rate
     wait(.01);
     pc.printf("\n\r\n\r HobbyKing Cheetah\n\r\n\r");
     wait(.01);
@@ -524,7 +527,7 @@
         wait(.1);
         //printf("%.3f  %.3f\n\r" , observer.temperature, observer.q_in);
         if(controller.otw_flag){gpio.led->write(!gpio.led->read());}
-             /*
+             
         if(state == MOTOR_MODE)
         {
             if(controller.otw_flag){gpio.led->write(!gpio.led->read());}
@@ -533,9 +536,10 @@
             //printf("%.3f  %.3f  %.3f %.3f %.3f\n\r", controller.v_d, controller.v_q, controller.i_d_filt, controller.i_q_filt, controller.dtheta_elec);
             //printf("%.3f  %.3f  %.3f %.3f\n\r", controller.dtheta_elec, observer.resistance, observer.temperature, observer.temp_measured);
             //printf("%.3f  %.3f\n\r" , observer.temperature, observer.temp_measured);
+            printf("%.3f\n\r",controller.dtheta_mech);
         }
         
-        */
+        
 
     }
 }
--- a/structs.h	Thu Oct 10 15:03:12 2019 +0000
+++ b/structs.h	Fri Oct 16 09:08:47 2020 +0000
@@ -44,7 +44,8 @@
     } ControllerStruct;
 
 typedef struct{
-    double temperature;                                              // Estimated temperature
+//    double temperature;                                              // Estimated temperature
+    float temperature;                                              // Estimated temperature
     float temp_measured;
     float q_in, q_out;
     float resistance;