aaaaa

Dependencies:   mbed Servo

System/Process/Process.cpp

Committer:
Ryosei
Date:
2019-02-25
Revision:
12:8321e464475f
Parent:
11:88f17bc0724f

File content as of revision 12:8321e464475f:


//2018/02/24のやつ

#include "Process.h"
#include "mbed.h"
#include "../../Communication/XBee/XBee.h"
#include "../../Input/Switch/Switch.h"
#include "../../Output/Motor/Motor.h"
#include "../../Output/Servo/Servo.h"

//_____________________
/*---------------- HOW TO WRITE ----------------/

    ・motor の割り当てを決める
        #define TIRE_L 1

    ・リミットスイッチの割り当てを決める
        #define ARM_L 1

    ・他にも自由に定義してもいいです (pwmとか)

/---------------- HOW TO WRITE ----------------*/
//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

#define a 0
#define b 1
#define c 2
#define d 3
#define e 4
#define ARMlim 0
#define lim 1


int Air0=0;
int Air1=1;
int homes=0;



//////////////////関数、タイマーの宣言///////////////
DigitalOut Air[]= {
    DigitalOut(A5),
    DigitalOut(A4),
};
Timer Airtime;
Timer home;
void AirOut(int pin,int mode)
{
    Air[pin]=mode;
}
////////////
float s=Airtime.read();//エアータイム

int a_array[15][15] = {
    {-80, -70, -60, -50, -40, -20, -10, 0,   10,  20,  40,  50,  60,  70,  80},
    {-79, -69, -55, -47, -35, -20, -10, 0,   10,  20,  35,  47,  55,  69,  79},
    {-77, -68, -50, -45, -30, -20, -10, 0,   10,  20,  30,  45,  50,  68,  77},
    {-75, -67, -49, -40, -25, -20, -10, 0,   10,  20,  25,  40,  49,  67,  75},
    {-73, -66, -48, -37, -20, -20, -10, 0,   10,  20,  20,  37,  48,  66,  73},
    {-71, -62, -46, -32, -20, -10, 0, 0,   0,  10,  20,  32,  46,  62,  71},
    {-70, -60, -45, -30, -20, -10, 0, 0,   0,  10,  20,  30,  45,  60,  70},
    {-71, -62, -46, -32, 10, -10, 0, 0,   0,  10,  20,  32,  46,  62,  71},
    {-72, -64, -47, -35, 20, -10, -10, 0,   10,  10,  20,  35,  47,  64,  72},
    {-73, -66, -48, -37, -20, -20, -10, 0,   10,  20,  20,  37,  48,  66,  73},
    {-75, -67, -49, -40, 40, -20, -10, 0,   10,  20,  25,  40,  49,  67,  75},
    {-77, -68, -50, -45, 60, -20, -10, 0,   10,  20,  30,  45,  50,  68,  77},
    {-79, -69, -55, -47, 70, -20, -10, 0,   10,  20,  35,  47,  55,  69,  79},
    {-80, -70, -60, -50, -40, -20, -10, 0,   10,  20,  40,  50,  60,  70,  80},
    {-80, -70, -60, -50, -40, -20,s-10, 0,   10,  20,  40,  50,  60,  70,  80}
};

int b_array[15][15] = {
    {80,  80,  80, 77, 75, 72, 71, 70,  60,  50,  40,  30,  20,  10,  0},
    {80,  80,  75, 70, 65, 60, 55, 50,  45,  40,  30,  20,  10,  0,  -10},
    {80,  71,  70, 60, 55, 50, 45, 40,  35,  30,  20,  10,  0,   -10, -13},
    {60,  60,  57, 50, 45, 40, 35, 30,  25,  20,  10,  0,  -10, -13, -17},
    {50,  50,  50, 40, 35, 30, 23, 20,  15,  10,  0,  -10, -15, -17, -20},
    {45,  45,  43, 35, 30, 25, 10, 10,  10,  0,  -10, -15, -20, -20, -25},
    {40,  37,  35, 30, 25, 20, 0, 0,  0,  -10, -15, -20, -25, -25, -30},
    {35,  30,  30, 25, 20, 15, 0, 0,  0,  -15, -20, -25, -30, -30, -35},
    {30,  25,  25, 20, 15, 10, 0, 0,  0,  -20, -25, -30, -35, -37, -40},
    {20,  17,  15, 10, 0, -10, -15,-20, -23, -30,-35,-40,-50,-50, -50},
    {17,  13,  10, 0, -10, -20, -25,-30, -35, -40,-45,-50,-57,-60, -60},
    {13,  10,  0, -10, -20, -30, -35,-40, -45, -50,-55,-60, -70, -71, -80},
    {10,  0,  -10, -20, -30, -40, -45,-50, -55, -60,-65,-70,-75,-80, -80},
    {0,  -10, -20, -30, -40, -50, -60,-70, -71, -72,-75,-77,-80,-80, -80},
    {0,  -10, -20, -30, -40, -50, -60,-70, -71, -72,-75,-77,-80,-80, -80}
};

