Advertisement
Guest User

Untitled

a guest
Feb 4th, 2018
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.63 KB | None | 0 0
  1. #include "defines.h"
  2. #include "hardware.h"
  3.  
  4. // adjust pids in pid.c file
  5.  
  6. //**********************************************************************************************************************
  7. //***********************************************HARDWARE SELECTION*****************************************************
  8.  
  9. // *************DEFINE FLIGHT CONTROLLER HARDWARE
  10. // *************SELECT ONLY ONE
  11. // *************uncomment BWHOOP define for bwhoop, bwhoop pro, E011C Santa Edition, and Beta FPV Lite Flight Controllers
  12. // *************uncomment E011 define for E011 flight Controller
  13. // *************uncomment H8mini_blue_board for the H8 mini flight controller with blue circuit board
  14. //#define BWHOOP
  15. #define E011
  16. //#define H8mini_blue_board
  17.  
  18.  
  19. //**********************************************************************************************************************
  20. //***********************************************RECEIVER SETTINGS******************************************************
  21.  
  22. // *************rate in deg/sec
  23. // *************for acro mode
  24. #define MAX_RATE 360.0
  25. #define MAX_RATEYAW 360.0
  26.  
  27. // *************max angle for level mode
  28. #define MAX_ANGLE_HI 55.0f
  29.  
  30. // ************* low rates multiplier if rates are assigned to a channel
  31. #define LOW_RATES_MULTI 0.5f
  32.  
  33. // *************EXPO from 0.00 to 1.00 , 0 = no exp
  34. // *************positive = less sensitive near center
  35. #define EXPO_XY 0.65
  36. #define EXPO_YAW 0.5
  37.  
  38. // *************transmitter stick adjustable deadband for roll/pitch/yaw
  39. // *************.01f = 1% of stick range - comment out to disable
  40. #define STICKS_DEADBAND .01f
  41.  
  42. // *************Radio protocol selection
  43. // *************select only one
  44. //#define RX_CG023_PROTOCOL
  45. //#define RX_H7_PROTOCOL
  46. #define RX_BAYANG_PROTOCOL
  47. //#define RX_BAYANG_PROTOCOL_TELEMETRY
  48. //#define RX_BAYANG_PROTOCOL_BLE_BEACON
  49. //#define RX_BAYANG_BLE_APP
  50. //#define RX_CX10BLUE_PROTOCOL
  51. //#define RX_SBUS
  52.  
  53. // *************Transmitter Type Selection
  54. #define USE_STOCK_TX
  55. //#define USE_DEVO
  56. //#define USE_MULTI
  57.  
  58. // *******************************SWITCH SELECTION*****************************
  59. // *************CHAN_ON - on always ( all protocols)
  60. // *************CHAN_OFF - off always ( all protocols)
  61. // *************Aux channels are selectable as CHAN_5 through CHAN_10 for DEVO and MULTIMODULE users
  62. // *************Toy transmitters have only CHAN_5 (rates button), CHAN_6 (stick gestures RRD/LLD), and CHAN_7 (headfree button)
  63.  
  64. //*************Idle up-Arm switch
  65. //*************comment out to disable
  66. //#define IDLE_UP CHAN_5
  67. //#define IDLE_THR 0.05f
  68. //#define RATES CHAN_5
  69. //#define RATES CH_EXPERT // from og config, works idk?
  70.  
  71. //*************Assign feature to auxiliary channel
  72. #define LEVELMODE CHAN_6
  73. //#define ACROMODE CHAN_6 // useradded -- find out if this is a thing and use this if it is
  74. #define RACEMODE CHAN_7
  75. #define LEDS_ON CHAN_ON
  76. #define RATES CHAN_ON
  77.  
  78. // *************switch for fpv / other, requires fet
  79. // *************comment out to disable
  80. //#define FPV_ON CHAN_ON
  81.  
  82. // *************start in level mode for toy tx.
  83. #define AUX1_START_ON
  84.  
  85. // *************automatically remove center bias in toy tx ( needs throttle off for 1 second )
  86. //#define STOCK_TX_AUTOCENTER
  87.  
  88.  
  89.  
  90. //**********************************************************************************************************************
  91. //***********************************************VOLTAGE SETTINGS*******************************************************
  92.  
  93. // *************battery saver
  94. // *************do not start software if battery is too low
  95. // *************flashes 2 times repeatedly at startup
  96. #define STOP_LOWBATTERY
  97.  
  98. // *************voltage to start warning
  99. #define VBATTLOW 3.5
  100.  
  101. // *************compensation for battery voltage vs throttle drop
  102. #define VDROP_FACTOR 0.7
  103. // *************calculate above factor automatically
  104. #define AUTO_VDROP_FACTOR
  105.  
  106. // *************voltage hysteresys in volts
  107. #define HYST 0.10
  108.  
  109. // *************lower throttle when battery below treshold - forced landing low voltage cutoff
  110. //#define LVC_LOWER_THROTTLE
  111. #define LVC_LOWER_THROTTLE_VOLTAGE 3.30
  112. #define LVC_LOWER_THROTTLE_VOLTAGE_RAW 2.70
  113. #define LVC_LOWER_THROTTLE_KP 3.0
  114.  
  115.  
  116.  
  117.  
  118. //**********************************************************************************************************************
  119. //***********************************************FILTER SETTINGS********************************************************
  120.  
  121. // *************gyro low pass filter ( iir )
  122. // *************set only one below - kalman, 1st order, or second order - and adjust frequency
  123. //**************ABOVE 100 ADJUST IN INCRIMENTS OF 20, BELOW 100 ADJUST IN INCRIMENTS OF 10
  124. #define SOFT_KALMAN_GYRO KAL1_HZ_90
  125. //#define SOFT_LPF_1ST_HZ 80
  126. //#define SOFT_LPF_2ND_HZ 80
  127.  
  128.  
  129. // *************D term low pass filter type - set only one below and adjust frequency if adjustable filter is used
  130. // *************1st order adjustable, second order adjustable, or 3rd order fixed (non adjustable)
  131. //#define DTERM_LPF_1ST_HZ 100
  132. #define DTERM_LPF_2ND_HZ 100
  133. //#define DTERM_LPF3_88
  134.  
  135. //**********************************************************************************************************************
  136. //***********************************************MOTOR OUTPUT SETTINGS**************************************************
  137.  
  138. // *************enable motor output filter - select and adjust frequency
  139. #define MOTOR_FILTER2_ALPHA MFILT1_HZ_90
  140. //#define MOTOR_KAL KAL1_HZ_70
  141.  
  142. // *************pwm frequency for motor control
  143. // *************a higher frequency makes the motors more linear
  144. // *************in Hz
  145. #define PWMFREQ 32000
  146.  
  147. // *************motor curve to use - select one
  148. // *************the pwm frequency has to be set independently
  149. #define MOTOR_CURVE_NONE
  150. //#define MOTOR_CURVE_6MM_490HZ
  151. //#define MOTOR_CURVE_85MM_8KHZ
  152. //#define MOTOR_CURVE_85MM_32KHZ
  153. //#define BOLDCLASH_716MM_8K
  154. //#define BOLDCLASH_716MM_24K
  155.  
  156. // *************clip feedforward attempts to resolve issues that occur near full throttle
  157. //#define CLIP_FF
  158.  
  159. // *************torque boost is a highly eperimental feature. it is a lpf D term on motor outputs that will accelerate the response
  160. // *************of the motors when the command to the motors is changing by increasing or decreasing the voltage thats sent. It differs
  161. // *************from throttle transient compensation in that it acts on all motor commands - not just throttle changes. this feature
  162. // *************is very noise sensative so D term specifically has to be lowered and gyro/d filtering may need to be increased.
  163. // *************reccomendation right now is to leave boost at or below 2, drop your p gains a few points, then cut your D in half and
  164. // *************retune it back up to where it feels good. I'm finding about 60 to 65% of my previous D value seems to work.
  165. //#define TORQUE_BOOST 0.5
  166.  
  167. // *************makes throttle feel more poppy - can intensify small throttle imbalances visible in FPV if factor is set too high
  168. //#define THROTTLE_TRANSIENT_COMPENSATION
  169. #define THROTTLE_TRANSIENT_COMPENSATION_FACTOR 4.0
  170.  
  171. // *************throttle angle compensation in level mode
  172. //#define AUTO_THROTTLE
  173.  
  174. // *************mix lower throttle reduces thrust imbalances by reducing throttle proportionally to the adjustable reduction percent
  175. // *************mix increase throttle increases the authority of the pid controller at lowest throttle values like airmode when combined with idle up
  176. // *************mix3 has a stronger effect and works better with brushless
  177. #define MIX_LOWER_THROTTLE
  178. #define MIX_THROTTLE_REDUCTION_PERCENT 10
  179. //#define MIX_INCREASE_THROTTLE
  180.  
  181. //#define MIX_LOWER_THROTTLE_3
  182. #define MIX_INCREASE_THROTTLE_3
  183.  
  184. // *************invert yaw pid for "PROPS OUT" configuration
  185. //#define INVERT_YAW_PID
  186.  
  187.  
  188.  
  189. //**********************************************************************************************************************
  190. //***********************************************ADDITIONAL FEATURES****************************************************
  191.  
  192. // *************lost quad beeps using motors (30 sec timeout)
  193. #define MOTOR_BEEPS
  194.  
  195. // *************0 - 7 - power for telemetry
  196. #define TX_POWER 7
  197.  
  198. // *************Flash saving features
  199. //#define DISABLE_GESTURES2
  200.  
  201. // *************led brightness in-flight ( solid lights only)
  202. // *************0- 15 range
  203. #define LED_BRIGHTNESS 0
  204.  
  205. // *************external buzzer - pins in hardware.h
  206. //#define BUZZER_ENABLE
  207.  
  208. // *************Comment out to disable pid tuning gestures
  209. #define PID_GESTURE_TUNING
  210. #define COMBINE_PITCH_ROLL_PID_TUNING
  211.  
  212. // *************flash save method
  213. // *************flash_save 1: pids + accel calibration
  214. // *************flash_save 2: accel calibration to option bytes
  215. #define FLASH_SAVE1
  216. //#define FLASH_SAVE2
  217.  
  218.  
  219. // enable inverted flight code ( brushless only )
  220. //#define INVERTED_ENABLE
  221. //#define FN_INVERTED CH_OFF //for brushless only
  222.  
  223.  
  224.  
  225.  
  226.  
  227.  
  228.  
  229. //#############################################################################################################################
  230. //#############################################################################################################################
  231. // debug / other things
  232. // this should not be usually changed
  233. //#############################################################################################################################
  234. //#############################################################################################################################
  235.  
  236. // Gyro LPF filter frequency
  237. // gyro filter 0 = 250hz delay 0.97mS
  238. // gyro filter 1 = 184hz delay 2.9mS
  239. // gyro filter 2 = 92hz delay 3.9mS
  240. // gyro filter 3 = 41hz delay 5.9mS (Default)
  241. // gyro filter 4 = 20hz
  242. // gyro filter 5 = 10hz
  243. // gyro filter 6 = 5hz
  244. // gyro filter 7 = 3600hz delay 0.17mS
  245. #define GYRO_LOW_PASS_FILTER 0
  246.  
  247. // disable inbuilt expo functions
  248. //#define DISABLE_EXPO
  249.  
  250. #define DISABLE_FLIP_SEQUENCER
  251. #define STARTFLIP CHAN_OFF
  252.  
  253. // level mode "manual" trims ( in degrees)
  254. // pitch positive forward
  255. // roll positive right
  256. #define TRIM_PITCH 0.0
  257. #define TRIM_ROLL 0.0
  258.  
  259. // disable motors for testing
  260. //#define NOMOTORS
  261.  
  262. // throttle direct to motors for thrust measure
  263. // #define MOTORS_TO_THROTTLE
  264.  
  265. // throttle direct to motors for thrust measure as a flight mode
  266. //#define MOTORS_TO_THROTTLE_MODE MULTI_CHAN_8
  267.  
  268.  
  269. // loop time in uS
  270. // this affects soft gyro lpf frequency if used
  271. #define LOOPTIME 1000
  272.  
  273. // failsafe time in uS
  274. #define FAILSAFETIME 1000000 // one second
  275.  
  276. // max rate used by level pid ( limit )
  277. #define LEVEL_MAX_RATE 360
  278.  
  279. // debug things ( debug struct and other)
  280. //#define DEBUG
  281.  
  282. // rxdebug structure
  283. //#define RXDEBUG
  284.  
  285. // enable motors if pitch / roll controls off center (at zero throttle)
  286. // possible values: 0 / 1
  287. // use in acro build only
  288. #define ENABLESTIX 0
  289. #define ENABLESTIX_TRESHOLD 0.3
  290. #define ENABLESTIX_TIMEOUT 1e6
  291.  
  292. // overclock to 64Mhz
  293. #define ENABLE_OVERCLOCK
  294.  
  295.  
  296. // limit minimum motor output to a value (0.0 - 1.0)
  297. //#define MOTOR_MIN_ENABLE
  298. #define MOTOR_MIN_VALUE 0.05
  299.  
  300.  
  301.  
  302.  
  303.  
  304. #pragma diag_warning 1035 , 177 , 4017
  305. #pragma diag_error 260
  306.  
  307. //--fpmode=fast
  308.  
  309.  
  310.  
  311.  
  312.  
  313. // define logic - do not change
  314. ///////////////
  315.  
  316. // used for pwm calculations
  317. #ifdef ENABLE_OVERCLOCK
  318. #define SYS_CLOCK_FREQ_HZ 64000000
  319. #else
  320. #define SYS_CLOCK_FREQ_HZ 48000000
  321. #endif
  322.  
  323.  
  324.  
  325. #ifdef MOTOR_BEEPS
  326. #ifdef USE_ESC_DRIVER
  327. #warning "MOTOR BEEPS_WORKS WITH BRUSHED MOTORS ONLY"
  328. #endif
  329. #endif
  330.  
  331.  
  332.  
  333. // for the ble beacon to work after in-flight reset
  334. #ifdef RX_BAYANG_PROTOCOL_BLE_BEACON
  335. #undef STOP_LOWBATTERY
  336. #endif
  337.  
  338.  
  339. // gcc warnings in main.c
  340.  
  341.  
  342.  
  343. //Hardware defines moved from hardware.h so that board selection of bwhoop or e011 can be performed in config.h file
  344.  
  345. #ifdef BWHOOP
  346. #define LED_NUMBER 2
  347. #define LED1PIN GPIO_Pin_2
  348. #define LED1PORT GPIOA
  349. #define LED1_INVERT
  350. #define LED2_INVERT
  351. #define GYRO_ID_2 0x98 // new id
  352. #define SENSOR_ROTATE_90_CW
  353. // SPI PINS DEFINITONS ( for radio ic )
  354. #define SPI_MOSI_PIN GPIO_Pin_0
  355. #define SPI_MOSI_PORT GPIOA
  356. //#define SPI_MISO_PIN GPIO_Pin_15
  357. //#define SPI_MISO_PORT GPIOA
  358. #define SPI_CLK_PIN GPIO_Pin_1
  359. #define SPI_CLK_PORT GPIOF
  360. #define SPI_SS_PIN GPIO_Pin_0
  361. #define SPI_SS_PORT GPIOF
  362.  
  363. // Assingment of pin to motor
  364. // back-left motor ( motor 0 )
  365. #define MOTOR0_PIN_PB1
  366. // front-left motor ( motor 1 )
  367. #define MOTOR1_PIN_PA4
  368. // back-right motor ( motor 2 )
  369. #define MOTOR2_PIN_PA6
  370. // front-right motor ( motor 3 )
  371. #define MOTOR3_PIN_PA7
  372. #endif
  373.  
  374. #ifdef E011
  375. #define LED_NUMBER 2
  376. #define LED1PIN GPIO_Pin_2
  377. #define LED1PORT GPIOA
  378. #define LED1_INVERT
  379. #define LED2_INVERT
  380. #define GYRO_ID_2 0x98 // new id
  381. #define SENSOR_ROTATE_90_CW
  382. #define SOFTI2C_PUSHPULL_CLK
  383. // SPI PINS DEFINITONS ( for radio ic )
  384. #define SPI_MOSI_PIN GPIO_Pin_0
  385. #define SPI_MOSI_PORT GPIOF
  386. //#define SPI_MISO_PIN GPIO_Pin_15
  387. //#define SPI_MISO_PORT GPIOA
  388. #define SPI_CLK_PIN GPIO_Pin_1
  389. #define SPI_CLK_PORT GPIOF
  390. #define SPI_SS_PIN GPIO_Pin_0
  391. #define SPI_SS_PORT GPIOA
  392.  
  393. // Assingment of pin to motor
  394. // back-left motor ( motor 0 )
  395. #define MOTOR0_PIN_PA6
  396. // front-left motor ( motor 1 )
  397. #define MOTOR1_PIN_PA4
  398. // back-right motor ( motor 2 )
  399. #define MOTOR2_PIN_PB1
  400. // front-right motor ( motor 3 )
  401. #define MOTOR3_PIN_PA7
  402. #endif
  403.  
  404. #ifdef H8mini_blue_board
  405. #define LED_NUMBER 1
  406. #define LED1PIN GPIO_Pin_1
  407. #define LED1PORT GPIOF
  408. #define SOFTI2C_PUSHPULL_CLK
  409. #define GYRO_ID_2 0x78 // common h8 gyro
  410. #define SENSOR_ROTATE_180
  411. #define SPI_MOSI_PIN GPIO_Pin_1
  412. #define SPI_MOSI_PORT GPIOA
  413. #define SPI_CLK_PIN GPIO_Pin_2
  414. #define SPI_CLK_PORT GPIOA
  415. #define SPI_SS_PIN GPIO_Pin_3
  416. #define SPI_SS_PORT GPIOA
  417. #define MOTOR0_PIN_PA6
  418. #define MOTOR1_PIN_PA4
  419. #define MOTOR2_PIN_PB1
  420. #define MOTOR3_PIN_PA7
  421. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement