michael hollegha
/
BertlCard
BertlCard
BertlCard.cpp@0:46edd470c018, 2015-10-14 (annotated)
- Committer:
- hollegha2
- Date:
- Wed Oct 14 14:39:03 2015 +0000
- Revision:
- 0:46edd470c018
- Child:
- 1:69daffc2b325
V1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hollegha2 | 0:46edd470c018 | 1 | |
hollegha2 | 0:46edd470c018 | 2 | #include "mbed.h" |
hollegha2 | 0:46edd470c018 | 3 | #include "Serial_HL.h" |
hollegha2 | 0:46edd470c018 | 4 | #include "Bertl14.h" |
hollegha2 | 0:46edd470c018 | 5 | #include "BertlObjects.h" |
hollegha2 | 0:46edd470c018 | 6 | |
hollegha2 | 0:46edd470c018 | 7 | SerialBLK pc(USBTX, USBRX); |
hollegha2 | 0:46edd470c018 | 8 | // SerialBLK pc(p9, p10); // BlueTooth |
hollegha2 | 0:46edd470c018 | 9 | SvProtocol ua0(&pc); |
hollegha2 | 0:46edd470c018 | 10 | |
hollegha2 | 0:46edd470c018 | 11 | // main=2^0 LS ENC 2^2 |
hollegha2 | 0:46edd470c018 | 12 | BusOut boardPow(p30, P1_6, P1_7); |
hollegha2 | 0:46edd470c018 | 13 | |
hollegha2 | 0:46edd470c018 | 14 | void CommandHandler(); |
hollegha2 | 0:46edd470c018 | 15 | |
hollegha2 | 0:46edd470c018 | 16 | float gForw=0.0, gTurn=0.0; |
hollegha2 | 0:46edd470c018 | 17 | |
hollegha2 | 0:46edd470c018 | 18 | int main(void) |
hollegha2 | 0:46edd470c018 | 19 | { |
hollegha2 | 0:46edd470c018 | 20 | InitBertl(); |
hollegha2 | 0:46edd470c018 | 21 | pex.useISR=0; |
hollegha2 | 0:46edd470c018 | 22 | leds=0; |
hollegha2 | 0:46edd470c018 | 23 | pex.ClearLeds(); |
hollegha2 | 0:46edd470c018 | 24 | // pex.SetLedPort(LED_FL1|LED_FR1); |
hollegha2 | 0:46edd470c018 | 25 | pex.SetLedPort(LED_BR2|LED_BL1); |
hollegha2 | 0:46edd470c018 | 26 | pc.format(8,SerialBLK::None,1); |
hollegha2 | 0:46edd470c018 | 27 | pc.baud(115200); // 115200 |
hollegha2 | 0:46edd470c018 | 28 | boardPow = 1; |
hollegha2 | 0:46edd470c018 | 29 | ua0.SvMessage("BertlKart_5"); // Meldung zum PC senden |
hollegha2 | 0:46edd470c018 | 30 | |
hollegha2 | 0:46edd470c018 | 31 | Timer stw; |
hollegha2 | 0:46edd470c018 | 32 | stw.start(); |
hollegha2 | 0:46edd470c018 | 33 | while(1) { |
hollegha2 | 0:46edd470c018 | 34 | CommandHandler(); |
hollegha2 | 0:46edd470c018 | 35 | if( (stw.read_ms()>10) ) { // 100Hz |
hollegha2 | 0:46edd470c018 | 36 | // dieser Teil wird mit 100Hz aufgerufen |
hollegha2 | 0:46edd470c018 | 37 | stw.reset(); |
hollegha2 | 0:46edd470c018 | 38 | if( ua0.acqON ) { |
hollegha2 | 0:46edd470c018 | 39 | // nur wenn vom PC aus das Senden eingeschaltet wurde |
hollegha2 | 0:46edd470c018 | 40 | // wird auch etwas gesendet |
hollegha2 | 0:46edd470c018 | 41 | ua0.WriteSvI16(1, gForw*100); |
hollegha2 | 0:46edd470c018 | 42 | ua0.WriteSvI16(2, gTurn*100); |
hollegha2 | 0:46edd470c018 | 43 | } |
hollegha2 | 0:46edd470c018 | 44 | } |
hollegha2 | 0:46edd470c018 | 45 | } |
hollegha2 | 0:46edd470c018 | 46 | return 1; |
hollegha2 | 0:46edd470c018 | 47 | } |
hollegha2 | 0:46edd470c018 | 48 | |
hollegha2 | 0:46edd470c018 | 49 | void CommandHandler() |
hollegha2 | 0:46edd470c018 | 50 | { |
hollegha2 | 0:46edd470c018 | 51 | uint8_t cmd; |
hollegha2 | 0:46edd470c018 | 52 | // Fragen ob überhaupt etwas im RX-Reg steht |
hollegha2 | 0:46edd470c018 | 53 | if( !pc.IsDataAvail() ) |
hollegha2 | 0:46edd470c018 | 54 | return; |
hollegha2 | 0:46edd470c018 | 55 | // wenn etwas im RX-Reg steht |
hollegha2 | 0:46edd470c018 | 56 | // Kommando lesen |
hollegha2 | 0:46edd470c018 | 57 | cmd = ua0.GetCommand(); |
hollegha2 | 0:46edd470c018 | 58 | |
hollegha2 | 0:46edd470c018 | 59 | if( cmd==2 ) { |
hollegha2 | 0:46edd470c018 | 60 | if( ua0.ReadI16() ) |
hollegha2 | 0:46edd470c018 | 61 | pex.SetLedPort(LED_FL1|LED_FR1); |
hollegha2 | 0:46edd470c018 | 62 | else |
hollegha2 | 0:46edd470c018 | 63 | pex.ClearLeds(); |
hollegha2 | 0:46edd470c018 | 64 | } |
hollegha2 | 0:46edd470c018 | 65 | if( cmd==4 ) { |
hollegha2 | 0:46edd470c018 | 66 | mL.SetPow(ua0.ReadF()); |
hollegha2 | 0:46edd470c018 | 67 | mR.SetPow(ua0.ReadF()); |
hollegha2 | 0:46edd470c018 | 68 | } |
hollegha2 | 0:46edd470c018 | 69 | if( cmd==5 ) { |
hollegha2 | 0:46edd470c018 | 70 | gForw = ua0.ReadF(); |
hollegha2 | 0:46edd470c018 | 71 | // gForw = -ua0.ReadF(); // Wetz |
hollegha2 | 0:46edd470c018 | 72 | mL.SetPow(gForw+gTurn); |
hollegha2 | 0:46edd470c018 | 73 | mR.SetPow(gForw-gTurn); |
hollegha2 | 0:46edd470c018 | 74 | } else if( cmd==6 ) { |
hollegha2 | 0:46edd470c018 | 75 | gTurn = ua0.ReadF(); |
hollegha2 | 0:46edd470c018 | 76 | // gTurn = -ua0.ReadF(); // Wetz |
hollegha2 | 0:46edd470c018 | 77 | mL.SetPow(gForw+gTurn); |
hollegha2 | 0:46edd470c018 | 78 | mR.SetPow(gForw-gTurn); |
hollegha2 | 0:46edd470c018 | 79 | } |
hollegha2 | 0:46edd470c018 | 80 | } |
hollegha2 | 0:46edd470c018 | 81 | |
hollegha2 | 0:46edd470c018 | 82 | |
hollegha2 | 0:46edd470c018 | 83 |