code:parafoil_tsip
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
code:parafoil_tsip [2009/01/15 03:48] – laurenceb | code:parafoil_tsip [2009/02/26 02:19] (current) – laurenceb | ||
---|---|---|---|
Line 6: | Line 6: | ||
#include " | #include " | ||
//globals | //globals | ||
+ | #include " | ||
#ifdef GROUND | #ifdef GROUND | ||
volatile u16 diff; | volatile u16 diff; | ||
Line 18: | Line 18: | ||
signed char EEMEM windeast[254]; | signed char EEMEM windeast[254]; | ||
signed char EEMEM windnorth[254]; | signed char EEMEM windnorth[254]; | ||
+ | |||
unsigned char EEMEM flight_status; | unsigned char EEMEM flight_status; | ||
#ifdef EEPROM | #ifdef EEPROM | ||
Line 80: | Line 80: | ||
| | ||
sbi(PINB, | sbi(PINB, | ||
+ | |||
//enable the power to the servo | //enable the power to the servo | ||
ENABLE_SMPS; | ENABLE_SMPS; | ||
+ | |||
//SPI setup - do this here as the /SS pin is already set as an output | //SPI setup - do this here as the /SS pin is already set as an output | ||
SPCR = (1<< | SPCR = (1<< | ||
//outb( SPSR, (1<< | //outb( SPSR, (1<< | ||
+ | |||
//Timer 1 setup | //Timer 1 setup | ||
TCCR1B = (1<< | TCCR1B = (1<< | ||
Line 107: | Line 107: | ||
sbi(TCCR1A, | sbi(TCCR1A, | ||
cbi(TCCR1A, | cbi(TCCR1A, | ||
+ | |||
//Turn on the servo pwm - OCR1B will previously have been at 0 - we've left the SMPS for a while to stabilise | //Turn on the servo pwm - OCR1B will previously have been at 0 - we've left the SMPS for a while to stabilise | ||
OCR1B=3*PWM_COUNT_TIME; | OCR1B=3*PWM_COUNT_TIME; | ||
- | + | ||
- | + | ||
//Kalman setup // | //Kalman setup // | ||
our_model.F.tl=1.0; | our_model.F.tl=1.0; | ||
Line 170: | Line 170: | ||
GYRO_OFF; | GYRO_OFF; | ||
return ( (a<< | return ( (a<< | ||
- | } | ||
- | |||
- | float air_density(float alt) // | ||
- | { | ||
- | float temp,pres; | ||
- | if (alt < 11000.0) | ||
- | | ||
- | temp = 15.04 - (0.00649 * alt); | ||
- | pres = 101.29 * pow((temp + 273.1) / 288.08, 5.256); | ||
- | } | ||
- | else | ||
- | { | ||
- | if (alt < 25000.0) | ||
- | { // between 11Km and 25Km - lower Stratosphere | ||
- | temp = -56.46; | ||
- | pres = 22.65 * exp(1.73 - ( 0.000157 * alt)); | ||
- | } | ||
- | else | ||
- | { // above 25Km - upper Stratosphere | ||
- | temp = -131.21 + (0.00299 * alt); | ||
- | pres = 2.488 * pow((temp + 273.1) / 216.6, -11.388); | ||
- | } | ||
- | } | ||
- | |||
- | | ||
} | } | ||
Line 325: | Line 300: | ||
} | } | ||
} | } | ||
+ | |||
void wiggleservo() | void wiggleservo() | ||
{ | { | ||
Line 357: | Line 332: | ||
while(!Gps.packetflag); | while(!Gps.packetflag); | ||
} | } | ||
- | /* | + | |
- | float driftfactor(int altitude) | + | |
- | { | + | |
- | return WEIGHTINGFACTOR*exp(SCALEHEIGHT*((float)altitude-0.5)); | + | |
- | } | + | |
- | */ | + | |
void dataprint(u08 flight_status, | void dataprint(u08 flight_status, | ||
{ | { | ||
Line 425: | Line 395: | ||
return ; | return ; | ||
} | } | ||
+ | |||
void put_char(unsigned char c) | void put_char(unsigned char c) | ||
{ | { | ||
Line 451: | Line 421: | ||
u08 Heightupto=1; | u08 Heightupto=1; | ||
float K; | float K; | ||
+ | float b, | ||
float descent_drift_n=0; | float descent_drift_n=0; | ||
float descent_drift_e=0; | float descent_drift_e=0; | ||
float Wind_e=0.0; | float Wind_e=0.0; | ||
float Wind_n=0.0; | float Wind_n=0.0; | ||
- | float descent_variable=DESCENT_INIT; | ||
- | float sqrt_density; | ||
- | float descent_variable_noise=DESCENT_NOISE_INIT; | ||
setup(); | setup(); | ||
#ifdef EEPROM | #ifdef EEPROM | ||
Line 600: | Line 568: | ||
#ifdef EEPROM | #ifdef EEPROM | ||
I2Caddress=findtop(); | I2Caddress=findtop(); | ||
- | #endif/* | + | #endif |
if(eeprom_read_byte(& | if(eeprom_read_byte(& | ||
{ | { | ||
getgps(); | getgps(); | ||
Heightupto=(int)(Gps.altitude/ | Heightupto=(int)(Gps.altitude/ | ||
- | for(L=0; | ||
- | { | ||
- | K=driftfactor(L); | ||
- | descent_drift_e+=(float)(s08)eeprom_read_byte((u08*)& | ||
- | descent_drift_n+=(float)(s08)eeprom_read_byte((u08*)& | ||
- | } | ||
} | } | ||
else | else | ||
{ | { | ||
- | for(L=0; | + | for(L=0; |
{ | { | ||
- | K=driftfactor(L); | ||
- | descent_drift_e+=(float)(s08)eeprom_read_byte((u08*)& | ||
- | descent_drift_n+=(float)(s08)eeprom_read_byte((u08*)& | ||
Heightupto++; | Heightupto++; | ||
} | } | ||
- | }*/ | + | } |
L=0; | L=0; | ||
rprintfProgStr(PSTR(" | rprintfProgStr(PSTR(" | ||
Line 636: | Line 595: | ||
| | ||
| | ||
- | if (Gps.altitude > Heightupto*100) // | + | if (Gps.altitude > Heightupto*100) // |
{ | { | ||
Wind_e/ | Wind_e/ | ||
Line 642: | Line 601: | ||
eeprom_write_byte((u08*)& | eeprom_write_byte((u08*)& | ||
eeprom_write_byte((u08*)& | eeprom_write_byte((u08*)& | ||
- | // | ||
- | // | ||
- | // | ||
Heightupto++; | Heightupto++; | ||
L = 0; | L = 0; | ||
Line 675: | Line 631: | ||
while(time< | while(time< | ||
{ | { | ||
- | if((s08)eeprom_read_byte((u08*)& | + | if((s08)eeprom_read_byte((u08*)& |
{ | { | ||
Wind_e=(float)(s08)eeprom_read_byte((u08*)& | Wind_e=(float)(s08)eeprom_read_byte((u08*)& | ||
Line 693: | Line 649: | ||
Wind_n=0.0; | Wind_n=0.0; | ||
} | } | ||
- | }/* | + | } |
- | if((int)Gps.altitude< | + | |
- | { | + | |
- | if((s08)eeprom_read_byte((u08*)& | + | |
- | { // | + | |
- | K=driftfactor(Heightupto); | + | |
- | descent_drift_e-=Wind_e*K; | + | |
- | descent_drift_n-=Wind_n*K; | + | |
- | } | + | |
- | Heightupto--; | + | |
- | }*/ | + | |
// | // | ||
// | // | ||
Line 761: | Line 707: | ||
i2cstop(); | i2cstop(); | ||
#endif | #endif | ||
- | descent_variable_noise+=DESCENT_PROCESS_NOISE;// | + | L=(int)(Gps.altitude/100.0); |
- | if(Gps.vup< | + | if(descent_variable> |
- | { // | + | |
- | sqrt_density=sqrt(air_density(Gps.altitude)); | + | |
- | K=(-100.0/1012000.0)/ | + | |
- | sqrt_density=(-GPS_VEL_NOISE*K/ | + | |
- | descent_variable+=descent_variable_noise*((K-descent_variable)/ | + | |
- | descent_variable_noise-=descent_variable_noise*descent_variable_noise/sqrt_density; | + | |
- | } | + | |
- | for(Heightupto=0; | + | |
{ | { | ||
- | K=descent_variable*sqrt(air_density(100.0*((float)Heightupto-0.5))); | + | for(Heightupto=0;(Heightupto< |
- | descent_drift_e+=(s08)eeprom_read_byte((u08*)& | + | { |
- | descent_drift_n+=(s08)eeprom_read_byte((u08*)& | + | K=descent_variable*(float)pgm_read_byte(& |
+ | descent_drift_e+=(s08)eeprom_read_byte((u08*)& | ||
+ | descent_drift_n+=(s08)eeprom_read_byte((u08*)& | ||
+ | } | ||
+ | } | ||
+ | Heightupto++; | ||
+ | descent_variable_noise+=DESCENT_PROCESS_NOISE; | ||
+ | if(Gps.vup< | ||
+ | { //we run if we are descending and estimate the transit time coefficient | ||
+ | b=(float)pgm_read_byte(& | ||
+ | K=descent_variable_noise/ | ||
+ | b=(-100.0)/ | ||
+ | descent_variable+=K*(b-descent_variable); | ||
+ | descent_variable_noise-=descent_variable_noise*K; | ||
} | } | ||
- | Heightupto++; | ||
getgps(); | getgps(); | ||
} | } | ||
Line 784: | Line 734: | ||
} | } | ||
///////////////////////////// | ///////////////////////////// | ||
- | |||
cbi(TIMSK1, | cbi(TIMSK1, | ||
cbi(TCCR1A, | cbi(TCCR1A, | ||
Line 800: | Line 749: | ||
getgps(); | getgps(); | ||
} | } | ||
- | } | + | }</ |
- | + | ||
- | </ | + | |
- | + | ||
- | + | ||
==== Main.h ==== | ==== Main.h ==== | ||
Line 816: | Line 760: | ||
#include " | #include " | ||
#include " | #include " | ||
- | #include " | ||
#include < | #include < | ||
#include < | #include < | ||
Line 826: | Line 769: | ||
#include < | #include < | ||
#define BAUDRATE (int)9600 // | #define BAUDRATE (int)9600 // | ||
- | #define DELTA_TIME (float)0.02 //20ms | + | #define DELTA_TIME (float)0.02 //20ms |
#define DELAY _delay_loop_2((u16)((float)F_CPU/ | #define DELAY _delay_loop_2((u16)((float)F_CPU/ | ||
#define SET PORTD |= 0x10 // | #define SET PORTD |= 0x10 // | ||
#define CLEAR PORTD &= ~0x10 | #define CLEAR PORTD &= ~0x10 | ||
+ | |||
//kalman filter - NOTE: these constants are airframe specific | //kalman filter - NOTE: these constants are airframe specific | ||
#define DAMPING_CONSTANT (float)0.3 // | #define DAMPING_CONSTANT (float)0.3 // | ||
#define CONTROL (float)0.75 // | #define CONTROL (float)0.75 // | ||
#define CONTROL_GAIN (DAMPING_CONSTANT*CONTROL) // | #define CONTROL_GAIN (DAMPING_CONSTANT*CONTROL) // | ||
+ | |||
#define TOP_COUNT (u16)((float)F_CPU*DELTA_TIME/ | #define TOP_COUNT (u16)((float)F_CPU*DELTA_TIME/ | ||
#define PWM_COUNT_TIME (u16)((float)F_CPU*0.0005/ | #define PWM_COUNT_TIME (u16)((float)F_CPU*0.0005/ | ||
- | + | ||
- | #define I_C -0.001 //control loop | + | #define I_C -0.001 //control loop |
#define P_C -0.3 | #define P_C -0.3 | ||
#define D_C -0.5 | #define D_C -0.5 | ||
#define INTEGRAL_LIMIT 0.2/ | #define INTEGRAL_LIMIT 0.2/ | ||
+ | |||
+ | #define GPS_VEL_NOISE (0.25*(6378000.0/ | ||
+ | #define DESCENT_PROCESS_NOISE 1.0e-22 // | ||
+ | #define DESCENT_INIT 1.5e-8 | ||
+ | #define DESCENT_NOISE_INIT 5.0e-17 | ||
- | #define SCALEHEIGHT (float)(-1.0/ | ||
- | #define WEIGHTINGFACTOR (float)(20.0)/ | ||
- | #define GPS_VEL_NOISE 0.25 | ||
- | #define DESCENT_PROCESS_NOISE 0.0001 | ||
- | |||
#define read_rate (u08)0b10010100 // | #define read_rate (u08)0b10010100 // | ||
#define read_temp (u08)0b10011100 | #define read_temp (u08)0b10011100 | ||
#define read_melexis (u08)0x80 | #define read_melexis (u08)0x80 | ||
- | + | ||
- | #define gyro_null | + | #define gyro_null |
#define altitudelimit 10000 // | #define altitudelimit 10000 // | ||
#define timelimit 30 // | #define timelimit 30 // | ||
- | #define targeteast (float)(-1.0*Deg2rad) //target waypoint ~ Cambridge | + | #define targeteast (float)(0.1*Deg2rad) //target waypoint ~ Cambridge |
#define targetnorth (float)(52.0*Deg2rad) | #define targetnorth (float)(52.0*Deg2rad) | ||
#define Rad2deg 180.0/ | #define Rad2deg 180.0/ | ||
#define Deg2rad PI/180.0 | #define Deg2rad PI/180.0 | ||
+ | |||
#define PRINT_COMMA rprintfChar(pgm_read_byte(& | #define PRINT_COMMA rprintfChar(pgm_read_byte(& | ||
#define battery_factor (float)0.02505 // | #define battery_factor (float)0.02505 // | ||
- | #define battery_chan 0x00 //ADC0 | + | #define battery_chan 0x00 //ADC0 |
- | #define toggle_pin PIND=0x20 //led on port D.5 | + | #define toggle_pin PIND=0x20 //led on port D.5 |
#define BAUDDIV | #define BAUDDIV | ||
+ | |||
#define radio_cts bit_is_set(PIND, | #define radio_cts bit_is_set(PIND, | ||
+ | |||
#define led_left PORTC = ((PORTC & ~0x0C) | 0x04) | #define led_left PORTC = ((PORTC & ~0x0C) | 0x04) | ||
#define led_right PORTC = ((PORTC & ~0x0C) | 0x08) | #define led_right PORTC = ((PORTC & ~0x0C) | 0x08) | ||
+ | |||
#define USER_PRESENT !(PINC& | #define USER_PRESENT !(PINC& | ||
+ | |||
#define cutter_on PORTD|=(1<< | #define cutter_on PORTD|=(1<< | ||
#define cutter_off PORTD& | #define cutter_off PORTD& | ||
+ | |||
#define DISABLE_SMPS PORTD|=(1<< | #define DISABLE_SMPS PORTD|=(1<< | ||
#define ENABLE_SMPS PORTD& | #define ENABLE_SMPS PORTD& | ||
+ | |||
#define GYRO_OFF PORTB|=1<< | #define GYRO_OFF PORTB|=1<< | ||
#define GYRO_ON PORTB& | #define GYRO_ON PORTB& | ||
+ | |||
#ifdef ADCSRA | #ifdef ADCSRA | ||
#ifndef ADCSR | #ifndef ADCSR | ||
Line 898: | Line 841: | ||
#endif | #endif | ||
#ifdef GROUND | #ifdef GROUND | ||
- | # | + | void enable_ground_control(); //enables the input capture interrupt |
- | # | + | void disable_ground_control(); //disables input capture interrupt |
- | #define PULSE_MIN 0.001*F_CPU/8 //pwm must be in the range 1 to 2 ms | + | #define PULSE_MIN |
- | #define PULSE_MAX 0.002*F_CPU/8 | + | #define PULSE_MAX |
#define GROUND_LED_ON PORTD|=(1<< | #define GROUND_LED_ON PORTD|=(1<< | ||
#define GROUND_LED_OFF PORTD& | #define GROUND_LED_OFF PORTD& | ||
#define GROUND_LED_SET PORTD& | #define GROUND_LED_SET PORTD& | ||
+ | void run_ground_control(); | ||
#endif | #endif | ||
Line 926: | Line 870: | ||
void _delay_10ms(char time); | void _delay_10ms(char time); | ||
float driftfactor(int altitude); | float driftfactor(int altitude); | ||
+ | u08 I2Cdataprint(u32* I2Caddress); | ||
</ | </ |
code/parafoil_tsip.1231991295.txt.gz · Last modified: 2009/01/15 03:48 by laurenceb