int c_array[15][15] = {
    {0,   10,  20, 30, 40, 50, 60,70,  71,  72, 75, 77, 80, 80, 80},
    {-10, 0, 10, 20, 30, 40, 45,50, 55, 60,65,70,75,80,80},
    {-13, -10, 0, 10, 20, 30, 35,40, 45, 50,55,60,70,71,80},
    {-17, -13, -10, 0, 10, 20, 25,30, 35, 40,45,50,57,60,60},
    {-20, -17, -15, -10, 0, 10, 15,20, 23, 30,35,40,50,50,50},
    {-25, -20, -20, -15, -10, 0, 10,10, 10, 25,30,35,43,45,45},
    {-30, -25, -25, -20, -15, -10, 0,0, 0, 20,25,30,35,37,40},
    {-35, -30, -30, -25, -20, -15, 0,0, 0, 15,20,25,30,30,35},
    {-40, -37, -35, -30, -25, -20, 0,0, 0, 10,15,20,25,25,30},
    {-50, -50, -50, -40, -35, -30, -23,-20, -15, -10,0,10,15,17,20},
    {-60, -60, -57, -50, -45, -40, -35,-30, -25, -20,-10,0,10,13,17},
    {-80, -71, -70, -60, -55, -50, -45,-40, -35, -30,-20,-10,0,10,13},
    {-80, -80, -75, -70, -65, -60, -55,-50, -45, -40,-30,-20,-10,0,10},
    {-80, -80, -80, -77, -75, -72, -71,-70, -60, -50,-40,-30,-20,-10,0},
    {-80, -80, -80, -77, -75, -72, -71,-70, -60, -50,-40,-30,-20,-10,0}
};






#define usiro 0
#define mae 0
uint8_t motorData[5];
uint8_t pwmData[5];

int conlx;
int conly;
int conrx;
int conry;

int mode=1;

//↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
//_____________________

//#define USE_USB_SERIAL
#ifdef USE_USB_SERIAL
Serial pc(SERIAL_TX, SERIAL_RX);
#endif
XBEE::ControllerData *controller;
MOTOR::MotorStatus motor[MOUNTING_MOTOR_NUM];

using namespace SWITCH;

