yei

Dependencies:   interface mbed enc_1multi calPID motorout KondoServoLibrary

Fork of cat18_operate by Catch the GIANT Caplico!

Committer:
shimizuta
Date:
Thu Aug 09 07:22:46 2018 +0000
Revision:
5:af5ccfce1b90
Parent:
4:187c62291654
Child:
7:35972aae0647
compile ok

Who changed what in which revision?

UserRevisionLine numberNew contents of line
shimizuta 2:4515e8cc6b60 1 #include "interrupt.h"
shimizuta 2:4515e8cc6b60 2 #include "mbed.h"
shimizuta 2:4515e8cc6b60 3 #include "go.h"
shimizuta 2:4515e8cc6b60 4 #include "check.h"
shimizuta 2:4515e8cc6b60 5 #include "pinnames.h"
shimizuta 2:4515e8cc6b60 6 #include "cat18_can_info.h"
shimizuta 2:4515e8cc6b60 7
shimizuta 2:4515e8cc6b60 8 #define RIGHT//右用ならRIGHT,左用ならLEFT
shimizuta 2:4515e8cc6b60 9
shimizuta 2:4515e8cc6b60 10 Ticker ticker;
shimizuta 2:4515e8cc6b60 11 CAN can(pin_can_rd,pin_can_td);
shimizuta 2:4515e8cc6b60 12 int counterpart_is_in_common;
shimizuta 2:4515e8cc6b60 13 char can_pub_data[kCanlength_rightleft];
shimizuta 5:af5ccfce1b90 14 const double kTicker_s = 0.01;
shimizuta 2:4515e8cc6b60 15 const int kCanCount = kCanTicker_s / kTicker_s;
shimizuta 2:4515e8cc6b60 16
shimizuta 2:4515e8cc6b60 17 void TimerInterrupt();
shimizuta 2:4515e8cc6b60 18 void CanRead();
shimizuta 2:4515e8cc6b60 19 void CanSend();
shimizuta 2:4515e8cc6b60 20
shimizuta 2:4515e8cc6b60 21 void InterruptSetup()
shimizuta 2:4515e8cc6b60 22 {
shimizuta 2:4515e8cc6b60 23 can.frequency(kCanFrequency);
shimizuta 2:4515e8cc6b60 24 ticker.attach(TimerInterrupt,kTicker_s);
shimizuta 2:4515e8cc6b60 25 }
shimizuta 2:4515e8cc6b60 26 void TimerInterrupt()
shimizuta 2:4515e8cc6b60 27 {
shimizuta 2:4515e8cc6b60 28 PIDInterrupt();
shimizuta 4:187c62291654 29 ServoTargetInterrupt();
shimizuta 2:4515e8cc6b60 30 static int i = 0;
shimizuta 2:4515e8cc6b60 31 ++i;
shimizuta 2:4515e8cc6b60 32 if(i > kCanCount) {
shimizuta 2:4515e8cc6b60 33 CanRead();
shimizuta 2:4515e8cc6b60 34 CanSend();
shimizuta 2:4515e8cc6b60 35 i = 0;
shimizuta 2:4515e8cc6b60 36 }
shimizuta 2:4515e8cc6b60 37 }
shimizuta 2:4515e8cc6b60 38 int GetCounterpartIsInCommon()
shimizuta 2:4515e8cc6b60 39 {
shimizuta 2:4515e8cc6b60 40 return counterpart_is_in_common;
shimizuta 2:4515e8cc6b60 41 }
shimizuta 2:4515e8cc6b60 42
shimizuta 2:4515e8cc6b60 43 void CanRead()
shimizuta 2:4515e8cc6b60 44 {
shimizuta 2:4515e8cc6b60 45 CANMessage msg;
shimizuta 2:4515e8cc6b60 46 if(!can.read(msg)) {
shimizuta 2:4515e8cc6b60 47 return;
shimizuta 2:4515e8cc6b60 48 }
shimizuta 2:4515e8cc6b60 49 switch (msg.id) {
shimizuta 2:4515e8cc6b60 50 #ifdef RIGHT
shimizuta 2:4515e8cc6b60 51 case CANID_LEFT :
shimizuta 2:4515e8cc6b60 52 #elif defined LEFT
shimizuta 2:4515e8cc6b60 53 case CANID_RIGHT :
shimizuta 2:4515e8cc6b60 54 #endif
shimizuta 2:4515e8cc6b60 55 counterpart_is_in_common = msg.data[0];
shimizuta 2:4515e8cc6b60 56 break;
shimizuta 2:4515e8cc6b60 57
shimizuta 2:4515e8cc6b60 58 }
shimizuta 2:4515e8cc6b60 59 }
shimizuta 2:4515e8cc6b60 60 void CanSend()
shimizuta 2:4515e8cc6b60 61 {
shimizuta 2:4515e8cc6b60 62 static int state = 1;
shimizuta 2:4515e8cc6b60 63 switch(state) {
shimizuta 2:4515e8cc6b60 64 #ifdef RIGHT
shimizuta 2:4515e8cc6b60 65 case CANID_RIGHT :
shimizuta 2:4515e8cc6b60 66 #elif defined LEFT
shimizuta 2:4515e8cc6b60 67 case CANID_LEFT:
shimizuta 2:4515e8cc6b60 68 #endif
shimizuta 2:4515e8cc6b60 69 {
shimizuta 2:4515e8cc6b60 70 can_pub_data[0] = IsInCommonArea();
shimizuta 2:4515e8cc6b60 71 CANMessage msg(state,can_pub_data,kCanlength_rightleft);
shimizuta 2:4515e8cc6b60 72 can.write(msg);
shimizuta 2:4515e8cc6b60 73 break;
shimizuta 2:4515e8cc6b60 74 }
shimizuta 2:4515e8cc6b60 75 }
shimizuta 2:4515e8cc6b60 76 state ++;
shimizuta 2:4515e8cc6b60 77 if(state >= CANID_FINISH) {
shimizuta 2:4515e8cc6b60 78 state = 1;
shimizuta 2:4515e8cc6b60 79 }
shimizuta 2:4515e8cc6b60 80 }