haruki yokota / Mbed 2 deprecated mainboardnrp2018

Dependencies:   mbed Servo

Committer:
yokotaharuki
Date:
Wed Jan 29 08:54:06 2020 +0000
Revision:
9:10276c46b467
Parent:
8:cb53beff4bb2
aa;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
t_yamamoto 8:cb53beff4bb2 1 //2018/02/24のやつ
t_yamamoto 0:562021ed1ba9 2 #include "Process.h"
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 8:cb53beff4bb2 7 #include "../../Output/Servo/Servo.h"
t_yamamoto 8:cb53beff4bb2 8
t_yamamoto 0:562021ed1ba9 9 //_____________________
yokotaharuki 9:10276c46b467 10
yokotaharuki 9:10276c46b467 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 //↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
yokotaharuki 9:10276c46b467 24 bool up_flag = true;
yokotaharuki 9:10276c46b467 25 bool down_flag = true;
yokotaharuki 9:10276c46b467 26 double s = 0;
yokotaharuki 9:10276c46b467 27 double n = 0;
yokotaharuki 9:10276c46b467 28 double ao = 0;
yokotaharuki 9:10276c46b467 29 double aka = 0;
yokotaharuki 9:10276c46b467 30 int zone = 1;//1で青 0で赤
t_yamamoto 0:562021ed1ba9 31
t_yamamoto 0:562021ed1ba9 32
yokotaharuki 9:10276c46b467 33 DigitalOut deng1(A7);
yokotaharuki 9:10276c46b467 34 DigitalOut deng2(A6);
t_yamamoto 0:562021ed1ba9 35
t_yamamoto 0:562021ed1ba9 36 //↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
t_yamamoto 0:562021ed1ba9 37 //_____________________
t_yamamoto 0:562021ed1ba9 38
t_yamamoto 8:cb53beff4bb2 39 //#define USE_USB_SERIAL
t_yamamoto 0:562021ed1ba9 40 #ifdef USE_USB_SERIAL
t_yamamoto 0:562021ed1ba9 41 #endif
t_yamamoto 0:562021ed1ba9 42 XBEE::ControllerData *controller;
t_yamamoto 0:562021ed1ba9 43 MOTOR::MotorStatus motor[MOUNTING_MOTOR_NUM];
t_yamamoto 0:562021ed1ba9 44 using namespace SWITCH;
t_yamamoto 8:cb53beff4bb2 45 void SystemProcess(void) {
t_yamamoto 0:562021ed1ba9 46 while(true) {
t_yamamoto 0:562021ed1ba9 47 controller = XBEE::Controller::GetData();
t_yamamoto 0:562021ed1ba9 48 //____________________________
t_yamamoto 0:562021ed1ba9 49 /*------------------------ HOW TO WRITE ------------------------/
t_yamamoto 0:562021ed1ba9 50
t_yamamoto 0:562021ed1ba9 51 ここにメインのプログラムを書く
t_yamamoto 0:562021ed1ba9 52
t_yamamoto 0:562021ed1ba9 53 ・コントローラから受け取ったデータをもとに動作のプログラムを書く
t_yamamoto 0:562021ed1ba9 54 (コントローラのデータは controller-> で取る)
t_yamamoto 0:562021ed1ba9 55
t_yamamoto 0:562021ed1ba9 56 if(controller->Button.RIGHT) {
t_yamamoto 0:562021ed1ba9 57 motor[TIRE_L].dir = FOR;
t_yamamoto 0:562021ed1ba9 58 motor[TIRE_R].dir = BACK;
t_yamamoto 7:f4252ddc480d 59 motor[TIRE_L].pwm = 12.3;
t_yamamoto 7:f4252ddc480d 60 motor[TIRE_R].pwm = 12.3;
t_yamamoto 0:562021ed1ba9 61 }
t_yamamoto 0:562021ed1ba9 62
t_yamamoto 6:c294736ba99d 63 motor[0].dirは FOR (正転)
t_yamamoto 0:562021ed1ba9 64 BACK (逆転)
t_yamamoto 0:562021ed1ba9 65 BRAKE (ブレーキ)
t_yamamoto 0:562021ed1ba9 66 FREE (フリー)
t_yamamoto 0:562021ed1ba9 67
t_yamamoto 0:562021ed1ba9 68 motor[0].pwmは 0.0(%) ~ 100.0(%)
t_yamamoto 0:562021ed1ba9 69
t_yamamoto 0:562021ed1ba9 70 controllerは XBee.hの構造体の中身
t_yamamoto 0:562021ed1ba9 71
t_yamamoto 0:562021ed1ba9 72 (AnalogL・Rを使いたかったら、頑張って考える or 聞いてください)
t_yamamoto 0:562021ed1ba9 73
t_yamamoto 0:562021ed1ba9 74 ・リミットスイッチの値をもとに動作のプログラムを書く
t_yamamoto 0:562021ed1ba9 75
t_yamamoto 0:562021ed1ba9 76 if(Switch::CheckPushed(ARM_L))
t_yamamoto 0:562021ed1ba9 77 {
yokotaharuki 9:10276c46b467 78 if(controller->AnalogL.Y != 7)
t_yamamoto 0:562021ed1ba9 79 {
yokotaharuki 9:10276c46b467 80 if(controller->AnalogL.Y>7){
yokotaharuki 9:10276c46b467 81 motor[ARM].dir = FOR;
yokotaharuki 9:10276c46b467 82 motor[ARM].pwm = 80.0;
t_yamamoto 0:562021ed1ba9 83 }
t_yamamoto 0:562021ed1ba9 84 if(motor[ARM].dir == BACK)
t_yamamoto 0:562021ed1ba9 85 {
t_yamamoto 0:562021ed1ba9 86 motor[ARM].dir = BRAKE;
t_yamamoto 0:562021ed1ba9 87 }
t_yamamoto 0:562021ed1ba9 88 }
t_yamamoto 0:562021ed1ba9 89
t_yamamoto 0:562021ed1ba9 90 →関数 Switch::CheckPushed の引数はリミットスイッチの名前 (limitSw[0]みたいな), 返り値はbool型 (true or false)
t_yamamoto 0:562021ed1ba9 91
t_yamamoto 0:562021ed1ba9 92 ・他にもやりたいことがあったら自由にどうぞ
t_yamamoto 0:562021ed1ba9 93
t_yamamoto 0:562021ed1ba9 94 ps.わからないことがあったら聞いてください
t_yamamoto 0:562021ed1ba9 95
t_yamamoto 0:562021ed1ba9 96 /------------------------ HOW TO WRITE ------------------------*/
t_yamamoto 0:562021ed1ba9 97 //↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
yokotaharuki 9:10276c46b467 98 if(zone == 1)
yokotaharuki 9:10276c46b467 99 {
yokotaharuki 9:10276c46b467 100 n = 53.8;
yokotaharuki 9:10276c46b467 101 if(controller->Button.ZR || controller->Button.ZL)
yokotaharuki 9:10276c46b467 102 {
yokotaharuki 9:10276c46b467 103 if(controller->Button.ZR)
yokotaharuki 9:10276c46b467 104 {
yokotaharuki 9:10276c46b467 105 motor[3].dir = FOR;
yokotaharuki 9:10276c46b467 106 motor[3].pwm = s;
yokotaharuki 9:10276c46b467 107 }
yokotaharuki 9:10276c46b467 108 if(controller->Button.ZL)
yokotaharuki 9:10276c46b467 109 {
yokotaharuki 9:10276c46b467 110 motor[4].dir = FOR;
yokotaharuki 9:10276c46b467 111 motor[4].pwm = 52;
yokotaharuki 9:10276c46b467 112 }
yokotaharuki 9:10276c46b467 113 }else
yokotaharuki 9:10276c46b467 114 {
yokotaharuki 9:10276c46b467 115 motor[3].dir = FREE;
yokotaharuki 9:10276c46b467 116 motor[4].dir = FREE;
yokotaharuki 9:10276c46b467 117 }
yokotaharuki 9:10276c46b467 118 }else
yokotaharuki 9:10276c46b467 119 {
yokotaharuki 9:10276c46b467 120 n = 57.9;
yokotaharuki 9:10276c46b467 121 if(controller->Button.ZR || controller->Button.ZL)
yokotaharuki 9:10276c46b467 122 {
yokotaharuki 9:10276c46b467 123 if(controller->Button.ZR)
yokotaharuki 9:10276c46b467 124 {
yokotaharuki 9:10276c46b467 125 motor[3].dir = FOR;
yokotaharuki 9:10276c46b467 126 motor[3].pwm = 48;
yokotaharuki 9:10276c46b467 127 }
yokotaharuki 9:10276c46b467 128 if(controller->Button.ZL)
yokotaharuki 9:10276c46b467 129 {
yokotaharuki 9:10276c46b467 130 motor[4].dir = FOR;
yokotaharuki 9:10276c46b467 131 motor[4].pwm = s;
yokotaharuki 9:10276c46b467 132 }
yokotaharuki 9:10276c46b467 133 }else
yokotaharuki 9:10276c46b467 134 {
yokotaharuki 9:10276c46b467 135 motor[3].dir = FREE;
yokotaharuki 9:10276c46b467 136 motor[4].dir = FREE;
yokotaharuki 9:10276c46b467 137 }
yokotaharuki 9:10276c46b467 138 }
t_yamamoto 0:562021ed1ba9 139
yokotaharuki 9:10276c46b467 140 //足回り
yokotaharuki 9:10276c46b467 141 if(controller->AnalogR.Y == 7)
yokotaharuki 9:10276c46b467 142 {
yokotaharuki 9:10276c46b467 143 motor[0].dir =FREE;
yokotaharuki 9:10276c46b467 144 }
yokotaharuki 9:10276c46b467 145 else if(controller->AnalogR.Y > 7)
yokotaharuki 9:10276c46b467 146 {
yokotaharuki 9:10276c46b467 147 motor[0].dir = FOR;
yokotaharuki 9:10276c46b467 148 motor[0].pwm = (controller->AnalogR.Y - 7) * 14;
yokotaharuki 9:10276c46b467 149 }else
yokotaharuki 9:10276c46b467 150 {
yokotaharuki 9:10276c46b467 151 motor[0].dir = BACK;
yokotaharuki 9:10276c46b467 152 motor[0].pwm = (7 - controller->AnalogR.Y) * 14;
yokotaharuki 9:10276c46b467 153 }
t_yamamoto 0:562021ed1ba9 154
yokotaharuki 9:10276c46b467 155 if(controller->AnalogL.Y == 7)
yokotaharuki 9:10276c46b467 156 {
yokotaharuki 9:10276c46b467 157 motor[1].dir =FREE;
yokotaharuki 9:10276c46b467 158 }else
yokotaharuki 9:10276c46b467 159 {
yokotaharuki 9:10276c46b467 160 if(controller->AnalogL.Y < 7)
yokotaharuki 9:10276c46b467 161 {
yokotaharuki 9:10276c46b467 162 motor[1].dir = FOR;
yokotaharuki 9:10276c46b467 163 motor[1].pwm = ( 7 - controller->AnalogL.Y) * 14;
yokotaharuki 9:10276c46b467 164 }else{
yokotaharuki 9:10276c46b467 165 motor[1].dir = BACK;
yokotaharuki 9:10276c46b467 166 motor[1].pwm = (controller->AnalogL.Y - 7) * 14;
yokotaharuki 9:10276c46b467 167 }
yokotaharuki 9:10276c46b467 168 }
t_yamamoto 0:562021ed1ba9 169
yokotaharuki 9:10276c46b467 170 if(controller->Button.UP || controller->Button.DOWN || controller->Button.LEFT || controller->Button.RIGHT )
yokotaharuki 9:10276c46b467 171 {
yokotaharuki 9:10276c46b467 172 if(controller->Button.UP)
yokotaharuki 9:10276c46b467 173 {
yokotaharuki 9:10276c46b467 174 motor[0].dir = BACK;
yokotaharuki 9:10276c46b467 175 motor[0].pwm =20;
yokotaharuki 9:10276c46b467 176 motor[1].dir = FOR;
yokotaharuki 9:10276c46b467 177 motor[1].pwm =20;
yokotaharuki 9:10276c46b467 178 }
yokotaharuki 9:10276c46b467 179 if(controller->Button.DOWN)
yokotaharuki 9:10276c46b467 180 {
yokotaharuki 9:10276c46b467 181 motor[0].dir = FOR;
yokotaharuki 9:10276c46b467 182 motor[0].pwm =77;
yokotaharuki 9:10276c46b467 183 motor[1].dir = BACK;
yokotaharuki 9:10276c46b467 184 motor[1].pwm =74;
yokotaharuki 9:10276c46b467 185 }
yokotaharuki 9:10276c46b467 186 if(controller->Button.LEFT)
yokotaharuki 9:10276c46b467 187 {
yokotaharuki 9:10276c46b467 188 motor[0].dir = BACK;
yokotaharuki 9:10276c46b467 189 motor[0].pwm =20;
yokotaharuki 9:10276c46b467 190 motor[1].dir = BACK;
yokotaharuki 9:10276c46b467 191 motor[1].pwm =20;
yokotaharuki 9:10276c46b467 192 }
yokotaharuki 9:10276c46b467 193 if(controller->Button.RIGHT)
yokotaharuki 9:10276c46b467 194 {
yokotaharuki 9:10276c46b467 195 motor[0].dir = BACK;
yokotaharuki 9:10276c46b467 196 motor[0].pwm =20;
yokotaharuki 9:10276c46b467 197 motor[1].dir = BACK;
yokotaharuki 9:10276c46b467 198 motor[1].pwm =20;
yokotaharuki 9:10276c46b467 199 motor[0].dir = FOR;
yokotaharuki 9:10276c46b467 200 motor[0].pwm =20;
yokotaharuki 9:10276c46b467 201 motor[1].dir = FOR;
yokotaharuki 9:10276c46b467 202 motor[1].pwm =20;
yokotaharuki 9:10276c46b467 203 }
yokotaharuki 9:10276c46b467 204 }
t_yamamoto 0:562021ed1ba9 205
yokotaharuki 9:10276c46b467 206 if(controller->Button.B)//
yokotaharuki 9:10276c46b467 207 {
yokotaharuki 9:10276c46b467 208 motor[0].dir = FOR;
yokotaharuki 9:10276c46b467 209 motor[0].pwm =27;
yokotaharuki 9:10276c46b467 210 motor[1].dir = BACK;
yokotaharuki 9:10276c46b467 211 motor[1].pwm =24;
yokotaharuki 9:10276c46b467 212 }else
yokotaharuki 9:10276c46b467 213 {
yokotaharuki 9:10276c46b467 214 deng1 = 0;
yokotaharuki 9:10276c46b467 215 }
yokotaharuki 9:10276c46b467 216 if(controller->Button.L)
yokotaharuki 9:10276c46b467 217 {
yokotaharuki 9:10276c46b467 218 deng1 = 1;
yokotaharuki 9:10276c46b467 219 }else
yokotaharuki 9:10276c46b467 220 {
yokotaharuki 9:10276c46b467 221 deng1 = 0;
yokotaharuki 9:10276c46b467 222 }
yokotaharuki 9:10276c46b467 223 if(controller->Button.R)
yokotaharuki 9:10276c46b467 224 {
yokotaharuki 9:10276c46b467 225 deng2 = 1;
yokotaharuki 9:10276c46b467 226 }else
yokotaharuki 9:10276c46b467 227 {
yokotaharuki 9:10276c46b467 228 deng2 = 0;
yokotaharuki 9:10276c46b467 229 }
t_yamamoto 0:562021ed1ba9 230
yokotaharuki 9:10276c46b467 231 if(controller->Button.START && up_flag )//速度変更用
yokotaharuki 9:10276c46b467 232 {
yokotaharuki 9:10276c46b467 233 up_flag = false;
yokotaharuki 9:10276c46b467 234 s += 0.1;
yokotaharuki 9:10276c46b467 235 }else if(controller->Button.SELECT && down_flag)
yokotaharuki 9:10276c46b467 236 {
yokotaharuki 9:10276c46b467 237 down_flag = false;
yokotaharuki 9:10276c46b467 238 s -= 0.1;
yokotaharuki 9:10276c46b467 239 }
yokotaharuki 9:10276c46b467 240 if(!controller->Button.START)
yokotaharuki 9:10276c46b467 241 {
yokotaharuki 9:10276c46b467 242 up_flag = true;
yokotaharuki 9:10276c46b467 243 }
yokotaharuki 9:10276c46b467 244 if(!controller->Button.SELECT)
yokotaharuki 9:10276c46b467 245 {
yokotaharuki 9:10276c46b467 246 down_flag = true;
yokotaharuki 9:10276c46b467 247 }
yokotaharuki 9:10276c46b467 248
yokotaharuki 9:10276c46b467 249 if(controller->Button.HOME)
yokotaharuki 9:10276c46b467 250 {
yokotaharuki 9:10276c46b467 251 s = n;
yokotaharuki 9:10276c46b467 252 }
yokotaharuki 9:10276c46b467 253
yokotaharuki 9:10276c46b467 254 if(controller->Button.Y || controller->Button.A)
yokotaharuki 9:10276c46b467 255 {
yokotaharuki 9:10276c46b467 256 if(controller->Button.Y)
yokotaharuki 9:10276c46b467 257 {
yokotaharuki 9:10276c46b467 258 motor[2].dir = FOR;
yokotaharuki 9:10276c46b467 259 motor[2].pwm =50;
yokotaharuki 9:10276c46b467 260 }
yokotaharuki 9:10276c46b467 261 if(controller->Button.A)
yokotaharuki 9:10276c46b467 262 {
yokotaharuki 9:10276c46b467 263 motor[2].dir = BACK;
yokotaharuki 9:10276c46b467 264 motor[2].pwm =50;
yokotaharuki 9:10276c46b467 265 }
yokotaharuki 9:10276c46b467 266 }else
yokotaharuki 9:10276c46b467 267 {
yokotaharuki 9:10276c46b467 268 motor[2].dir =FREE;
yokotaharuki 9:10276c46b467 269 }
t_yamamoto 0:562021ed1ba9 270
t_yamamoto 0:562021ed1ba9 271 //↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
t_yamamoto 0:562021ed1ba9 272 //____________________________
t_yamamoto 0:562021ed1ba9 273
t_yamamoto 0:562021ed1ba9 274 MOTOR::Motor::Update(motor);
t_yamamoto 0:562021ed1ba9 275 }
t_yamamoto 0:562021ed1ba9 276 }
t_yamamoto 0:562021ed1ba9 277