![](/media/cache/group/1348113303_goodyear_blimp_12_450op.jpg.50x50_q85.jpg)
getestet und funktioniert per pc
main.cpp@1:353c3b1ad238, 2015-10-07 (annotated)
- Committer:
- andreashatzl
- Date:
- Wed Oct 07 18:14:48 2015 +0000
- Revision:
- 1:353c3b1ad238
- Parent:
- 0:aadc51983820
Ansteuerung Blth. Mit eindeutigen links rechts Befehl. So als auch eine zeitlich gesteuerte Drehzahlerh?hung mit Ticker;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
RaphaelKreuzer | 0:aadc51983820 | 1 | |
RaphaelKreuzer | 0:aadc51983820 | 2 | #include "mbed.h" |
RaphaelKreuzer | 0:aadc51983820 | 3 | #include "Serial_HL.h" |
RaphaelKreuzer | 0:aadc51983820 | 4 | |
RaphaelKreuzer | 0:aadc51983820 | 5 | // Testprogramm um zu sehen ob die RGB-Led richtig verlötet |
RaphaelKreuzer | 0:aadc51983820 | 6 | // ist und ob sie sich auch dimmen lässt |
RaphaelKreuzer | 0:aadc51983820 | 7 | |
RaphaelKreuzer | 0:aadc51983820 | 8 | SerialBLK pc(p13,p14); |
RaphaelKreuzer | 0:aadc51983820 | 9 | SvProtocol ua0(&pc); |
RaphaelKreuzer | 0:aadc51983820 | 10 | DigitalOut led1(LED1); |
andreashatzl | 1:353c3b1ad238 | 11 | Ticker t1; |
RaphaelKreuzer | 0:aadc51983820 | 12 | |
RaphaelKreuzer | 0:aadc51983820 | 13 | PwmOut servo1(p21),servo2(p22),servo3(p23); |
RaphaelKreuzer | 0:aadc51983820 | 14 | int16_t stickVal1,stickVal2,stickVal3; |
andreashatzl | 1:353c3b1ad238 | 15 | int speed=1000; |
RaphaelKreuzer | 0:aadc51983820 | 16 | |
RaphaelKreuzer | 0:aadc51983820 | 17 | void CommandHandler(); |
andreashatzl | 1:353c3b1ad238 | 18 | |
andreashatzl | 1:353c3b1ad238 | 19 | void morespeed() { |
andreashatzl | 1:353c3b1ad238 | 20 | if (stickVal1 == 1) |
andreashatzl | 1:353c3b1ad238 | 21 | { if(speed < 2000) |
andreashatzl | 1:353c3b1ad238 | 22 | { |
andreashatzl | 1:353c3b1ad238 | 23 | speed = speed + 50; |
andreashatzl | 1:353c3b1ad238 | 24 | servo1.pulsewidth_us(speed); |
andreashatzl | 1:353c3b1ad238 | 25 | servo2.pulsewidth_us(speed); |
andreashatzl | 1:353c3b1ad238 | 26 | ua0.SvMessage("+100"); |
andreashatzl | 1:353c3b1ad238 | 27 | } |
andreashatzl | 1:353c3b1ad238 | 28 | } |
andreashatzl | 1:353c3b1ad238 | 29 | if (stickVal1 == 2) |
andreashatzl | 1:353c3b1ad238 | 30 | { |
andreashatzl | 1:353c3b1ad238 | 31 | if(speed > 1000) |
andreashatzl | 1:353c3b1ad238 | 32 | { |
andreashatzl | 1:353c3b1ad238 | 33 | speed = speed - 50; |
andreashatzl | 1:353c3b1ad238 | 34 | servo1.pulsewidth_us(speed); |
andreashatzl | 1:353c3b1ad238 | 35 | servo2.pulsewidth_us(speed); |
andreashatzl | 1:353c3b1ad238 | 36 | ua0.SvMessage("-100"); |
andreashatzl | 1:353c3b1ad238 | 37 | } |
andreashatzl | 1:353c3b1ad238 | 38 | } |
andreashatzl | 1:353c3b1ad238 | 39 | } |
RaphaelKreuzer | 0:aadc51983820 | 40 | |
RaphaelKreuzer | 0:aadc51983820 | 41 | int main() |
andreashatzl | 1:353c3b1ad238 | 42 | { |
RaphaelKreuzer | 0:aadc51983820 | 43 | servo1.period_ms(20); |
RaphaelKreuzer | 0:aadc51983820 | 44 | servo2.period_ms(20); |
RaphaelKreuzer | 0:aadc51983820 | 45 | servo3.period_ms(20); |
andreashatzl | 1:353c3b1ad238 | 46 | t1.attach(&morespeed, 3.0); |
RaphaelKreuzer | 0:aadc51983820 | 47 | |
andreashatzl | 1:353c3b1ad238 | 48 | pc.format(8,SerialBLK::None,1);pc.baud(9600); |
RaphaelKreuzer | 0:aadc51983820 | 49 | ua0.SvMessage("ServoTest"); |
RaphaelKreuzer | 0:aadc51983820 | 50 | |
RaphaelKreuzer | 0:aadc51983820 | 51 | Timer stw; stw.start(); |
RaphaelKreuzer | 0:aadc51983820 | 52 | while(1) |
RaphaelKreuzer | 0:aadc51983820 | 53 | { |
RaphaelKreuzer | 0:aadc51983820 | 54 | CommandHandler(); |
RaphaelKreuzer | 0:aadc51983820 | 55 | if((stw.read_ms()>100)) |
RaphaelKreuzer | 0:aadc51983820 | 56 | { |
RaphaelKreuzer | 0:aadc51983820 | 57 | stw.reset(); |
RaphaelKreuzer | 0:aadc51983820 | 58 | if(ua0.acqON) |
RaphaelKreuzer | 0:aadc51983820 | 59 | { |
RaphaelKreuzer | 0:aadc51983820 | 60 | ua0.WriteSvI16(1, stickVal1); |
RaphaelKreuzer | 0:aadc51983820 | 61 | ua0.WriteSvI16(2, stickVal2); |
RaphaelKreuzer | 0:aadc51983820 | 62 | ua0.WriteSvI16(3, stickVal3); |
RaphaelKreuzer | 0:aadc51983820 | 63 | } |
RaphaelKreuzer | 0:aadc51983820 | 64 | } |
RaphaelKreuzer | 0:aadc51983820 | 65 | } |
RaphaelKreuzer | 0:aadc51983820 | 66 | |
RaphaelKreuzer | 0:aadc51983820 | 67 | return 1; |
RaphaelKreuzer | 0:aadc51983820 | 68 | } |
RaphaelKreuzer | 0:aadc51983820 | 69 | |
RaphaelKreuzer | 0:aadc51983820 | 70 | |
RaphaelKreuzer | 0:aadc51983820 | 71 | void CommandHandler() |
RaphaelKreuzer | 0:aadc51983820 | 72 | { |
RaphaelKreuzer | 0:aadc51983820 | 73 | uint8_t cmd; |
RaphaelKreuzer | 0:aadc51983820 | 74 | |
RaphaelKreuzer | 0:aadc51983820 | 75 | |
RaphaelKreuzer | 0:aadc51983820 | 76 | // Fragen ob überhaupt etwas im RX-Reg steht |
RaphaelKreuzer | 0:aadc51983820 | 77 | if( !pc.IsDataAvail() ) |
RaphaelKreuzer | 0:aadc51983820 | 78 | return; |
RaphaelKreuzer | 0:aadc51983820 | 79 | |
RaphaelKreuzer | 0:aadc51983820 | 80 | // wenn etwas im RX-Reg steht |
RaphaelKreuzer | 0:aadc51983820 | 81 | // Kommando lesen |
RaphaelKreuzer | 0:aadc51983820 | 82 | cmd = ua0.GetCommand(); |
RaphaelKreuzer | 0:aadc51983820 | 83 | |
RaphaelKreuzer | 0:aadc51983820 | 84 | if( cmd==2 ) { |
RaphaelKreuzer | 0:aadc51983820 | 85 | // cmd2 hat 2 int16 Parameter |
andreashatzl | 1:353c3b1ad238 | 86 | |
andreashatzl | 1:353c3b1ad238 | 87 | led1 = 1; |
RaphaelKreuzer | 0:aadc51983820 | 88 | stickVal1 = ua0.ReadI16(); |
andreashatzl | 1:353c3b1ad238 | 89 | //servo1.pulsewidth_us(1000+stickVal1); |
andreashatzl | 1:353c3b1ad238 | 90 | //servo2.pulsewidth_us(1000+stickVal1); |
andreashatzl | 1:353c3b1ad238 | 91 | //ua0.SvMessage("Gerade"); |
RaphaelKreuzer | 0:aadc51983820 | 92 | } |
RaphaelKreuzer | 0:aadc51983820 | 93 | if( cmd==3 ) { |
RaphaelKreuzer | 0:aadc51983820 | 94 | // cmd2 hat 2 int16 Parameter |
RaphaelKreuzer | 0:aadc51983820 | 95 | stickVal2 = ua0.ReadI16(); |
RaphaelKreuzer | 0:aadc51983820 | 96 | servo2.pulsewidth_us(1000+stickVal2); |
RaphaelKreuzer | 0:aadc51983820 | 97 | } |
RaphaelKreuzer | 0:aadc51983820 | 98 | if( cmd==4 ) { |
RaphaelKreuzer | 0:aadc51983820 | 99 | // cmd2 hat 2 int16 Parameter |
RaphaelKreuzer | 0:aadc51983820 | 100 | stickVal3 = ua0.ReadI16(); |
andreashatzl | 1:353c3b1ad238 | 101 | //servo3.pulsewidth_us(1000+stickVal3); |
andreashatzl | 1:353c3b1ad238 | 102 | if(stickVal3 == 1) |
andreashatzl | 1:353c3b1ad238 | 103 | {servo3.pulsewidth_us(1000); |
andreashatzl | 1:353c3b1ad238 | 104 | ua0.SvMessage("Links"); |
andreashatzl | 1:353c3b1ad238 | 105 | } |
andreashatzl | 1:353c3b1ad238 | 106 | if(stickVal3 == 2) |
andreashatzl | 1:353c3b1ad238 | 107 | {servo3.pulsewidth_us(1500); |
andreashatzl | 1:353c3b1ad238 | 108 | ua0.SvMessage("Gerade"); |
andreashatzl | 1:353c3b1ad238 | 109 | } |
andreashatzl | 1:353c3b1ad238 | 110 | if(stickVal3 == 3) |
andreashatzl | 1:353c3b1ad238 | 111 | {servo3.pulsewidth_us(1650); |
andreashatzl | 1:353c3b1ad238 | 112 | ua0.SvMessage("Rechts"); |
andreashatzl | 1:353c3b1ad238 | 113 | } |
andreashatzl | 1:353c3b1ad238 | 114 | |
RaphaelKreuzer | 0:aadc51983820 | 115 | } |
RaphaelKreuzer | 0:aadc51983820 | 116 | } |
RaphaelKreuzer | 0:aadc51983820 | 117 | |
RaphaelKreuzer | 0:aadc51983820 | 118 | |
RaphaelKreuzer | 0:aadc51983820 | 119 |