Merge branch 'master' of http://git.brisky.space:441/btl143/firmware_zinnia
This commit is contained in:
@@ -49,7 +49,7 @@ void by_frame_parse(uint8_t data_num, uint32_t *data_array)
|
|||||||
uint16_t crc_cal = 0;
|
uint16_t crc_cal = 0;
|
||||||
uint32_t read_length = 50;
|
uint32_t read_length = 50;
|
||||||
|
|
||||||
if (fifo_used(&frame_fifo) >= 12) {
|
if (fifo_used(&frame_fifo) >= 4 + 4 * data_num) {
|
||||||
fifo_read_buffer(&frame_fifo, frame_buffer_parse, &read_length, FIFO_READ_AND_CLEAN);
|
fifo_read_buffer(&frame_fifo, frame_buffer_parse, &read_length, FIFO_READ_AND_CLEAN);
|
||||||
while (1) {
|
while (1) {
|
||||||
if (cnt_ptr < 50) {
|
if (cnt_ptr < 50) {
|
||||||
@@ -88,8 +88,9 @@ void by_frame_parse(uint8_t data_num, uint32_t *data_array)
|
|||||||
if (!cnt_crc) {
|
if (!cnt_crc) {
|
||||||
if (crc_cal == crc16_check(data_array_temp, 2 + data_num * sizeof(uint32_t))) {
|
if (crc_cal == crc16_check(data_array_temp, 2 + data_num * sizeof(uint32_t))) {
|
||||||
memcpy(data_array, data_array_temp + 2, data_num * sizeof(uint32_t));
|
memcpy(data_array, data_array_temp + 2, data_num * sizeof(uint32_t));
|
||||||
|
fifo_clear(&frame_fifo); // TODO 确认是否有必要清除
|
||||||
|
// lwrb_reset(&lwrb_struct); // 处理完直接清空缓冲区,避免堆积产生处理阻塞
|
||||||
memset(data_array_temp, 0, sizeof(data_array_temp));
|
memset(data_array_temp, 0, sizeof(data_array_temp));
|
||||||
// printf("parsed done!\r\n");
|
|
||||||
for (uint8_t i = 0; i < data_num; i++) {
|
for (uint8_t i = 0; i < data_num; i++) {
|
||||||
for (uint8_t j = 0; j < 4; j++) {
|
for (uint8_t j = 0; j < 4; j++) {
|
||||||
uart_write_byte(DEBUG_UART_INDEX, data_array[i] >> (j * 8));
|
uart_write_byte(DEBUG_UART_INDEX, data_array[i] >> (j * 8));
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ uint8 bt_buffer; // 接收字符存入
|
|||||||
uint32_t bt_run_flag = 0;
|
uint32_t bt_run_flag = 0;
|
||||||
uint8_t bt_fly_flag = 0;
|
uint8_t bt_fly_flag = 0;
|
||||||
uint32_t bt_run = 0;
|
uint32_t bt_run = 0;
|
||||||
uint32_t bt_fly = 0;
|
uint32_t bt_fly = 500;
|
||||||
enum bt_order {
|
enum bt_order {
|
||||||
Fly_ctrl = 0x01, // 起飞转换
|
Fly_ctrl = 0x01, // 起飞转换
|
||||||
Fly_up = 0x02, // 起飞程度增加
|
Fly_up = 0x02, // 起飞程度增加
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ float out_speed;
|
|||||||
float set_speed = 0.0f;
|
float set_speed = 0.0f;
|
||||||
|
|
||||||
int cnt1 = 0;
|
int cnt1 = 0;
|
||||||
|
int cnt2 = 0;
|
||||||
float sport_get_speed(void)
|
float sport_get_speed(void)
|
||||||
{
|
{
|
||||||
#define ALPHA (0.97f)
|
#define ALPHA (0.97f)
|
||||||
@@ -60,6 +60,7 @@ void sport_motion(void)
|
|||||||
{
|
{
|
||||||
|
|
||||||
cnt1++;
|
cnt1++;
|
||||||
|
cnt2++;
|
||||||
imu660ra_get_gyro();
|
imu660ra_get_gyro();
|
||||||
in_gyro = imu660ra_gyro_z; // 陀螺仪输入
|
in_gyro = imu660ra_gyro_z; // 陀螺仪输入
|
||||||
// in_angle = 0; // 图像远端输入
|
// in_angle = 0; // 图像远端输入
|
||||||
@@ -68,27 +69,40 @@ void sport_motion(void)
|
|||||||
PID_Compute(&far_gyro_pid);
|
PID_Compute(&far_gyro_pid);
|
||||||
|
|
||||||
if (cnt1 >= 10) {
|
if (cnt1 >= 10) {
|
||||||
PID_Compute(&far_angle_pid);
|
|
||||||
PID_Compute(&speed_pid);
|
PID_Compute(&speed_pid);
|
||||||
// in_speed = -encoder_get_count(TIM5_ENCOEDER); // 速度输入,m/s
|
in_speed = -sport_get_speed();
|
||||||
in_speed = sport_get_speed();
|
|
||||||
// printf("rate:%d\r\n", (int16_t)in_speed);
|
// printf("rate:%d\r\n", (int16_t)in_speed);
|
||||||
PID_Compute(&near_pos_pid);
|
PID_Compute(&near_pos_pid);
|
||||||
cnt1 = 0;
|
cnt1 = 0;
|
||||||
}
|
}
|
||||||
|
if (cnt2 >= 20) {
|
||||||
|
cnt2 = 0;
|
||||||
|
PID_Compute(&far_angle_pid);
|
||||||
|
}
|
||||||
if (bt_run_flag == 1) {
|
if (bt_run_flag == 1) {
|
||||||
by_pwm_power_duty((int32_t)(500 + out_pos + out_gyro),
|
if (out_gyro > 0) {
|
||||||
(int32_t)(500 - out_pos - out_gyro),
|
by_pwm_power_duty((int32_t)(500 - 1 * out_pos + 0 * out_gyro),
|
||||||
(int32_t)(500 + out_speed + out_gyro),
|
(int32_t)(500 + 1 * out_pos - 0 * out_gyro),
|
||||||
(int32_t)(500 + out_speed - out_gyro));
|
(int32_t)(500 + out_speed + out_gyro),
|
||||||
|
(int32_t)(500 + out_speed - out_gyro));
|
||||||
|
|
||||||
|
} else if (out_gyro <= 0) {
|
||||||
|
by_pwm_power_duty((int32_t)(500 - 1 * out_pos + 0 * out_gyro),
|
||||||
|
(int32_t)(500 + 1 * out_pos - 0 * out_gyro),
|
||||||
|
(int32_t)(500 + out_speed + out_gyro),
|
||||||
|
(int32_t)(500 + out_speed - out_gyro));
|
||||||
|
}
|
||||||
|
|
||||||
|
// by_pwm_power_duty(500+out_gyro, 500-out_gyro, 500+out_gyro , 500-out_gyro);
|
||||||
} else {
|
} else {
|
||||||
by_pwm_power_duty(500, 500, 500, 500);
|
by_pwm_power_duty(500, 500, 500, 500);
|
||||||
}
|
}
|
||||||
if (bt_fly_flag == 0) {
|
if (bt_fly_flag == 0) {
|
||||||
bt_fly = 0;
|
by_pwm_update_duty(0 + 500, 0 + 500);
|
||||||
|
} else {
|
||||||
|
by_pwm_update_duty(bt_fly + 500, bt_fly + 500);
|
||||||
}
|
}
|
||||||
by_pwm_update_duty(bt_fly + 500, bt_fly + 500);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -98,7 +112,7 @@ void sport_motion(void)
|
|||||||
void sport_pid_init()
|
void sport_pid_init()
|
||||||
{
|
{
|
||||||
|
|
||||||
PID(&far_angle_pid, &in_angle, &out_angle, &set_angle, an_Kp, an_Ki, an_Kd, 0, 1);
|
PID(&far_angle_pid, &in_angle, &out_angle, &set_angle, an_Kp, an_Ki, an_Kd, 1, 1);
|
||||||
PID(&far_gyro_pid, &in_gyro, &out_gyro, &out_angle, gy_Kp, gy_Ki, gy_Kd, 1, 1);
|
PID(&far_gyro_pid, &in_gyro, &out_gyro, &out_angle, gy_Kp, gy_Ki, gy_Kd, 1, 1);
|
||||||
PID_Init(&far_angle_pid);
|
PID_Init(&far_angle_pid);
|
||||||
PID_Init(&far_gyro_pid);
|
PID_Init(&far_gyro_pid);
|
||||||
@@ -109,13 +123,13 @@ void sport_pid_init()
|
|||||||
PID_SetMode(&far_gyro_pid, 1);
|
PID_SetMode(&far_gyro_pid, 1);
|
||||||
PID_SetMode(&far_angle_pid, 1);
|
PID_SetMode(&far_angle_pid, 1);
|
||||||
|
|
||||||
PID(&near_pos_pid, &in_pos, &out_pos, &set_pos, po_Kp, po_Ki, po_Kd, 0, 0);
|
PID(&near_pos_pid, &in_pos, &out_pos, &set_pos, po_Kp, po_Ki, po_Kd, 1, 0);
|
||||||
PID(&speed_pid, &in_speed, &out_speed, &set_speed, sp_Kp, sp_Ki, sp_Kd, 1, 0);
|
PID(&speed_pid, &in_speed, &out_speed, &set_speed, sp_Kp, sp_Ki, sp_Kd, 1, 0);
|
||||||
PID_Init(&near_pos_pid);
|
PID_Init(&near_pos_pid);
|
||||||
PID_Init(&speed_pid);
|
PID_Init(&speed_pid);
|
||||||
|
|
||||||
PID_SetOutputLimits(&near_pos_pid, -500.0f, 500.0f);
|
PID_SetOutputLimits(&near_pos_pid, -500.0f, 500.0f);
|
||||||
PID_SetOutputLimits(&speed_pid, -400.0f, 400.0f);
|
PID_SetOutputLimits(&speed_pid, 0.0f, 400.0f);
|
||||||
|
|
||||||
PID_SetMode(&near_pos_pid, 1);
|
PID_SetMode(&near_pos_pid, 1);
|
||||||
PID_SetMode(&speed_pid, 1);
|
PID_SetMode(&speed_pid, 1);
|
||||||
|
|||||||
@@ -21,9 +21,9 @@ void jj_param_eeprom_init(void)
|
|||||||
PARAM_REG(angle_Ki, &an_Ki, EFLOAT, 1, "an_I:"); // 注冊
|
PARAM_REG(angle_Ki, &an_Ki, EFLOAT, 1, "an_I:"); // 注冊
|
||||||
PARAM_REG(angle_Kd, &an_Kd, EFLOAT, 1, "an_D:");
|
PARAM_REG(angle_Kd, &an_Kd, EFLOAT, 1, "an_D:");
|
||||||
|
|
||||||
PARAM_REG(gyro_Kp, &gy_Kp, EFLOAT, 1, "im_P:"); // 注冊
|
PARAM_REG(gyro_Kp, &gy_Kp, EFLOAT, 1, "gy_P:"); // 注冊
|
||||||
PARAM_REG(gyro_Ki, &gy_Ki, EFLOAT, 1, "im_I:"); // 注冊
|
PARAM_REG(gyro_Ki, &gy_Ki, EFLOAT, 1, "gy_I:"); // 注冊
|
||||||
PARAM_REG(gyro_Kd, &gy_Kd, EFLOAT, 1, "im_D:");
|
PARAM_REG(gyro_Kd, &gy_Kd, EFLOAT, 1, "gy_D:");
|
||||||
|
|
||||||
PARAM_REG(speed_Kp, &sp_Kp, EFLOAT, 1, "sp_P:"); // 注冊
|
PARAM_REG(speed_Kp, &sp_Kp, EFLOAT, 1, "sp_P:"); // 注冊
|
||||||
PARAM_REG(speed_Ki, &sp_Ki, EFLOAT, 1, "sp_I:"); // 注冊
|
PARAM_REG(speed_Ki, &sp_Ki, EFLOAT, 1, "sp_I:"); // 注冊
|
||||||
|
|||||||
@@ -63,18 +63,9 @@ int main(void)
|
|||||||
while (1) {
|
while (1) {
|
||||||
Page_Run();
|
Page_Run();
|
||||||
by_frame_parse(2, &test_data[0].u32);
|
by_frame_parse(2, &test_data[0].u32);
|
||||||
// uart_write_byte(UART_8, 0x1F);
|
|
||||||
by_buzzer_run();
|
by_buzzer_run();
|
||||||
jj_bt_run();
|
jj_bt_run();
|
||||||
in_pos = test_data[1].f32;
|
in_pos = test_data[1].f32;
|
||||||
in_angle = test_data[0].f32;
|
in_angle = test_data[0].f32;
|
||||||
ips200_show_float(40, 40, test_data[0].f32, 4, 1);
|
|
||||||
ips200_show_float(40, 60, test_data[1].f32, 4, 1);
|
|
||||||
ips200_show_float(40, 80, in_gyro, 4, 2);
|
|
||||||
ips200_show_float(40, 100, in_speed, 4, 4);
|
|
||||||
ips200_show_string(0, 120, "outang");
|
|
||||||
ips200_show_float(80, 120, out_angle, 4, 1);
|
|
||||||
ips200_show_string(0, 140, "outgyr");
|
|
||||||
ips200_show_float(80, 140, out_gyro, 4, 1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ uint8_t Page_GetStatus(void)
|
|||||||
void Page_Run(void)
|
void Page_Run(void)
|
||||||
{
|
{
|
||||||
uint8_t temp_status = by_get_rb_status(); // 轮询旋钮状态
|
uint8_t temp_status = by_get_rb_status(); // 轮询旋钮状态
|
||||||
if(temp_status){
|
if (temp_status) {
|
||||||
pagelist[now_page].EventCallback(temp_status);
|
pagelist[now_page].EventCallback(temp_status);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -124,12 +124,12 @@ void Page_Run(void)
|
|||||||
void Page_Init(void)
|
void Page_Init(void)
|
||||||
{
|
{
|
||||||
PAGE_REG(page_menu);
|
PAGE_REG(page_menu);
|
||||||
// PAGE_REG(page_rtcam);
|
// PAGE_REG(page_rtcam);
|
||||||
PAGE_REG(page_param);
|
PAGE_REG(page_param);
|
||||||
// PAGE_REG(page_argv);
|
// PAGE_REG(page_argv);
|
||||||
// PAGE_REG(page_sys);
|
// PAGE_REG(page_sys);
|
||||||
// PAGE_REG(page_run);
|
// PAGE_REG(page_run);
|
||||||
|
PAGE_REG(page_dparam);
|
||||||
Page_Shift(page_menu);
|
Page_Shift(page_menu);
|
||||||
|
|
||||||
pagelist[now_page].SetupCallback(); // 先构建一遍
|
pagelist[now_page].SetupCallback(); // 先构建一遍
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ enum PageID {
|
|||||||
page_menu,
|
page_menu,
|
||||||
//page_rtcam,
|
//page_rtcam,
|
||||||
page_param,
|
page_param,
|
||||||
|
page_dparam,
|
||||||
// page_argv,
|
// page_argv,
|
||||||
// page_sys,
|
// page_sys,
|
||||||
// page_run,
|
// page_run,
|
||||||
|
|||||||
95
app/page/page_dparam.c
Normal file
95
app/page/page_dparam.c
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
#include "jj_param.h"
|
||||||
|
#include "page_ui_widget.h"
|
||||||
|
#include "jj_motion.h"
|
||||||
|
#include "page.h"
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
#define LINE_HEAD 0
|
||||||
|
#define LINE_END DATA_NUM - 2
|
||||||
|
static char Text[] = "dParam";
|
||||||
|
static int8_t Curser = LINE_HEAD; // 定义光标位置
|
||||||
|
static int8_t Curser_Last = LINE_HEAD; // 定义光标位置
|
||||||
|
/***************************************************************************************
|
||||||
|
*
|
||||||
|
* 以下为页面模板函数
|
||||||
|
*
|
||||||
|
***************************************************************************************/
|
||||||
|
/**
|
||||||
|
* @brief 页面初始化事件
|
||||||
|
* @param 无
|
||||||
|
* @retval 无
|
||||||
|
*/
|
||||||
|
static void Setup()
|
||||||
|
{
|
||||||
|
ips200_clear();
|
||||||
|
Print_Curser(Curser, Curser_Last, RGB565_PURPLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 页面退出事件
|
||||||
|
* @param 无
|
||||||
|
* @retval 无
|
||||||
|
*/
|
||||||
|
static void Exit()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 页面循环执行的内容
|
||||||
|
* @param 无
|
||||||
|
* @retval 无
|
||||||
|
*/
|
||||||
|
static void Loop()
|
||||||
|
{
|
||||||
|
ips200_show_string(0, 40, "far");
|
||||||
|
ips200_show_float(80, 40, in_angle, 4, 1);
|
||||||
|
ips200_show_string(0, 60, "near");
|
||||||
|
ips200_show_float(80, 60, in_pos, 4, 1);
|
||||||
|
ips200_show_string(0, 80, "gyrz");
|
||||||
|
ips200_show_float(80, 80, in_gyro, 4, 2);
|
||||||
|
ips200_show_string(0, 100, "speed");
|
||||||
|
ips200_show_float(80, 100, in_speed, 4, 4);
|
||||||
|
ips200_show_string(0, 120, "outang");
|
||||||
|
ips200_show_float(80, 120, out_angle, 4, 1);
|
||||||
|
ips200_show_string(0, 140, "outgyr");
|
||||||
|
ips200_show_float(80, 140, out_gyro, 4, 1);
|
||||||
|
ips200_show_string(0, 160, "outpos");
|
||||||
|
ips200_show_float(80, 160, out_pos, 4, 1);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @brief 页面事件
|
||||||
|
* @param btn:发出事件的按键
|
||||||
|
* @param event:事件编号
|
||||||
|
* @retval 无
|
||||||
|
*/
|
||||||
|
static void Event(page_event event)
|
||||||
|
{
|
||||||
|
|
||||||
|
Curser_Last = Curser;
|
||||||
|
if (page_event_forward == event) {
|
||||||
|
Curser--; // 光标上移
|
||||||
|
} else if (page_event_backward == event) {
|
||||||
|
Curser++; // 光标下移
|
||||||
|
} else if (page_event_press_short == event) {
|
||||||
|
sport_pid_init();
|
||||||
|
} else if (page_event_press_long == event) {
|
||||||
|
Page_Shift(page_menu);
|
||||||
|
}
|
||||||
|
if (Curser < LINE_HEAD) {
|
||||||
|
Curser = LINE_END;
|
||||||
|
} else if (Curser > LINE_END) {
|
||||||
|
Curser = LINE_HEAD;
|
||||||
|
}
|
||||||
|
Print_Curser(Curser, Curser_Last, RGB565_PURPLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 页面注册函数
|
||||||
|
*
|
||||||
|
* @param pageID
|
||||||
|
*/
|
||||||
|
void PageRegister_page_dparam(unsigned char pageID)
|
||||||
|
{
|
||||||
|
Page_Register(pageID, Text, Setup, Loop, Exit, Event);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user