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)

cpp 复制代码
float32_t our_arm_sin_f32(float32_t x)
{
  float32_t sinVal, fract, in;                           /* Temporary variables for input, output */
  uint16_t index;                                        /* Index variable */
  float32_t a, b;                                        /* Two nearest output values */
  int32_t n;
  float32_t findex;

  /* input x is in radians */
  /* Scale the input to [0 1] range from [0 2*PI] , divide input by 2*pi */
  in = x * 0.159154943092f;

  /* Calculation of floor value of input */
  n = (int32_t) in;

  /* Make negative values towards -infinity */
  if (x < 0.0f)
  {
    n--;
  }

  /* Map input value to [0 1] */
  in = in - (float32_t) n;

  /* Calculation of index of the table */
  findex = (float32_t)FAST_MATH_TABLE_SIZE * in;
  index = (uint16_t)findex;

  /* when "in" is exactly 1, we need to rotate the index down to 0 */
  if (index >= FAST_MATH_TABLE_SIZE) {
    index = 0;
    findex -= (float32_t)FAST_MATH_TABLE_SIZE;
  }

  /* fractional value calculation */
  fract = findex - (float32_t) index;

  /* Read two nearest values of input value from the sin table */
  a = sinTable_f32[index];
  b = sinTable_f32[index+1];

  /* Linear interpolation process */
  sinVal = (1.0f-fract)*a + fract*b;

  /* Return the output value */
  return (sinVal);
}

/**
 * @} end of sin group
 */
相关推荐
llilian_1619 小时前
晶体频率测试仪 破解晶振品控核心难题:晶体频率网络测试仪深度解析 晶体网络分析仪
网络·功能测试·单片机·嵌入式硬件·测试工具·51单片机
YJlio20 小时前
《Windows Internals》10.5.1 ETW 概述:看懂 Windows 的“事件高速公路”
java·windows·笔记·stm32·嵌入式硬件·学习·eclipse
平凡灵感码头20 小时前
(方案优化师第 1 期) 旺仔牛奶音响
单片机·嵌入式硬件
YJlio20 小时前
Windows Internals 10.5.3:ETW 架构详解,从事件产生到性能分析的完整链路
windows·笔记·python·stm32·嵌入式硬件·学习·架构
bubiyoushang8881 天前
STM32F103C8T6+DM9051以太网功能实现方案
stm32·单片机·嵌入式硬件
IT_阿水1 天前
基于STM32河流水质检测
stm32·单片机·嵌入式硬件
黑白园1 天前
STM32定时器中断
stm32·单片机·嵌入式硬件
weixin_456808381 天前
【沁恒蓝牙开发】ADC DMA定时采样、转化
单片机·嵌入式硬件
华普微HOPERF1 天前
MCU+BLE射频+丰富外设,BLE SoC如何高效传输数据?
单片机·嵌入式硬件
振南的单片机世界1 天前
时钟开关:不用的外设,把它的时钟关掉,省电!
stm32·单片机·嵌入式硬件