标签:void float for div bsp fine 函数 def 优化
1 //优化前: 2 static void _get_pid_param(uint8_t *buffer, float *kpid) 3 { 4 kpid[0] = (float)((1/PID_PARAM_FACTOR) * ((int16_t)(*(buffer + 4) << 8) | *(buffer + 5))); 5 kpid[1] = (float)((1/PID_PARAM_FACTOR) * ((int16_t)(*(buffer + 6) << 8) | *(buffer + 7))); 6 kpid[2] = (float)((1/PID_PARAM_FACTOR) * ((int16_t)(*(buffer + 8) << 8) | *(buffer + 9))); 7 kpid[3] = (float)((1/PID_PARAM_FACTOR) * ((int16_t)(*(buffer + 10) << 8) | *(buffer + 11))); 8 kpid[4] = (float)((1/PID_PARAM_FACTOR) * ((int16_t)(*(buffer + 12) << 8) | *(buffer + 13))); 9 kpid[5] = (float)((1/PID_PARAM_FACTOR) * ((int16_t)(*(buffer + 14) << 8) | *(buffer + 15))); 10 kpid[6] = (float)((1/PID_PARAM_FACTOR) * ((int16_t)(*(buffer + 16) << 8) | *(buffer + 17))); 11 kpid[7] = (float)((1/PID_PARAM_FACTOR) * ((int16_t)(*(buffer + 18) << 8) | *(buffer + 19))); 12 kpid[8] = (float)((1/PID_PARAM_FACTOR) * ((int16_t)(*(buffer + 20) << 8) | *(buffer + 21))); 13 } 14 15 //优化后: 16 #define GET_PID_PARAM(buffer, offset) (float)((1/PID_PARAM_FACTOR) * ((int16_t)(*(buffer + offset) << 8) | *(buffer + (offset + 1)))); 17 18 static void _get_pid_param(uint8_t *buffer, float *kpid) 19 { 20 for(int i = 0; i < 9; i++) 21 { 22 kpid[i] = GET_PID_PARAM(buffer, (i + 2) * 2); 23 } 24 }
开源组件rt-robot,文件ano.c, 函数_get_pid_param优化
标签:void float for div bsp fine 函数 def 优化
原文地址:https://www.cnblogs.com/linpeng1577/p/12195646.html