IT评测·应用市场-qidao123.com技术社区

标题: Odrive0.5.1-FOC电机控制 arm_cos_f32.cpp arm_sin_f32.cpp代码实现(二) [打印本页]

作者: 火影    时间: 2025-4-10 16:32
标题: Odrive0.5.1-FOC电机控制 arm_cos_f32.cpp arm_sin_f32.cpp代码实现(二)
01 理论原理

见arm_cos_f32.c 代码分析文章Odrive0.5.1-FOC电机控制 arm_cos_f32.cpp arm_sin_f32.cpp代码实现(一)-CSDN博客
02 float32_t our_arm_sin_f32(float32_t x)

  1. float32_t our_arm_sin_f32(float32_t x)
  2. {
  3.   float32_t sinVal, fract, in;                           /* Temporary variables for input, output */
  4.   uint16_t index;                                        /* Index variable */
  5.   float32_t a, b;                                        /* Two nearest output values */
  6.   int32_t n;
  7.   float32_t findex;
  8.   /* input x is in radians */
  9.   /* Scale the input to [0 1] range from [0 2*PI] , divide input by 2*pi */
  10.   in = x * 0.159154943092f;
  11.   /* Calculation of floor value of input */
  12.   n = (int32_t) in;
  13.   /* Make negative values towards -infinity */
  14.   if (x < 0.0f)
  15.   {
  16.     n--;
  17.   }
  18.   /* Map input value to [0 1] */
  19.   in = in - (float32_t) n;
  20.   /* Calculation of index of the table */
  21.   findex = (float32_t)FAST_MATH_TABLE_SIZE * in;
  22.   index = (uint16_t)findex;
  23.   /* when "in" is exactly 1, we need to rotate the index down to 0 */
  24.   if (index >= FAST_MATH_TABLE_SIZE) {
  25.     index = 0;
  26.     findex -= (float32_t)FAST_MATH_TABLE_SIZE;
  27.   }
  28.   /* fractional value calculation */
  29.   fract = findex - (float32_t) index;
  30.   /* Read two nearest values of input value from the sin table */
  31.   a = sinTable_f32[index];
  32.   b = sinTable_f32[index+1];
  33.   /* Linear interpolation process */
  34.   sinVal = (1.0f-fract)*a + fract*b;
  35.   /* Return the output value */
  36.   return (sinVal);
  37. }
  38. /**
  39. * @} end of sin group
  40. */
复制代码


免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。




欢迎光临 IT评测·应用市场-qidao123.com技术社区 (https://dis.qidao123.com/) Powered by Discuz! X3.4