projects:ukhas_glider_project:code
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
projects:ukhas_glider_project:code [2007/12/04 16:39] – Zagi code laurenceb | projects:ukhas_glider_project:code [2008/07/19 23:33] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 8: | Line 8: | ||
<code c> | <code c> | ||
- | //untested, first draft, compiles ok | + | //main code |
- | //- Laurenceb | + | // |
+ | |||
//////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////// | ||
#include < | #include < | ||
#include < | #include < | ||
#include < | #include < | ||
- | #include < | + | //#include < |
#include < | #include < | ||
+ | #include < | ||
+ | #include < | ||
#include < | #include < | ||
+ | #include < | ||
#include " | #include " | ||
+ | #include " | ||
#define altitudelimit 4000 //4km cutdown | #define altitudelimit 4000 //4km cutdown | ||
+ | #define timelimit 600 //10 minutes | ||
+ | #define Deg2rad M_PI/180 | ||
+ | #define Rad2deg 180/M_PI | ||
+ | #define tweakingfactor 0.002 | ||
+ | #define batteryinput 4 | ||
+ | #define batteryfactor 8/1024 | ||
- | void wiggleservo(); | + | void wiggleservo(void); |
- | u08 cutdownrulecheck(); | + | void cutdown(char channel, |
+ | void updategpsdata(void); | ||
+ | char *datastring(float k, float Target, attitude_type *ourattitude); | ||
+ | float getbatteryvoltage(void); | ||
+ | u08 cutdownrulecheck(void); | ||
+ | u08 checksum(char *c_buf); | ||
+ | char EEMEM windeast[1020]; | ||
+ | char EEMEM windnorth[1020]; | ||
float targetnorth; | float targetnorth; | ||
float targeteast; | float targeteast; | ||
+ | int time; //time | ||
+ | |||
+ | |||
+ | char *datastring(float k, float Target, attitude_type *ourattitude) | ||
+ | { | ||
+ | static char outputbuffer[80]; | ||
+ | char longitude; | ||
+ | char latitude; | ||
+ | |||
+ | if (gpsGetInfo()-> | ||
+ | { | ||
+ | | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | | ||
+ | } | ||
+ | if (gpsGetInfo()-> | ||
+ | { | ||
+ | | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | | ||
+ | } | ||
+ | sprintf(outputbuffer," | ||
+ | latitude, | ||
+ | ourattitude-> | ||
+ | sprintf(outputbuffer," | ||
+ | return (outputbuffer); | ||
+ | } | ||
+ | |||
+ | |||
+ | float getbatteryvoltage() | ||
+ | { | ||
+ | return (a2dConvert10bit(batteryinput)*batteryfactor); | ||
+ | } | ||
+ | |||
+ | u08 checksum(char *c_buf) | ||
+ | { | ||
+ | u08 i; | ||
+ | u08 sum=0; | ||
+ | u08 size=strlen(c_buf); | ||
+ | for(i=0 ; i<size ; i++, | ||
+ | { | ||
+ | sum += *c_buf; | ||
+ | } | ||
+ | return(sum); | ||
+ | } | ||
Line 44: | Line 110: | ||
| | ||
{ | { | ||
+ | stdout=& | ||
+ | printf(" | ||
+ | stdout=& | ||
+ | printf(" | ||
return 1; | return 1; | ||
} | } | ||
- | return 0; | + | |
+ | { | ||
+ | stdout=& | ||
+ | printf(" | ||
+ | stdout=& | ||
+ | printf(" | ||
+ | return 2; | ||
+ | } | ||
+ | return 0; | ||
} | } | ||
+ | void cutdown(char channel, | ||
+ | { | ||
+ | | ||
+ | { | ||
+ | PORTD|=(1<< | ||
+ | _delay_ms(1000*time); | ||
+ | PORTD& | ||
+ | } | ||
+ | | ||
+ | { | ||
+ | PORTD|=(1<< | ||
+ | _delay_ms(1000*time); | ||
+ | PORTD& | ||
+ | } | ||
+ | } | ||
- | + | void updategpsdata() | |
+ | { | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | || gpsGetInfo()-> | ||
+ | { | ||
+ | nmeaProcess(Rxbuff0); | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | } | ||
int main() | int main() | ||
{ | { | ||
+ | uint16_t mem; | ||
+ | int Heightupto, | ||
+ | float K, | ||
init(); | init(); | ||
- | printf(" | + | printf(" |
- | printf(" | + | printf(" |
- | scanf(" | + | scanf(" |
printf(" | printf(" | ||
- | scanf(" | + | scanf(" |
printf(" | printf(" | ||
disablegroundcontrol(); | disablegroundcontrol(); | ||
timerDetach(TIMER0OVERFLOW_INT); | timerDetach(TIMER0OVERFLOW_INT); | ||
- | printf(" | + | printf(" |
timer1PWMASet (trimAbias); | timer1PWMASet (trimAbias); | ||
timer1PWMBSet (trimBbias); | timer1PWMBSet (trimBbias); | ||
+ | for (mem=0; | ||
+ | { | ||
+ | | ||
+ | | ||
+ | | ||
+ | } | ||
+ | time=0; | ||
while(!cutdownrulecheck()) | while(!cutdownrulecheck()) | ||
{ | { | ||
- | ; //ascent code | + | time++; |
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | K = gpsGetInfo()-> | ||
+ | if ((int)K > Heightupto) | ||
+ | { | ||
+ | | ||
+ | | ||
+ | | ||
+ | L = 0; | ||
+ | } | ||
| | ||
+ | | ||
+ | | ||
} | } | ||
- | //cutdown(1, | + | cutdown(1, |
reinitlowlevel(); | reinitlowlevel(); | ||
while(1) | while(1) | ||
{ | { | ||
- | ; //descent code | + | updategpsdata(); |
+ | East = targeteast - gpsGetInfo()-> | ||
+ | | ||
+ | K = cos(Deg2rad*North); | ||
+ | East = East * K; | ||
+ | North = targetnorth - North; | ||
+ | | ||
+ | | ||
+ | { | ||
+ | Target = Target - 180; | ||
+ | } | ||
+ | if( Target < -180) | ||
+ | { | ||
+ | Target = Target + 360; // | ||
+ | } | ||
+ | X = gpsGetInfo()-> | ||
+ | Y = gpsGetInfo()-> | ||
+ | if(Y == 0) | ||
+ | | ||
+ | X = 0; // | ||
+ | } | ||
+ | | ||
+ | { | ||
+ | X = X / Y; | ||
+ | | ||
+ | K = Rad2deg*atan(X); | ||
+ | if (Y < 0) | ||
+ | { | ||
+ | K = K - 180; | ||
+ | | ||
+ | if(K < -180) | ||
+ | { | ||
+ | K = K + 360; //K is now our air vector heading | ||
+ | } | ||
+ | K = K - Target; | ||
+ | if (K >180) | ||
+ | { | ||
+ | K = K - 360; | ||
+ | | ||
+ | if(K < -180) | ||
+ | { | ||
+ | K = K + 360; | ||
+ | | ||
+ | if (K > 0) | ||
+ | { | ||
+ | PORTG& | ||
+ | PORTG|=(1<< | ||
+ | } | ||
+ | | ||
+ | { | ||
+ | PORTG& | ||
+ | PORTG|=(1<< | ||
+ | } | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | { | ||
+ | enablegroundcontrol(); | ||
+ | } | ||
+ | | ||
+ | if (bit_is_set(PIND, | ||
+ | | ||
+ | | ||
+ | | ||
} | } | ||
return(1); | return(1); | ||
} | } | ||
- | |||
- | |||
- | |||
- | |||
- | |||
Line 93: | Line 282: | ||
<code c> | <code c> | ||
- | // this is under construction | + | // initialisation code |
// - Laurenceb | // - Laurenceb | ||
#include " | #include " | ||
Line 114: | Line 303: | ||
} | } | ||
- | static | + | int put_char1(char c, FILE *stream) |
{ | { | ||
| | ||
Line 121: | Line 310: | ||
- | static | + | int put_char0(char c, FILE *stream) |
{ | { | ||
| | ||
Line 132: | Line 321: | ||
{ | { | ||
char teststr[15]; | char teststr[15]; | ||
- | sbi(DDRD, | + | sbi(DDRD, |
sbi(DDRB, | sbi(DDRB, | ||
sbi(DDRB, | sbi(DDRB, | ||
+ | sbi(DDRG, | ||
+ | sbi(DDRG, | ||
+ | sbi(DDRD, | ||
+ | sbi(DDRD, | ||
+ | sbi(PORTD, | ||
uartInit(); | uartInit(); | ||
uartSetBaudRate(0, | uartSetBaudRate(0, | ||
Line 149: | Line 343: | ||
// | // | ||
// | // | ||
+ | FILE mystdio1 = FDEV_SETUP_STREAM(put_char1, | ||
+ | FILE mystdio0 = FDEV_SETUP_STREAM(put_char0, | ||
stdout = & | stdout = & | ||
stdin = & | stdin = & | ||
Line 175: | Line 371: | ||
cbi(TIMSK, TOIE3); | cbi(TIMSK, TOIE3); | ||
timer1PWMInitICR(40000); | timer1PWMInitICR(40000); | ||
+ | a2dInit(); | ||
printf(" | printf(" | ||
enablegroundcontrol(); | enablegroundcontrol(); | ||
Line 408: | Line 605: | ||
} | } | ||
pwmpitch=(pitchrunningaverage*PP)+(deltapitchrunningaverage*DP)+(pitchintegral*IP); | pwmpitch=(pitchrunningaverage*PP)+(deltapitchrunningaverage*DP)+(pitchintegral*IP); | ||
- | pwmroll=(rollrunningaverage*PR)+(rollrunningaverage*DR)+(rollintegral*IR)+tweakfactor; | + | pwmroll=(rollrunningaverage*PR)+(deltarollrunningaverage*DR)+(rollintegral*IR)+tweakfactor; |
servoa=trimAgain*(pwmpitch+pwmroll)+trimAbias; | servoa=trimAgain*(pwmpitch+pwmroll)+trimAbias; | ||
if (servoa> | if (servoa> |
projects/ukhas_glider_project/code.1196786360.txt.gz · Last modified: 2008/07/19 23:32 (external edit)