yei
Dependencies: interface mbed enc_1multi calPID motorout KondoServoLibrary
Fork of cat18_operate by
interrupt/interrupt.cpp
- Committer:
- shimizuta
- Date:
- 2018-08-09
- Revision:
- 4:187c62291654
- Parent:
- 2:4515e8cc6b60
- Child:
- 5:af5ccfce1b90
File content as of revision 4:187c62291654:
#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 int kCanCount = kCanTicker_s / kTicker_s; void TimerInterrupt(); void CanRead(); void CanSend(); void InterruptSetup() { can.frequency(kCanFrequency); ticker.attach(TimerInterrupt,kTicker_s); } void TimerInterrupt() { PIDInterrupt(); ServoTargetInterrupt(); static int i = 0; ++i; if(i > kCanCount) { CanRead(); CanSend(); i = 0; } } 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; } }