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
 */
相关推荐
Ronin-Lotus20 分钟前
嵌入式硬件篇---CAN
单片机·嵌入式硬件·can·stm32f103rct6
mini_nine4 小时前
DSP28335 串口中断收发及FIFO使用
单片机·dsp开发
走错路的程序员6 小时前
stm32测频率占空比最好的方案
stm32·单片机·嵌入式硬件
前进的程序员6 小时前
ARM 芯片上移植 Ubuntu 操作系统详细步骤
linux·arm开发·ubuntu
楚灵魈7 小时前
[Linux]从零开始的STM32MP157 Busybox根文件系统构建
linux·arm开发·stm32
Ronin-Lotus7 小时前
嵌入式硬件篇---SPI
单片机·嵌入式硬件
白天学嵌入式8 小时前
STM32f103 标准库 零基础学习之按键点灯(不涉及中断)
stm32·单片机·学习
Ronin-Lotus8 小时前
嵌入式硬件篇---陀螺仪|PID
单片机·嵌入式硬件
小智学长 | 嵌入式8 小时前
单片机-STM32部分:12、I2C
单片机·嵌入式硬件
四夕白告木贞9 小时前
stm32week15
stm32·单片机·嵌入式硬件·学习