Dead by Daylight

Dependencies:   mbed Servo

System/Process/Process.cpp

Committer:
t_yamamoto
Date:
2018-01-16
Revision:
1:e73cf2469f83
Parent:
0:562021ed1ba9
Child:
2:db575b3b2171

File content as of revision 1:e73cf2469f83:

#include "Process.h"

#include "mbed.h"
#include "../../Communication/XBee/XBee.h"
#include "../../Input/Switch/Switch.h"
#include "../../Output/Motor/Motor.h"
//_____________________
/*---------------- HOW TO WRITE ----------------/

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

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

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

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








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

// #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].dir = 12.3;
            motor[TIRE_R].dir = 12.3;
        }

     motor[0].dirは     FRONT (正転)
                        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 = FRONT;
                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 ------------------------*/
//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

        if(controller->Button.X)        motor[0].dir = FOR;
        else if(controller->Button.B)   motor[0].dir = BACK;
        else                            motor[0].dir = FREE;

        if(controller->Button.A)        motor[1].dir = FOR;
        else if(controller->Button.Y)   motor[1].dir = BACK;
        else                            motor[1].dir = FREE;

        if(controller->Button.UP)        motor[2].dir = FOR;
        else if(controller->Button.DOWN) motor[2].dir = BACK;
        else                             motor[2].dir = FREE;

        if(controller->Button.RIGHT)     motor[3].dir = FOR;
        else if(controller->Button.LEFT) motor[3].dir = BACK;
        else                             motor[3].dir = FREE;

        if(controller->Button.R)        motor[4].dir = FOR;
        else if(controller->Button.L)   motor[4].dir = BACK;
        else                            motor[4].dir = FREE;

        motor[0].pwm = 20;
        motor[1].pwm = 20;
        motor[2].pwm = 20;
        motor[3].pwm = 20;
        motor[4].pwm = 20;

        if(controller->Button.ZL)       motor[0].pwm = 100;
        if(controller->Button.ZR)       motor[1].pwm = 100;
        if(controller->Button.SELECT)   motor[2].pwm = 100;
        if(controller->Button.HOME)     motor[3].pwm = 100;
        if(controller->Button.START)    motor[4].pwm = 100;

        if(Switch::checkPushed(limitSw[0])) motor[0].pwm = 0;
        if(Switch::checkPushed(limitSw[1])) motor[1].pwm = 0;
        if(Switch::checkPushed(limitSw[2])) motor[2].pwm = 0;
        if(Switch::checkPushed(limitSw[3])) motor[3].pwm = 0;


//↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
//____________________________

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