yei
Dependencies: interface mbed enc_1multi calPID motorout KondoServoLibrary
Fork of cat18_operate by
interrupt/interrupt.cpp
- Committer:
- shimizuta
- Date:
- 2018-08-09
- Revision:
- 7:35972aae0647
- Parent:
- 5:af5ccfce1b90
- Child:
- 13:126c3f7f9b89
File content as of revision 7:35972aae0647:
#include "interrupt.h" #include "mbed.h" #include "go.h" #include "check.h" #include "pinnames.h" #include "cat18_can_info.h" #define RIGHT//右用ならRIGHT,左用ならLEFT Ticker ticker; 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(); void CanSend(); void InterruptSetup() { can.frequency(kCanFrequency); ticker.attach(TimerInterrupt,kTicker_s); } void TimerInterrupt() { static int count = 0; PIDInterrupt(); if(count % kServoCount==0){ ServoTargetInterrupt(); } if(count % kCanCount==0){ CanRead(); CanSend(); } if(count == kCountReset) count=0; count++; } int GetCounterpartIsInCommon() { return counterpart_is_in_common; } void CanRead() { CANMessage msg; if(!can.read(msg)) { return; } switch (msg.id) { #ifdef RIGHT case CANID_LEFT : #elif defined LEFT case CANID_RIGHT : #endif counterpart_is_in_common = msg.data[0]; break; } } void CanSend() { static int state = 1; switch(state) { #ifdef RIGHT case CANID_RIGHT : #elif defined LEFT case CANID_LEFT: #endif { can_pub_data[0] = IsInCommonArea(); CANMessage msg(state,can_pub_data,kCanlength_rightleft); can.write(msg); break; } } state ++; if(state >= CANID_FINISH) { state = 1; } }