123487

Dependencies:   mbed-dev-f303 FastPWM3

Revision:
54:d889fe62bc0c
Parent:
52:15a8de8af562
Child:
56:9353ebcf19c6
--- a/main.cpp	Mon Aug 05 12:17:50 2019 +0000
+++ b/main.cpp	Thu Aug 29 08:48:20 2019 +0000
@@ -57,10 +57,15 @@
 volatile int count = 0;
 volatile int state = REST_MODE;
 volatile int state_change;
+volatile int counthjb = 0;
 
 void onMsgReceived() {
     //msgAvailable = true;
-    printf("%df\n\r", rxMsg.id);
+    counthjb++;
+    if(counthjb>100)
+      {printf("%df\n\r", rxMsg.id);
+      counthjb=0;
+      }
     can.read(rxMsg);  
     if((rxMsg.id == CAN_ID)){
         controller.timeout = 0;
@@ -254,6 +259,11 @@
     while(pc.readable()){
         char c = pc.getc();
         if(c == 27){
+                 //===============================================HJB added====================================================//
+                wait_us(100);                                                             //HJB add, to clear fault
+                drv.write_DCR(0x0, 0x0, 0x0, PWM_MODE_3X, 0x0, 0x0, 0x0, 0x0, 0x1);       //HJB add, to clear fault
+                //Init_pos = controller.theta_mech;                                         //Input the local mechanical theta
+                //===============================================HJB ended====================================================//
                 state = REST_MODE;
                 state_change = 1;
                 char_count = 0;
@@ -360,6 +370,7 @@
     }
        
 int main() {
+    wait(1);           //hjb added
     controller.v_bus = V_BUS;
     controller.mode = 0;
     Init_All_HW(&gpio);                                                         // Setup PWM, ADC, GPIO
@@ -420,7 +431,7 @@
     spi.WriteLUT(lut);                                                          // Set potision sensor nonlinearity lookup table
     init_controller_params(&controller);
 
-    pc.baud(115200);                                                            // set serial baud rate
+    pc.baud(460800);                                                            // set serial baud rate
     wait(.01);
     pc.printf("\n\r\n\r HobbyKing Cheetah\n\r\n\r");
     wait(.01);
@@ -447,11 +458,16 @@
 
 
     int counter = 0;
+    //===============================================HJB added====================================================//
+                wait_us(100);                                                             //HJB add, to clear fault
+                drv.write_DCR(0x0, 0x0, 0x0, PWM_MODE_3X, 0x0, 0x0, 0x0, 0x0, 0x1);       //HJB add, to clear fault
+                //Init_pos = controller.theta_mech;                                         //Input the local mechanical theta
+                //===============================================HJB ended====================================================//
     while(1) {
         drv.print_faults();
        wait(.1);
        //printf("%.4f\n\r", controller.v_bus);
-       /*
+       
         if(state == MOTOR_MODE)
         {
             //printf("%.3f  %.3f  %.3f\n\r", (float)observer.temperature, (float)observer.temperature2, observer.resistance);
@@ -459,7 +475,7 @@
             //printf("%.3f\n\r", controller.dtheta_mech);
             wait(.002);
         }
-        */
+        
 
     }
 }