yei

Dependencies:   interface mbed enc_1multi calPID motorout KondoServoLibrary

Fork of cat18_operate by Catch the GIANT Caplico!

Committer:
shimizuta
Date:
Fri Aug 17 00:10:25 2018 +0000
Revision:
18:05f5a3323bda
Parent:
13:126c3f7f9b89
Child:
19:48c3af917932
changed AllowChangeDirection

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 13:126c3f7f9b89 5 #include "coordinate.h"
shimizuta 2:4515e8cc6b60 6 #include "pinnames.h"
shimizuta 2:4515e8cc6b60 7 #include "cat18_can_info.h"
shimizuta 13:126c3f7f9b89 8 #include "debug.h"
shimizuta 18:05f5a3323bda 9 #include "workposition.h"
shimizuta 2:4515e8cc6b60 10 #define RIGHT//右用ならRIGHT,左用ならLEFT
shimizuta 2:4515e8cc6b60 11
shimizuta 2:4515e8cc6b60 12 Ticker ticker;
shimizuta 2:4515e8cc6b60 13 CAN can(pin_can_rd,pin_can_td);
shimizuta 2:4515e8cc6b60 14 int counterpart_is_in_common;
shimizuta 2:4515e8cc6b60 15 char can_pub_data[kCanlength_rightleft];
shimizuta 7:35972aae0647 16
shimizuta 5:af5ccfce1b90 17 const double kTicker_s = 0.01;
shimizuta 2:4515e8cc6b60 18 const int kCanCount = kCanTicker_s / kTicker_s;
shimizuta 7:35972aae0647 19 const int kPIDCount = kPIDTicker_s / kTicker_s;
shimizuta 7:35972aae0647 20 const int kServoCount = kServoTicker_s / kTicker_s;
shimizuta 7:35972aae0647 21 const int kCountReset=kPIDCount*kServoCount*kCanCount;
shimizuta 2:4515e8cc6b60 22
shimizuta 2:4515e8cc6b60 23 void TimerInterrupt();
shimizuta 2:4515e8cc6b60 24 void CanRead();
shimizuta 2:4515e8cc6b60 25 void CanSend();
shimizuta 2:4515e8cc6b60 26
shimizuta 2:4515e8cc6b60 27 void InterruptSetup()
shimizuta 2:4515e8cc6b60 28 {
shimizuta 2:4515e8cc6b60 29 can.frequency(kCanFrequency);
shimizuta 2:4515e8cc6b60 30 ticker.attach(TimerInterrupt,kTicker_s);
shimizuta 2:4515e8cc6b60 31 }
shimizuta 2:4515e8cc6b60 32 void TimerInterrupt()
shimizuta 2:4515e8cc6b60 33 {
shimizuta 7:35972aae0647 34 static int count = 0;
shimizuta 2:4515e8cc6b60 35 PIDInterrupt();
shimizuta 7:35972aae0647 36 if(count % kServoCount==0){
shimizuta 7:35972aae0647 37 ServoTargetInterrupt();
shimizuta 7:35972aae0647 38 }
shimizuta 13:126c3f7f9b89 39 /*
shimizuta 7:35972aae0647 40 if(count % kCanCount==0){
shimizuta 2:4515e8cc6b60 41 CanRead();
shimizuta 2:4515e8cc6b60 42 CanSend();
shimizuta 2:4515e8cc6b60 43 }
shimizuta 13:126c3f7f9b89 44 */
shimizuta 7:35972aae0647 45 if(count == kCountReset) count=0;
shimizuta 7:35972aae0647 46 count++;
shimizuta 2:4515e8cc6b60 47 }
shimizuta 2:4515e8cc6b60 48 int GetCounterpartIsInCommon()
shimizuta 2:4515e8cc6b60 49 {
shimizuta 18:05f5a3323bda 50 if(shootingbox[9].is_exist == 0) counterpart_is_in_common = 1;
shimizuta 2:4515e8cc6b60 51 return counterpart_is_in_common;
shimizuta 2:4515e8cc6b60 52 }
shimizuta 2:4515e8cc6b60 53
shimizuta 2:4515e8cc6b60 54 void CanRead()
shimizuta 2:4515e8cc6b60 55 {
shimizuta 2:4515e8cc6b60 56 CANMessage msg;
shimizuta 2:4515e8cc6b60 57 if(!can.read(msg)) {
shimizuta 2:4515e8cc6b60 58 return;
shimizuta 2:4515e8cc6b60 59 }
shimizuta 2:4515e8cc6b60 60 switch (msg.id) {
shimizuta 2:4515e8cc6b60 61 #ifdef RIGHT
shimizuta 2:4515e8cc6b60 62 case CANID_LEFT :
shimizuta 2:4515e8cc6b60 63 #elif defined LEFT
shimizuta 2:4515e8cc6b60 64 case CANID_RIGHT :
shimizuta 2:4515e8cc6b60 65 #endif
shimizuta 2:4515e8cc6b60 66 counterpart_is_in_common = msg.data[0];
shimizuta 2:4515e8cc6b60 67 break;
shimizuta 2:4515e8cc6b60 68
shimizuta 2:4515e8cc6b60 69 }
shimizuta 2:4515e8cc6b60 70 }
shimizuta 2:4515e8cc6b60 71 void CanSend()
shimizuta 2:4515e8cc6b60 72 {
shimizuta 2:4515e8cc6b60 73 static int state = 1;
shimizuta 2:4515e8cc6b60 74 switch(state) {
shimizuta 2:4515e8cc6b60 75 #ifdef RIGHT
shimizuta 2:4515e8cc6b60 76 case CANID_RIGHT :
shimizuta 2:4515e8cc6b60 77 #elif defined LEFT
shimizuta 2:4515e8cc6b60 78 case CANID_LEFT:
shimizuta 2:4515e8cc6b60 79 #endif
shimizuta 2:4515e8cc6b60 80 {
shimizuta 13:126c3f7f9b89 81 double now_position_mm[3] = {GetNowTipLocateX(),GetNowTipLocateY(),GetNowTipLocateZ()};
shimizuta 18:05f5a3323bda 82 if(CheckBanArea(0, now_position_mm[0], now_position_mm) == 0) can_pub_data[0] = 1;
shimizuta 18:05f5a3323bda 83 else can_pub_data[0] = 0;
shimizuta 2:4515e8cc6b60 84 CANMessage msg(state,can_pub_data,kCanlength_rightleft);
shimizuta 2:4515e8cc6b60 85 can.write(msg);
shimizuta 2:4515e8cc6b60 86 break;
shimizuta 2:4515e8cc6b60 87 }
shimizuta 2:4515e8cc6b60 88 }
shimizuta 2:4515e8cc6b60 89 state ++;
shimizuta 2:4515e8cc6b60 90 if(state >= CANID_FINISH) {
shimizuta 2:4515e8cc6b60 91 state = 1;
shimizuta 2:4515e8cc6b60 92 }
shimizuta 2:4515e8cc6b60 93 }