A fork of AR8000
Dependents: Sumo_v2 Sumo_v2_Unstable Sumo_v2_RG13
Revision 10:0c22ced44247, committed 2013-04-13
- Comitter:
- lfsantarelli
- Date:
- Sat Apr 13 00:55:57 2013 +0000
- Parent:
- 9:c57888a66a5f
- Commit message:
- First Version
Changed in this revision
diff -r c57888a66a5f -r 0c22ced44247 AR8000.cpp --- a/AR8000.cpp Fri Apr 20 11:02:25 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,76 +0,0 @@ -#include "mbed.h" -#include "AR8000.h" - - -//Initialisieren -AR8000::AR8000() : -#ifdef AR8000_CONNECTORS_MIRRORED - ChInt0(InterruptIn(p17)), - ChInt1(InterruptIn(p16)), - ChInt2(InterruptIn(p12)), - ChInt3(InterruptIn(p11)), - ChInt4(InterruptIn(p8)), - ChInt5(InterruptIn(p7)), - ChInt6(InterruptIn(p6)), - ChInt7(InterruptIn(p5)) -#else - ChInt0(InterruptIn(p5)), - ChInt1(InterruptIn(p6)), - ChInt2(InterruptIn(p7)), - ChInt3(InterruptIn(p8)), - ChInt4(InterruptIn(p11)), - ChInt5(InterruptIn(p12)), - ChInt6(InterruptIn(p16)), - ChInt7(InterruptIn(p17)) -#endif -{} - -void AR8000::Init() -{ - Time.start(); - - for(int i= 0; i < 8; i++) - { - LastRise[i]= 0; - dTime[i]= 1000; - } - - ChInt0.mode(PullDown); ChInt0.rise<AR8000>(this, &AR8000::Rise0); ChInt0.fall<AR8000>(this, &AR8000::Fall0); - ChInt1.mode(PullDown); ChInt1.rise<AR8000>(this, &AR8000::Rise1); ChInt1.fall<AR8000>(this, &AR8000::Fall1); - ChInt2.mode(PullDown); ChInt2.rise<AR8000>(this, &AR8000::Rise2); ChInt2.fall<AR8000>(this, &AR8000::Fall2); - ChInt3.mode(PullDown); ChInt3.rise<AR8000>(this, &AR8000::Rise3); ChInt3.fall<AR8000>(this, &AR8000::Fall3); - ChInt4.mode(PullDown); ChInt4.rise<AR8000>(this, &AR8000::Rise4); ChInt4.fall<AR8000>(this, &AR8000::Fall4); - ChInt5.mode(PullDown); ChInt5.rise<AR8000>(this, &AR8000::Rise5); ChInt5.fall<AR8000>(this, &AR8000::Fall5); - ChInt6.mode(PullDown); ChInt6.rise<AR8000>(this, &AR8000::Rise6); ChInt6.fall<AR8000>(this, &AR8000::Fall6); - ChInt7.mode(PullDown); ChInt7.rise<AR8000>(this, &AR8000::Rise7); ChInt7.fall<AR8000>(this, &AR8000::Fall7); - - Update(); -} - -//Update-Methode -void AR8000::Update() -{ - //Rohdaten �hmen - for(int i= 0; i<8; i++) - RawChannels[i]= dTime[i]; - - //Steuerbefehle berechnen - Throttle= float(dTime[0]-1000) * 0.001; - Aileron= float(dTime[1]-1500) * 0.002; - Elevator= float(dTime[2]-1500) * 0.002; - Rudder= float(dTime[3]-1500) * 0.002; - - Aux1= float(dTime[6]-1500) * 0.002; - Aux2= float(dTime[7]-1500) * 0.002; - if(dTime[4] < 1500) - { - State1= 0; - Aux3= float(dTime[4]-1250) * 0.004; - } - else - { - State1= 1; - Aux3= float(dTime[4]-1750) * 0.004; - } - State2= dTime[5] < 1200 ? 0 : dTime[5] < 1700 ? 1 : 2; -} \ No newline at end of file
diff -r c57888a66a5f -r 0c22ced44247 AR8000.h --- a/AR8000.h Fri Apr 20 11:02:25 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,68 +0,0 @@ -#pragma once - -#define AR8000_CONNECTORS_MIRRORED - -//Interrupt-Callback Vorlage -#define AR8000_RISE_FALL(Ch)\ -void Rise##Ch()\ -{\ - LastRise[Ch]= Time.read_us();\ -}\ -void Fall##Ch()\ -{\ - int dT= Time.read_us() - LastRise[Ch];\ - if(dT > 900 && dT < 2100)\ - dTime[Ch]= dT;\ -} - - -class AR8000 -{ -private: - InterruptIn ChInt0; //Interrupt-Handler fuer jeden Pin - InterruptIn ChInt1; - InterruptIn ChInt2; - InterruptIn ChInt3; - InterruptIn ChInt4; - InterruptIn ChInt5; - InterruptIn ChInt6; - InterruptIn ChInt7; - - Timer Time; //Timer for all 8 Channels - volatile int LastRise[8]; //Zeitpunkt der letzten steigende Flanke - volatile int dTime[8]; //Pulsdauer in us [1000...2000] - -public: - int RawChannels[8]; //Rohdaten [1000...2000] - - //Die Steuerbefehle - float Throttle; //0=Aus, 1=Vollgas - float Aileron; //-1=Links, 0=Nichts, +1=Rechts - float Elevator; //-1=Sinken, 0=Nichts, +1=Steigen - float Rudder; //-1=Links, 0=Nichts, +1=Rechts - - float Aux1; //-1...+1 Left Trim - float Aux2; //-1...+1 Right Trim - float Aux3; //-1...+1 Knob - - int State1; //0, 1 Gear - int State2; //0, 1, 2 F-Mode - - - //Initialisieren - AR8000(); - void Init(); - - //Interrupt-Callbacks definieren - AR8000_RISE_FALL(0); - AR8000_RISE_FALL(1); - AR8000_RISE_FALL(2); - AR8000_RISE_FALL(3); - AR8000_RISE_FALL(4); - AR8000_RISE_FALL(5); - AR8000_RISE_FALL(6); - AR8000_RISE_FALL(7); - - //Update-Methode - void Update(); -}; \ No newline at end of file
diff -r c57888a66a5f -r 0c22ced44247 RadioIn.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/RadioIn.cpp Sat Apr 13 00:55:57 2013 +0000 @@ -0,0 +1,41 @@ +#include "mbed.h" +#include "RadioIn.h" + + +//Initialization +RadioIn::RadioIn() : + ChInt0(InterruptIn(p21)), + ChInt1(InterruptIn(p22)), + ChInt2(InterruptIn(p23)) +{} + +void RadioIn::Init() +{ + Time.start(); + + for(int i= 0; i < 2; i++) + { + LastRise[i]= 0; + dTime[i]= 1000; + } + + ChInt0.mode(PullDown); ChInt0.rise<RadioIn>(this, &RadioIn::Rise0); ChInt0.fall<RadioIn>(this, &RadioIn::Fall0); + ChInt1.mode(PullDown); ChInt1.rise<RadioIn>(this, &RadioIn::Rise1); ChInt1.fall<RadioIn>(this, &RadioIn::Fall1); + ChInt2.mode(PullDown); ChInt2.rise<RadioIn>(this, &RadioIn::Rise2); ChInt2.fall<RadioIn>(this, &RadioIn::Fall2); + Update(); +} + +//Update Method +void RadioIn::Update() +{ + for(int i= 0; i<2; i++) + RawChannels[i]= dTime[i]; + + //time to float conversion + chan1= float(dTime[0]-1500) * 0.002; + if (chan1>1){chan1=1;} if (chan1<-1){chan1=-1;} + chan2= float(dTime[1]-1500) * 0.002; + if (chan2>1){chan2=1;} if (chan2<-1){chan2=-1;} + chan3= float(dTime[2]-1500) * 0.002; + if (chan3>1){chan3=1;} if (chan3<-1){chan3=-1;} + } \ No newline at end of file
diff -r c57888a66a5f -r 0c22ced44247 RadioIn.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/RadioIn.h Sat Apr 13 00:55:57 2013 +0000 @@ -0,0 +1,47 @@ +#pragma once + +//Interrupt-Callback Function +#define RadioIn_RISE_FALL(Ch)\ +void Rise##Ch()\ +{\ + LastRise[Ch]= Time.read_us();\ +}\ +void Fall##Ch()\ +{\ + int dT= Time.read_us() - LastRise[Ch];\ + if(dT > 900 && dT < 2100)\ + dTime[Ch]= dT;\ +} + + +class RadioIn +{ +private: + InterruptIn ChInt0; //Interrupt-Handler + InterruptIn ChInt1; + InterruptIn ChInt2; + + Timer Time; //Timer for all 3 Channels + volatile int LastRise[3]; //Time of the last rise + volatile int dTime[3]; //Pulse in us [1000...2000] + +public: + int RawChannels[3]; //Raw Data [1000...2000] + + //Channels (0.0 - 1.0) + float chan1; + float chan2; + float chan3; + + //Initialization + RadioIn(); + void Init(); + + //Interrupt-Callbacks + RadioIn_RISE_FALL(0); + RadioIn_RISE_FALL(1); + RadioIn_RISE_FALL(2); + + //Update Method + void Update(); +}; \ No newline at end of file