UKHAS Wiki

UK High Altitude Society

User Tools

Site Tools


projects:ukhas_glider_project:code

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
projects:ukhas_glider_project:code [2007/12/06 18:12] – Zagi code laurencebprojects:ukhas_glider_project:code [2008/07/19 23:33] (current) – external edit 127.0.0.1
Line 22: Line 22:
 #include <avr/eeprom.h> #include <avr/eeprom.h>
 #include "init.h" #include "init.h"
 +#include "attitude.h"
 #define altitudelimit 4000          //4km cutdown #define altitudelimit 4000          //4km cutdown
 #define timelimit 600               //10 minutes #define timelimit 600               //10 minutes
 #define Deg2rad M_PI/180 #define Deg2rad M_PI/180
 #define Rad2deg 180/M_PI #define Rad2deg 180/M_PI
 +#define tweakingfactor 0.002
 +#define batteryinput 4
 +#define batteryfactor 8/1024
  
 void wiggleservo(void); void wiggleservo(void);
 void cutdown(char channel,char time); void cutdown(char channel,char time);
 void updategpsdata(void); void updategpsdata(void);
 +char *datastring(float k, float Target, attitude_type *ourattitude);
 +float getbatteryvoltage(void);
 u08 cutdownrulecheck(void); u08 cutdownrulecheck(void);
 +u08 checksum(char *c_buf);
 char EEMEM windeast[1020]; char EEMEM windeast[1020];
 char EEMEM windnorth[1020]; char EEMEM windnorth[1020];
Line 37: Line 44:
 float targeteast; float targeteast;
 int time;                          //time int time;                          //time
 +
 +
 +char *datastring(float k, float Target, attitude_type *ourattitude)
 +{
 +static char outputbuffer[80];
 +char longitude;
 +char latitude;
 +
 +if (gpsGetInfo()->PosLLA.lon.f>0)
 + {
 + longitude='E';
 + }
 +else
 + {
 + longitude='W';
 + }
 +if (gpsGetInfo()->PosLLA.lat.f>0)
 + {
 + latitude='N';
 + }
 +else
 + {
 + latitude='S';
 + }
 +sprintf(outputbuffer,"%.6f,%c,%.6f,%c,%.1f,M,%.1f,%.1f,%c,%.1f,%.1f,%.2f,",gpsGetInfo()->PosLLA.lat.f,
 +latitude,gpsGetInfo()->PosLLA.lon.f,longitude,gpsGetInfo()->PosLLA.alt.f,k,Target,ourattitude->status,
 +ourattitude->pitch,ourattitude->roll,getbatteryvoltage());
 +sprintf(outputbuffer,"%s%X",outputbuffer,checksum(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++,c_buf++)
 + {
 +                sum += *c_buf;
 +        }
 +        return(sum);
 +}
 +
  
 void wiggleservos() void wiggleservos()
Line 95: Line 151:
  || gpsGetInfo()->VelHS.updates<=updatecounterHS)                     //while we still have some old data  || gpsGetInfo()->VelHS.updates<=updatecounterHS)                     //while we still have some old data
  {  {
-  nmeaProcess(Rxbuff0);                                               //look for new data +  nmeaProcess(Rxbuff0);   
-  updatecounterLLA=gpsGetInfo()->PosLLA.updates; +                                             //look for new data 
-  updatecounterENU=gpsGetInfo()->VelENU.updates; + updatecounterLLA=gpsGetInfo()->PosLLA.updates; //set the update counters correctly 
-  updatecounterHS=gpsGetInfo()->VelHS.updates; + updatecounterENU=gpsGetInfo()->VelENU.updates; 
- + updatecounterHS=gpsGetInfo()->VelHS.updates;
  
  
Line 202: Line 258:
   PORTG|=(1<<3);      PORTG|=(1<<3);   
  }  }
- ; //descent code+ tweakfactor=K*tweakingfactor; 
 + L=(int)gpsGetInfo()->PosLLA.alt.f/50; 
 + Wind_x=(float)windeast[L]-127; 
 + Wind_y=(float)windnorth[L]-127; 
 + if(L<5) 
 + { 
 +  enablegroundcontrol();                               //groundcontrol enabled for smooth landing 
 + } 
 + stdout=&mystdio0; 
 + if (bit_is_set(PIND,4))                             //CTS from radio 
 + {printf("UKHAS, %s\r\n",datastring(K,Target,getattitude()));
 + stdout=&mystdio1; 
 + printf("UKHAS, %s\r\n",datastring(K,Target,getattitude())); 
 } }
  
Line 214: Line 282:
  
 <code c> <code c>
-// this is under construction+// initialisation code
 // - Laurenceb // - Laurenceb
 #include "init.h" #include "init.h"
Line 253: Line 321:
 { {
  char teststr[15];   char teststr[15]; 
-sbi(DDRD,5);                      //lcd is output+sbi(DDRD,5);                      //led is output
 sbi(DDRB,5); sbi(DDRB,5);
 sbi(DDRB,6);                      //pwm outputs  sbi(DDRB,6);                      //pwm outputs 
 +sbi(DDRG,3);                      //direction led
 +sbi(DDRG,4);
 +sbi(DDRD,6);                      //cutdowns
 +sbi(DDRD,7);
 +sbi(PORTD,4);
 uartInit();                       //init uarts uartInit();                       //init uarts
 uartSetBaudRate(0,4800);          //GPS+radio uartSetBaudRate(0,4800);          //GPS+radio
Line 310: Line 383:
 printf("initialisation complete, bye\r\n"); printf("initialisation complete, bye\r\n");
 } }
 +
  
  
Line 531: 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;                                    // V tail mixing in SW   servoa=trimAgain*(pwmpitch+pwmroll)+trimAbias;                                    // V tail mixing in SW
   if (servoa>(trimAbias+limitA))   if (servoa>(trimAbias+limitA))
projects/ukhas_glider_project/code.1196964778.txt.gz · Last modified: 2008/07/19 23:32 (external edit)

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki