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:34] – Zagi code laurencebprojects:ukhas_glider_project:code [2008/07/19 23:33] (current) – external edit 127.0.0.1
Line 8: Line 8:
  
 <code c> <code c>
 +//main code
 +//-Laurenceb
 + 
 +////////////////////////////////////////////////////////////////
 +#include <avr/io.h> // include I/O definitions (port names, pin names, etc)
 +#include <avr/interrupt.h> // include interrupt support
 +#include <stdlib.h>
 +//#include <avr/iom64.h>
 +#include <stdio.h>
 +#include <string.h>
 +#include <math.h>
 +#include <util/delay.h>
 #include <avr/eeprom.h> #include <avr/eeprom.h>
 #include "init.h" #include "init.h"
Line 16: Line 28:
 #define Rad2deg 180/M_PI #define Rad2deg 180/M_PI
 #define tweakingfactor 0.002 #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);+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 30: Line 46:
  
  
-char datastring(float k, float Target, attitude_type ourattitude)+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 91: 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 207: Line 267:
  }  }
  stdout=&mystdio0;  stdout=&mystdio0;
- //printf("UKHAS, %s\r\n",datastring());+ if (bit_is_set(PIND,4))                             //CTS from radio 
 + {printf("UKHAS, %s\r\n",datastring(K,Target,getattitude()));}
  stdout=&mystdio1;  stdout=&mystdio1;
- //printf("UKHAS, %s\r\n",datastring()); + printf("UKHAS, %s\r\n",datastring(K,Target,getattitude())); 
 } }
  
Line 221: Line 282:
  
 <code c> <code c>
-// this is under construction+// initialisation code
 // - Laurenceb // - Laurenceb
 #include "init.h" #include "init.h"
Line 260: 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 317: Line 383:
 printf("initialisation complete, bye\r\n"); printf("initialisation complete, bye\r\n");
 } }
 +
  
  
Line 538: 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.1196966077.txt.gz · Last modified: 2008/07/19 23:32 (external edit)

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki