日常更新,适配3.5寸桨叶版,新加障碍分段参数
This commit is contained in:
@@ -42,7 +42,6 @@ inline static float clip_f32(float x, float low, float up)
|
||||
}
|
||||
|
||||
#define FIX_DRIVE 0
|
||||
|
||||
void by_pwm_init(void)
|
||||
{
|
||||
gpio_init(D4, GPO, 1, GPO_PUSH_PULL);
|
||||
@@ -61,9 +60,9 @@ void by_pwm_init(void)
|
||||
pwm_init(FAN_RB_PWM_B_PIN, 20000, 7000);
|
||||
while (1);
|
||||
#elif FIX_DRIVE == 2
|
||||
pwm_init(FAN_LS_PWM_A_PIN, 20000, 0);
|
||||
pwm_init(FAN_LS_PWM_A_PIN, 20000, 1000);
|
||||
pwm_init(FAN_LS_PWM_B_PIN, 20000, 0);
|
||||
pwm_init(FAN_RS_PWM_A_PIN, 20000, 0);
|
||||
pwm_init(FAN_RS_PWM_A_PIN, 20000, 1000);
|
||||
pwm_init(FAN_RS_PWM_B_PIN, 20000, 0);
|
||||
pwm_init(FAN_LB_PWM_A_PIN, 20000,1000);
|
||||
pwm_init(FAN_LB_PWM_B_PIN, 20000, 0);
|
||||
|
||||
144
app/jj_motion.c
144
app/jj_motion.c
@@ -8,8 +8,7 @@
|
||||
#include "by_imu.h"
|
||||
|
||||
PID_TypeDef far_angle_pid;
|
||||
PID_TypeDef str_angle_pid;
|
||||
PID_TypeDef tur_cal_pid;
|
||||
PID_TypeDef pos_pid;
|
||||
PID_TypeDef far_gyro_pid;
|
||||
PID_TypeDef speed_pid;
|
||||
PID_TypeDef cir_pos_pid;
|
||||
@@ -25,16 +24,29 @@ float an_Kd0 = 0.0f;
|
||||
float an_Kp1 = 45.0f;
|
||||
float an_Ki1 = 0.0f;
|
||||
float an_Kd1 = 0.0f;
|
||||
// 避障后面角度环
|
||||
float za_Kp = 50.f;
|
||||
float za_Ki = 0;
|
||||
float za_Kd = 0;
|
||||
|
||||
float zg_Kp = 7.f;
|
||||
float zg_Ki = 0;
|
||||
float zg_Kd = 0;
|
||||
|
||||
float zp_Kp = 300.f;
|
||||
float zp_Ki = 0;
|
||||
float zp_Kd = 0;
|
||||
|
||||
// 圆环后面风扇角度环
|
||||
float yu_Kp0 = 53.0f;
|
||||
float yu_Kp0 = 60.0f;
|
||||
float yu_Ki0 = 0.0f;
|
||||
float yu_Kd0 = 0.0f;
|
||||
// 弯道侧面风扇角度环
|
||||
float cn_Kp1 = 300.0f;
|
||||
float cn_Kp1 = 400.0f;
|
||||
float cn_Ki1 = 0.f;
|
||||
float cn_Kd1 = 0.0f;
|
||||
// 直道侧面风扇角度环
|
||||
float po_Kp1 = 250.0f;
|
||||
float po_Kp1 = 200.0f;
|
||||
float po_Ki1 = 0.0f;
|
||||
float po_Kd1 = 0.0f;
|
||||
// 期望和当前量
|
||||
@@ -44,7 +56,6 @@ float out_angle;
|
||||
float in_pos;
|
||||
float out_pos;
|
||||
float set_pos = 0.0f;
|
||||
float out_cal;
|
||||
// 弯道角速度环
|
||||
float gy_Kp0 = 8.80f;
|
||||
float gy_Ki0 = 0.0f;
|
||||
@@ -54,7 +65,7 @@ float gy_Kp1 = 7.0f;
|
||||
float gy_Ki1 = 0.0f;
|
||||
float gy_Kd1 = 0.0f;
|
||||
// 圆环角速度环
|
||||
float ygy_Kp0 = 7.0f;
|
||||
float ygy_Kp0 = 6.0f;
|
||||
float ygy_Ki0 = 0.0f;
|
||||
float ygy_Kd0 = 0.0f;
|
||||
// 当前和输入量
|
||||
@@ -63,7 +74,7 @@ float out_gyro;
|
||||
// float set_gyro = 0.0f;
|
||||
// 速度环
|
||||
float sp_Kp = 10.0f;
|
||||
float sp_Ki = 80.f;
|
||||
float sp_Ki = 60.f;
|
||||
float sp_Kd = 0.0f;
|
||||
|
||||
float in_speed;
|
||||
@@ -71,9 +82,10 @@ float out_speed;
|
||||
|
||||
float set_speed;
|
||||
float set_speed0 = 900.0f;
|
||||
float set_speed1 = 1100.0f;
|
||||
float set_speed2 = 830.f;
|
||||
float set_speed1 = 1200.0f;
|
||||
float set_speed2 = 700.f;
|
||||
float set_speed3 = 900.f;
|
||||
float set_speed4 = 500.f;
|
||||
int cnt1 = 0;
|
||||
int cnt2 = 0;
|
||||
int cnt3 = 0;
|
||||
@@ -129,13 +141,11 @@ void sport_motion()
|
||||
imu660ra_get_acc();
|
||||
get_vol();
|
||||
in_gyro = imu660ra_gyro_z;
|
||||
// last_gy=in_gyro;
|
||||
// 抖动停车
|
||||
// if (imu660ra_acc_z <= 300) {
|
||||
if (imu660ra_acc_z <= 800) {
|
||||
|
||||
// bt_fly_flag = bt_run_flag = 0;
|
||||
// bt_printf("ting");
|
||||
// }
|
||||
bt_fly_flag = bt_run_flag = 0;
|
||||
bt_printf("ting");
|
||||
}
|
||||
// 斑马线停车
|
||||
if (1 == in_stop) {
|
||||
stop_flag = 1;
|
||||
@@ -160,14 +170,18 @@ void sport_motion()
|
||||
set_speed = set_speed1;
|
||||
PID_SetTunings(&far_angle_pid, an_Kp1, an_Ki1, an_Kd1);
|
||||
PID_SetTunings(&far_gyro_pid, gy_Kp1, gy_Ki1, gy_Kd1);
|
||||
|
||||
PID_SetTunings(&pos_pid, po_Kp1, po_Ki1, po_Kd1);
|
||||
}
|
||||
if ((last_state != in_state) && (in_state == 1 || in_state == 5)) { // 弯道或者障碍物,暂时没加障碍物的分段
|
||||
if ((last_state != in_state) && in_state == 1) { // 弯道
|
||||
bt_printf("to 入弯");
|
||||
set_speed = set_speed0;
|
||||
cnt3_flag = 1;
|
||||
|
||||
PID_SetTunings(&far_angle_pid, an_Kp0, an_Ki0, an_Kd0);
|
||||
PID_SetTunings(&far_gyro_pid, gy_Kp0, gy_Ki0, gy_Kd0);
|
||||
|
||||
PID_SetTunings(&pos_pid, cn_Kp1, cn_Ki1, cn_Kd1);
|
||||
}
|
||||
if ((last_state != in_state) && in_state == 3) { // 圆环
|
||||
bt_printf("to 圆环");
|
||||
@@ -176,6 +190,18 @@ void sport_motion()
|
||||
cnt3_flag = 1;
|
||||
PID_SetTunings(&far_angle_pid, yu_Kp0, yu_Ki0, yu_Kd0);
|
||||
PID_SetTunings(&far_gyro_pid, ygy_Kp0, ygy_Ki0, ygy_Kd0);
|
||||
|
||||
PID_SetTunings(&pos_pid, cn_Kp1, cn_Ki1, cn_Kd1);
|
||||
}
|
||||
if ((last_state != in_state) && in_state == 5) { // 圆环
|
||||
bt_printf("to 障碍");
|
||||
set_speed = set_speed4;
|
||||
|
||||
cnt3_flag = 1;
|
||||
PID_SetTunings(&far_angle_pid, za_Kp, za_Ki, za_Kd);
|
||||
PID_SetTunings(&far_gyro_pid, zg_Kp, zg_Ki, zg_Kd);
|
||||
|
||||
PID_SetTunings(&pos_pid, zp_Kp, zp_Ki, zp_Kd);
|
||||
}
|
||||
last_state = in_state;
|
||||
// pid计算
|
||||
@@ -185,30 +211,20 @@ void sport_motion()
|
||||
}
|
||||
if (cnt2 >= 10) {
|
||||
in_speed = sport_get_speed();
|
||||
|
||||
cnt2 = 0;
|
||||
cnt2 = 0;
|
||||
}
|
||||
if (cnt5 >= 20) {
|
||||
|
||||
PID_Compute(&far_angle_pid);
|
||||
PID_Compute(&str_angle_pid);
|
||||
PID_Compute(&tur_cal_pid);
|
||||
PID_Compute(&pos_pid);
|
||||
PID_Compute(&speed_pid);
|
||||
cnt5 = 0;
|
||||
}
|
||||
// 输出限幅
|
||||
if (in_state == 0 || in_state == 2) {
|
||||
pwm_duty_ls = (int32_t)myclip_f(-out_pos, 0.0f, 7000.f);
|
||||
pwm_duty_rs = (int32_t)myclip_f(out_pos, 0.0f, 7000.f);
|
||||
pwm_duty_lb = (int32_t)myclip_f(out_speed + out_gyro, 0.0f, 7000.f);
|
||||
pwm_duty_rb = (int32_t)myclip_f(out_speed - out_gyro, 0.0f, 7000.f);
|
||||
} else if (in_state == 1 || in_state == 3 || in_state == 4 || in_state == 5) {
|
||||
|
||||
pwm_duty_ls = (int32_t)myclip_f(-out_cal, 0.0f, 7000.f);
|
||||
pwm_duty_rs = (int32_t)myclip_f(out_cal, 0.0f, 7000.f);
|
||||
pwm_duty_lb = (int32_t)myclip_f(out_speed + out_gyro, 0.0f, 7000.f);
|
||||
pwm_duty_rb = (int32_t)myclip_f(out_speed - out_gyro, 0.0f, 7000.f);
|
||||
}
|
||||
pwm_duty_ls = (int32_t)myclip_f(-out_pos, 0.0f, 5000.f);
|
||||
pwm_duty_rs = (int32_t)myclip_f(out_pos, 0.0f, 5000.f);
|
||||
pwm_duty_lb = (int32_t)myclip_f(out_speed + out_gyro, 0.0f, 7000.f);
|
||||
pwm_duty_rb = (int32_t)myclip_f(out_speed - out_gyro, 0.0f, 7000.f);
|
||||
|
||||
by_pwm_power_duty(pwm_duty_ls, pwm_duty_rs, pwm_duty_lb, pwm_duty_rb);
|
||||
|
||||
@@ -223,12 +239,19 @@ void sport_motion()
|
||||
|
||||
cnt3++;
|
||||
if (in_state == 3) {
|
||||
if (cnt3 >= 400) // 200ms
|
||||
if (cnt3 >= 250) // 200ms
|
||||
{
|
||||
bt_printf("to 环内");
|
||||
cnt3_flag = 2;
|
||||
cnt3 = 0;
|
||||
}
|
||||
if (in_speed > set_speed - 100) {
|
||||
qd_down = 5 * fabs(in_pos) + 75;
|
||||
} else if (in_speed > set_speed - 200) {
|
||||
qd_down = 2.5 * fabs(in_pos) + 30;
|
||||
} else {
|
||||
qd_down = 0;
|
||||
}
|
||||
} else if (in_state == 1) {
|
||||
if (cnt3 >= 500) // 200ms
|
||||
{
|
||||
@@ -236,27 +259,35 @@ void sport_motion()
|
||||
cnt3_flag = 2;
|
||||
cnt3 = 0;
|
||||
}
|
||||
if (in_speed > set_speed - 100) {
|
||||
qd_down = 5 * fabs(in_pos) + 50;
|
||||
} else if (in_speed > set_speed - 200) {
|
||||
qd_down = 2.5 * fabs(in_pos) + 10;
|
||||
} else {
|
||||
qd_down = 0;
|
||||
}
|
||||
} else if (in_state == 5) {
|
||||
if (cnt3 >= 200) // 200ms
|
||||
if (cnt3 >= 400) // 200ms
|
||||
{
|
||||
bt_printf("to 障碍");
|
||||
bt_printf("to 开张");
|
||||
cnt3_flag = 2;
|
||||
cnt3 = 0;
|
||||
}
|
||||
if (in_speed > set_speed - 100) {
|
||||
qd_down = 150;
|
||||
} else if (in_speed > set_speed - 200) {
|
||||
qd_down = 75;
|
||||
} else {
|
||||
qd_down = 25;
|
||||
}
|
||||
}
|
||||
if (in_speed > set_speed - 100) {
|
||||
qd_down = 5 * fabs(in_pos) + 50;
|
||||
} else if (in_speed > set_speed - 200) {
|
||||
qd_down = 2.5 * fabs(in_pos)+10;
|
||||
} else {
|
||||
qd_down = 0;
|
||||
}
|
||||
|
||||
by_pwm_update_duty(bt_fly + 500 - qd_down, bt_fly + 500 - qd_down);
|
||||
} else {
|
||||
if(in_state==1) {
|
||||
if (in_state == 1) {
|
||||
qd_down = 15;
|
||||
}else{
|
||||
qd_down=0;
|
||||
} else {
|
||||
qd_down = 0;
|
||||
}
|
||||
if (in_state == 4) {
|
||||
by_pwm_update_duty(bt_fly + 500 - qd_down, bt_fly + 500 - qd_down);
|
||||
@@ -279,21 +310,12 @@ void sport_pid_init()
|
||||
PID_SetMode(&far_angle_pid, _PID_MODE_AUTOMATIC);
|
||||
PID_SetSampleTime(&far_angle_pid, 20);
|
||||
PID_SetOutputLimits(&far_angle_pid, -4000.0f, 4000.0f);
|
||||
// 直道侧面位置环
|
||||
PID(&str_angle_pid, &in_angle, &out_pos, &set_pos, po_Kp1, po_Ki1, po_Kd1, _PID_P_ON_E, _PID_CD_REVERSE);
|
||||
PID_SetMode(&str_angle_pid, _PID_MODE_AUTOMATIC);
|
||||
PID_SetSampleTime(&str_angle_pid, 20);
|
||||
PID_SetOutputLimits(&str_angle_pid, -6000.0f, 6000.0f);
|
||||
// 弯道侧面曲率环
|
||||
PID(&tur_cal_pid, &in_angle, &out_cal, &set_pos, cn_Kp1, cn_Ki1, cn_Kd1, _PID_P_ON_E, _PID_CD_REVERSE);
|
||||
PID_SetMode(&tur_cal_pid, _PID_MODE_AUTOMATIC);
|
||||
PID_SetSampleTime(&tur_cal_pid, 20);
|
||||
PID_SetOutputLimits(&tur_cal_pid, -6000.0f, 6000.0f);
|
||||
// // 圆环
|
||||
// PID(&cir_pos_pid, &in_angle, &out_ci, &set_pos, ci_Kp0, ci_Ki0, ci_Kd0, _PID_P_ON_E, _PID_CD_REVERSE);
|
||||
// PID_SetMode(&cir_pos_pid, _PID_MODE_AUTOMATIC);
|
||||
// PID_SetSampleTime(&cir_pos_pid, 20);
|
||||
// PID_SetOutputLimits(&cir_pos_pid, -7000.0f, 7000.0f);
|
||||
// 侧面位置环
|
||||
PID(&pos_pid, &in_angle, &out_pos, &set_pos, po_Kp1, po_Ki1, po_Kd1, _PID_P_ON_E, _PID_CD_REVERSE);
|
||||
PID_SetMode(&pos_pid, _PID_MODE_AUTOMATIC);
|
||||
PID_SetSampleTime(&pos_pid, 20);
|
||||
PID_SetOutputLimits(&pos_pid, -5000.0f, 5000.0f);
|
||||
|
||||
/* 角速度控制 */
|
||||
PID(&far_gyro_pid, &in_gyro, &out_gyro, &out_angle, gy_Kp1, gy_Ki1, gy_Kd1, _PID_P_ON_E, _PID_CD_REVERSE); // m是增量
|
||||
PID_SetMode(&far_gyro_pid, _PID_MODE_AUTOMATIC);
|
||||
|
||||
@@ -12,7 +12,6 @@ extern float an_Kd1;
|
||||
extern float in_angle;
|
||||
extern float set_angle;
|
||||
extern float out_angle;
|
||||
extern float out_cal;
|
||||
extern float cn_Kp1;
|
||||
extern float cn_Ki1;
|
||||
extern float cn_Kd1;
|
||||
@@ -37,6 +36,16 @@ extern float set_pos;
|
||||
extern float ygy_Kp0;
|
||||
extern float ygy_Ki0;
|
||||
extern float ygy_Kd0;
|
||||
extern float za_Kp;
|
||||
extern float za_Ki;
|
||||
extern float za_Kd;
|
||||
extern float zg_Kp;
|
||||
extern float zg_Ki;
|
||||
extern float zg_Kd;
|
||||
|
||||
extern float zp_Kp;
|
||||
extern float zp_Ki;
|
||||
extern float zp_Kd;
|
||||
extern float sp_Kp;
|
||||
extern float sp_Ki;
|
||||
extern float sp_Kd;
|
||||
@@ -47,6 +56,7 @@ extern float set_speed1;
|
||||
extern float set_speed2;
|
||||
extern float set_speed3;
|
||||
extern float set_speed;
|
||||
extern float set_speed4;
|
||||
extern int32_t pwm_duty_ls;
|
||||
extern int32_t pwm_duty_rs;
|
||||
extern int32_t pwm_duty_lb;
|
||||
|
||||
@@ -17,7 +17,7 @@ TYPE_UNION temp_frame_param[20];
|
||||
void jj_param_eeprom_init(void)
|
||||
{
|
||||
soft_iic_init(&eeprom_param, K24C02_DEV_ADDR, K24C02_SOFT_IIC_DELAY, K24C02_SCL_PIN, K24C02_SDA_PIN); // eeprom初始化
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
PARAM_REG(angle_Kp0, &an_Kp0, EFLOAT, 1, "an_P0:"); // 注冊
|
||||
PARAM_REG(angle_Ki0, &an_Ki0, EFLOAT, 1, "an_I0:"); // 注冊
|
||||
PARAM_REG(angle_Kd0, &an_Kd0, EFLOAT, 1, "an_D0:");
|
||||
@@ -33,7 +33,7 @@ void jj_param_eeprom_init(void)
|
||||
PARAM_REG(fly_pwm, &bt_fly, EFLOAT, 1, "fly:");
|
||||
|
||||
PARAM_REG(param_set_speed0, &set_speed0, EFLOAT, 1, "rate0:");
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
PARAM_REG(angle_Kp1, &an_Kp1, EFLOAT, 1, "an_P1:"); // 注冊
|
||||
PARAM_REG(angle_Ki1, &an_Ki1, EFLOAT, 1, "an_I1:"); // 注冊
|
||||
PARAM_REG(angle_Kd1, &an_Kd1, EFLOAT, 1, "an_D1:");
|
||||
@@ -47,7 +47,7 @@ void jj_param_eeprom_init(void)
|
||||
PARAM_REG(pos_Kd1, &po_Kd1, EFLOAT, 1, "po_D1:");
|
||||
|
||||
PARAM_REG(param_set_speed1, &set_speed1, EFLOAT, 1, "rate1:");
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
PARAM_REG(yuan_Kp0, &yu_Kp0, EFLOAT, 1, "an_P0:"); // 注冊
|
||||
PARAM_REG(yuan_Ki0, &yu_Ki0, EFLOAT, 1, "an_I0:"); // 注冊
|
||||
PARAM_REG(yuan_Kd0, &yu_Kd0, EFLOAT, 1, "an_D0:");
|
||||
@@ -62,6 +62,20 @@ void jj_param_eeprom_init(void)
|
||||
|
||||
PARAM_REG(param_set_speed2, &set_speed2, EFLOAT, 1, "rate2:");
|
||||
PARAM_REG(param_set_speed3, &set_speed3, EFLOAT, 1, "rate3:");
|
||||
/////////////////////////////////////////////////////////////
|
||||
PARAM_REG(zhan_Kp, &za_Kp, EFLOAT, 1, "an_P:"); // 注冊
|
||||
PARAM_REG(zhan_Ki, &za_Ki, EFLOAT, 1, "an_I:"); // 注冊
|
||||
PARAM_REG(zhan_Kd, &za_Kd, EFLOAT, 1, "an_D:");
|
||||
|
||||
PARAM_REG(zhgy_Kp, &zg_Kp, EFLOAT, 1, "gy_P1:"); // 注冊
|
||||
PARAM_REG(zhgy_Ki, &zg_Ki, EFLOAT, 1, "gy_I1:"); // 注冊
|
||||
PARAM_REG(zhgy_Kd, &zg_Kd, EFLOAT, 1, "gy_D1:");
|
||||
|
||||
PARAM_REG(zhpo_Kp, &zp_Kp, EFLOAT, 1, "po_P1:"); // 注冊
|
||||
PARAM_REG(zhpo_Ki, &zp_Ki, EFLOAT, 1, "po_I1:"); // 注冊
|
||||
PARAM_REG(zhpo_Kd, &zp_Kd, EFLOAT, 1, "po_D1:");
|
||||
|
||||
PARAM_REG(param_set_speed4, &set_speed4, EFLOAT, 1, "rate4:");
|
||||
jj_param_read(); // 注冊
|
||||
}
|
||||
/**
|
||||
|
||||
@@ -62,6 +62,21 @@ typedef enum {
|
||||
|
||||
param_set_speed2,
|
||||
param_set_speed3,
|
||||
|
||||
Page4_head,
|
||||
zhgy_Kp = Page4_head,
|
||||
zhgy_Ki,
|
||||
zhgy_Kd,
|
||||
|
||||
zhan_Kp,
|
||||
zhan_Ki,
|
||||
zhan_Kd,
|
||||
|
||||
zhpo_Kp,
|
||||
zhpo_Ki,
|
||||
zhpo_Kd,
|
||||
|
||||
param_set_speed4,
|
||||
DATA_IN_FLASH_NUM,
|
||||
|
||||
delta_x,
|
||||
|
||||
@@ -128,7 +128,7 @@ void Page_Init(void)
|
||||
PAGE_REG(page_param_pid0);
|
||||
PAGE_REG(page_param_pid1);
|
||||
PAGE_REG(page_param_pid2);
|
||||
|
||||
PAGE_REG(page_param_pid3);
|
||||
PAGE_REG(page_dparam);
|
||||
Page_Shift(page_menu);
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ enum PageID {
|
||||
page_param_pid0,
|
||||
page_param_pid1,
|
||||
page_param_pid2,
|
||||
page_param_pid3,
|
||||
page_dparam,
|
||||
// page_argv,
|
||||
// page_sys,
|
||||
|
||||
@@ -60,10 +60,8 @@ static void Loop()
|
||||
ips200_show_float(80, 140, out_gyro, 4, 1);
|
||||
ips200_show_string(0, 160, "outpos");
|
||||
ips200_show_float(80, 160, out_pos, 4, 1);
|
||||
ips200_show_string(0, 180, "outcal");
|
||||
ips200_show_float(80, 180, out_cal, 4, 1);
|
||||
ips200_show_string(0, 200, "vol");
|
||||
ips200_show_float(80, 200, (float)now_vol, 4,2);
|
||||
ips200_show_string(0, 180, "vol");
|
||||
ips200_show_float(80, 180, (float)now_vol, 4,2);
|
||||
|
||||
ips200_show_string(180, 0, "ls");
|
||||
ips200_show_float(220, 0, pwm_duty_ls, 4, 1);
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include "jj_blueteeth.h"
|
||||
|
||||
#define LINE_HEAD 1
|
||||
#define LINE_END 4
|
||||
#define LINE_END 5
|
||||
|
||||
static char Text[] = "Menu";
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include <math.h>
|
||||
|
||||
#define LINE_HEAD 1
|
||||
#define LINE_END DATA_IN_FLASH_NUM - Page3_head
|
||||
#define LINE_END Page4_head - Page3_head
|
||||
#define Strat_param Page3_head
|
||||
static char Text[] = "cir_pid";
|
||||
static int event_flag = 0;
|
||||
|
||||
137
app/page/page_param_pid3.c
Normal file
137
app/page/page_param_pid3.c
Normal file
@@ -0,0 +1,137 @@
|
||||
#include "jj_param.h"
|
||||
#include "page_ui_widget.h"
|
||||
#include "jj_motion.h"
|
||||
#include "page.h"
|
||||
#include <math.h>
|
||||
|
||||
#define LINE_HEAD 1
|
||||
#define LINE_END DATA_IN_FLASH_NUM - Page4_head
|
||||
#define Strat_param Page4_head
|
||||
static char Text[] = "barr_pid";
|
||||
static int event_flag = 0;
|
||||
static int index_power = 0;
|
||||
static int8_t Curser = LINE_HEAD; // 定义光标位置
|
||||
static int8_t Curser_Last = LINE_HEAD; // 定义光标位置
|
||||
static void jj_param_show();
|
||||
/***************************************************************************************
|
||||
*
|
||||
* 以下为页面模板函数
|
||||
*
|
||||
***************************************************************************************/
|
||||
/**
|
||||
* @brief 页面初始化事件
|
||||
* @param 无
|
||||
* @retval 无
|
||||
*/
|
||||
static void Setup()
|
||||
{
|
||||
ips200_clear();
|
||||
ips200_show_string(0, 2,"barrir");
|
||||
Print_Curser(Curser, Curser_Last, RGB565_PURPLE);
|
||||
for (int16 i = 0; i < LINE_END; i++) {
|
||||
ips200_show_string(0, i * 18 + 20, Param_Data[i +Strat_param ].text);
|
||||
if (Param_Data[i + Strat_param].type == EINT32)
|
||||
ips200_show_int(50, i * 18 + 20, *((int32 *)(Param_Data[i + Strat_param].p_data)), 5);
|
||||
else if (Param_Data[i + Strat_param].type == EFLOAT)
|
||||
ips200_show_float(50, i * 18 + 20, *((float *)(Param_Data[i + Strat_param].p_data)), 4, 5);
|
||||
}
|
||||
ips200_show_int(100, 2, index_power, 5);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 页面退出事件
|
||||
* @param 无
|
||||
* @retval 无
|
||||
*/
|
||||
static void Exit()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 页面循环执行的内容
|
||||
* @param 无
|
||||
* @retval 无
|
||||
*/
|
||||
static void Loop()
|
||||
{
|
||||
}
|
||||
/**
|
||||
* @brief 页面事件
|
||||
* @param btn:发出事件的按键
|
||||
* @param event:事件编号
|
||||
* @retval 无
|
||||
*/
|
||||
static void Event(page_event event)
|
||||
{
|
||||
|
||||
if (0 == event_flag) {
|
||||
|
||||
Curser_Last = Curser;
|
||||
if (page_event_forward == event) {
|
||||
Curser--; // 光标上移
|
||||
} else if (page_event_backward == event) {
|
||||
Curser++; // 光标下移
|
||||
} else if (page_event_press_short == event) {
|
||||
event_flag = 1; // 选中参数
|
||||
Print_Curser(Curser, Curser_Last, RGB565_RED);
|
||||
return;
|
||||
} else if (page_event_press_long == event) {
|
||||
jj_param_write();
|
||||
sport_pid_init();
|
||||
Page_Shift(page_menu);
|
||||
return;
|
||||
}
|
||||
if (Curser < LINE_HEAD) {
|
||||
Curser = LINE_END;
|
||||
} else if (Curser > LINE_END) {
|
||||
Curser = LINE_HEAD;
|
||||
}
|
||||
Print_Curser(Curser, Curser_Last, RGB565_PURPLE);
|
||||
} else if (1 == event_flag) {
|
||||
if (page_event_forward == event) {
|
||||
if (Param_Data[Curser + Strat_param-1].type == EFLOAT) {
|
||||
*((float *)(Param_Data[Curser + Strat_param-1].p_data)) += powf(10.0f, (float)index_power);
|
||||
} else if (Param_Data[Curser + Strat_param-1].type == EINT32) {
|
||||
*((int32 *)(Param_Data[Curser + Strat_param-1].p_data)) += 1;
|
||||
} else if (Param_Data[Curser + Strat_param-1].type == EUINT32) {
|
||||
*((uint32 *)(Param_Data[Curser + Strat_param-1].p_data)) += 1;
|
||||
}
|
||||
} else if (page_event_backward == event) {
|
||||
if (Param_Data[Curser + Strat_param-1].type == EFLOAT) {
|
||||
*((float *)(Param_Data[Curser + Strat_param-1].p_data)) -= powf(10.0f, (float)index_power);
|
||||
} else if (Param_Data[Curser + Strat_param-1].type == EINT32) {
|
||||
*((int32 *)(Param_Data[Curser + Strat_param-1].p_data)) -= 1;
|
||||
} else if (Param_Data[Curser + Strat_param-1].type == EUINT32) {
|
||||
*((uint32 *)(Param_Data[Curser + Strat_param-1].p_data)) -= 1;
|
||||
}
|
||||
} else if (page_event_press_short == event) {
|
||||
index_power++;
|
||||
if (index_power > 2) {
|
||||
index_power = -2;
|
||||
}
|
||||
ips200_show_int(100, 2, index_power, 5);
|
||||
} else if (page_event_press_long == event) {
|
||||
event_flag = 0;
|
||||
Print_Curser(Curser, Curser_Last, RGB565_PURPLE);
|
||||
}
|
||||
jj_param_show();
|
||||
}
|
||||
}
|
||||
static void jj_param_show()
|
||||
{
|
||||
if (EINT32 == Param_Data[Curser + Strat_param-1].type)
|
||||
ips200_show_int(50, Curser * 18 + 2, *((int32 *)(Param_Data[Curser + Strat_param-1].p_data)), 5);
|
||||
else if (EUINT32 == Param_Data[Curser + Strat_param-1].type)
|
||||
ips200_show_uint(50, Curser * 18 + 2, *((int32 *)(Param_Data[Curser + Strat_param-1].p_data)), 5);
|
||||
else if (EFLOAT == Param_Data[Curser + Strat_param-1].type)
|
||||
ips200_show_float(50, Curser * 18 + 2, *((float *)(Param_Data[Curser + Strat_param-1].p_data)), 4, 5);
|
||||
}
|
||||
/**
|
||||
* @brief 页面注册函数
|
||||
*
|
||||
* @param pageID
|
||||
*/
|
||||
void PageRegister_page_param_pid3(unsigned char pageID)
|
||||
{
|
||||
Page_Register(pageID, Text, Setup, Loop, Exit, Event);
|
||||
}
|
||||
Reference in New Issue
Block a user