基本クラス
Dependents: 300_PS3com Quadrifoglio_PS3COM
Master.cpp@2:9d9681465f4a, 2022-06-15 (annotated)
- Committer:
- piroro4560
- Date:
- Wed Jun 15 09:32:21 2022 +0000
- Revision:
- 2:9d9681465f4a
- Parent:
- 1:60319e61775d
- Child:
- 3:9b1aefdd251a
PinSet
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
piroro4560 | 0:e2da5742a718 | 1 | #include "Master.h" |
piroro4560 | 0:e2da5742a718 | 2 | |
piroro4560 | 0:e2da5742a718 | 3 | Master::Master() : |
piroro4560 | 0:e2da5742a718 | 4 | pc(USBTX, USBRX, 115200) |
piroro4560 | 0:e2da5742a718 | 5 | ,shot(kicker) |
piroro4560 | 0:e2da5742a718 | 6 | ,drib(ESCpin) |
piroro4560 | 0:e2da5742a718 | 7 | { |
piroro4560 | 2:9d9681465f4a | 8 | omni.wheel[0].setRadian(PI * 1.0 / 4.0); |
piroro4560 | 2:9d9681465f4a | 9 | omni.wheel[1].setRadian(PI * 3.0 / 4.0); |
piroro4560 | 2:9d9681465f4a | 10 | omni.wheel[2].setRadian(PI * 5.0 / 4.0); |
piroro4560 | 2:9d9681465f4a | 11 | omni.wheel[3].setRadian(PI * 7.0 / 4.0); |
piroro4560 | 1:60319e61775d | 12 | motor[0] = new KohiMD(Pin_motor_0); |
piroro4560 | 1:60319e61775d | 13 | motor[1] = new KohiMD(Pin_motor_1); |
piroro4560 | 1:60319e61775d | 14 | motor[2] = new KohiMD(Pin_motor_2); |
piroro4560 | 1:60319e61775d | 15 | motor[3] = new KohiMD(Pin_motor_3); |
piroro4560 | 0:e2da5742a718 | 16 | shot.setkickperiod(2.0); |
piroro4560 | 0:e2da5742a718 | 17 | shot.setoutputtime(0.1); |
piroro4560 | 0:e2da5742a718 | 18 | drib.setspeed(0.0); |
piroro4560 | 0:e2da5742a718 | 19 | } |
piroro4560 | 0:e2da5742a718 | 20 | |
piroro4560 | 0:e2da5742a718 | 21 | void Master::SetPS3Address(bool *button_, uint8_t *trigger_, uint8_t *stick_) |
piroro4560 | 0:e2da5742a718 | 22 | { |
piroro4560 | 0:e2da5742a718 | 23 | button = button_; |
piroro4560 | 0:e2da5742a718 | 24 | stick = stick_; |
piroro4560 | 0:e2da5742a718 | 25 | trigger = trigger_; |
piroro4560 | 0:e2da5742a718 | 26 | } |
piroro4560 | 0:e2da5742a718 | 27 | |
piroro4560 | 0:e2da5742a718 | 28 | void Master::PS3Com() |
piroro4560 | 0:e2da5742a718 | 29 | { |
piroro4560 | 0:e2da5742a718 | 30 | for(int i=0; i < 4; i++) { |
piroro4560 | 0:e2da5742a718 | 31 | if (button[i+4]) { |
piroro4560 | 0:e2da5742a718 | 32 | pwm = 0.5; |
piroro4560 | 0:e2da5742a718 | 33 | } else if (button[i+4+4]){ |
piroro4560 | 0:e2da5742a718 | 34 | pwm = -0.5; |
piroro4560 | 0:e2da5742a718 | 35 | } else { |
piroro4560 | 0:e2da5742a718 | 36 | pwm = 0; |
piroro4560 | 0:e2da5742a718 | 37 | } |
piroro4560 | 2:9d9681465f4a | 38 | SetValueMotor(i, pwm); |
piroro4560 | 0:e2da5742a718 | 39 | } |
piroro4560 | 0:e2da5742a718 | 40 | if (button[2]) Shot(); |
piroro4560 | 0:e2da5742a718 | 41 | if (button[3]) Dribble(0.6); |
piroro4560 | 0:e2da5742a718 | 42 | } |
piroro4560 | 2:9d9681465f4a | 43 | |
piroro4560 | 0:e2da5742a718 | 44 | void Master::Shot() |
piroro4560 | 0:e2da5742a718 | 45 | { |
piroro4560 | 0:e2da5742a718 | 46 | shot.outPut(); |
piroro4560 | 0:e2da5742a718 | 47 | } |
piroro4560 | 2:9d9681465f4a | 48 | |
piroro4560 | 0:e2da5742a718 | 49 | void Master::Dribble(float power) |
piroro4560 | 0:e2da5742a718 | 50 | { |
piroro4560 | 0:e2da5742a718 | 51 | drib.setspeed(power); |
piroro4560 | 0:e2da5742a718 | 52 | } |
piroro4560 | 2:9d9681465f4a | 53 | |
piroro4560 | 0:e2da5742a718 | 54 | void Master::SetValueMotor(int num, double val) |
piroro4560 | 0:e2da5742a718 | 55 | { |
piroro4560 | 0:e2da5742a718 | 56 | motor[num]->setSpeed(val); |
piroro4560 | 0:e2da5742a718 | 57 | } |