修改单个参数读取

This commit is contained in:
2025-07-30 11:28:53 +08:00
parent 242dcb6feb
commit febaad3dc6
2 changed files with 483 additions and 466 deletions

View File

@@ -431,6 +431,11 @@ void computeInverseKinematics(float linear_velocity_x, float yaw_rate, float max
// linear_velocity_x = constrain(linear_velocity_x, -max_torque, max_torque); // linear_velocity_x = constrain(linear_velocity_x, -max_torque, max_torque);
// yaw_rate = constrain(yaw_rate, -2*max_torque, 2*max_torque); // yaw_rate = constrain(yaw_rate, -2*max_torque, 2*max_torque);
if( diff_data.min_Torq > fabs(linear_velocity_x) )//20250728 增加死区 解决手柄回中,不停车问题
{
linear_velocity_x = 0;
}
left_speed_mps = linear_velocity_x + yaw_rate; left_speed_mps = linear_velocity_x + yaw_rate;
right_speed_mps = linear_velocity_x - yaw_rate; right_speed_mps = linear_velocity_x - yaw_rate;
@@ -608,7 +613,7 @@ static void diffProcess(void *signal_id)
// 限制输出速度在当前速度和最大加速度计算出来的速度之间 // 限制输出速度在当前速度和最大加速度计算出来的速度之间
// output_speed = constrain(output_speed, diff_data.speed - max_acceleration * dt, diff_data.speed + max_acceleration * dt); // output_speed = constrain(output_speed, diff_data.speed - max_acceleration * dt, diff_data.speed + max_acceleration * dt);
if( (0 == diff_data.desired_yaw_rate) && (0 == diff_data.desired_speed) )//手柄回中速度小的时候清0 if( (0 == diff_data.desired_yaw_rate) && (0 == diff_data.desired_speed) && ( 10 > fabs(diff_data.left_motor_speed) ) && ( 10 > fabs(diff_data.right_motor_speed) ) )//手柄回中速度小的时候清0
{ {
resetPidIntegral(&speed_pid); resetPidIntegral(&speed_pid);
resetPidIntegral(&yaw_rate_pid); resetPidIntegral(&yaw_rate_pid);
@@ -622,6 +627,7 @@ static void diffProcess(void *signal_id)
computeInverseKinematics(output_speed, output_yaw_rate, diff_data.max_speed, out_torque); computeInverseKinematics(output_speed, output_yaw_rate, diff_data.max_speed, out_torque);
if( fabs(diff_data.left_front_motor_speed - diff_data.left_rear_motor_speed) >= diff_data.diff_dead_zone )//如果超过系数 if( fabs(diff_data.left_front_motor_speed - diff_data.left_rear_motor_speed) >= diff_data.diff_dead_zone )//如果超过系数
{ {
diff_data.left_speed_diff = diff_data.left_front_motor_speed - diff_data.left_rear_motor_speed; diff_data.left_speed_diff = diff_data.left_front_motor_speed - diff_data.left_rear_motor_speed;

View File

@@ -278,21 +278,31 @@ void processWriteRequestFrame(UnParamRequest *paramRequest, uint32_t sender_ip,
void processReadRequestFrame(UnParamRequest *paramRequest, uint32_t sender_ip, uint16_t sender_port) { void processReadRequestFrame(UnParamRequest *paramRequest, uint32_t sender_ip, uint16_t sender_port) {
// 处理读请求的逻辑
printf("Processing read request.\n"); printf("Processing read request.\n");
// 清零 paramRequest // 先备份原始请求数据
UnParamRequest originalRequest;
memcpy(&originalRequest, paramRequest, sizeof(UnParamRequest));
// 清零响应数据
memset(paramRequest, 0, sizeof(UnParamRequest)); memset(paramRequest, 0, sizeof(UnParamRequest));
// 先发送信号,然后从结构体读 // 处理客户端请求的参
for (int i = 0; i < 256; ++i) { for (int i = 0; i < 256; ++i) {
if (strlen((char *)paramRequest->bit_data.param_name[i]) > 0) { if (strlen((char *)originalRequest.bit_data.param_name[i]) > 0) {
float readData = readParameter(paramRequest->bit_data.param_name[i]); // 复制参数名到响应
memcpy(paramRequest->bit_data.data[i], &readData, sizeof(paramRequest->bit_data.data[i])); strcpy((char *)paramRequest->bit_data.param_name[i],
(char *)originalRequest.bit_data.param_name[i]);
// 读取参数值
float readData = readParameter(originalRequest.bit_data.param_name[i]);
memcpy(paramRequest->bit_data.data[i], &readData, sizeof(float));
printf("Read parameter: %s = %f\n",
originalRequest.bit_data.param_name[i], readData);
} }
} }
// 发送响应 // 发送响应 - 直接传递 paramRequest
sendParamRequestResponse(paramRequest, sender_ip, sender_port, 0); sendParamRequestResponse(paramRequest, sender_ip, sender_port, 0);
} }
@@ -300,6 +310,7 @@ void processReadRequestFrame(UnParamRequest *paramRequest, uint32_t sender_ip, u
void OnParamSignal(void *data) void OnParamSignal(void *data)
{ {
RequestContext *signal = (RequestContext *)data; RequestContext *signal = (RequestContext *)data;