Ansteuerung_motor_2509

Dependencies:   Serial_HL mbed

Committer:
andreashatzl
Date:
Thu Oct 01 18:22:03 2015 +0000
Revision:
0:433a8e843e38
ansteuerung motor seriel

Who changed what in which revision?

UserRevisionLine numberNew contents of line
andreashatzl 0:433a8e843e38 1
andreashatzl 0:433a8e843e38 2 #include "mbed.h"
andreashatzl 0:433a8e843e38 3 #include "Serial_HL.h"
andreashatzl 0:433a8e843e38 4
andreashatzl 0:433a8e843e38 5 // Testprogramm um zu sehen ob die RGB-Led richtig verlötet
andreashatzl 0:433a8e843e38 6 // ist und ob sie sich auch dimmen lässt
andreashatzl 0:433a8e843e38 7
andreashatzl 0:433a8e843e38 8 SerialBLK pc(USBTX, USBRX);
andreashatzl 0:433a8e843e38 9 SvProtocol ua0(&pc);
andreashatzl 0:433a8e843e38 10
andreashatzl 0:433a8e843e38 11 PwmOut servo1(p21),servo2(p22),servo3(p23);
andreashatzl 0:433a8e843e38 12 int16_t stickVal1,stickVal2,stickVal3;
andreashatzl 0:433a8e843e38 13
andreashatzl 0:433a8e843e38 14 void CommandHandler();
andreashatzl 0:433a8e843e38 15
andreashatzl 0:433a8e843e38 16 int main()
andreashatzl 0:433a8e843e38 17 {
andreashatzl 0:433a8e843e38 18 servo1.period_ms(20);
andreashatzl 0:433a8e843e38 19 servo2.period_ms(20);
andreashatzl 0:433a8e843e38 20 servo3.period_ms(20);
andreashatzl 0:433a8e843e38 21
andreashatzl 0:433a8e843e38 22 pc.format(8,SerialBLK::None,1);pc.baud(500000);
andreashatzl 0:433a8e843e38 23 ua0.SvMessage("ServoTest");
andreashatzl 0:433a8e843e38 24
andreashatzl 0:433a8e843e38 25 Timer stw; stw.start();
andreashatzl 0:433a8e843e38 26 while(1)
andreashatzl 0:433a8e843e38 27 {
andreashatzl 0:433a8e843e38 28 CommandHandler();
andreashatzl 0:433a8e843e38 29 if((stw.read_ms()>100))
andreashatzl 0:433a8e843e38 30 {
andreashatzl 0:433a8e843e38 31 stw.reset();
andreashatzl 0:433a8e843e38 32 if(ua0.acqON)
andreashatzl 0:433a8e843e38 33 {
andreashatzl 0:433a8e843e38 34 ua0.WriteSvI16(1, stickVal1);
andreashatzl 0:433a8e843e38 35 ua0.WriteSvI16(2, stickVal2);
andreashatzl 0:433a8e843e38 36 ua0.WriteSvI16(3, stickVal3);
andreashatzl 0:433a8e843e38 37 }
andreashatzl 0:433a8e843e38 38 }
andreashatzl 0:433a8e843e38 39 }
andreashatzl 0:433a8e843e38 40
andreashatzl 0:433a8e843e38 41 return 1;
andreashatzl 0:433a8e843e38 42 }
andreashatzl 0:433a8e843e38 43
andreashatzl 0:433a8e843e38 44
andreashatzl 0:433a8e843e38 45 void CommandHandler()
andreashatzl 0:433a8e843e38 46 {
andreashatzl 0:433a8e843e38 47 uint8_t cmd;
andreashatzl 0:433a8e843e38 48
andreashatzl 0:433a8e843e38 49
andreashatzl 0:433a8e843e38 50 // Fragen ob überhaupt etwas im RX-Reg steht
andreashatzl 0:433a8e843e38 51 if( !pc.IsDataAvail() )
andreashatzl 0:433a8e843e38 52 return;
andreashatzl 0:433a8e843e38 53
andreashatzl 0:433a8e843e38 54 // wenn etwas im RX-Reg steht
andreashatzl 0:433a8e843e38 55 // Kommando lesen
andreashatzl 0:433a8e843e38 56 cmd = ua0.GetCommand();
andreashatzl 0:433a8e843e38 57
andreashatzl 0:433a8e843e38 58 if( cmd==2 ) {
andreashatzl 0:433a8e843e38 59 // cmd2 hat 2 int16 Parameter
andreashatzl 0:433a8e843e38 60 stickVal1 = ua0.ReadI16();
andreashatzl 0:433a8e843e38 61 servo1.pulsewidth_us(1000+stickVal1);
andreashatzl 0:433a8e843e38 62 }
andreashatzl 0:433a8e843e38 63 if( cmd==3 ) {
andreashatzl 0:433a8e843e38 64 // cmd2 hat 2 int16 Parameter
andreashatzl 0:433a8e843e38 65 stickVal2 = ua0.ReadI16();
andreashatzl 0:433a8e843e38 66 servo2.pulsewidth_us(1000+stickVal2);
andreashatzl 0:433a8e843e38 67 }
andreashatzl 0:433a8e843e38 68 if( cmd==4 ) {
andreashatzl 0:433a8e843e38 69 // cmd2 hat 2 int16 Parameter
andreashatzl 0:433a8e843e38 70 stickVal3 = ua0.ReadI16();
andreashatzl 0:433a8e843e38 71 servo3.pulsewidth_us(1000+stickVal3);
andreashatzl 0:433a8e843e38 72 }
andreashatzl 0:433a8e843e38 73 }