Modified Motor Driver Firmware to include Flash + Thermal

Dependencies:   FastPWM3 mbed-dev-STM-lean

Revision:
71:b314182de37f
Parent:
70:2ea6c555a2cb
Child:
72:3163691b0851
diff -r 2ea6c555a2cb -r b314182de37f main.cpp
--- a/main.cpp	Thu Apr 01 18:23:53 2021 +0000
+++ b/main.cpp	Fri Aug 26 21:44:23 2022 +0000
@@ -135,6 +135,12 @@
     wait_us(10);
     printf(" %-4s %-31s %-5s %-6s %.1f\n\r", "c", "Continuous Current (A)", "0", "40.0", I_MAX_CONT);
     wait_us(10);
+    printf(" %-4s %-31s %-5s %-6s %.1f\n\r", "s", "Current Controller K_SCALE", "0", "0.1", K_SCALE);                                                 //ADDED --> FOR CURRENT CONTROL GAINS (KP)
+    wait_us(10);
+    printf(" %-4s %-31s %-5s %-6s %.1f\n\r", "d", "Current Controller KI_D", "0", "1.0", KI_D);                                                       //ADDED --> FOR CURRENT CONTROL GAINS (KI D-Axis)
+    wait_us(10);
+    printf(" %-4s %-31s %-5s %-6s %.1f\n\r", "q", "Current Controller KI_Q", "0", "1.0", KI_Q);                                                       //ADDED --> FOR CURRENT CONTROL GAINS (KI Q-Axis)
+    wait_us(10);
     printf("\n\r To change a value, type 'prefix''value''ENTER'\n\r i.e. 'b1000''ENTER'\n\r\n\r");
     wait_us(10);
     state_change = 0;
@@ -395,6 +401,15 @@
                     case 'c':
                         I_MAX_CONT = fmaxf(fminf(atof(cmd_val), 40.0f), 0.0f);
                         break;
+                    case 's':                                                                                                                   //CURRENT CONTROL K_SCALE
+                        K_SCALE = fmaxf(fminf(atof(cmd_val), 0.1f), 0.0f);
+                        break;
+                    case 'd':                                                                                                                   //CURRENT CONTORL KI_D
+                        KI_D = fmaxf(fminf(atof(cmd_val), 1.0f), 0.0f);
+                        break;
+                    case 'q':                                                                                                                   //CURRENT CONTORL KI_Q
+                        KI_Q = fmaxf(fminf(atof(cmd_val), 1.0f), 0.0f);
+                        break;
                     default:
                         printf("\n\r '%c' Not a valid command prefix\n\r\n\r", cmd_id);
                         break;
@@ -493,6 +508,9 @@
     if(isnan(R_NOMINAL) || R_NOMINAL==-1){R_NOMINAL = 0.0f;}
     if(isnan(TEMP_MAX) || TEMP_MAX==-1){TEMP_MAX = 125.0f;}
     if(isnan(I_MAX_CONT) || I_MAX_CONT==-1){I_MAX_CONT = 14.0f;}
+    if(isnan(K_SCALE) || K_SCALE==-1){K_SCALE = 0.00013310f;}                                                                                           //CURRENT CONTROLLER K_SCALE
+    if(isnan(KI_D) || KI_D==-1){KI_D = 0.0373f;}                                                                                                        //CURRENT CONTROLLER KI_D
+    if(isnan(KI_Q) || KI_Q==-1){KI_Q = 0.0373f;}                                                                                                        //CURRENT CONTROLLER KI_Q
     spi.SetElecOffset(E_OFFSET);                                                // Set position sensor offset
     spi.SetMechOffset(M_OFFSET);
     spi.Sample(1.0f);