void SystemProcess(void)
{
    while(true) {
        controller = XBEE::Controller::GetData();
//____________________________
        /*------------------------ HOW TO WRITE ------------------------/

            ここにメインのプログラムを書く

            ・コントローラから受け取ったデータをもとに動作のプログラムを書く
             (コントローラのデータは controller-> で取る)

                if(controller->Button.RIGHT) {
                    motor[TIRE_L].dir = FOR;
                    motor[TIRE_R].dir = BACK;
                    motor[TIRE_L].pwm = 12.3;
                    motor[TIRE_R].pwm = 12.3;
                }

             motor[0].dirは     FOR   (正転)
                                BACK  (逆転)
                                BRAKE (ブレーキ)
                                FREE  (フリー)

             motor[0].pwmは     0.0(%) ~ 100.0(%)

             controllerは       XBee.hの構造体の中身

             (AnalogL・Rを使いたかったら、頑張って考える or 聞いてください)

            ・リミットスイッチの値をもとに動作のプログラムを書く

                if(Switch::CheckPushed(ARM_L))
                {
                    if(controller->Button.L)
                    {
                        motor[ARM].dir = FOR;
                        motor[ARM].pwm = 80.0;
                    }
                    if(motor[ARM].dir == BACK)
                    {
                        motor[ARM].dir = BRAKE;
                    }
                }

             →関数 Switch::CheckPushed の引数はリミットスイッチの名前 (limitSw[0]みたいな), 返り値はbool型 (true or false)

            ・他にもやりたいことがあったら自由にどうぞ

            ps.わからないことがあったら聞いてください

        /------------------------ HOW TO WRITE ------------------------*/
//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

        conlx = controller->AnalogL.X;
        conly = controller->AnalogL.Y;
        conrx = controller->AnalogR.X;
        conry = controller->AnalogR.Y;
//conba = controller->Button.A;
//conbb = controller->Button.B;
//conby = controller->Button.Y;
//conbx = controller->Button.X;

        if(a_array[conly][conlx]<0) {
            motor[a].pwm = (-1*a_array[conly][conlx]*100)/80;
            motor[a].dir = FOR;
        } else if(a_array[conly][conlx] > 0) {
            motor[a].pwm = (a_array[conly][conlx]*100)/80;
            motor[a].dir = BACK;
        } else if(a_array[conly][conlx] == 0) {
            if(conry < 6) {
                motor[a].dir = BACK;
                motor[b].dir = BACK;
                motor[c].dir = BACK;
                motor[a].pwm = 100.0;
                motor[b].pwm = 100.0;
                motor[c].pwm = 100.0;
            } else if(conry > 8) {
                motor[a].dir = FOR;
                motor[b].dir = FOR;
                motor[c].dir = FOR;
                motor[a].pwm = 100.0;
                motor[b].pwm = 100.0;
                motor[c].pwm = 100.0;
            } else {
                motor[a].dir = BRAKE;
                motor[b].dir = BRAKE;
                motor[c].dir = BRAKE;
                motor[a].pwm = 100.0;
                motor[b].pwm = 100.0;
                motor[c].pwm = 100.0;
            }
        }

        if(b_array[conly][conlx] <0 ) {
            motor[b].pwm = (-1*b_array[conly][conlx]*100)/80;
            motor[b].dir = FOR;
        } else if(b_array[conly][conlx] > 0) {
            motor[b].pwm = (b_array[conly][conlx]*100)/80;
            motor[b].dir = BACK;
        } else if(a_array[conly][conlx] == 0 ) {
            if(conrx < 6 ) {
                motor[a].dir = BACK;
                motor[b].dir = BACK;
                motor[c].dir = BACK;
                motor[a].pwm = 100.0;
                motor[b].pwm = 100.0;
                motor[c].pwm = 100.0;
            } else if(conrx > 8) {
                motor[a].dir = FOR;
                motor[b].dir = FOR;
                motor[c].dir = FOR;
                motor[a].pwm = 100.0;
                motor[b].pwm = 100.0;
                motor[c].pwm = 100.0;
            } else {
                motor[a].dir = BRAKE;
                motor[b].dir = BRAKE;
                motor[c].dir = BRAKE;
                motor[a].pwm = 100.0;
                motor[b].pwm = 100.0;
                motor[c].pwm = 100.0;
            }
        }

        if(c_array[conly][conlx] <0 ) {
            motor[c].pwm =(-1*c_array[conly][conlx]*100)/80;
            motor[c].dir = BACK;
        } else if(c_array[conly][conlx] > 0) {
            motor[c].pwm =(c_array[conly][conlx]*100)/80;
            motor[c].dir = FOR;
        } else if(a_array[conly][conlx] == 0 ) {
            if(conrx < 6 ) {
                motor[a].dir = BACK;
                motor[b].dir = BACK;
                motor[c].dir = BACK;
                motor[a].pwm = 100.0;
                motor[b].pwm = 100.0;
                motor[c].pwm = 100.0;
            } else if(conrx > 8) {
                motor[a].dir = FOR;
                motor[b].dir = FOR;
                motor[c].dir = FOR;
                motor[a].pwm = 100.0;
                motor[b].pwm = 100.0;
                motor[c].pwm = 100.0;
            } else {
                motor[a].dir = BRAKE;
                motor[b].dir = BRAKE;
                motor[c].dir = BRAKE;
                motor[a].pwm = 100.0;
                motor[b].pwm = 100.0;
                motor[c].pwm = 100.0;
            }
        }

////////////課題1////////////
        if(controller->Button.X) {
            if(Switch::checkPushed(ARMlim)) {
                motor[d].dir = BRAKE;
                motor[d].pwm = 100;
            } else {
                motor[d].dir = FOR;
                motor[d].pwm = 100;
            }
        } else   if(controller->Button.Y) {
            motor[d].dir = BACK;
            motor[d].pwm = 100;
        } else {
            motor[d].dir = BRAKE;
            motor[d].pwm = 100;
        }
        if(controller->Button.A) {
            AirOut(Air0,1);
        } else if(controller->Button.B) {
            AirOut(Air0,0);
        }
//////////////課題2/////////////////////
        s=Airtime.read();
        if((controller->Button.ZL)&&(mode==1)) {
            mode=2;
            Airtime.start();
        }
        if((mode==2)&&(s>=1)) {
            mode=3;
        }
        if((mode==3)&&(s>=3)) {
            mode=4;
        }
        if((mode==4)&&(!(Switch::checkPushed(lim)))) {
            mode=5;
            Airtime.stop();
            Airtime.reset();
        }
        if((mode==5)&&(Switch::checkPushed(lim))) {
            mode=1;
        }

        if(mode==1) {
            AirOut(1,1);
            motor[4].dir=BRAKE;
            motor[4].pwm=100;
        } else if(mode==2) {
            AirOut(1,0);
        } else if(mode==3) {
            AirOut(1,1);
        } else if(mode==4) {
            motor[4].dir=FOR;
            motor[4].pwm=50;
        } else if(mode==5) {
            motor[4].dir=FOR;
            motor[4].pwm=50;
        } else {
            mode=1;
            AirOut(1,1);
        }

//↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
//___________________________



        MOTOR::Motor::Update(motor);
    }
}