タコ 駆動側
Dependencies: 2017NHKpin_config FEP R1307 PID ikarashiMDC omni_wheel
Fork of NHK2017_octopus2 by
bot/bot.cpp@16:50651ff960b9, 2017-09-25 (annotated)
- Committer:
- uchitake
- Date:
- Mon Sep 25 18:15:43 2017 +0900
- Branch:
- develop1
- Revision:
- 16:50651ff960b9
- Parent:
- 15:9aa11febe517
- Child:
- 17:79fa65706f92
fix keybind
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
uchitake |
1:845af5425eec | 1 | #include "bot.h" |
uchitake |
1:845af5425eec | 2 | |
uchitake |
1:845af5425eec | 3 | Bot::Bot() : |
uchitake |
6:fe9767a50891 | 4 | PIDC(), |
UCHITAKE |
15:9aa11febe517 | 5 | pad(XBee2TX, XBee2RX, ADDR), |
uchitake |
9:39be1525dfe0 | 6 | RS485(MDTX, MDRX, 38400), |
uchitake |
9:39be1525dfe0 | 7 | RS485Controller(PWM1), |
UCHITAKE |
15:9aa11febe517 | 8 | powerSwitch(MDstop), |
uchitake |
9:39be1525dfe0 | 9 | quadOmni(&RS485Controller, &RS485), |
uchitake |
9:39be1525dfe0 | 10 | slider(&RS485Controller, &RS485), |
uchitake |
9:39be1525dfe0 | 11 | armMotor({ |
UCHITAKE |
11:a8385ca0a275 | 12 | ikarashiMDC({&RS485Controller, 1, 1, SM, &RS485}), |
UCHITAKE |
11:a8385ca0a275 | 13 | ikarashiMDC({&RS485Controller, 1, 2, SM, &RS485}), |
UCHITAKE |
11:a8385ca0a275 | 14 | ikarashiMDC({&RS485Controller, 1, 3, SM, &RS485}) |
uchitake |
9:39be1525dfe0 | 15 | }), |
uchitake |
9:39be1525dfe0 | 16 | receiveSuccessed(0), |
uchitake |
14:1fadf7d2f583 | 17 | led({DebugLED3, DebugLED4, DebugLED5}), |
uchitake |
9:39be1525dfe0 | 18 | debugSerial(USBTX, USBRX, 115200) |
uchitake |
1:845af5425eec | 19 | { |
uchitake |
9:39be1525dfe0 | 20 | for(int i = 0; i < 3; i++) { |
uchitake |
9:39be1525dfe0 | 21 | armMotor[i].braking = true; |
uchitake |
9:39be1525dfe0 | 22 | } |
uchitake |
9:39be1525dfe0 | 23 | |
uchitake |
9:39be1525dfe0 | 24 | quadOmni.moveXY(0, 0, 0); |
uchitake |
9:39be1525dfe0 | 25 | |
UCHITAKE |
15:9aa11febe517 | 26 | powerSwitch = true; |
uchitake |
14:1fadf7d2f583 | 27 | for(int i = 0; i < 3; i++) { |
uchitake |
14:1fadf7d2f583 | 28 | led[i] = true; |
uchitake |
9:39be1525dfe0 | 29 | wait(0.1); |
uchitake |
14:1fadf7d2f583 | 30 | led[i] = false; |
UCHITAKE |
10:99dc4ae08998 | 31 | } |
uchitake |
1:845af5425eec | 32 | } |
uchitake |
1:845af5425eec | 33 | |
uchitake |
1:845af5425eec | 34 | void Bot::confirmAll() |
uchitake |
1:845af5425eec | 35 | { |
uchitake |
6:fe9767a50891 | 36 | receiveSuccessed = pad.receiveState(); |
uchitake |
16:50651ff960b9 | 37 | if(!pad.getButton2(3) && !pad.getButton2(0)) { |
uchitake |
16:50651ff960b9 | 38 | powerSwitch = 0; |
uchitake |
16:50651ff960b9 | 39 | } |
uchitake |
14:1fadf7d2f583 | 40 | led[0] = receiveSuccessed; |
uchitake |
6:fe9767a50891 | 41 | if(!receiveSuccessed) { |
uchitake |
9:39be1525dfe0 | 42 | quadOmni.moveXY(0, 0, 0); |
uchitake |
9:39be1525dfe0 | 43 | slider.slide(0); |
uchitake |
9:39be1525dfe0 | 44 | for(int i = 0; i < 3; i++) { |
uchitake |
9:39be1525dfe0 | 45 | armMotor[i].setSpeed(0); |
uchitake |
9:39be1525dfe0 | 46 | } |
uchitake |
1:845af5425eec | 47 | } |
uchitake |
1:845af5425eec | 48 | } |
uchitake |
1:845af5425eec | 49 | |
uchitake |
1:845af5425eec | 50 | void Bot::controllDrive() |
uchitake |
1:845af5425eec | 51 | { |
uchitake |
6:fe9767a50891 | 52 | if(receiveSuccessed) { |
uchitake |
14:1fadf7d2f583 | 53 | led[1] = !led[1]; |
uchitake |
3:369d9ee17e84 | 54 | if(pad.getNorm(1) > 0.5) { |
UCHITAKE |
15:9aa11febe517 | 55 | // PIDC::PID::setSetPoint((pad.getRadian(1) - M_PI / 2) * (180.0 / M_PI)); |
UCHITAKE |
15:9aa11febe517 | 56 | // PIDC::confirm(); |
uchitake |
3:369d9ee17e84 | 57 | } |
uchitake |
9:39be1525dfe0 | 58 | quadOmni.moveXY( |
UCHITAKE |
15:9aa11febe517 | 59 | pad.getStick(0), |
UCHITAKE |
15:9aa11febe517 | 60 | -pad.getStick(1), |
UCHITAKE |
15:9aa11febe517 | 61 | - pad.getStick(2) / 3.0 // PIDC::calculationResult |
uchitake |
6:fe9767a50891 | 62 | ); |
uchitake |
3:369d9ee17e84 | 63 | } else { |
uchitake |
9:39be1525dfe0 | 64 | quadOmni.moveXY(0, 0, 0); |
uchitake |
3:369d9ee17e84 | 65 | } |
uchitake |
3:369d9ee17e84 | 66 | } |
uchitake |
3:369d9ee17e84 | 67 | |
uchitake |
3:369d9ee17e84 | 68 | void Bot::controllDrive2() |
uchitake |
3:369d9ee17e84 | 69 | { |
uchitake |
4:1073deb368df | 70 | float moment = 0; |
uchitake |
3:369d9ee17e84 | 71 | static float beforestick = pad.getStick(2); |
uchitake |
6:fe9767a50891 | 72 | |
uchitake |
5:16ea97725085 | 73 | if(!pad.getButton2(2)) { |
uchitake |
6:fe9767a50891 | 74 | PIDC::resetPlaneOffset(); |
uchitake |
5:16ea97725085 | 75 | } |
uchitake |
3:369d9ee17e84 | 76 | |
uchitake |
4:1073deb368df | 77 | if((beforestick >= 0.5 && pad.getStick(2) < 0.5) || (beforestick <= -0.5 && pad.getStick(2) > -0.5)) { |
uchitake |
5:16ea97725085 | 78 | PIDC::PID::setSetPoint(0.0); |
uchitake |
6:fe9767a50891 | 79 | PIDC::resetAxisOffset(); |
uchitake |
3:369d9ee17e84 | 80 | } |
uchitake |
3:369d9ee17e84 | 81 | |
uchitake |
4:1073deb368df | 82 | if(pad.getStick(2) > 0.5 || pad.getStick(2) < -0.5) { |
uchitake |
5:16ea97725085 | 83 | moment = pad.getStick(2) / 4.0; |
uchitake |
3:369d9ee17e84 | 84 | PIDC::confirm(); |
uchitake |
4:1073deb368df | 85 | } |
uchitake |
4:1073deb368df | 86 | if(fabs(pad.getStick(2)) < 0.5) { |
uchitake |
3:369d9ee17e84 | 87 | PIDC::confirm(); |
uchitake |
6:fe9767a50891 | 88 | moment = PIDC::calculationResult; |
uchitake |
3:369d9ee17e84 | 89 | } |
uchitake |
3:369d9ee17e84 | 90 | |
uchitake |
6:fe9767a50891 | 91 | if(receiveSuccessed) { |
uchitake |
14:1fadf7d2f583 | 92 | led[1] = !led[1]; |
uchitake |
9:39be1525dfe0 | 93 | quadOmni.moveCircular( |
uchitake |
6:fe9767a50891 | 94 | pad.getNorm(0) / 2.0, |
uchitake |
6:fe9767a50891 | 95 | pad.getRadian(0) - PIDC::planeCurrentDegree / 10.0 * (M_PI / 180.0) + M_PI, |
uchitake |
6:fe9767a50891 | 96 | moment |
uchitake |
6:fe9767a50891 | 97 | ); |
uchitake |
3:369d9ee17e84 | 98 | } else { |
uchitake |
9:39be1525dfe0 | 99 | quadOmni.moveXY(0, 0, 0); |
uchitake |
3:369d9ee17e84 | 100 | } |
uchitake |
3:369d9ee17e84 | 101 | beforestick = pad.getStick(2); |
uchitake |
1:845af5425eec | 102 | } |
uchitake |
1:845af5425eec | 103 | |
uchitake |
1:845af5425eec | 104 | void Bot::controllMech() |
uchitake |
1:845af5425eec | 105 | { |
uchitake |
6:fe9767a50891 | 106 | if(receiveSuccessed) { |
uchitake |
1:845af5425eec | 107 | // if(!pad.getButton1(0)) motor.moveSlider(ARM_MAX_SPEED); |
uchitake |
1:845af5425eec | 108 | // if(!pad.getButton1(1)) motor.moveSlider(-ARM_MAX_SPEED); |
uchitake |
1:845af5425eec | 109 | // if(pad.getButton1(0) && pad.getButton1(1)) motor.moveSlider(0); |
uchitake |
1:845af5425eec | 110 | // |
uchitake |
1:845af5425eec | 111 | // if(!pad.getButton1(3)) motor.shakeHead(ARM_MAX_SPEED); |
uchitake |
1:845af5425eec | 112 | // if(!pad.getButton1(4)) motor.shakeHead(-ARM_MAX_SPEED); |
uchitake |
1:845af5425eec | 113 | // if(pad.getButton1(3) && pad.getButton1(4)) motor.shakeHead(0); |
uchitake |
1:845af5425eec | 114 | // |
uchitake |
16:50651ff960b9 | 115 | if(!pad.getButton1(6)) { |
uchitake |
16:50651ff960b9 | 116 | armMotor[SWORD].setSpeed(0.6); |
uchitake |
16:50651ff960b9 | 117 | } |
uchitake |
16:50651ff960b9 | 118 | if(pad.getButton1(6)) armMotor[SWORD].setSpeed(0.0); |
uchitake |
1:845af5425eec | 119 | |
UCHITAKE |
15:9aa11febe517 | 120 | if(!pad.getButton1(3)) slider.slide(1.0); |
UCHITAKE |
15:9aa11febe517 | 121 | if(!pad.getButton1(4)) slider.slide(-1.0); |
UCHITAKE |
15:9aa11febe517 | 122 | if(pad.getButton1(3) && pad.getButton1(4)) slider.slide(0.0); |
UCHITAKE |
15:9aa11febe517 | 123 | |
uchitake |
16:50651ff960b9 | 124 | if(!pad.getButton2(1)) { |
UCHITAKE |
15:9aa11febe517 | 125 | armMotor[DESTROY].setSpeed(-1.0); |
UCHITAKE |
15:9aa11febe517 | 126 | } else { |
UCHITAKE |
15:9aa11febe517 | 127 | armMotor[DESTROY].setSpeed(0.0); |
UCHITAKE |
15:9aa11febe517 | 128 | } |
uchitake |
1:845af5425eec | 129 | // |
uchitake |
1:845af5425eec | 130 | // if(!pad.getButton1(2)) { |
uchitake |
1:845af5425eec | 131 | // motor.destroy(DESTROY_MAX_SPEED); |
uchitake |
1:845af5425eec | 132 | // } else { |
uchitake |
1:845af5425eec | 133 | // motor.destroy(0); |
uchitake |
1:845af5425eec | 134 | // } |
uchitake |
1:845af5425eec | 135 | // |
uchitake |
3:369d9ee17e84 | 136 | } else { |
uchitake |
9:39be1525dfe0 | 137 | slider.slide(0); |
uchitake |
9:39be1525dfe0 | 138 | for(int i = 0; i < 3; i++) { |
uchitake |
9:39be1525dfe0 | 139 | armMotor[i].setSpeed(0); |
uchitake |
9:39be1525dfe0 | 140 | } |
uchitake |
3:369d9ee17e84 | 141 | } |
uchitake |
1:845af5425eec | 142 | } |
uchitake |
1:845af5425eec | 143 | |
uchitake |
1:845af5425eec | 144 | |
uchitake |
1:845af5425eec | 145 | void Bot::calibrate() |
uchitake |
1:845af5425eec | 146 | { |
uchitake |
6:fe9767a50891 | 147 | if(receiveSuccessed && |
uchitake |
6:fe9767a50891 | 148 | !pad.getButton2(0) && |
uchitake |
6:fe9767a50891 | 149 | !pad.getButton2(1) |
uchitake |
6:fe9767a50891 | 150 | ) { |
uchitake |
1:845af5425eec | 151 | PIDC::calibration(HMC6352_ENTER_CALIB); |
uchitake |
9:39be1525dfe0 | 152 | quadOmni.moveXY(0, 0, 0.4); |
uchitake |
3:369d9ee17e84 | 153 | wait(5.0); |
uchitake |
9:39be1525dfe0 | 154 | quadOmni.moveXY(0, 0, 0); |
uchitake |
1:845af5425eec | 155 | PIDC::calibration(HMC6352_EXIT_CALIB); |
uchitake |
1:845af5425eec | 156 | } |
uchitake |
3:369d9ee17e84 | 157 | } |