Odrive0.5.1-FOC电机控制 arm_cos_f32.cpp arm_sin_f32.cpp代码实现(二) ...

火影  论坛元老 | 2025-4-10 16:32:34 | 显示全部楼层 | 阅读模式
打印 上一主题 下一主题

主题 1769|帖子 1769|积分 5307

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

x
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企服之家,中国第一个企服评测及商务社交产业平台。
回复

举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

火影

论坛元老
这个人很懒什么都没写!
快速回复 返回顶部 返回列表