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
 */
相关推荐
芯片设计-曾工8 小时前
当精准脉冲遇上清晰视界——CH2205E模块与YL1621的“黄金搭档“
驱动开发·stm32·单片机·51单片机·硬件工程
LCG元14 小时前
STM32 硬件 SPI + DMA 驱动 OLED 显示屏(SSD1306):从原理到 112fps 高速刷新全流程
stm32·单片机·嵌入式硬件
天吾cc15 小时前
RTT-ADC
单片机·嵌入式硬件·学习
qq_4480111615 小时前
C语言中的野指针和空指针
c语言·开发语言·单片机
崇山峻岭之间16 小时前
STM32F407的FOC驱动01
stm32·单片机·嵌入式硬件
橘色的喵21 小时前
ARM-Linux 嵌入式消息总线:高优先级驱逐机制设计
linux·arm开发·性能优化·嵌入式·newosp
Lzh编程小栈21 小时前
【嵌入式硬核精讲】I2C通信协议万字详解(时序帧格式、同步半双工、重复起始、一对多挂载、寄存器、面试必考)
stm32·单片机·嵌入式硬件·面试
十月的皮皮21 小时前
STM32从零到量产开发:四路继电器工业控制模块开发 -上位机 Program.cs 应用程序入口设计说明
c语言·stm32·单片机·stm32cubemx·hal库
LCG元21 小时前
STM32F103+MPU6050互补滤波姿态解算与OLED实时显示实战(附完整工程代码)
stm32·单片机·嵌入式硬件