Files
tc264smart/code/pid_tuning.c
T
32343 843447835d Initial commit: TC264 smart car project with IPS200 menu system
- IPS200 display menu with real-time status and parameter settings
- Camera image processing and line tracking
- IMU attitude solution and PID control
- WiFi SPI oscilloscope data transmission
2026-05-10 21:38:49 +08:00

76 lines
2.6 KiB
C

/*********************************************************************************************************************
* TC264 智能车 - PID调参桥接模块 (pid_tuning.c)
*
* 功能:
* 1. 将菜单的 test_pid_value / test_user_value 同步到真实 PID 结构体
* 2. 将关键控制变量推送到虚拟示波器, 用于上位机波形显示
*
* 菜单 PID 组映射:
* 组0 "SpdL" → g_pid_speed_left (左轮速度环 P/I/D)
* 组1 "SpdR" → g_pid_speed_right (右轮速度环 P/I/D)
* 组2 "Steering" → g_pid_steering (转向环 P/I/D)
*
* 菜单浮点参数 (cleanup 后, PARAM_TOTAL_NUM=9):
* [1] Base Spd — 手动速度模式时作为 g_target_speed
* [2] Vac Duty — 真空泵占空比, user_menu.c 直接控制
* [3] Max Spd — 保留(以后用)
* [4] Crn Comp — 保留(以后用)
*
* 虚拟示波器通道:
* CH1: 目标速度 (脉冲/100ms)
* CH2: 左轮实际速度 (脉冲/100ms)
* CH3: 右轮实际速度 (脉冲/100ms)
* CH4: 左右平均电机 PWM
*********************************************************************************************************************/
#include "zf_common_headfile.h"
#include "pid_control.h"
#include "pid_tuning.h"
#include "zf_device_virtual_oscilloscope.h"
extern float test_user_value[];
extern float test_pid_value[PID_TUNING_LOOP_COUNT][3];
extern char test_pid_loop[PID_TUNING_LOOP_COUNT][12];
extern int16 pid_switch_num;
static float g_last_speed_left = 0.0f;
static float g_last_speed_right = 0.0f;
float g_last_pwm = 0.0f;
float g_last_pwm_left = 0.0f;
float g_last_pwm_right = 0.0f;
void pid_tuning_sync(void)
{
g_pid_speed_left.kp = test_pid_value[0][0];
g_pid_speed_left.ki = test_pid_value[0][1];
g_pid_speed_left.kd = test_pid_value[0][2];
g_pid_speed_right.kp = test_pid_value[1][0];
g_pid_speed_right.ki = test_pid_value[1][1];
g_pid_speed_right.kd = test_pid_value[1][2];
g_pid_steering.kp = test_pid_value[2][0];
g_pid_steering.ki = test_pid_value[2][1];
g_pid_steering.kd = test_pid_value[2][2];
g_target_speed = test_user_value[1];
g_last_speed_left = g_pid_speed_left.feedback;
g_last_speed_right = g_pid_speed_right.feedback;
g_last_pwm_left = g_motor_pwm_left_cmd;
g_last_pwm_right = g_motor_pwm_right_cmd;
g_last_pwm = (g_last_pwm_left + g_last_pwm_right) * 0.5f;
}
void pid_tuning_scope_output(void)
{
int16 ch1, ch2, ch3, ch4;
ch1 = (int16)g_target_speed;
ch2 = (int16)g_last_speed_left;
ch3 = (int16)g_last_speed_right;
ch4 = (int16)g_last_pwm;
virtual_oscilloscope_data_conversion(ch1, ch2, ch3, ch4);
}