aaaaa

Dependencies:   mbed Servo

System/Process/Process.cpp

Committer:
Ryosei
Date:
2019-02-18
Revision:
9:6901b1dfa688
Parent:
8:cb53beff4bb2
Child:
10:53a92f2ab1c4

File content as of revision 9:6901b1dfa688:

//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 TIRE_1 0
#define TIRE_2 1
#define TIRE_3 2
#define ARM 3
#define AIR_1 0
#define AIR_2 1
#define ARM_roll 0

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

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

};
Timer Airtime;
void AirOut(int pin,int mode){
    Air[pin]=mode;
}
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 ------------------------*/
//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
        float precision;
        float s=Airtime.read();
        pc.printf("time= %d",Airtime.read());
        if(controller->Button.ZR){
            precision=0.5;
        }else{
            precision=1.0;
        }
        
        if(controller->Button.X){
            motor[ARM].dir=FOR;
            motor[ARM].pwm=80;
        }else if((controller->Button.Y)&&(Switch::checkPushed(ARM_roll))){
            motor[ARM].dir=BACK;
            motor[ARM].pwm=80;
        }else{
            motor[ARM].dir=BRAKE;
            motor[ARM].pwm=100;
        }
        
        
        if(controller->Button.L) {
            motor[TIRE_1].dir = FOR;
            motor[TIRE_2].dir = FOR;
            motor[TIRE_3].dir = FOR;
            motor[TIRE_1].pwm = 100*precision;
            motor[TIRE_2].pwm = 100*precision;
            motor[TIRE_3].pwm = 100*precision;
        }else if(controller->Button.R){
            motor[TIRE_1].dir = BACK;
            motor[TIRE_2].dir = BACK;
            motor[TIRE_3].dir = BACK;
            motor[TIRE_1].pwm = 100*precision;
            motor[TIRE_2].pwm = 100*precision;
            motor[TIRE_3].pwm = 100*precision;
        }else if(controller->Button.RIGHT) {
            motor[TIRE_1].dir = BACK;
            motor[TIRE_2].dir = FOR;
            motor[TIRE_3].dir = FOR;
            motor[TIRE_1].pwm = 100*precision;
            motor[TIRE_2].pwm = 60*precision;
            motor[TIRE_3].pwm = 60*precision;
        }else if(controller->Button.LEFT){
            motor[TIRE_1].dir = FOR;
            motor[TIRE_2].dir = BACK;
            motor[TIRE_3].dir = BACK;
            motor[TIRE_1].pwm = 100*precision;
            motor[TIRE_2].pwm = 60*precision;
            motor[TIRE_3].pwm = 60*precision;
        }else if(controller->Button.DOWN){
            motor[TIRE_1].dir = BRAKE;
            motor[TIRE_2].dir = FOR;
            motor[TIRE_3].dir = BACK;
                        motor[TIRE_1].pwm = 100;
            motor[TIRE_2].pwm = 100*precision;
            motor[TIRE_3].pwm = 100*precision;
        }else if(controller->Button.UP){
            motor[TIRE_1].dir = BRAKE;
            motor[TIRE_2].dir = BACK;
            motor[TIRE_3].dir = FOR;
            motor[TIRE_1].pwm = 100;
            motor[TIRE_2].pwm = 100*precision;
            motor[TIRE_3].pwm = 100*precision;
        }else if((controller->Button.UP) && (controller->Button.RIGHT)){
            motor[TIRE_1].dir = BACK;
            motor[TIRE_2].dir = BRAKE;
            motor[TIRE_3].dir = FOR;
            motor[TIRE_1].pwm = 100*precision;
            motor[TIRE_2].pwm = 100;
            motor[TIRE_3].pwm = 100*precision;          
        }else if((controller->Button.UP) && (controller->Button.LEFT)){
            motor[TIRE_1].dir = FOR;
            motor[TIRE_2].dir = BACK;
            motor[TIRE_3].dir = BRAKE;
            motor[TIRE_1].pwm = 100*precision;
            motor[TIRE_2].pwm = 100*precision;
            motor[TIRE_3].pwm = 100; 
        }else if((controller->Button.DOWN) && (controller->Button.RIGHT)){
            motor[TIRE_1].dir = BACK;
            motor[TIRE_2].dir = FOR;
            motor[TIRE_3].dir = BRAKE;
            motor[TIRE_1].pwm = 100*precision;
            motor[TIRE_2].pwm = 100*precision;
            motor[TIRE_3].pwm = 100; 
        }else if((controller->Button.DOWN) && (controller->Button.LEFT)){
            motor[TIRE_1].dir = FOR;
            motor[TIRE_2].dir = BRAKE;
            motor[TIRE_3].dir = BACK;
            motor[TIRE_1].pwm = 100*precision;
            motor[TIRE_2].pwm = 100;
            motor[TIRE_3].pwm = 100*precision;   
        }else{
            motor[TIRE_1].dir=BRAKE;
            motor[TIRE_2].dir=BRAKE;
            motor[TIRE_3].dir=BRAKE;
            motor[TIRE_1].pwm=100;
            motor[TIRE_2].pwm=100;
            motor[TIRE_3].pwm=100;
        }
        
        if(controller->Button.A){
            AirOut(AIR_1,1);
        }else if(controller->Button.B){
            AirOut(AIR_1,0);
        }
        
        if(controller->Button.ZL){
            Airtime.start();
            AirOut(AIR_2,0);
        }
        if(s>1){
            Airtime.stop();
            Airtime.reset();
            AirOut(AIR_2,1);
        }


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

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