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
 */
相关推荐
不知所云,19 小时前
5. STM32 时钟系统分配
stm32·单片机·嵌入式硬件
电子科技圈20 小时前
芯科科技FG23L无线SoC现已全面供货,为Sub-GHz物联网应用提供最佳性价比
科技·嵌入式硬件·mcu·物联网·制造·智能硬件·交通物流
天天爱吃肉821821 小时前
【比亚迪璇玑架构深度解析:重新定义智能电动汽车的“整车智能”】
数据库·人工智能·嵌入式硬件·架构·汽车
糖糖单片机设计21 小时前
硬件开发_基于物联网的沼气池环境监测系统
stm32·单片机·嵌入式硬件·物联网·51单片机
沐欣工作室_lvyiyi1 天前
基于单片机的全自动洗衣机控制系统(论文+源码)
stm32·单片机·嵌入式硬件·毕业设计
The️1 天前
STM32-FreeRTOS操作系统-二值信号量与计数信号量
arm开发·stm32·单片机·嵌入式硬件·物联网
如愿小李1 天前
STM32之水质浑浊度传感器模块
stm32·单片机·嵌入式硬件
GilgameshJSS1 天前
【学习K230-例程21】GT6700-UDP-Client
网络·python·单片机·网络协议·学习·udp
深圳市尚想信息技术有限公司1 天前
APT32F0042F6P6 32位微控制器(MCU)单片机 APT爱普特微电子 芯片核心解析
单片机·集成电路·电子元器件·爱普特