Rev 1.0

Dependencies:   BertlLib mbed

Fork of MotorTest by michael hollegha

Committer:
hollegha2
Date:
Tue Feb 24 11:28:43 2015 +0000
Revision:
1:ef44156a6e44
Parent:
ProcVisDemo.cpp@0:9ac39e20730c
Rev1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hollegha2 1:ef44156a6e44 1
hollegha2 0:9ac39e20730c 2 #include "mbed.h"
hollegha2 0:9ac39e20730c 3 #include "Serial_HL.h"
hollegha2 1:ef44156a6e44 4 #include "Bertl14.h"
hollegha2 1:ef44156a6e44 5 #include "BertlObjects.h"
hollegha2 1:ef44156a6e44 6
hollegha2 0:9ac39e20730c 7 SerialBLK pc(USBTX, USBRX);
hollegha2 0:9ac39e20730c 8 SvProtocol ua0(&pc);
hollegha2 0:9ac39e20730c 9
hollegha2 0:9ac39e20730c 10 void CommandHandler();
hollegha2 0:9ac39e20730c 11
hollegha2 0:9ac39e20730c 12 int main(void)
hollegha2 0:9ac39e20730c 13 {
hollegha2 1:ef44156a6e44 14 InitBertl();
hollegha2 1:ef44156a6e44 15 pex.useISR=0; leds=9;
hollegha2 1:ef44156a6e44 16 pex.ClearLeds();
hollegha2 1:ef44156a6e44 17 pc.format(8,SerialBLK::None,1); pc.baud(500000); // 115200
hollegha2 1:ef44156a6e44 18
hollegha2 1:ef44156a6e44 19 ua0.SvMessage("MotorTest1"); // Meldung zum PC senden
hollegha2 1:ef44156a6e44 20
hollegha2 1:ef44156a6e44 21 Timer stw; stw.start();
hollegha2 1:ef44156a6e44 22 while(1)
hollegha2 1:ef44156a6e44 23 {
hollegha2 1:ef44156a6e44 24 CommandHandler();
hollegha2 1:ef44156a6e44 25 if( (stw.read_ms()>10) ) // 100Hz
hollegha2 1:ef44156a6e44 26 { // dieser Teil wird mit 100Hz aufgerufen
hollegha2 1:ef44156a6e44 27 stw.reset();
hollegha2 1:ef44156a6e44 28 if( ua0.acqON ) {
hollegha2 1:ef44156a6e44 29 // nur wenn vom PC aus das Senden eingeschaltet wurde
hollegha2 1:ef44156a6e44 30 // wird auch etwas gesendet
hollegha2 1:ef44156a6e44 31 ua0.WriteSvI16(1, mL.encCnt);
hollegha2 1:ef44156a6e44 32 ua0.WriteSvI16(2, mR.encCnt);
hollegha2 1:ef44156a6e44 33 ua0.WriteSvI16(3, us.distCM*100.0);
hollegha2 1:ef44156a6e44 34 us.StartMeas(); // for next cycle
hollegha2 1:ef44156a6e44 35 }
hollegha2 0:9ac39e20730c 36 }
hollegha2 1:ef44156a6e44 37 }
hollegha2 1:ef44156a6e44 38 return 1;
hollegha2 0:9ac39e20730c 39 }
hollegha2 0:9ac39e20730c 40
hollegha2 0:9ac39e20730c 41 void CommandHandler()
hollegha2 0:9ac39e20730c 42 {
hollegha2 1:ef44156a6e44 43 uint8_t cmd;
hollegha2 1:ef44156a6e44 44 // Fragen ob überhaupt etwas im RX-Reg steht
hollegha2 1:ef44156a6e44 45 if( !pc.IsDataAvail() )
hollegha2 1:ef44156a6e44 46 return;
hollegha2 1:ef44156a6e44 47 // wenn etwas im RX-Reg steht
hollegha2 0:9ac39e20730c 48 // Kommando lesen
hollegha2 0:9ac39e20730c 49 cmd = ua0.GetCommand();
hollegha2 1:ef44156a6e44 50
hollegha2 1:ef44156a6e44 51 if( cmd==2 ) // Encoder auf 0 setzen
hollegha2 1:ef44156a6e44 52 {
hollegha2 1:ef44156a6e44 53 mL.encCnt=0; mR.encCnt=0;
hollegha2 1:ef44156a6e44 54 ua0.SvMessage("Clear Encoder");
hollegha2 1:ef44156a6e44 55 }
hollegha2 1:ef44156a6e44 56 if( cmd==3 ) // bei beiden Motoren Gas geben
hollegha2 1:ef44156a6e44 57 {
hollegha2 1:ef44156a6e44 58 mL.SetPow(ua0.ReadF());
hollegha2 1:ef44156a6e44 59 mR.SetPow(ua0.ReadF());
hollegha2 1:ef44156a6e44 60 ua0.SvMessage("Set Power");
hollegha2 1:ef44156a6e44 61 }
hollegha2 0:9ac39e20730c 62 }
hollegha2 0:9ac39e20730c 63
hollegha2 0:9ac39e20730c 64