StoRC
Autonomous Payload Delivery System
storc.h File Reference

Main header file, contains global variables, includes, macros, etc. More...

Go to the source code of this file.

Defines

#define LOG   0
 Easy way to turn logging on (1) and off (0)
#define TELEMETRY   1
 Easy way to turn telemetry on (1) and off (0)
#define CONTROLS   1
 Easy way to turn controls on (1) and off (0) - if off, Payload release is ON.
#define NAVIGATION   0
 Turn outer loop navigation on (1) and off (0)
#define GRAVITY   9.81
 acceleration due to gravity
#define K_DRIFT   0.2564
#define OFFSET_DRIFT   6.4577
#define DEG2RAD(x)   (x*0.0174532925)
 Macro to convert degrees to radians.
#define RAD2DEG(x)   (x*57.2957795)
 Macro to convert radians to degrees.
#define DELT_M2GPS_LAT(x)   (x*105.37407797)
 Macro to convert a delta of meters to a delta of GPS decimal*10^7 (latitude)
#define DELT_M2GPS_LON(x)   (x*74.51564828)
 Macro to convert a delta of meters to a delta of GPS decimal*10^7 (longitude)
#define DELT_GPS_LAT2M(x)   (x*0.00949)
 Macro to convert a delta of GPS decimal*10^7 to a delta of meters (latitude)
#define DELT_GPS_LON2M(x)   (x*0.01342)
 Macro to convert a delta of GPS decimal*10^7 to a delta of meters (longitude)
#define SYSTEM_CLOCK   16000000
 ATmega 2560 clock speed in Hz.
#define SLOW_LOOP_CLOCK   5
 Slow loop clock speed in Hz.
#define MED_LOOP_CLOCK   25
 Medium loop clock speed in Hz.
#define FAST_LOOP_CLOCK   50
 Fast loop clock speed in Hz.
#define TELEMETRY_CLOCK   5
 Telemetry transmit speed in Hz.
#define LOGGING_CLOCK   15
 Logging speed in Hz (except for GPS and barometer, which are in the slow loop)
#define A_LED   37
 set this pin to output to control LED A on the shield
#define B_LED   36
 set this pin to output to control LED B on the shield
#define C_LED   35
 set this pin to output to control LED C on the shield
#define SLIDE_SWITCH   40
 set this pin to input to read the state of the sliding switch on the shield
#define RELAY_SWITCH   47
 set this pin to output to control the Relay Switch on the shield
#define LOGGING_SWITCH   6
 switch attached to analog 6 to control whether or not to log
#define PITOT_CH   7
 The external ADC channel for the pitot probe.
#define PITOT_RATIO   1.0
 Conversion between pitot probe voltage and kPa: once the offset (PITOT_OFFSET) is subtracted, 2V -> 2 kPa.
#define PITOT_OFFSET   2.8
 This voltage reading from the pitot probe corresponds to 0 pressure difference between static and dynamic.
#define RHO   1.2
 The density of air at sea level.
#define ELEVATOR_CH   0
 Elevator Channel definition.
#define RUDDER_CH   1
 Rudder Channel definition.
#define THROTTLE_CH   2
 Throttle Channel definition.
#define RC4_CH   3
 Payload Drop Channel Switch: Ouput #9 on Receiver - Input #4 on APM.
#define DROP_SERVO   3
 Drop servo on APM output #4.
#define RC5_CH   4
 RC ch5 definition.
#define RC6_CH   5
 RC ch6 definition.
#define RC7_CH   6
 RC ch7 definition.
#define RC8_CH   7
 RC ch8 definition.
#define SEC_PER_DAY   86400
 Number of seconds in a day.
#define SEC_PER_HOUR   3600
 Number of seconds in an hour.
#define SEC_PER_MIN   60
 Number of seconds in a minute.
#define HEAD_BYTE1   0xA3
 Header byte for flash memory writing (Decimal 163)
#define HEAD_BYTE2   0x95
 Header byte for flash memory writing (Decimal 149)
#define END_BYTE   0xBA
 End byte for flash memory writing (Decimal 186)
#define LOG_INDEX_MSG   0xF0
 Index header byte for flash memory writing (for determining log numbering)
#define LOG_ATTITUDE_MSG   0x01
 Attitude header byte for flash memory writing (used by ArduPilot Mega, here to keep track of what's used)
#define LOG_GPS_MSG   0x02
 GPS header byte for flash memory writing.
#define LOG_MODE_MSG   0X03
 Mode header byte for flash memory writing (used by ArduPilot Mega, here to keep track of what's used)
#define LOG_BAROMETER_MSG   0X04
 Barometer header byte for flash memory writing.
#define LOG_IMU_MSG   0X05
 IMU header byte for flash memory writing.
#define LOG_RC_MSG   0X06
 RC header byte for flash memory writing.
#define LOG_AIRSPEED_MSG   0x07
 Airspeed header byte for flash memory writing.
#define LOG_MAG_MSG   0x08
 Magnetometer header byte for flash memory writing.
#define LOG_CONTROLS_RUDDER_MSG   0x09
 Controls roll comp header byte for flash memory writing.
#define LOG_CONTROLS_ELEVATOR_MSG   0x0A
 Controls elevator header byte for flash memory writing.
#define LOG_CONTROLS_THROTTLE_MSG   0x0B
 Controls throttle header byte for flash memory writing.
#define LOG_STATE_MSG   0x0C
 State header byte for flash memory writing.
#define LOG_NAVIGATION_MSG   0x0D
 Navigation header byte for flash memory writing.
#define TYPE_AIRSTART_MSG   0x00
 Airstart header byte for flash memory writing (used by ArduPilot Mega, here to keep track of what's used)
#define TYPE_GROUNDSTART_MSG   0x01
 Groundstart header byte for flash memory writing (used by ArduPilot Mega, here to keep track of what's used)
#define MAX_NUM_LOGS   50
 Maximum number of logs allowed in flash memory.
#define GYRO_INT_TIME   0.02
 Gyro integration time for the DCM.

Functions

 FastSerialPort0 (Serial)
 setup fast serial port (for FTDI)
 FastSerialPort1 (Serial1)
 setup fast serial port (for GPS) to make gps library happy
 FastSerialPort3 (Serial3)
 setup fast serial port for telemetry communication

Variables

unsigned long fast_timer
unsigned long medium_timer
unsigned long slow_timer
unsigned long telemetry_timer
unsigned long logging_timer
int rc_elevator = 0
 RC Elevator Input.
int rc_rudder = 0
 RC Rudder Input.
int rc_throttle = 0
 RC Throttle Input.
int rc_4 = 0
 RC Payload Drop Input & ELE_control on/off.
int rc_5 = 0
 RC switch for turning controls on/off.
int rc_6 = 0
 RC knob for adjusting controls gain.
int rc_7 = 0
 RC knob for adjusting controls gain.
int rc_8 = 0
unsigned long drop_timer
 makes sure the rc input wasnt just a fluke, keeps track of how long the input is high to make sure you want to drop
float airspeed
 stores current airspeed reading
float pitot_pressure_offset
 stores an offset for zeroing the pitot pressure measurements
boolean get_wind_profile = true
float sum_wind_ns = 0
 running sum of wind samples in North South direction during ascent
float sum_wind_ew = 0
 running sum of wind samples in East West direction during ascent
int total_ns = 0
 total number of wind samples in NS direction during ascent
int total_ew = 0
 total number of wind samples in EW direction during ascent
float avg_wind_ns = 0
 average wind in NS direction during ascent
float avg_wind_ew = 0
 average wind in EW direction during ascent
float drift_ns = 0.0
float drift_ew = 0.0
int slide_sw = LOW
 state of hardware switch on shield ( either LOW (0) or HIGH (1) )
int logging_sw = 0
 state of the logging switch on analog 6 (see LOGGING_SWITCH)
boolean drop_state = false
 state of the drop servo
boolean use_gps = false
 whether or not to use gps, based on reading the slide_switch at power-on
Vector3f accel
Vector3f gyro
long gps_start_lat = 0
long gps_start_lon = 0
AP_GPS_Auto gps_driver & Serial1
 Initialize GPS (has to be outside of a function for some reason)
APM_BMP085_Class barometer
 declare an instance of the Barometer class
AP_Compass_HMC5843 compass
 declare an instance of the Magnetometer class
AP_DCM dcm & imu
 declare an instance of the DCM class

Detailed Description

Main header file, contains global variables, includes, macros, etc.

Author:
Michael Posner (CIS, MEAM '12)
Timothy Hennelly (ESE '12)
Jacob Orloff (MEAM '12)

Definition in file storc.h.


Define Documentation

#define A_LED   37

set this pin to output to control LED A on the shield

Definition at line 66 of file storc.h.

#define B_LED   36

set this pin to output to control LED B on the shield

Definition at line 67 of file storc.h.

#define C_LED   35

set this pin to output to control LED C on the shield

Definition at line 68 of file storc.h.

#define CONTROLS   1

Easy way to turn controls on (1) and off (0) - if off, Payload release is ON.

Definition at line 42 of file storc.h.

#define DEG2RAD (   x)    (x*0.0174532925)

Macro to convert degrees to radians.

Definition at line 49 of file storc.h.

#define DELT_GPS_LAT2M (   x)    (x*0.00949)

Macro to convert a delta of GPS decimal*10^7 to a delta of meters (latitude)

Definition at line 54 of file storc.h.

#define DELT_GPS_LON2M (   x)    (x*0.01342)

Macro to convert a delta of GPS decimal*10^7 to a delta of meters (longitude)

Definition at line 55 of file storc.h.

#define DELT_M2GPS_LAT (   x)    (x*105.37407797)

Macro to convert a delta of meters to a delta of GPS decimal*10^7 (latitude)

Definition at line 52 of file storc.h.

#define DELT_M2GPS_LON (   x)    (x*74.51564828)

Macro to convert a delta of meters to a delta of GPS decimal*10^7 (longitude)

Definition at line 53 of file storc.h.

#define DROP_SERVO   3

Drop servo on APM output #4.

Definition at line 86 of file storc.h.

#define ELEVATOR_CH   0

Elevator Channel definition.

Definition at line 80 of file storc.h.

#define END_BYTE   0xBA

End byte for flash memory writing (Decimal 186)

Definition at line 101 of file storc.h.

#define FAST_LOOP_CLOCK   50

Fast loop clock speed in Hz.

Definition at line 61 of file storc.h.

#define GRAVITY   9.81

acceleration due to gravity

Definition at line 45 of file storc.h.

#define GYRO_INT_TIME   0.02

Gyro integration time for the DCM.

Definition at line 123 of file storc.h.

#define HEAD_BYTE1   0xA3

Header byte for flash memory writing (Decimal 163)

Definition at line 99 of file storc.h.

#define HEAD_BYTE2   0x95

Header byte for flash memory writing (Decimal 149)

Definition at line 100 of file storc.h.

#define K_DRIFT   0.2564

Definition at line 46 of file storc.h.

#define LOG   0

Easy way to turn logging on (1) and off (0)

Definition at line 40 of file storc.h.

#define LOG_AIRSPEED_MSG   0x07

Airspeed header byte for flash memory writing.

Definition at line 110 of file storc.h.

#define LOG_ATTITUDE_MSG   0x01

Attitude header byte for flash memory writing (used by ArduPilot Mega, here to keep track of what's used)

Definition at line 104 of file storc.h.

#define LOG_BAROMETER_MSG   0X04

Barometer header byte for flash memory writing.

Definition at line 107 of file storc.h.

#define LOG_CONTROLS_ELEVATOR_MSG   0x0A

Controls elevator header byte for flash memory writing.

Definition at line 113 of file storc.h.

#define LOG_CONTROLS_RUDDER_MSG   0x09

Controls roll comp header byte for flash memory writing.

Definition at line 112 of file storc.h.

#define LOG_CONTROLS_THROTTLE_MSG   0x0B

Controls throttle header byte for flash memory writing.

Definition at line 114 of file storc.h.

#define LOG_GPS_MSG   0x02

GPS header byte for flash memory writing.

Definition at line 105 of file storc.h.

#define LOG_IMU_MSG   0X05

IMU header byte for flash memory writing.

Definition at line 108 of file storc.h.

#define LOG_INDEX_MSG   0xF0

Index header byte for flash memory writing (for determining log numbering)

Definition at line 103 of file storc.h.

#define LOG_MAG_MSG   0x08

Magnetometer header byte for flash memory writing.

Definition at line 111 of file storc.h.

#define LOG_MODE_MSG   0X03

Mode header byte for flash memory writing (used by ArduPilot Mega, here to keep track of what's used)

Definition at line 106 of file storc.h.

#define LOG_NAVIGATION_MSG   0x0D

Navigation header byte for flash memory writing.

Definition at line 116 of file storc.h.

#define LOG_RC_MSG   0X06

RC header byte for flash memory writing.

Definition at line 109 of file storc.h.

#define LOG_STATE_MSG   0x0C

State header byte for flash memory writing.

Definition at line 115 of file storc.h.

#define LOGGING_CLOCK   15

Logging speed in Hz (except for GPS and barometer, which are in the slow loop)

Definition at line 63 of file storc.h.

#define LOGGING_SWITCH   6

switch attached to analog 6 to control whether or not to log

Definition at line 71 of file storc.h.

#define MAX_NUM_LOGS   50

Maximum number of logs allowed in flash memory.

Definition at line 120 of file storc.h.

#define MED_LOOP_CLOCK   25

Medium loop clock speed in Hz.

Definition at line 60 of file storc.h.

#define NAVIGATION   0

Turn outer loop navigation on (1) and off (0)

Definition at line 43 of file storc.h.

#define OFFSET_DRIFT   6.4577

Definition at line 47 of file storc.h.

#define PITOT_CH   7

The external ADC channel for the pitot probe.

Definition at line 74 of file storc.h.

#define PITOT_OFFSET   2.8

This voltage reading from the pitot probe corresponds to 0 pressure difference between static and dynamic.

Definition at line 76 of file storc.h.

#define PITOT_RATIO   1.0

Conversion between pitot probe voltage and kPa: once the offset (PITOT_OFFSET) is subtracted, 2V -> 2 kPa.

Definition at line 75 of file storc.h.

#define RAD2DEG (   x)    (x*57.2957795)

Macro to convert radians to degrees.

Definition at line 50 of file storc.h.

#define RC4_CH   3

Payload Drop Channel Switch: Ouput #9 on Receiver - Input #4 on APM.

Definition at line 85 of file storc.h.

#define RC5_CH   4

RC ch5 definition.

Definition at line 88 of file storc.h.

#define RC6_CH   5

RC ch6 definition.

Definition at line 89 of file storc.h.

#define RC7_CH   6

RC ch7 definition.

Definition at line 90 of file storc.h.

#define RC8_CH   7

RC ch8 definition.

Definition at line 91 of file storc.h.

#define RELAY_SWITCH   47

set this pin to output to control the Relay Switch on the shield

Definition at line 70 of file storc.h.

#define RHO   1.2

The density of air at sea level.

Definition at line 77 of file storc.h.

#define RUDDER_CH   1

Rudder Channel definition.

Definition at line 81 of file storc.h.

#define SEC_PER_DAY   86400

Number of seconds in a day.

Definition at line 94 of file storc.h.

#define SEC_PER_HOUR   3600

Number of seconds in an hour.

Definition at line 95 of file storc.h.

#define SEC_PER_MIN   60

Number of seconds in a minute.

Definition at line 96 of file storc.h.

#define SLIDE_SWITCH   40

set this pin to input to read the state of the sliding switch on the shield

Definition at line 69 of file storc.h.

#define SLOW_LOOP_CLOCK   5

Slow loop clock speed in Hz.

Definition at line 59 of file storc.h.

#define SYSTEM_CLOCK   16000000

ATmega 2560 clock speed in Hz.

Definition at line 58 of file storc.h.

#define TELEMETRY   1

Easy way to turn telemetry on (1) and off (0)

Definition at line 41 of file storc.h.

#define TELEMETRY_CLOCK   5

Telemetry transmit speed in Hz.

Definition at line 62 of file storc.h.

#define THROTTLE_CH   2

Throttle Channel definition.

Definition at line 82 of file storc.h.

#define TYPE_AIRSTART_MSG   0x00

Airstart header byte for flash memory writing (used by ArduPilot Mega, here to keep track of what's used)

Definition at line 118 of file storc.h.

#define TYPE_GROUNDSTART_MSG   0x01

Groundstart header byte for flash memory writing (used by ArduPilot Mega, here to keep track of what's used)

Definition at line 119 of file storc.h.


Function Documentation

FastSerialPort0 ( Serial  )

setup fast serial port (for FTDI)

FastSerialPort1 ( Serial1  )

setup fast serial port (for GPS) to make gps library happy

FastSerialPort3 ( Serial3  )

setup fast serial port for telemetry communication


Variable Documentation

Vector3f accel

Definition at line 176 of file storc.h.

float airspeed

stores current airspeed reading

Definition at line 154 of file storc.h.

float avg_wind_ew = 0

average wind in EW direction during ascent

Definition at line 163 of file storc.h.

float avg_wind_ns = 0

average wind in NS direction during ascent

Definition at line 162 of file storc.h.

APM_BMP085_Class barometer

declare an instance of the Barometer class

Definition at line 195 of file storc.h.

AP_Compass_HMC5843 compass

declare an instance of the Magnetometer class

Definition at line 199 of file storc.h.

float drift_ew = 0.0

Definition at line 166 of file storc.h.

float drift_ns = 0.0

Definition at line 165 of file storc.h.

boolean drop_state = false

state of the drop servo

Definition at line 171 of file storc.h.

unsigned long drop_timer

makes sure the rc input wasnt just a fluke, keeps track of how long the input is high to make sure you want to drop

Definition at line 151 of file storc.h.

unsigned long fast_timer

timer for fast loop: stores how much time has elapsed since the last time this loop was run (in milliseconds)

Definition at line 129 of file storc.h.

boolean get_wind_profile = true

Definition at line 157 of file storc.h.

long gps_start_lat = 0

Definition at line 180 of file storc.h.

long gps_start_lon = 0

Definition at line 181 of file storc.h.

Vector3f gyro

Definition at line 177 of file storc.h.

AP_DCM dcm& imu

declare an instance of the DCM class

Definition at line 201 of file storc.h.

int logging_sw = 0

state of the logging switch on analog 6 (see LOGGING_SWITCH)

Definition at line 170 of file storc.h.

unsigned long logging_timer

timer for higher speed logging: stores how much time has elapsed since the last time data was transmitted (in milliseconds)

Definition at line 137 of file storc.h.

unsigned long medium_timer

timer for medium loop: stores how much time has elapsed since the last time this loop was run (in milliseconds)

Definition at line 131 of file storc.h.

stores an offset for zeroing the pitot pressure measurements

Definition at line 155 of file storc.h.

int rc_4 = 0

RC Payload Drop Input & ELE_control on/off.

Definition at line 144 of file storc.h.

int rc_5 = 0

RC switch for turning controls on/off.

Definition at line 145 of file storc.h.

int rc_6 = 0

RC knob for adjusting controls gain.

Definition at line 146 of file storc.h.

int rc_7 = 0

RC knob for adjusting controls gain.

Definition at line 147 of file storc.h.

int rc_8 = 0

Definition at line 148 of file storc.h.

int rc_elevator = 0

RC Elevator Input.

Definition at line 141 of file storc.h.

int rc_rudder = 0

RC Rudder Input.

Definition at line 142 of file storc.h.

int rc_throttle = 0

RC Throttle Input.

Definition at line 143 of file storc.h.

AP_GPS_Auto gps_driver& Serial1

Initialize GPS (has to be outside of a function for some reason)

Definition at line 191 of file storc.h.

int slide_sw = LOW

state of hardware switch on shield ( either LOW (0) or HIGH (1) )

Definition at line 169 of file storc.h.

unsigned long slow_timer

timer for slow loop: stores how much time has elapsed since the last time this loop was run (in milliseconds)

Definition at line 133 of file storc.h.

float sum_wind_ew = 0

running sum of wind samples in East West direction during ascent

Definition at line 159 of file storc.h.

float sum_wind_ns = 0

running sum of wind samples in North South direction during ascent

Definition at line 158 of file storc.h.

unsigned long telemetry_timer

timer for telemetry: stores how much time has elapsed since the last time data was transmitted (in milliseconds)

Definition at line 135 of file storc.h.

int total_ew = 0

total number of wind samples in EW direction during ascent

Definition at line 161 of file storc.h.

int total_ns = 0

total number of wind samples in NS direction during ascent

Definition at line 160 of file storc.h.

boolean use_gps = false

whether or not to use gps, based on reading the slide_switch at power-on

Definition at line 173 of file storc.h.