Skip to content

Commit 9bf1e83

Browse files
committed
* estimate the hover thrust value according to the battery voltage
1 parent 420d33c commit 9bf1e83

4 files changed

Lines changed: 39 additions & 9 deletions

File tree

Control/C/Control.c

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,32 @@ uint8_t isAltLimit=0;
238238
float 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

Control/H/control.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@
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-
2521
enum {CLIMB_RATE=0,MANUAL,LANDING};
2622
extern uint8_t altCtrlMode;
2723
extern float hoverThrust;
@@ -71,6 +67,7 @@ void CtrlMotor(void);
7167
void CtrlTest(void);
7268
void CtrlAttiRateNew(void);
7369
void CtrlAttiNew(void);
70+
float estimateHoverThru(void);
7471

7572
void SetHeadFree(uint8_t on);
7673

HardWareDriver/C/Tim.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff 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

7576
void 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
}

User_Src/CommApp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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;

0 commit comments

Comments
 (0)