yei

Dependencies:   interface mbed enc_1multi calPID motorout KondoServoLibrary

Fork of cat18_operate by Catch the GIANT Caplico!

Revision:
7:35972aae0647
Parent:
5:af5ccfce1b90
Child:
13:126c3f7f9b89
--- a/interrupt/interrupt.cpp	Thu Aug 09 07:22:59 2018 +0000
+++ b/interrupt/interrupt.cpp	Thu Aug 09 07:47:09 2018 +0000
@@ -11,8 +11,12 @@
 CAN can(pin_can_rd,pin_can_td);
 int counterpart_is_in_common;
 char can_pub_data[kCanlength_rightleft];
+
 const double kTicker_s = 0.01;
 const int kCanCount = kCanTicker_s / kTicker_s;
+const int kPIDCount = kPIDTicker_s / kTicker_s;
+const int kServoCount = kServoTicker_s / kTicker_s;
+const int kCountReset=kPIDCount*kServoCount*kCanCount;
 
 void TimerInterrupt();
 void CanRead();
@@ -25,15 +29,17 @@
 }
 void TimerInterrupt()
 {
+    static int count = 0;
     PIDInterrupt();
-    ServoTargetInterrupt();
-    static int i = 0;
-    ++i;
-    if(i > kCanCount) {
+    if(count % kServoCount==0){
+        ServoTargetInterrupt();
+    }
+    if(count % kCanCount==0){
         CanRead();
         CanSend();
-        i = 0;
     }
+    if(count == kCountReset) count=0;
+    count++;
 }
 int GetCounterpartIsInCommon()
 {