aaaaa

Dependencies:   mbed Servo

Committer:
Ryosei
Date:
Mon Feb 18 05:40:03 2019 +0000
Revision:
9:6901b1dfa688
Parent:
8:cb53beff4bb2
Child:
10:53a92f2ab1c4
unko

Who changed what in which revision?

UserRevisionLine numberNew contents of line
t_yamamoto 8:cb53beff4bb2 1 //2018/02/24のやつ
t_yamamoto 5:a802ab60df1b 2
t_yamamoto 0:562021ed1ba9 3 #include "Process.h"
t_yamamoto 0:562021ed1ba9 4
t_yamamoto 0:562021ed1ba9 5 #include "mbed.h"
t_yamamoto 0:562021ed1ba9 6 #include "../../Communication/XBee/XBee.h"
t_yamamoto 0:562021ed1ba9 7 #include "../../Input/Switch/Switch.h"
t_yamamoto 0:562021ed1ba9 8 #include "../../Output/Motor/Motor.h"
t_yamamoto 8:cb53beff4bb2 9 #include "../../Output/Servo/Servo.h"
t_yamamoto 8:cb53beff4bb2 10
t_yamamoto 0:562021ed1ba9 11 //_____________________
t_yamamoto 0:562021ed1ba9 12 /*---------------- HOW TO WRITE ----------------/
t_yamamoto 0:562021ed1ba9 13
t_yamamoto 0:562021ed1ba9 14 ・motor の割り当てを決める
t_yamamoto 0:562021ed1ba9 15 #define TIRE_L 1
t_yamamoto 0:562021ed1ba9 16
t_yamamoto 0:562021ed1ba9 17 ・リミットスイッチの割り当てを決める
t_yamamoto 0:562021ed1ba9 18 #define ARM_L 1
t_yamamoto 0:562021ed1ba9 19
t_yamamoto 0:562021ed1ba9 20 ・他にも自由に定義してもいいです (pwmとか)
t_yamamoto 0:562021ed1ba9 21
t_yamamoto 0:562021ed1ba9 22 /---------------- HOW TO WRITE ----------------*/
t_yamamoto 0:562021ed1ba9 23 //↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
t_yamamoto 0:562021ed1ba9 24
t_yamamoto 0:562021ed1ba9 25
Ryosei 9:6901b1dfa688 26 #define TIRE_1 0
Ryosei 9:6901b1dfa688 27 #define TIRE_2 1
Ryosei 9:6901b1dfa688 28 #define TIRE_3 2
Ryosei 9:6901b1dfa688 29 #define ARM 3
Ryosei 9:6901b1dfa688 30 #define AIR_1 0
Ryosei 9:6901b1dfa688 31 #define AIR_2 1
Ryosei 9:6901b1dfa688 32 #define ARM_roll 0
t_yamamoto 0:562021ed1ba9 33
t_yamamoto 0:562021ed1ba9 34 //↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
t_yamamoto 0:562021ed1ba9 35 //_____________________
t_yamamoto 0:562021ed1ba9 36
t_yamamoto 8:cb53beff4bb2 37 //#define USE_USB_SERIAL
t_yamamoto 0:562021ed1ba9 38 #ifdef USE_USB_SERIAL
t_yamamoto 0:562021ed1ba9 39 Serial pc(SERIAL_TX, SERIAL_RX);
t_yamamoto 0:562021ed1ba9 40 #endif
Ryosei 9:6901b1dfa688 41 Serial pc(SERIAL_TX,SERIAL_RX);
t_yamamoto 0:562021ed1ba9 42 XBEE::ControllerData *controller;
t_yamamoto 0:562021ed1ba9 43 MOTOR::MotorStatus motor[MOUNTING_MOTOR_NUM];
Ryosei 9:6901b1dfa688 44 DigitalOut Air[]={
Ryosei 9:6901b1dfa688 45 DigitalOut(A7),
Ryosei 9:6901b1dfa688 46 DigitalOut(A6),
t_yamamoto 0:562021ed1ba9 47
Ryosei 9:6901b1dfa688 48 };
Ryosei 9:6901b1dfa688 49 Timer Airtime;
Ryosei 9:6901b1dfa688 50 void AirOut(int pin,int mode){
Ryosei 9:6901b1dfa688 51 Air[pin]=mode;
Ryosei 9:6901b1dfa688 52 }
t_yamamoto 0:562021ed1ba9 53 using namespace SWITCH;
t_yamamoto 0:562021ed1ba9 54
t_yamamoto 8:cb53beff4bb2 55 void SystemProcess(void) {
t_yamamoto 0:562021ed1ba9 56 while(true) {
t_yamamoto 0:562021ed1ba9 57 controller = XBEE::Controller::GetData();
t_yamamoto 0:562021ed1ba9 58 //____________________________
t_yamamoto 0:562021ed1ba9 59 /*------------------------ HOW TO WRITE ------------------------/
t_yamamoto 0:562021ed1ba9 60
t_yamamoto 0:562021ed1ba9 61 ここにメインのプログラムを書く
t_yamamoto 0:562021ed1ba9 62
t_yamamoto 0:562021ed1ba9 63 ・コントローラから受け取ったデータをもとに動作のプログラムを書く
t_yamamoto 0:562021ed1ba9 64 (コントローラのデータは controller-> で取る)
t_yamamoto 0:562021ed1ba9 65
t_yamamoto 0:562021ed1ba9 66 if(controller->Button.RIGHT) {
t_yamamoto 0:562021ed1ba9 67 motor[TIRE_L].dir = FOR;
t_yamamoto 0:562021ed1ba9 68 motor[TIRE_R].dir = BACK;
t_yamamoto 7:f4252ddc480d 69 motor[TIRE_L].pwm = 12.3;
t_yamamoto 7:f4252ddc480d 70 motor[TIRE_R].pwm = 12.3;
t_yamamoto 0:562021ed1ba9 71 }
t_yamamoto 0:562021ed1ba9 72
t_yamamoto 6:c294736ba99d 73 motor[0].dirは FOR (正転)
t_yamamoto 0:562021ed1ba9 74 BACK (逆転)
t_yamamoto 0:562021ed1ba9 75 BRAKE (ブレーキ)
t_yamamoto 0:562021ed1ba9 76 FREE (フリー)
t_yamamoto 0:562021ed1ba9 77
t_yamamoto 0:562021ed1ba9 78 motor[0].pwmは 0.0(%) ~ 100.0(%)
t_yamamoto 0:562021ed1ba9 79
t_yamamoto 0:562021ed1ba9 80 controllerは XBee.hの構造体の中身
t_yamamoto 0:562021ed1ba9 81
t_yamamoto 0:562021ed1ba9 82 (AnalogL・Rを使いたかったら、頑張って考える or 聞いてください)
t_yamamoto 0:562021ed1ba9 83
t_yamamoto 0:562021ed1ba9 84 ・リミットスイッチの値をもとに動作のプログラムを書く
t_yamamoto 0:562021ed1ba9 85
t_yamamoto 0:562021ed1ba9 86 if(Switch::CheckPushed(ARM_L))
t_yamamoto 0:562021ed1ba9 87 {
t_yamamoto 0:562021ed1ba9 88 if(controller->Button.L)
t_yamamoto 0:562021ed1ba9 89 {
t_yamamoto 6:c294736ba99d 90 motor[ARM].dir = FOR;
t_yamamoto 0:562021ed1ba9 91 motor[ARM].pwm = 80.0;
t_yamamoto 0:562021ed1ba9 92 }
t_yamamoto 0:562021ed1ba9 93 if(motor[ARM].dir == BACK)
t_yamamoto 0:562021ed1ba9 94 {
t_yamamoto 0:562021ed1ba9 95 motor[ARM].dir = BRAKE;
t_yamamoto 0:562021ed1ba9 96 }
t_yamamoto 0:562021ed1ba9 97 }
t_yamamoto 0:562021ed1ba9 98
t_yamamoto 0:562021ed1ba9 99 →関数 Switch::CheckPushed の引数はリミットスイッチの名前 (limitSw[0]みたいな), 返り値はbool型 (true or false)
t_yamamoto 0:562021ed1ba9 100
t_yamamoto 0:562021ed1ba9 101 ・他にもやりたいことがあったら自由にどうぞ
t_yamamoto 0:562021ed1ba9 102
t_yamamoto 0:562021ed1ba9 103 ps.わからないことがあったら聞いてください
t_yamamoto 0:562021ed1ba9 104
t_yamamoto 0:562021ed1ba9 105 /------------------------ HOW TO WRITE ------------------------*/
t_yamamoto 0:562021ed1ba9 106 //↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
Ryosei 9:6901b1dfa688 107 float precision;
Ryosei 9:6901b1dfa688 108 float s=Airtime.read();
Ryosei 9:6901b1dfa688 109 pc.printf("time= %d",Airtime.read());
Ryosei 9:6901b1dfa688 110 if(controller->Button.ZR){
Ryosei 9:6901b1dfa688 111 precision=0.5;
Ryosei 9:6901b1dfa688 112 }else{
Ryosei 9:6901b1dfa688 113 precision=1.0;
Ryosei 9:6901b1dfa688 114 }
Ryosei 9:6901b1dfa688 115
Ryosei 9:6901b1dfa688 116 if(controller->Button.X){
Ryosei 9:6901b1dfa688 117 motor[ARM].dir=FOR;
Ryosei 9:6901b1dfa688 118 motor[ARM].pwm=80;
Ryosei 9:6901b1dfa688 119 }else if((controller->Button.Y)&&(Switch::checkPushed(ARM_roll))){
Ryosei 9:6901b1dfa688 120 motor[ARM].dir=BACK;
Ryosei 9:6901b1dfa688 121 motor[ARM].pwm=80;
Ryosei 9:6901b1dfa688 122 }else{
Ryosei 9:6901b1dfa688 123 motor[ARM].dir=BRAKE;
Ryosei 9:6901b1dfa688 124 motor[ARM].pwm=100;
Ryosei 9:6901b1dfa688 125 }
Ryosei 9:6901b1dfa688 126
Ryosei 9:6901b1dfa688 127
Ryosei 9:6901b1dfa688 128 if(controller->Button.L) {
Ryosei 9:6901b1dfa688 129 motor[TIRE_1].dir = FOR;
Ryosei 9:6901b1dfa688 130 motor[TIRE_2].dir = FOR;
Ryosei 9:6901b1dfa688 131 motor[TIRE_3].dir = FOR;
Ryosei 9:6901b1dfa688 132 motor[TIRE_1].pwm = 100*precision;
Ryosei 9:6901b1dfa688 133 motor[TIRE_2].pwm = 100*precision;
Ryosei 9:6901b1dfa688 134 motor[TIRE_3].pwm = 100*precision;
Ryosei 9:6901b1dfa688 135 }else if(controller->Button.R){
Ryosei 9:6901b1dfa688 136 motor[TIRE_1].dir = BACK;
Ryosei 9:6901b1dfa688 137 motor[TIRE_2].dir = BACK;
Ryosei 9:6901b1dfa688 138 motor[TIRE_3].dir = BACK;
Ryosei 9:6901b1dfa688 139 motor[TIRE_1].pwm = 100*precision;
Ryosei 9:6901b1dfa688 140 motor[TIRE_2].pwm = 100*precision;
Ryosei 9:6901b1dfa688 141 motor[TIRE_3].pwm = 100*precision;
Ryosei 9:6901b1dfa688 142 }else if(controller->Button.RIGHT) {
Ryosei 9:6901b1dfa688 143 motor[TIRE_1].dir = BACK;
Ryosei 9:6901b1dfa688 144 motor[TIRE_2].dir = FOR;
Ryosei 9:6901b1dfa688 145 motor[TIRE_3].dir = FOR;
Ryosei 9:6901b1dfa688 146 motor[TIRE_1].pwm = 100*precision;
Ryosei 9:6901b1dfa688 147 motor[TIRE_2].pwm = 60*precision;
Ryosei 9:6901b1dfa688 148 motor[TIRE_3].pwm = 60*precision;
Ryosei 9:6901b1dfa688 149 }else if(controller->Button.LEFT){
Ryosei 9:6901b1dfa688 150 motor[TIRE_1].dir = FOR;
Ryosei 9:6901b1dfa688 151 motor[TIRE_2].dir = BACK;
Ryosei 9:6901b1dfa688 152 motor[TIRE_3].dir = BACK;
Ryosei 9:6901b1dfa688 153 motor[TIRE_1].pwm = 100*precision;
Ryosei 9:6901b1dfa688 154 motor[TIRE_2].pwm = 60*precision;
Ryosei 9:6901b1dfa688 155 motor[TIRE_3].pwm = 60*precision;
Ryosei 9:6901b1dfa688 156 }else if(controller->Button.DOWN){
Ryosei 9:6901b1dfa688 157 motor[TIRE_1].dir = BRAKE;
Ryosei 9:6901b1dfa688 158 motor[TIRE_2].dir = FOR;
Ryosei 9:6901b1dfa688 159 motor[TIRE_3].dir = BACK;
Ryosei 9:6901b1dfa688 160 motor[TIRE_1].pwm = 100;
Ryosei 9:6901b1dfa688 161 motor[TIRE_2].pwm = 100*precision;
Ryosei 9:6901b1dfa688 162 motor[TIRE_3].pwm = 100*precision;
Ryosei 9:6901b1dfa688 163 }else if(controller->Button.UP){
Ryosei 9:6901b1dfa688 164 motor[TIRE_1].dir = BRAKE;
Ryosei 9:6901b1dfa688 165 motor[TIRE_2].dir = BACK;
Ryosei 9:6901b1dfa688 166 motor[TIRE_3].dir = FOR;
Ryosei 9:6901b1dfa688 167 motor[TIRE_1].pwm = 100;
Ryosei 9:6901b1dfa688 168 motor[TIRE_2].pwm = 100*precision;
Ryosei 9:6901b1dfa688 169 motor[TIRE_3].pwm = 100*precision;
Ryosei 9:6901b1dfa688 170 }else if((controller->Button.UP) && (controller->Button.RIGHT)){
Ryosei 9:6901b1dfa688 171 motor[TIRE_1].dir = BACK;
Ryosei 9:6901b1dfa688 172 motor[TIRE_2].dir = BRAKE;
Ryosei 9:6901b1dfa688 173 motor[TIRE_3].dir = FOR;
Ryosei 9:6901b1dfa688 174 motor[TIRE_1].pwm = 100*precision;
Ryosei 9:6901b1dfa688 175 motor[TIRE_2].pwm = 100;
Ryosei 9:6901b1dfa688 176 motor[TIRE_3].pwm = 100*precision;
Ryosei 9:6901b1dfa688 177 }else if((controller->Button.UP) && (controller->Button.LEFT)){
Ryosei 9:6901b1dfa688 178 motor[TIRE_1].dir = FOR;
Ryosei 9:6901b1dfa688 179 motor[TIRE_2].dir = BACK;
Ryosei 9:6901b1dfa688 180 motor[TIRE_3].dir = BRAKE;
Ryosei 9:6901b1dfa688 181 motor[TIRE_1].pwm = 100*precision;
Ryosei 9:6901b1dfa688 182 motor[TIRE_2].pwm = 100*precision;
Ryosei 9:6901b1dfa688 183 motor[TIRE_3].pwm = 100;
Ryosei 9:6901b1dfa688 184 }else if((controller->Button.DOWN) && (controller->Button.RIGHT)){
Ryosei 9:6901b1dfa688 185 motor[TIRE_1].dir = BACK;
Ryosei 9:6901b1dfa688 186 motor[TIRE_2].dir = FOR;
Ryosei 9:6901b1dfa688 187 motor[TIRE_3].dir = BRAKE;
Ryosei 9:6901b1dfa688 188 motor[TIRE_1].pwm = 100*precision;
Ryosei 9:6901b1dfa688 189 motor[TIRE_2].pwm = 100*precision;
Ryosei 9:6901b1dfa688 190 motor[TIRE_3].pwm = 100;
Ryosei 9:6901b1dfa688 191 }else if((controller->Button.DOWN) && (controller->Button.LEFT)){
Ryosei 9:6901b1dfa688 192 motor[TIRE_1].dir = FOR;
Ryosei 9:6901b1dfa688 193 motor[TIRE_2].dir = BRAKE;
Ryosei 9:6901b1dfa688 194 motor[TIRE_3].dir = BACK;
Ryosei 9:6901b1dfa688 195 motor[TIRE_1].pwm = 100*precision;
Ryosei 9:6901b1dfa688 196 motor[TIRE_2].pwm = 100;
Ryosei 9:6901b1dfa688 197 motor[TIRE_3].pwm = 100*precision;
Ryosei 9:6901b1dfa688 198 }else{
Ryosei 9:6901b1dfa688 199 motor[TIRE_1].dir=BRAKE;
Ryosei 9:6901b1dfa688 200 motor[TIRE_2].dir=BRAKE;
Ryosei 9:6901b1dfa688 201 motor[TIRE_3].dir=BRAKE;
Ryosei 9:6901b1dfa688 202 motor[TIRE_1].pwm=100;
Ryosei 9:6901b1dfa688 203 motor[TIRE_2].pwm=100;
Ryosei 9:6901b1dfa688 204 motor[TIRE_3].pwm=100;
Ryosei 9:6901b1dfa688 205 }
Ryosei 9:6901b1dfa688 206
Ryosei 9:6901b1dfa688 207 if(controller->Button.A){
Ryosei 9:6901b1dfa688 208 AirOut(AIR_1,1);
Ryosei 9:6901b1dfa688 209 }else if(controller->Button.B){
Ryosei 9:6901b1dfa688 210 AirOut(AIR_1,0);
Ryosei 9:6901b1dfa688 211 }
Ryosei 9:6901b1dfa688 212
Ryosei 9:6901b1dfa688 213 if(controller->Button.ZL){
Ryosei 9:6901b1dfa688 214 Airtime.start();
Ryosei 9:6901b1dfa688 215 AirOut(AIR_2,0);
Ryosei 9:6901b1dfa688 216 }
Ryosei 9:6901b1dfa688 217 if(s>1){
Ryosei 9:6901b1dfa688 218 Airtime.stop();
Ryosei 9:6901b1dfa688 219 Airtime.reset();
Ryosei 9:6901b1dfa688 220 AirOut(AIR_2,1);
Ryosei 9:6901b1dfa688 221 }
t_yamamoto 0:562021ed1ba9 222
t_yamamoto 0:562021ed1ba9 223
t_yamamoto 0:562021ed1ba9 224 //↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
t_yamamoto 0:562021ed1ba9 225 //____________________________
t_yamamoto 0:562021ed1ba9 226
t_yamamoto 0:562021ed1ba9 227 MOTOR::Motor::Update(motor);
t_yamamoto 0:562021ed1ba9 228 }
t_yamamoto 0:562021ed1ba9 229 }
t_yamamoto 0:562021ed1ba9 230