UKHAS Wiki

UK High Altitude Society

User Tools

Site Tools


code:parafoil_v2

Differences

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

Link to this comparison view

code:parafoil_v2 [2009/03/27 03:36] – created laurencebcode:parafoil_v2 [2009/03/27 03:37] (current) laurenceb
Line 1: Line 1:
 +===== Main code =====
 +
 <code c> <code c>
 //UAV parafoil main code //UAV parafoil main code
Line 799: Line 801:
 } }
  
 +</code>
 +
 +===== header =====
 +<code c>
 +#include "global.h"
 +#include "avrlibdefs.h"
 +#include "avrlibtypes.h"
 +#include "matrix.h"
 +#include "kalman.h"
 +#include "TSIP.h"
 +#include "rprintf.h"
 +#include "i2cmem.h"
 +#include <avr/io.h>
 +#include <stdlib.h>
 +#include <math.h>
 +#include <avr/interrupt.h>
 +#include <avr/wdt.h>
 +#include <util/delay_basic.h>
 +#include <avr/eeprom.h>
 +#include <avr/pgmspace.h> 
 +#define BAUDRATE (int)9600 //9600 baud for lassen iq
 +#define DELTA_TIME (float)0.02 //20ms
 +#define DELAY _delay_loop_2((u16)((float)F_CPU/(4.0*(float)BAUDRATE))) //delay for suart routine
 +#define SET PORTD |= 0x10 //PORTD.4 is the tx
 +#define CLEAR PORTD &= ~0x10
 + 
 +//kalman filter - NOTE: these constants are airframe specific
 +#define DAMPING_CONSTANT (float)0.3 //approx how fast oscillations die down as faction per second
 +#define CONTROL (float)0.75 //full control input of 1 gives ~ this turn rate
 +#define CONTROL_GAIN (DAMPING_CONSTANT*CONTROL) //as used in the kalman filter
 + 
 +#define TOP_COUNT (u16)((float)F_CPU*DELTA_TIME/8.0) //timer1 pwm frequency
 +#define PWM_COUNT_TIME (u16)((float)F_CPU*0.0005/8.0) //500us
 + 
 +#define I_C -0.00037 //control loop
 +#define P_C -0.25 //values from previous accomodated for 20/16ms,+-1servo input,1:3.5 gearing
 +#define D_C -0.35 //and made 30% less agressive
 +#define R_C -0.0005 //new rate integral term, saturates after ~6 turns
 +#define INTEGRAL_LIMIT -0.2/I_C //integral servo shift limited to 1/5 of full scale range
 +#define RATE_INTEGRAL_LIMIT -0.4/I_C
 + 
 +//-we are now using flight data and descent valiable is a macro
 +#define DESCENT_CONSTANT 2.46e-8
 +
 +#define read_rate (u08)0b10010100 //gyro specific
 +#define read_temp (u08)0b10011100
 +#define read_melexis (u08)0x80
 + 
 +#define gyro_null 1022
 + 
 +#define altitudelimit 5000 //flight termination conditions
 +#define timelimit 3600 //NOTE: for flight (this is in seconds)
 + 
 +#define targeteast (float)(-0.096236*Deg2rad) //target waypoint -> EARS, track in front of launch area
 +#define targetnorth (float)(52.25106*Deg2rad)
 + 
 +#define Rad2deg 180.0/PI //bloody obvious
 +#define Deg2rad PI/180.0
 + 
 +#define PRINT_COMMA rprintfChar(pgm_read_byte(&comma)) //prints a comma
 + 
 +#define battery_factor (float)0.02505 //for measuring battery voltage- checked from test
 +#define battery_chan 0x00 //ADC0
 + 
 +#define TOGGLE_PIN PIND=0x20 //led on port D.5
 + 
 +#define BAUDDIV  (u16)( ((float)F_CPU/(BAUDRATE*16UL)) -1 )//baud divider
 + 
 +#define RADIO_CTS bit_is_set(PIND,2) //hardware, however its wired up
 + 
 +#define LED_LEFT PORTC = ((PORTC & ~0x0C) | 0x04)
 +#define LED_RIGHT PORTC = ((PORTC & ~0x0C) | 0x08)
 + 
 +#define USER_PRESENT !(PINC&0x02)
 + 
 +#define CUTTER_ON PORTD|=(1<<7) //release mechanism (hot resistor off mosfet)
 +#define CUTTER_OFF PORTD&=~(1<<7)
 + 
 +#define DISABLE_SMPS PORTD|=(1<<6) //turns the SMPS for the servo on/off - never send pwm if its off
 +#define ENABLE_SMPS PORTD&=~(1<<6)
 + 
 +#define GYRO_OFF PORTB|=1<<1 //SS line
 +#define GYRO_ON PORTB&=~(1<<1)
 + 
 +#ifdef ADCSRA
 + #ifndef ADCSR
 + #define ADCSR   ADCSRA
 + #endif
 +#endif
 +#ifdef ADATE
 + #define ADFR    ADATE
 +#endif
 +#ifdef GROUND
 + void enable_ground_control(); //enables the input capture interrupt
 + void disable_ground_control(); //disables input capture interrupt
 + #define PULSE_MIN (u16)(0.0008*(float)F_CPU/8.0) //pwm must be in the range 0.8 to 2.2 ms
 + #define PULSE_MAX (u16)(0.0022*(float)F_CPU/8.0) //due to the bit shift we divide by 16
 + #define GROUND_LED_ON PORTD|=(1<<3)
 + #define GROUND_LED_OFF PORTD&=~(1<<3)
 + #define GROUND_LED_SET PORTD&(1<<3)
 + void run_ground_control();
 +#endif
 + 
 +typedef struct
 +{
 + float vup;
 + float vnorth;
 + float veast;
 + float time;
 + float altitude;
 + float longitude;
 + float latitude;
 + u08 packetflag; //packetflag lets us see when our packet has been updated
 + u08 status;
 + u08 nosats;
 +} gps_type;
 + 
 +void put_char(unsigned char c); //talk to the UART
 +void suart_send(char c);
 +void run_ground_control();
 +void _delay_10ms(char time);
 +float driftfactor(int altitude);
 +u08 I2Cdataprint(u32* I2Caddress);
 </code> </code>
code/parafoil_v2.1238124998.txt.gz · Last modified: 2009/03/27 03:36 by laurenceb

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki