Versao que rodou durante a competicao
Dependencies: RadioIn Servo mbed
Fork of Sumo_v2_Unstable by
main.cpp@0:b59cb9ef5b5b, 2013-04-13 (annotated)
- Committer:
- lfsantarelli
- Date:
- Sat Apr 13 01:00:26 2013 +0000
- Revision:
- 0:b59cb9ef5b5b
- Child:
- 1:b11f1623539d
.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lfsantarelli | 0:b59cb9ef5b5b | 1 | #include "Servo.h" |
lfsantarelli | 0:b59cb9ef5b5b | 2 | #include "mbed.h" |
lfsantarelli | 0:b59cb9ef5b5b | 3 | #include "RadioIn.h" |
lfsantarelli | 0:b59cb9ef5b5b | 4 | #include "Config.h" |
lfsantarelli | 0:b59cb9ef5b5b | 5 | |
lfsantarelli | 0:b59cb9ef5b5b | 6 | void Drive(float m_esq, float m_dir){ // Valores de -1 a 1 em cada motor |
lfsantarelli | 0:b59cb9ef5b5b | 7 | saber1.write((m_esq/2)+0.5); |
lfsantarelli | 0:b59cb9ef5b5b | 8 | saber2.write((m_esq/2)+0.5); |
lfsantarelli | 0:b59cb9ef5b5b | 9 | } |
lfsantarelli | 0:b59cb9ef5b5b | 10 | |
lfsantarelli | 0:b59cb9ef5b5b | 11 | void DriveRC(){ |
lfsantarelli | 0:b59cb9ef5b5b | 12 | float trim=0; // Trim para casar o 0 da sabertooth com o PWM do Mbed |
lfsantarelli | 0:b59cb9ef5b5b | 13 | radio.Update(); |
lfsantarelli | 0:b59cb9ef5b5b | 14 | saber1.write((radio.chan1+1)/2+trim); |
lfsantarelli | 0:b59cb9ef5b5b | 15 | saber2.write((radio.chan2+1)/2+trim); |
lfsantarelli | 0:b59cb9ef5b5b | 16 | } |
lfsantarelli | 0:b59cb9ef5b5b | 17 | |
lfsantarelli | 0:b59cb9ef5b5b | 18 | |
lfsantarelli | 0:b59cb9ef5b5b | 19 | float ReadRadio(int chan){ // Retorna o valor do canal entre -1 e 1 |
lfsantarelli | 0:b59cb9ef5b5b | 20 | radio.Update(); |
lfsantarelli | 0:b59cb9ef5b5b | 21 | if (chan==1){return radio.chan1;} |
lfsantarelli | 0:b59cb9ef5b5b | 22 | if (chan==2){return radio.chan2;} |
lfsantarelli | 0:b59cb9ef5b5b | 23 | if (chan==3){return radio.chan3;} |
lfsantarelli | 0:b59cb9ef5b5b | 24 | else return 0; |
lfsantarelli | 0:b59cb9ef5b5b | 25 | } |
lfsantarelli | 0:b59cb9ef5b5b | 26 | |
lfsantarelli | 0:b59cb9ef5b5b | 27 | |
lfsantarelli | 0:b59cb9ef5b5b | 28 | // Melhor usar o V-Tail Mixer e fazer o mix via hardware |
lfsantarelli | 0:b59cb9ef5b5b | 29 | void DriveMixedRC(){ |
lfsantarelli | 0:b59cb9ef5b5b | 30 | radio.Update(); |
lfsantarelli | 0:b59cb9ef5b5b | 31 | saber1.write(((radio.chan1+radio.chan2)+1)/2); |
lfsantarelli | 0:b59cb9ef5b5b | 32 | saber2.write(((radio.chan1-radio.chan2)+1)/2); |
lfsantarelli | 0:b59cb9ef5b5b | 33 | } |
lfsantarelli | 0:b59cb9ef5b5b | 34 | |
lfsantarelli | 0:b59cb9ef5b5b | 35 | int main() |
lfsantarelli | 0:b59cb9ef5b5b | 36 | { |
lfsantarelli | 0:b59cb9ef5b5b | 37 | saber1.period_us(5); |
lfsantarelli | 0:b59cb9ef5b5b | 38 | saber2.period_us(5); |
lfsantarelli | 0:b59cb9ef5b5b | 39 | radio.Init(); |
lfsantarelli | 0:b59cb9ef5b5b | 40 | while(1){ |
lfsantarelli | 0:b59cb9ef5b5b | 41 | DriveMixedRC(); |
lfsantarelli | 0:b59cb9ef5b5b | 42 | } |
lfsantarelli | 0:b59cb9ef5b5b | 43 | } |