Miya Miyagawa
/
mainboardnrp2018
aaaaa
System/Process/Process.cpp@7:f4252ddc480d, 2018-01-27 (annotated)
- Committer:
- t_yamamoto
- Date:
- Sat Jan 27 05:29:03 2018 +0000
- Revision:
- 7:f4252ddc480d
- Parent:
- 6:c294736ba99d
- Child:
- 8:cb53beff4bb2
pwm???
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
t_yamamoto | 5:a802ab60df1b | 1 | //2018/01/26のやつ |
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 | 0:562021ed1ba9 | 9 | //_____________________ |
t_yamamoto | 0:562021ed1ba9 | 10 | /*---------------- HOW TO WRITE ----------------/ |
t_yamamoto | 0:562021ed1ba9 | 11 | |
t_yamamoto | 0:562021ed1ba9 | 12 | ・motor の割り当てを決める |
t_yamamoto | 0:562021ed1ba9 | 13 | #define TIRE_L 1 |
t_yamamoto | 0:562021ed1ba9 | 14 | |
t_yamamoto | 0:562021ed1ba9 | 15 | ・リミットスイッチの割り当てを決める |
t_yamamoto | 0:562021ed1ba9 | 16 | #define ARM_L 1 |
t_yamamoto | 0:562021ed1ba9 | 17 | |
t_yamamoto | 0:562021ed1ba9 | 18 | ・他にも自由に定義してもいいです (pwmとか) |
t_yamamoto | 0:562021ed1ba9 | 19 | |
t_yamamoto | 0:562021ed1ba9 | 20 | /---------------- HOW TO WRITE ----------------*/ |
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 | //_____________________ |
t_yamamoto | 0:562021ed1ba9 | 32 | |
t_yamamoto | 0:562021ed1ba9 | 33 | // #define USE_USB_SERIAL |
t_yamamoto | 0:562021ed1ba9 | 34 | #ifdef USE_USB_SERIAL |
t_yamamoto | 0:562021ed1ba9 | 35 | Serial pc(SERIAL_TX, SERIAL_RX); |
t_yamamoto | 0:562021ed1ba9 | 36 | #endif |
t_yamamoto | 0:562021ed1ba9 | 37 | XBEE::ControllerData *controller; |
t_yamamoto | 0:562021ed1ba9 | 38 | MOTOR::MotorStatus motor[MOUNTING_MOTOR_NUM]; |
t_yamamoto | 0:562021ed1ba9 | 39 | |
t_yamamoto | 0:562021ed1ba9 | 40 | using namespace SWITCH; |
t_yamamoto | 0:562021ed1ba9 | 41 | |
t_yamamoto | 0:562021ed1ba9 | 42 | void SystemProcess(void) { |
t_yamamoto | 0:562021ed1ba9 | 43 | while(true) { |
t_yamamoto | 0:562021ed1ba9 | 44 | controller = XBEE::Controller::GetData(); |
t_yamamoto | 0:562021ed1ba9 | 45 | //____________________________ |
t_yamamoto | 0:562021ed1ba9 | 46 | /*------------------------ HOW TO WRITE ------------------------/ |
t_yamamoto | 0:562021ed1ba9 | 47 | |
t_yamamoto | 0:562021ed1ba9 | 48 | ここにメインのプログラムを書く |
t_yamamoto | 0:562021ed1ba9 | 49 | |
t_yamamoto | 0:562021ed1ba9 | 50 | ・コントローラから受け取ったデータをもとに動作のプログラムを書く |
t_yamamoto | 0:562021ed1ba9 | 51 | (コントローラのデータは controller-> で取る) |
t_yamamoto | 0:562021ed1ba9 | 52 | |
t_yamamoto | 0:562021ed1ba9 | 53 | if(controller->Button.RIGHT) { |
t_yamamoto | 0:562021ed1ba9 | 54 | motor[TIRE_L].dir = FOR; |
t_yamamoto | 0:562021ed1ba9 | 55 | motor[TIRE_R].dir = BACK; |
t_yamamoto | 7:f4252ddc480d | 56 | motor[TIRE_L].pwm = 12.3; |
t_yamamoto | 7:f4252ddc480d | 57 | motor[TIRE_R].pwm = 12.3; |
t_yamamoto | 0:562021ed1ba9 | 58 | } |
t_yamamoto | 0:562021ed1ba9 | 59 | |
t_yamamoto | 6:c294736ba99d | 60 | motor[0].dirは FOR (正転) |
t_yamamoto | 0:562021ed1ba9 | 61 | BACK (逆転) |
t_yamamoto | 0:562021ed1ba9 | 62 | BRAKE (ブレーキ) |
t_yamamoto | 0:562021ed1ba9 | 63 | FREE (フリー) |
t_yamamoto | 0:562021ed1ba9 | 64 | |
t_yamamoto | 0:562021ed1ba9 | 65 | motor[0].pwmは 0.0(%) ~ 100.0(%) |
t_yamamoto | 0:562021ed1ba9 | 66 | |
t_yamamoto | 0:562021ed1ba9 | 67 | controllerは XBee.hの構造体の中身 |
t_yamamoto | 0:562021ed1ba9 | 68 | |
t_yamamoto | 0:562021ed1ba9 | 69 | (AnalogL・Rを使いたかったら、頑張って考える or 聞いてください) |
t_yamamoto | 0:562021ed1ba9 | 70 | |
t_yamamoto | 0:562021ed1ba9 | 71 | ・リミットスイッチの値をもとに動作のプログラムを書く |
t_yamamoto | 0:562021ed1ba9 | 72 | |
t_yamamoto | 0:562021ed1ba9 | 73 | if(Switch::CheckPushed(ARM_L)) |
t_yamamoto | 0:562021ed1ba9 | 74 | { |
t_yamamoto | 0:562021ed1ba9 | 75 | if(controller->Button.L) |
t_yamamoto | 0:562021ed1ba9 | 76 | { |
t_yamamoto | 6:c294736ba99d | 77 | motor[ARM].dir = FOR; |
t_yamamoto | 0:562021ed1ba9 | 78 | motor[ARM].pwm = 80.0; |
t_yamamoto | 0:562021ed1ba9 | 79 | } |
t_yamamoto | 0:562021ed1ba9 | 80 | if(motor[ARM].dir == BACK) |
t_yamamoto | 0:562021ed1ba9 | 81 | { |
t_yamamoto | 0:562021ed1ba9 | 82 | motor[ARM].dir = BRAKE; |
t_yamamoto | 0:562021ed1ba9 | 83 | } |
t_yamamoto | 0:562021ed1ba9 | 84 | } |
t_yamamoto | 0:562021ed1ba9 | 85 | |
t_yamamoto | 0:562021ed1ba9 | 86 | →関数 Switch::CheckPushed の引数はリミットスイッチの名前 (limitSw[0]みたいな), 返り値はbool型 (true or false) |
t_yamamoto | 0:562021ed1ba9 | 87 | |
t_yamamoto | 0:562021ed1ba9 | 88 | ・他にもやりたいことがあったら自由にどうぞ |
t_yamamoto | 0:562021ed1ba9 | 89 | |
t_yamamoto | 0:562021ed1ba9 | 90 | ps.わからないことがあったら聞いてください |
t_yamamoto | 0:562021ed1ba9 | 91 | |
t_yamamoto | 0:562021ed1ba9 | 92 | /------------------------ HOW TO WRITE ------------------------*/ |
t_yamamoto | 0:562021ed1ba9 | 93 | //↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ |
t_yamamoto | 0:562021ed1ba9 | 94 | |
t_yamamoto | 0:562021ed1ba9 | 95 | |
t_yamamoto | 0:562021ed1ba9 | 96 | |
t_yamamoto | 0:562021ed1ba9 | 97 | |
t_yamamoto | 0:562021ed1ba9 | 98 | |
t_yamamoto | 0:562021ed1ba9 | 99 | |
t_yamamoto | 0:562021ed1ba9 | 100 | |
t_yamamoto | 0:562021ed1ba9 | 101 | |
t_yamamoto | 2:db575b3b2171 | 102 | |
t_yamamoto | 0:562021ed1ba9 | 103 | |
t_yamamoto | 0:562021ed1ba9 | 104 | |
t_yamamoto | 0:562021ed1ba9 | 105 | //↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ |
t_yamamoto | 0:562021ed1ba9 | 106 | //____________________________ |
t_yamamoto | 0:562021ed1ba9 | 107 | |
t_yamamoto | 0:562021ed1ba9 | 108 | MOTOR::Motor::Update(motor); |
t_yamamoto | 0:562021ed1ba9 | 109 | } |
t_yamamoto | 0:562021ed1ba9 | 110 | } |
t_yamamoto | 0:562021ed1ba9 | 111 |