Octopus!!
Dependencies: 2017NHKpin_config FEP HMC6352 PID QEI R1307 ikarashiMDC omni_wheel
Fork of KANIv3 by
bot/bot.cpp@15:9aa11febe517, 2017-09-17 (annotated)
- Committer:
- UCHITAKE
- Date:
- Sun Sep 17 00:53:01 2017 +0900
- Branch:
- develop1
- Revision:
- 15:9aa11febe517
- Parent:
- 14:1fadf7d2f583
- Child:
- 16:50651ff960b9
work(noCompass)
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 |
15:9aa11febe517 | 37 | if(!pad.getButton2(3)) powerSwitch = 0; |
uchitake |
14:1fadf7d2f583 | 38 | led[0] = receiveSuccessed; |
uchitake |
6:fe9767a50891 | 39 | if(!receiveSuccessed) { |
uchitake |
9:39be1525dfe0 | 40 | quadOmni.moveXY(0, 0, 0); |
uchitake |
9:39be1525dfe0 | 41 | slider.slide(0); |
uchitake |
9:39be1525dfe0 | 42 | for(int i = 0; i < 3; i++) { |
uchitake |
9:39be1525dfe0 | 43 | armMotor[i].setSpeed(0); |
uchitake |
9:39be1525dfe0 | 44 | } |
uchitake |
1:845af5425eec | 45 | } |
uchitake |
1:845af5425eec | 46 | } |
uchitake |
1:845af5425eec | 47 | |
uchitake |
1:845af5425eec | 48 | void Bot::controllDrive() |
uchitake |
1:845af5425eec | 49 | { |
uchitake |
6:fe9767a50891 | 50 | if(receiveSuccessed) { |
uchitake |
14:1fadf7d2f583 | 51 | led[1] = !led[1]; |
uchitake |
3:369d9ee17e84 | 52 | if(pad.getNorm(1) > 0.5) { |
UCHITAKE |
15:9aa11febe517 | 53 | // PIDC::PID::setSetPoint((pad.getRadian(1) - M_PI / 2) * (180.0 / M_PI)); |
UCHITAKE |
15:9aa11febe517 | 54 | // PIDC::confirm(); |
uchitake |
3:369d9ee17e84 | 55 | } |
uchitake |
9:39be1525dfe0 | 56 | quadOmni.moveXY( |
UCHITAKE |
15:9aa11febe517 | 57 | pad.getStick(0), |
UCHITAKE |
15:9aa11febe517 | 58 | -pad.getStick(1), |
UCHITAKE |
15:9aa11febe517 | 59 | - pad.getStick(2) / 3.0 // PIDC::calculationResult |
uchitake |
6:fe9767a50891 | 60 | ); |
uchitake |
3:369d9ee17e84 | 61 | } else { |
uchitake |
9:39be1525dfe0 | 62 | quadOmni.moveXY(0, 0, 0); |
uchitake |
3:369d9ee17e84 | 63 | } |
uchitake |
3:369d9ee17e84 | 64 | } |
uchitake |
3:369d9ee17e84 | 65 | |
uchitake |
3:369d9ee17e84 | 66 | void Bot::controllDrive2() |
uchitake |
3:369d9ee17e84 | 67 | { |
uchitake |
4:1073deb368df | 68 | float moment = 0; |
uchitake |
3:369d9ee17e84 | 69 | static float beforestick = pad.getStick(2); |
uchitake |
6:fe9767a50891 | 70 | |
uchitake |
5:16ea97725085 | 71 | if(!pad.getButton2(2)) { |
uchitake |
6:fe9767a50891 | 72 | PIDC::resetPlaneOffset(); |
uchitake |
5:16ea97725085 | 73 | } |
uchitake |
3:369d9ee17e84 | 74 | |
uchitake |
4:1073deb368df | 75 | if((beforestick >= 0.5 && pad.getStick(2) < 0.5) || (beforestick <= -0.5 && pad.getStick(2) > -0.5)) { |
uchitake |
5:16ea97725085 | 76 | PIDC::PID::setSetPoint(0.0); |
uchitake |
6:fe9767a50891 | 77 | PIDC::resetAxisOffset(); |
uchitake |
3:369d9ee17e84 | 78 | } |
uchitake |
3:369d9ee17e84 | 79 | |
uchitake |
4:1073deb368df | 80 | if(pad.getStick(2) > 0.5 || pad.getStick(2) < -0.5) { |
uchitake |
5:16ea97725085 | 81 | moment = pad.getStick(2) / 4.0; |
uchitake |
3:369d9ee17e84 | 82 | PIDC::confirm(); |
uchitake |
4:1073deb368df | 83 | } |
uchitake |
4:1073deb368df | 84 | if(fabs(pad.getStick(2)) < 0.5) { |
uchitake |
3:369d9ee17e84 | 85 | PIDC::confirm(); |
uchitake |
6:fe9767a50891 | 86 | moment = PIDC::calculationResult; |
uchitake |
3:369d9ee17e84 | 87 | } |
uchitake |
3:369d9ee17e84 | 88 | |
uchitake |
6:fe9767a50891 | 89 | if(receiveSuccessed) { |
uchitake |
14:1fadf7d2f583 | 90 | led[1] = !led[1]; |
uchitake |
9:39be1525dfe0 | 91 | quadOmni.moveCircular( |
uchitake |
6:fe9767a50891 | 92 | pad.getNorm(0) / 2.0, |
uchitake |
6:fe9767a50891 | 93 | pad.getRadian(0) - PIDC::planeCurrentDegree / 10.0 * (M_PI / 180.0) + M_PI, |
uchitake |
6:fe9767a50891 | 94 | moment |
uchitake |
6:fe9767a50891 | 95 | ); |
uchitake |
3:369d9ee17e84 | 96 | } else { |
uchitake |
9:39be1525dfe0 | 97 | quadOmni.moveXY(0, 0, 0); |
uchitake |
3:369d9ee17e84 | 98 | } |
uchitake |
3:369d9ee17e84 | 99 | beforestick = pad.getStick(2); |
uchitake |
1:845af5425eec | 100 | } |
uchitake |
1:845af5425eec | 101 | |
uchitake |
1:845af5425eec | 102 | void Bot::controllMech() |
uchitake |
1:845af5425eec | 103 | { |
uchitake |
6:fe9767a50891 | 104 | if(receiveSuccessed) { |
uchitake |
1:845af5425eec | 105 | // if(!pad.getButton1(0)) motor.moveSlider(ARM_MAX_SPEED); |
uchitake |
1:845af5425eec | 106 | // if(!pad.getButton1(1)) motor.moveSlider(-ARM_MAX_SPEED); |
uchitake |
1:845af5425eec | 107 | // if(pad.getButton1(0) && pad.getButton1(1)) motor.moveSlider(0); |
uchitake |
1:845af5425eec | 108 | // |
uchitake |
1:845af5425eec | 109 | // if(!pad.getButton1(3)) motor.shakeHead(ARM_MAX_SPEED); |
uchitake |
1:845af5425eec | 110 | // if(!pad.getButton1(4)) motor.shakeHead(-ARM_MAX_SPEED); |
uchitake |
1:845af5425eec | 111 | // if(pad.getButton1(3) && pad.getButton1(4)) motor.shakeHead(0); |
uchitake |
1:845af5425eec | 112 | // |
uchitake |
9:39be1525dfe0 | 113 | if(!pad.getButton1(5)) armMotor[SWORD].setSpeed(0.6); |
uchitake |
9:39be1525dfe0 | 114 | if(!pad.getButton1(6)) armMotor[SWORD].setSpeed(-0.6); |
uchitake |
9:39be1525dfe0 | 115 | if(pad.getButton1(5) && pad.getButton1(6)) armMotor[SWORD].setSpeed(-0.0); |
uchitake |
1:845af5425eec | 116 | |
UCHITAKE |
15:9aa11febe517 | 117 | if(!pad.getButton1(3)) slider.slide(1.0); |
UCHITAKE |
15:9aa11febe517 | 118 | if(!pad.getButton1(4)) slider.slide(-1.0); |
UCHITAKE |
15:9aa11febe517 | 119 | if(pad.getButton1(3) && pad.getButton1(4)) slider.slide(0.0); |
UCHITAKE |
15:9aa11febe517 | 120 | |
UCHITAKE |
15:9aa11febe517 | 121 | if(!pad.getButton2(4)) { |
UCHITAKE |
15:9aa11febe517 | 122 | armMotor[DESTROY].setSpeed(-1.0); |
UCHITAKE |
15:9aa11febe517 | 123 | } else { |
UCHITAKE |
15:9aa11febe517 | 124 | armMotor[DESTROY].setSpeed(0.0); |
UCHITAKE |
15:9aa11febe517 | 125 | } |
uchitake |
1:845af5425eec | 126 | // |
uchitake |
1:845af5425eec | 127 | // if(!pad.getButton1(2)) { |
uchitake |
1:845af5425eec | 128 | // motor.destroy(DESTROY_MAX_SPEED); |
uchitake |
1:845af5425eec | 129 | // } else { |
uchitake |
1:845af5425eec | 130 | // motor.destroy(0); |
uchitake |
1:845af5425eec | 131 | // } |
uchitake |
1:845af5425eec | 132 | // |
uchitake |
3:369d9ee17e84 | 133 | } else { |
uchitake |
9:39be1525dfe0 | 134 | slider.slide(0); |
uchitake |
9:39be1525dfe0 | 135 | for(int i = 0; i < 3; i++) { |
uchitake |
9:39be1525dfe0 | 136 | armMotor[i].setSpeed(0); |
uchitake |
9:39be1525dfe0 | 137 | } |
uchitake |
3:369d9ee17e84 | 138 | } |
uchitake |
1:845af5425eec | 139 | } |
uchitake |
1:845af5425eec | 140 | |
uchitake |
1:845af5425eec | 141 | |
uchitake |
1:845af5425eec | 142 | void Bot::calibrate() |
uchitake |
1:845af5425eec | 143 | { |
uchitake |
6:fe9767a50891 | 144 | if(receiveSuccessed && |
uchitake |
6:fe9767a50891 | 145 | !pad.getButton2(0) && |
uchitake |
6:fe9767a50891 | 146 | !pad.getButton2(1) |
uchitake |
6:fe9767a50891 | 147 | ) { |
uchitake |
1:845af5425eec | 148 | PIDC::calibration(HMC6352_ENTER_CALIB); |
uchitake |
9:39be1525dfe0 | 149 | quadOmni.moveXY(0, 0, 0.4); |
uchitake |
3:369d9ee17e84 | 150 | wait(5.0); |
uchitake |
9:39be1525dfe0 | 151 | quadOmni.moveXY(0, 0, 0); |
uchitake |
1:845af5425eec | 152 | PIDC::calibration(HMC6352_EXIT_CALIB); |
uchitake |
1:845af5425eec | 153 | } |
uchitake |
3:369d9ee17e84 | 154 | } |