unkounko

Dependencies:   mbed Servo

Committer:
t_yamamoto
Date:
Tue Jan 16 08:47:01 2018 +0000
Revision:
1:e73cf2469f83
Parent:
0:562021ed1ba9
Child:
2:db575b3b2171
release version;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
t_yamamoto 0:562021ed1ba9 1 #include "Process.h"
t_yamamoto 0:562021ed1ba9 2
t_yamamoto 0:562021ed1ba9 3 #include "mbed.h"
t_yamamoto 0:562021ed1ba9 4 #include "../../Communication/XBee/XBee.h"
t_yamamoto 0:562021ed1ba9 5 #include "../../Input/Switch/Switch.h"
t_yamamoto 0:562021ed1ba9 6 #include "../../Output/Motor/Motor.h"
t_yamamoto 0:562021ed1ba9 7 //_____________________
t_yamamoto 0:562021ed1ba9 8 /*---------------- HOW TO WRITE ----------------/
t_yamamoto 0:562021ed1ba9 9
t_yamamoto 0:562021ed1ba9 10 ・motor の割り当てを決める
t_yamamoto 0:562021ed1ba9 11 #define TIRE_L 1
t_yamamoto 0:562021ed1ba9 12
t_yamamoto 0:562021ed1ba9 13 ・リミットスイッチの割り当てを決める
t_yamamoto 0:562021ed1ba9 14 #define ARM_L 1
t_yamamoto 0:562021ed1ba9 15
t_yamamoto 0:562021ed1ba9 16 ・他にも自由に定義してもいいです (pwmとか)
t_yamamoto 0:562021ed1ba9 17
t_yamamoto 0:562021ed1ba9 18 /---------------- HOW TO WRITE ----------------*/
t_yamamoto 0:562021ed1ba9 19 //↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
t_yamamoto 0:562021ed1ba9 20
t_yamamoto 0:562021ed1ba9 21
t_yamamoto 0:562021ed1ba9 22
t_yamamoto 0:562021ed1ba9 23
t_yamamoto 0:562021ed1ba9 24
t_yamamoto 0:562021ed1ba9 25
t_yamamoto 0:562021ed1ba9 26
t_yamamoto 0:562021ed1ba9 27
t_yamamoto 0:562021ed1ba9 28 //↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
t_yamamoto 0:562021ed1ba9 29 //_____________________
t_yamamoto 0:562021ed1ba9 30
t_yamamoto 0:562021ed1ba9 31 // #define USE_USB_SERIAL
t_yamamoto 0:562021ed1ba9 32 #ifdef USE_USB_SERIAL
t_yamamoto 0:562021ed1ba9 33 Serial pc(SERIAL_TX, SERIAL_RX);
t_yamamoto 0:562021ed1ba9 34 #endif
t_yamamoto 0:562021ed1ba9 35 XBEE::ControllerData *controller;
t_yamamoto 0:562021ed1ba9 36 MOTOR::MotorStatus motor[MOUNTING_MOTOR_NUM];
t_yamamoto 0:562021ed1ba9 37
t_yamamoto 0:562021ed1ba9 38 using namespace SWITCH;
t_yamamoto 0:562021ed1ba9 39
t_yamamoto 0:562021ed1ba9 40 void SystemProcess(void) {
t_yamamoto 0:562021ed1ba9 41 while(true) {
t_yamamoto 0:562021ed1ba9 42 controller = XBEE::Controller::GetData();
t_yamamoto 0:562021ed1ba9 43 //____________________________
t_yamamoto 0:562021ed1ba9 44 /*------------------------ HOW TO WRITE ------------------------/
t_yamamoto 0:562021ed1ba9 45
t_yamamoto 0:562021ed1ba9 46 ここにメインのプログラムを書く
t_yamamoto 0:562021ed1ba9 47
t_yamamoto 0:562021ed1ba9 48 ・コントローラから受け取ったデータをもとに動作のプログラムを書く
t_yamamoto 0:562021ed1ba9 49 (コントローラのデータは controller-> で取る)
t_yamamoto 0:562021ed1ba9 50
t_yamamoto 0:562021ed1ba9 51 if(controller->Button.RIGHT) {
t_yamamoto 0:562021ed1ba9 52 motor[TIRE_L].dir = FOR;
t_yamamoto 0:562021ed1ba9 53 motor[TIRE_R].dir = BACK;
t_yamamoto 0:562021ed1ba9 54 motor[TIRE_L].dir = 12.3;
t_yamamoto 0:562021ed1ba9 55 motor[TIRE_R].dir = 12.3;
t_yamamoto 0:562021ed1ba9 56 }
t_yamamoto 0:562021ed1ba9 57
t_yamamoto 0:562021ed1ba9 58 motor[0].dirは FRONT (正転)
t_yamamoto 0:562021ed1ba9 59 BACK (逆転)
t_yamamoto 0:562021ed1ba9 60 BRAKE (ブレーキ)
t_yamamoto 0:562021ed1ba9 61 FREE (フリー)
t_yamamoto 0:562021ed1ba9 62
t_yamamoto 0:562021ed1ba9 63 motor[0].pwmは 0.0(%) ~ 100.0(%)
t_yamamoto 0:562021ed1ba9 64
t_yamamoto 0:562021ed1ba9 65 controllerは XBee.hの構造体の中身
t_yamamoto 0:562021ed1ba9 66
t_yamamoto 0:562021ed1ba9 67 (AnalogL・Rを使いたかったら、頑張って考える or 聞いてください)
t_yamamoto 0:562021ed1ba9 68
t_yamamoto 0:562021ed1ba9 69 ・リミットスイッチの値をもとに動作のプログラムを書く
t_yamamoto 0:562021ed1ba9 70
t_yamamoto 0:562021ed1ba9 71 if(Switch::CheckPushed(ARM_L))
t_yamamoto 0:562021ed1ba9 72 {
t_yamamoto 0:562021ed1ba9 73 if(controller->Button.L)
t_yamamoto 0:562021ed1ba9 74 {
t_yamamoto 0:562021ed1ba9 75 motor[ARM].dir = FRONT;
t_yamamoto 0:562021ed1ba9 76 motor[ARM].pwm = 80.0;
t_yamamoto 0:562021ed1ba9 77 }
t_yamamoto 0:562021ed1ba9 78 if(motor[ARM].dir == BACK)
t_yamamoto 0:562021ed1ba9 79 {
t_yamamoto 0:562021ed1ba9 80 motor[ARM].dir = BRAKE;
t_yamamoto 0:562021ed1ba9 81 }
t_yamamoto 0:562021ed1ba9 82 }
t_yamamoto 0:562021ed1ba9 83
t_yamamoto 0:562021ed1ba9 84 →関数 Switch::CheckPushed の引数はリミットスイッチの名前 (limitSw[0]みたいな), 返り値はbool型 (true or false)
t_yamamoto 0:562021ed1ba9 85
t_yamamoto 0:562021ed1ba9 86 ・他にもやりたいことがあったら自由にどうぞ
t_yamamoto 0:562021ed1ba9 87
t_yamamoto 0:562021ed1ba9 88 ps.わからないことがあったら聞いてください
t_yamamoto 0:562021ed1ba9 89
t_yamamoto 0:562021ed1ba9 90 /------------------------ HOW TO WRITE ------------------------*/
t_yamamoto 0:562021ed1ba9 91 //↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
t_yamamoto 0:562021ed1ba9 92
t_yamamoto 1:e73cf2469f83 93 if(controller->Button.X) motor[0].dir = FOR;
t_yamamoto 1:e73cf2469f83 94 else if(controller->Button.B) motor[0].dir = BACK;
t_yamamoto 1:e73cf2469f83 95 else motor[0].dir = FREE;
t_yamamoto 0:562021ed1ba9 96
t_yamamoto 1:e73cf2469f83 97 if(controller->Button.A) motor[1].dir = FOR;
t_yamamoto 1:e73cf2469f83 98 else if(controller->Button.Y) motor[1].dir = BACK;
t_yamamoto 1:e73cf2469f83 99 else motor[1].dir = FREE;
t_yamamoto 0:562021ed1ba9 100
t_yamamoto 1:e73cf2469f83 101 if(controller->Button.UP) motor[2].dir = FOR;
t_yamamoto 1:e73cf2469f83 102 else if(controller->Button.DOWN) motor[2].dir = BACK;
t_yamamoto 1:e73cf2469f83 103 else motor[2].dir = FREE;
t_yamamoto 0:562021ed1ba9 104
t_yamamoto 1:e73cf2469f83 105 if(controller->Button.RIGHT) motor[3].dir = FOR;
t_yamamoto 1:e73cf2469f83 106 else if(controller->Button.LEFT) motor[3].dir = BACK;
t_yamamoto 1:e73cf2469f83 107 else motor[3].dir = FREE;
t_yamamoto 0:562021ed1ba9 108
t_yamamoto 1:e73cf2469f83 109 if(controller->Button.R) motor[4].dir = FOR;
t_yamamoto 1:e73cf2469f83 110 else if(controller->Button.L) motor[4].dir = BACK;
t_yamamoto 1:e73cf2469f83 111 else motor[4].dir = FREE;
t_yamamoto 0:562021ed1ba9 112
t_yamamoto 1:e73cf2469f83 113 motor[0].pwm = 20;
t_yamamoto 1:e73cf2469f83 114 motor[1].pwm = 20;
t_yamamoto 1:e73cf2469f83 115 motor[2].pwm = 20;
t_yamamoto 1:e73cf2469f83 116 motor[3].pwm = 20;
t_yamamoto 1:e73cf2469f83 117 motor[4].pwm = 20;
t_yamamoto 0:562021ed1ba9 118
t_yamamoto 1:e73cf2469f83 119 if(controller->Button.ZL) motor[0].pwm = 100;
t_yamamoto 1:e73cf2469f83 120 if(controller->Button.ZR) motor[1].pwm = 100;
t_yamamoto 1:e73cf2469f83 121 if(controller->Button.SELECT) motor[2].pwm = 100;
t_yamamoto 1:e73cf2469f83 122 if(controller->Button.HOME) motor[3].pwm = 100;
t_yamamoto 1:e73cf2469f83 123 if(controller->Button.START) motor[4].pwm = 100;
t_yamamoto 0:562021ed1ba9 124
t_yamamoto 1:e73cf2469f83 125 if(Switch::checkPushed(limitSw[0])) motor[0].pwm = 0;
t_yamamoto 1:e73cf2469f83 126 if(Switch::checkPushed(limitSw[1])) motor[1].pwm = 0;
t_yamamoto 1:e73cf2469f83 127 if(Switch::checkPushed(limitSw[2])) motor[2].pwm = 0;
t_yamamoto 1:e73cf2469f83 128 if(Switch::checkPushed(limitSw[3])) motor[3].pwm = 0;
t_yamamoto 0:562021ed1ba9 129
t_yamamoto 0:562021ed1ba9 130
t_yamamoto 0:562021ed1ba9 131 //↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
t_yamamoto 0:562021ed1ba9 132 //____________________________
t_yamamoto 0:562021ed1ba9 133
t_yamamoto 0:562021ed1ba9 134 MOTOR::Motor::Update(motor);
t_yamamoto 0:562021ed1ba9 135 }
t_yamamoto 0:562021ed1ba9 136 }
t_yamamoto 0:562021ed1ba9 137