NHK2017Ateamかにろぼ
Dependencies: 2017NHKpin_config mbed FEP HMC6352 MotorDriverController PID QEI omni
\ ̄\ / ̄/ /l \ \ / / lヽ | ヽ ヽ | | / / | \ ` ‐ヽ ヽ ● ● / / ‐ / \ __ l | ||___|| / l __ / \ \ / \/ /\| 人__人 |/\ //\| |/\\ //\| |/\\ / . \_____/ \ ┏┓ ┏━┓┏┓ ┏┓ ┏┓┏┓ ┏┓ ┏┓┗┛ ┏┓ ┗┓┃┗┛ ┏┛┗━┓ ┃┃┃┃ ┃┃┏━┛┗┓┏┓┏┛┗━┓┃┃┏┓┏┓┏━━━┓ ┗┓┏━┛ ┃┃┗┛ ┃┃┗━┓┏┛┗┛┗┓┏┓┃┗┛┗┛┃┃┗━━━┛ ┏┛┃┏━┓┃┗━━┓┃┃┏━┛┗┓ ┏┛┃┃┃ ┃┃ ┃┏┛┗━┛┗━━┓┃┃┃┃┏┓┏┛ ┗━┛┃┃ ┃┃┏┓ ┃┃┏━━┓┏━━┛┃┃┃┃┗┛┃ ┏┛┃ ┃┃┃┗━━┓ ┗┛┗━━┛┗━━━┛┗┛┗━━┛ ┗━┛ ┗┛┗━━━┛
bot/controller/controller.cpp@15:9a2dce34b660, 2017-08-30 (annotated)
- Committer:
- uchitake
- Date:
- Wed Aug 30 15:25:49 2017 +0900
- Revision:
- 15:9a2dce34b660
- Parent:
- 9:cba664555161
- Child:
- 16:86958857c739
fix controller class
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
UCHITAKE | 0:757e9800c103 | 1 | #include "controller.h" |
UCHITAKE | 0:757e9800c103 | 2 | |
uchitake |
9:cba664555161 | 3 | Controller::Controller() : FEP(XBee1TX, XBee1RX, ADDR) |
UCHITAKE | 0:757e9800c103 | 4 | { |
uchitake |
15:9a2dce34b660 | 5 | for(int i = 0; i < 7; i++) button1[i] = 0; |
uchitake |
15:9a2dce34b660 | 6 | for(int i = 0; i < 6; i++) button2[i] = 0; |
UCHITAKE | 1:269914e0aa07 | 7 | for(int i = 0; i < 6; i++) data[i] = 0; |
UCHITAKE | 1:269914e0aa07 | 8 | for(int i = 0; i < 4; i++) stick[i] = 0; |
uchitake |
15:9a2dce34b660 | 9 | for(int i = 0; i < 2; i++) radian[i] = 0; |
UCHITAKE | 1:269914e0aa07 | 10 | for(int i = 0; i < 2; i++) norm[i] = 0; |
UCHITAKE | 1:269914e0aa07 | 11 | fepTemp = 0; |
UCHITAKE | 1:269914e0aa07 | 12 | } |
UCHITAKE | 1:269914e0aa07 | 13 | |
UCHITAKE | 1:269914e0aa07 | 14 | void Controller::receiveState() |
UCHITAKE | 1:269914e0aa07 | 15 | { |
uchitake |
15:9a2dce34b660 | 16 | fepTemp = FEP::read(data, DATA_SIZE); |
UCHITAKE | 1:269914e0aa07 | 17 | if(fepTemp == FEP_SUCCESS) { |
uchitake |
15:9a2dce34b660 | 18 | for(int i = 0; i < 7; i++) { |
uchitake |
15:9a2dce34b660 | 19 | button1[i] = data[4] % 2; |
UCHITAKE | 1:269914e0aa07 | 20 | data[4] /= 2; |
UCHITAKE | 1:269914e0aa07 | 21 | } |
UCHITAKE | 1:269914e0aa07 | 22 | for(int i=0; i<6; i++) { |
uchitake |
15:9a2dce34b660 | 23 | button2[i] = data[5] % 2; |
UCHITAKE | 1:269914e0aa07 | 24 | data[5] /= 2; |
UCHITAKE | 1:269914e0aa07 | 25 | } |
UCHITAKE | 1:269914e0aa07 | 26 | for(int i = 0; i < 4; i++) { |
UCHITAKE | 1:269914e0aa07 | 27 | stick[i] = -((double)(data[i] / STICK_DIVIDE) * 2.0 - 1.0); |
UCHITAKE | 1:269914e0aa07 | 28 | } |
uchitake |
15:9a2dce34b660 | 29 | setStick(); |
UCHITAKE | 1:269914e0aa07 | 30 | } else if(fepTemp == FEP_NO_RESPONSE) { |
UCHITAKE | 1:269914e0aa07 | 31 | } else { |
UCHITAKE | 1:269914e0aa07 | 32 | } |
UCHITAKE | 1:269914e0aa07 | 33 | } |
UCHITAKE | 1:269914e0aa07 | 34 | |
uchitake |
15:9a2dce34b660 | 35 | void Controller::setStick() |
UCHITAKE | 1:269914e0aa07 | 36 | { |
UCHITAKE | 5:bc5ba4f070ad | 37 | for(int i = 0; i < 4; i++) { |
uchitake |
15:9a2dce34b660 | 38 | if(stick[i] < STICK_NEWTRAL && stick[i] > -STICK_NEWTRAL) stick[i] = 0; |
UCHITAKE | 5:bc5ba4f070ad | 39 | } |
uchitake |
15:9a2dce34b660 | 40 | |
uchitake |
15:9a2dce34b660 | 41 | radian[0] = atan2(stick[1], -stick[0]); |
uchitake |
15:9a2dce34b660 | 42 | radian[1] = atan2(stick[3], -stick[2]); |
UCHITAKE | 1:269914e0aa07 | 43 | |
UCHITAKE | 1:269914e0aa07 | 44 | norm[0] = hypot(stick[0], stick[1]); |
UCHITAKE | 1:269914e0aa07 | 45 | norm[1] = hypot(stick[2], stick[3]); |
UCHITAKE | 1:269914e0aa07 | 46 | |
UCHITAKE | 1:269914e0aa07 | 47 | if(norm[0] < STICK_NEWTRAL) norm[0] = 0; |
UCHITAKE | 1:269914e0aa07 | 48 | if(norm[1] < STICK_NEWTRAL) norm[1] = 0; |
UCHITAKE | 1:269914e0aa07 | 49 | if(norm[0] > STICK_NORM_MAX) norm[0] = STICK_NORM_MAX; |
UCHITAKE | 1:269914e0aa07 | 50 | if(norm[1] > STICK_NORM_MAX) norm[1] = STICK_NORM_MAX; |
uchitake |
9:cba664555161 | 51 | } |