yei

Dependencies:   interface mbed enc_1multi calPID motorout KondoServoLibrary

Fork of cat18_operate by Catch the GIANT Caplico!

interrupt/interrupt.cpp

Committer:
shimizuta
Date:
2018-08-17
Revision:
18:05f5a3323bda
Parent:
13:126c3f7f9b89
Child:
19:48c3af917932

File content as of revision 18:05f5a3323bda:

#include "interrupt.h"
#include "mbed.h"
#include "go.h"
#include "check.h"
#include "coordinate.h"
#include "pinnames.h"
#include "cat18_can_info.h"
#include "debug.h"
#include "workposition.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()
{
    if(shootingbox[9].is_exist == 0) counterpart_is_in_common = 1;
    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
        {
            double now_position_mm[3] = {GetNowTipLocateX(),GetNowTipLocateY(),GetNowTipLocateZ()};
            if(CheckBanArea(0, now_position_mm[0], now_position_mm) == 0) can_pub_data[0] = 1;
            else can_pub_data[0] = 0;
            CANMessage msg(state,can_pub_data,kCanlength_rightleft);
            can.write(msg);
            break;
        }
    }
    state ++;
    if(state >= CANID_FINISH) {
        state = 1;
    }
}