File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -238,6 +238,32 @@ uint8_t isAltLimit=0;
238238float altLand ;
239239//#define DEBUG_HOLD_REAL_ALT
240240
241+
242+ //函数名:estimateHoverThru()
243+ //输入:无
244+ //输出: 预估得到的悬停油门值
245+ //描述:预估悬停油门值,直接影响到该飞行器的z轴悬停
246+ //悬停油门值相关因素有:电池电压
247+ //Get a estimated value for hold throttle.It will have a direct affection on hover
248+ //Battery voltage
249+ float estimateHoverThru (void ){
250+ float hoverHru = 0.55f ;
251+
252+ //电池电压检测
253+ Battery .BatteryAD = GetBatteryAD ();
254+ Battery .BatteryVal = Battery .Bat_K * (Battery .BatteryAD /4096.0 ) * Battery .ADRef ;//实际电压 值计算
255+
256+ if (Battery .BatteryVal > 3.9 ){
257+ hoverHru = 0.45f ;
258+ }else if (Battery .BatteryVal > 3.8 ){
259+ hoverHru = 0.52f ;
260+ }else {
261+ hoverHru = 0.58f ;
262+ }
263+
264+ return hoverHru ;
265+ }
266+
241267//函数名:CtrlAlti()
242268//输入:无
243269//输出: 最终结果输出到全局变量thrustZSp
@@ -322,11 +348,12 @@ void CtrlAlti(void)
322348 posZVelSp = LAND_SPEED ;
323349
324350 //--------------pos z vel ctrl -----------//
325- if ( zIntReset ) //tobe tested . how to get hold throttle. give it a estimated value!!!!!!!!!!!
326- {
327- thrustZInt = HOVER_THRU ; //-manThr; //650/1000 = 0.65
328- zIntReset = 0 ;
351+ // get hold throttle. give it a estimated value
352+ if ( zIntReset ) {
353+ thrustZInt = estimateHoverThru ();
354+ zIntReset = 0 ;
329355 }
356+
330357 velZ = nav .vz ;
331358 velZErr = posZVelSp - velZ ;
332359 valZErrD = (spZMoveRate - velZ ) * alt_PID .P - (velZ - velZPrev ) / dt ; //spZMoveRate is from manual stick vel control
Original file line number Diff line number Diff line change 1818#define ALT_VEL_MAX 4.0f
1919#define THR_MIN 0.38f //min thrust ,根据机重和最小降速而定,用于下降速度过大时,油门过小,导致失衡。再增加fuzzy control ,在油门小时用更大的姿态参数
2020
21-
22- #define HOVER_THRU -0.55 //-0.5f //悬停
23-
24-
2521enum {CLIMB_RATE = 0 ,MANUAL ,LANDING };
2622extern uint8_t altCtrlMode ;
2723extern float hoverThrust ;
@@ -71,6 +67,7 @@ void CtrlMotor(void);
7167void CtrlTest (void );
7268void CtrlAttiRateNew (void );
7369void CtrlAttiNew (void );
70+ float estimateHoverThru (void );
7471
7572void SetHeadFree (uint8_t on );
7673
Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ Tim.c file
2323#include "tim.h"
2424#include "config.h"
2525#include "imu.h"
26+ #include "control.h"
2627
2728#define TASK_TICK_FREQ 1000 //Hz 主任务频率
2829
@@ -74,6 +75,8 @@ extern u8 RX_ADDRESS[5];
7475
7576void TIM3_IRQHandler (void ) //打印中断服务程序
7677{
78+ float hoverThru ;
79+
7780 if ( TIM_GetITStatus (TIM3 , TIM_IT_Update ) != RESET )
7881 {
7982 Battery .BatteryAD = GetBatteryAD (); //电池电压检测
@@ -111,6 +114,9 @@ void TIM3_IRQHandler(void) //打印中断服务程序
111114 printf ("====================================\r\n" );
112115 //根据采集到的AD值,计算实际电压。硬件上是对电池进行分压后给AD采集的,所以结果要乘以2
113116 printf (" Battery Voltage---> %3.2fv\r\n" ,Battery .BatteryVal );
117+
118+ hoverThru = estimateHoverThru ();
119+ printf (" Hover Thru---> %3.2f\r\n" ,hoverThru );
114120 printf (" RX Addr ---> 0x%x\r\n" ,RX_ADDRESS [4 ]);
115121 printf ("====================================\r\n" );
116122 }
Original file line number Diff line number Diff line change @@ -66,7 +66,7 @@ void RCDataProcess(void)
6666 altCtrlMode = MANUAL ; //上锁后加的处理
6767 zIntReset = 1 ; //
6868 thrustZSp = 0 ;
69- thrustZInt = HOVER_THRU ;
69+ thrustZInt = estimateHoverThru () ;
7070 offLandFlag = 0 ;
7171
7272 armState = DISARMED ;
You can’t perform that action at this time.
0 commit comments