sketchbook
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
MultiWii.h
Go to the documentation of this file.
1 #ifndef MULTIWII_H_
2 #define MULTIWII_H_
3 
4 #define VERSION 240
5 #define NAVI_VERSION 7 //This allow sync with GUI
6 #include "types.h"
7 #include "Alarms.h"
8 
9 #define MINCHECK 1100
10 #define MAXCHECK 1900
11 
12 extern volatile unsigned long timer0_overflow_count;
13 
14 extern const char pidnames[];
15 extern const char boxnames[];
16 extern const uint8_t boxids[];
17 
18 extern uint32_t currentTime;
19 extern uint16_t previousTime;
20 extern uint16_t cycleTime;
21 extern uint16_t calibratingA;
22 extern uint16_t calibratingB;
23 extern uint16_t calibratingG;
24 extern int16_t magHold,headFreeModeHold;
25 extern uint8_t vbatMin;
26 extern uint8_t rcOptions[CHECKBOXITEMS];
27 extern int32_t AltHold;
28 extern int16_t sonarAlt;
29 extern int16_t BaroPID;
30 extern int16_t errorAltitudeI;
31 
32 extern int16_t i2c_errors_count;
33 extern uint8_t alarmArray[ALRM_FAC_SIZE];
35 
36 extern imu_t imu;
37 extern analog_t analog;
38 extern alt_t alt;
39 extern att_t att;
40 #ifdef LOG_PERMANENT
41 extern plog_t plog;
42 #endif
43 
44 extern int16_t debug[4];
45 
46 extern conf_t conf;
47 extern int16_t annex650_overrun_count;
48 extern flags_struct_t f;
49 extern uint16_t intPowerTrigger1;
50 
51 extern int16_t gyroZero[3];
52 extern int16_t angle[2];
53 
54 
55 #if BARO
56  extern int32_t baroPressure;
57  extern int16_t baroTemperature; // temp in 0.01 deg
58  extern int32_t baroPressureSum;
59 #endif
60 
61 extern int16_t axisPID[3];
62 extern int16_t motor[8];
63 extern int16_t servo[8];
64 
65 extern int16_t failsafeEvents;
66 extern volatile int16_t failsafeCnt;
67 
68 extern int16_t rcData[RC_CHANS];
69 extern int16_t rcSerial[8];
70 extern int16_t rcCommand[4];
71 extern uint8_t rcSerialCount;
72 extern int16_t lookupPitchRollRC[5];
73 extern uint16_t lookupThrottleRC[11];
74 
75 #if defined(POWERMETER) || ( defined(LOG_VALUES) && (LOG_VALUES >= 3) )
76  #define PMOTOR_SUM 8 // index into pMeter[] for sum
77  extern uint32_t pMeter[PMOTOR_SUM + 1]; // we use [0:7] for eight motors,one extra for sum
78  extern uint8_t pMeterV; // dummy to satisfy the paramStruct logic in ConfigurationLoop()
79  extern uint32_t pAlarm; // we scale the eeprom value from [0:255] to this value we can directly compare to the sum in pMeter[6]
80  extern uint16_t powerValue; // last known current
81 #endif
82 
83 #if defined(LCD_TELEMETRY)
84  extern uint8_t telemetry;
85  extern uint8_t telemetry_auto;
86 #endif
87 #ifdef LCD_TELEMETRY_STEP
88  extern char telemetryStepSequence[];
89  extern uint8_t telemetryStepIndex;
90 #endif
91 
92 #if defined(LOG_VALUES) || defined(LCD_TELEMETRY)
93  extern uint16_t cycleTimeMax; // highest ever cycle timen
94  extern uint16_t cycleTimeMin; // lowest ever cycle timen
95  extern int32_t BAROaltMax; // maximum value
96  extern uint16_t GPS_speedMax; // maximum speed from gps
97  extern uint16_t powerValueMaxMAH;
98  extern uint16_t wattsMax;
99 #endif
100 #if defined(LOG_VALUES) || defined(LCD_TELEMETRY) || defined(ARMEDTIMEWARNING) || defined(LOG_PERMANENT)
101  extern uint32_t armedTime;
102 #endif
103 
104 #if GPS
105 // *************************************** begin GPS common variables and defines ******************************************************************
106 
107 extern gps_conf_struct GPS_conf;
108 
109 extern int16_t GPS_angle[2]; // the angles that must be applied for GPS correction
110 extern int32_t GPS_coord[2];
111 extern int32_t GPS_home[2];
112 extern int32_t GPS_hold[2];
113 extern int32_t GPS_prev[2];
114 extern int32_t GPS_poi[2]; // Coordinates of the current poi
115 extern int32_t GPS_directionToPoi; // direction to the actual poi (used to set heading to poi)
116 extern uint8_t GPS_numSat;
117 extern uint16_t GPS_distanceToHome; // distance to home - unit: meter
118 extern int16_t GPS_directionToHome; // direction to home - unit: degree
119 extern uint16_t GPS_altitude; // GPS altitude - unit: meter
120 extern uint16_t GPS_speed; // GPS speed - unit: cm/s
121 extern uint8_t GPS_update; // a binary toogle to distinct a GPS position update
122 extern uint16_t GPS_ground_course; // - unit: degree*10
123 extern uint32_t GPS_time;
124 
125 extern uint8_t GPS_mode; // contains the current selected gps flight mode
126 
127 extern uint8_t NAV_error; //Last error situation of the nav engine
128 extern uint8_t NAV_state; //State of the nav engine
129 extern uint8_t GPS_saved_mission_state; //The mission state saved when poshold invoked during mission
130 extern uint8_t prv_gps_modes; //GPS_checkbox items packed into 1 byte for checking GPS mode changes
131 extern uint32_t nav_timer_stop; //common timer used in navigation (contains the desired stop time in millis()
132 extern uint16_t nav_hold_time; //time in seconds to hold position
133 extern uint8_t NAV_paused_at; //This contains the mission step where poshold paused the runing mission.
134 extern uint8_t next_step; //The mission step which is upcoming it equals with the mission_step stored in EEPROM
135 
136 //Altitude control state
137 #define ASCENDING 1
138 #define DESCENDING -1
139 #define REACHED_ALT 0
140 
141 // The orginal altitude used as base our new altitude during nav
142 extern int32_t original_altitude;
143 //This is the target what we want to reach
144 extern int32_t target_altitude;
145 //This is the interim value which is feeded into the althold controller
146 extern int32_t alt_to_hold;
147 
148 extern uint32_t alt_change_timer;
149 extern int8_t alt_change_flag;
150 extern uint32_t alt_change;
151 extern int16_t jump_times; //How many loops do we have to do (alt/100 from mission step) -10 means not used jet, -1 unlimited
152 extern uint8_t land_detect; //land detector variable
153 
154 
155 // ************************
156 // mission step structure
157 // ************************
158 extern mission_step_struct mission_step;
159 
160 //possible action codes for a mission step
161 #define MISSION_WAYPOINT 1 //Set waypoint
162 #define MISSION_HOLD_UNLIM 2 //Poshold unlimited
163 #define MISSION_HOLD_TIME 3 //Hold for a predetermined time
164 #define MISSION_RTH 4 //Return to HOME
165 #define MISSION_SET_POI 5 //Set POINT of interest
166 #define MISSION_JUMP 6 //Jump to the given step (#times)
167 #define MISSION_SET_HEADING 7 //Set heading to a given orientation (parameter 1 is the waym 0-359 degree
168 #define MISSION_LAND 8 //Land at the given position
169 
170 
171 #define MISSION_FLAG_END 0xA5 //Flags that this is the last step
172 #define MISSION_FLAG_CRC_ERROR 0xFE //Returned WP had an EEPROM CRC error
173 #define MISSION_FLAG_HOME 0x01 //Returned WP is the home position
174 #define MISSION_FLAG_HOLD 0x02 //Returned WP is the hold position
175 #define MISSION_FLAG_DO_LAND 0x20 //Land when reached desired point (used in RTH)
176 #define MISSION_FLAG_NAV_IN_PROG 0xff //Navigation is in progress, returned wp is home
177 
178 #define LAT 0
179 #define LON 1
180 
181 extern int16_t nav[2];
182 
183 
184 #endif
185 
186 // default POSHOLD control gains
187 #define POSHOLD_P .15
188 #define POSHOLD_I 0.0
189 #define POSHOLD_IMAX 20 // degrees
190 
191 #define POSHOLD_RATE_P 3.4
192 #define POSHOLD_RATE_I 0.14 // Wind control
193 #define POSHOLD_RATE_D 0.053 // try 2 or 3 for POSHOLD_RATE 1
194 #define POSHOLD_RATE_IMAX 20 // degrees
195 
196 // default Navigation PID gains
197 #define NAV_P 2.5
198 #define NAV_I 0.33 // Wind control
199 #define NAV_D 0.083 //
200 #define NAV_IMAX 20 // degrees
201 
202 
203 // *************************************** end GPS common variables and defines ******************************************************************
204 
205 extern volatile uint8_t spekFrameFlags;
206 extern volatile uint32_t spekTimeLast;
207 extern uint8_t spekFrameDone;
208 
209 #if defined(OPENLRSv2MULTI)
210 extern uint8_t pot_P,pot_I; // OpenLRS onboard potentiometers for P and I trim or other usages
211 #endif
212 
213 // **********************
214 //Automatic ACC Offset Calibration
215 // **********************
216 #if defined(INFLIGHT_ACC_CALIBRATION)
217 extern uint16_t InflightcalibratingA;
218 extern int16_t AccInflightCalibrationArmed;
219 extern uint16_t AccInflightCalibrationMeasurementDone;
220 extern uint16_t AccInflightCalibrationSavetoEEProm;
221 extern uint16_t AccInflightCalibrationActive;
222 #endif
223 
224 #if defined(ARMEDTIMEWARNING)
225  extern uint32_t ArmedTimeWarningMicroSeconds;
226 #endif
227 
228 #if defined(THROTTLE_ANGLE_CORRECTION)
229  extern int16_t throttleAngleCorrection;
230  extern int8_t cosZ;
231 #endif
232 
233 void annexCode();
234 void go_disarm();
235 #endif /* MULTIWII_H_ */
const char boxnames[]
Definition: MultiWii.cpp:46
int32_t GPS_coord[2]
Definition: MultiWii.cpp:318
const char pidnames[]
int16_t baroTemperature
Definition: Uno_MultiWii_HardwarePlatform_Test.ino:63
Definition: types.h:86
uint8_t spekFrameDone
uint16_t calibratingG
Definition: MultiWii.cpp:162
uint8_t prv_gps_modes
Definition: MultiWii.cpp:335
volatile uint8_t spekFrameFlags
alt_t alt
Definition: MultiWii.cpp:180
uint16_t cycleTime
Definition: MultiWii.cpp:159
global_conf_t global_conf
Definition: MultiWii.cpp:303
conf_t conf
Definition: MultiWii.cpp:305
int8_t alt_change_flag
Definition: MultiWii.cpp:359
uint8_t NAV_error
Definition: MultiWii.cpp:334
void annexCode()
Definition: MultiWii.cpp:370
uint16_t intPowerTrigger1
Definition: MultiWii.cpp:239
uint8_t rcOptions[CHECKBOXITEMS]
Definition: MultiWii.cpp:165
analog_t analog
Definition: MultiWii.cpp:178
uint16_t calibratingA
Definition: MultiWii.cpp:160
uint16_t GPS_distanceToHome
Definition: MultiWii.cpp:324
int16_t sonarAlt
Definition: MultiWii.cpp:167
uint8_t rcSerialCount
Definition: MultiWii.cpp:276
int32_t GPS_prev[2]
Definition: MultiWii.cpp:321
int16_t lookupPitchRollRC[5]
Definition: MultiWii.cpp:277
uint32_t currentTime
Definition: MultiWii.cpp:157
uint8_t NAV_state
Definition: MultiWii.cpp:333
uint8_t NAV_paused_at
time in seconds to hold position
Definition: MultiWii.cpp:338
volatile uint32_t spekTimeLast
int16_t debug[4]
Definition: MultiWii.cpp:188
uint8_t next_step
Definition: MultiWii.cpp:340
uint16_t GPS_altitude
Definition: MultiWii.cpp:327
int32_t baroPressureSum
Definition: Uno_MultiWii_HardwarePlatform_Test.ino:66
int16_t gyroZero[3]
Definition: MultiWii.cpp:174
int32_t GPS_home[2]
Definition: MultiWii.cpp:319
uint8_t vbatMin
Definition: MultiWii.cpp:164
int32_t GPS_directionToPoi
Definition: MultiWii.cpp:326
int32_t original_altitude
Definition: MultiWii.cpp:352
uint8_t alarmArray[ALRM_FAC_SIZE]
Definition: MultiWii.cpp:362
int16_t annex650_overrun_count
int32_t alt_to_hold
Definition: MultiWii.cpp:356
int16_t motor[8]
Definition: MultiWii.cpp:295
uint32_t alt_change_timer
Definition: MultiWii.cpp:358
flags_struct_t f
Definition: MultiWii.cpp:190
uint8_t GPS_numSat
Definition: MultiWii.cpp:323
#define RC_CHANS
Definition: def.h:1839
int16_t GPS_directionToHome
Definition: MultiWii.cpp:325
int16_t angle[2]
Definition: types.h:89
uint16_t lookupThrottleRC[11]
Definition: MultiWii.cpp:278
int16_t i2c_errors_count
Definition: MultiWii.cpp:209
int16_t GPS_angle[2]
Definition: MultiWii.cpp:317
int16_t rcSerial[8]
Definition: MultiWii.cpp:274
imu_t imu
Definition: MultiWii.cpp:176
uint32_t nav_timer_stop
GPS_checkbox items packed into 1 byte for checking GPS mode changes.
Definition: MultiWii.cpp:336
uint16_t GPS_speed
Definition: MultiWii.cpp:328
int16_t BaroPID
Definition: MultiWii.cpp:168
Definition: types.h:106
int16_t rcCommand[4]
Definition: MultiWii.cpp:275
Definition: types.h:172
int16_t axisPID[3]
Definition: MultiWii.cpp:294
volatile int16_t failsafeCnt
Definition: MultiWii.cpp:271
uint16_t calibratingB
Definition: MultiWii.cpp:161
uint16_t GPS_ground_course
Definition: MultiWii.cpp:330
int16_t failsafeEvents
Definition: MultiWii.cpp:270
int16_t rcData[RC_CHANS]
Definition: MultiWii.cpp:273
volatile unsigned long timer0_overflow_count
Definition: types.h:111
Definition: types.h:116
int16_t servo[8]
Definition: MultiWii.cpp:296
uint16_t nav_hold_time
common timer used in navigation (contains the desired stop time in millis()
Definition: MultiWii.cpp:337
uint16_t previousTime
Definition: MultiWii.cpp:158
int16_t nav[2]
Definition: MultiWii.cpp:348
int16_t jump_times
The mission step which is upcoming it equals with the mission_step stored in EEPROM.
Definition: MultiWii.cpp:341
Definition: Alarms.h:42
int32_t baroPressure
Definition: Uno_MultiWii_HardwarePlatform_Test.ino:62
void go_disarm()
Definition: MultiWii.cpp:806
int32_t GPS_poi[2]
Definition: MultiWii.cpp:322
int32_t AltHold
Definition: MultiWii.cpp:166
uint32_t alt_change
Definition: MultiWii.cpp:360
uint8_t GPS_update
Definition: MultiWii.cpp:329
int16_t magHold
Definition: MultiWii.cpp:163
Definition: types.h:97
int16_t errorAltitudeI
Definition: MultiWii.cpp:169
const uint8_t boxids[]
Definition: MultiWii.cpp:101
int32_t GPS_hold[2]
Definition: MultiWii.cpp:320
att_t att
Definition: MultiWii.cpp:182
int32_t target_altitude
Definition: MultiWii.cpp:354
int16_t headFreeModeHold
Definition: MultiWii.cpp:163
Definition: types.h:151