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
 */
相关推荐
简单电磁炮6 小时前
STM32 B型漏电流检测项目
stm32·单片机·嵌入式硬件
Milky.Way8 小时前
单片机——基础介绍(CPU内部)
单片机·嵌入式硬件
..Dauntless..9 小时前
【stm32】中断(四)——保护与恢复
stm32·单片机·嵌入式硬件
创界工坊工作室11 小时前
133-基于Arduino六足爬虫机器人设计
stm32·单片机·嵌入式硬件·机器人·51单片机·proteus
LabVIEW开发12 小时前
SIM928 电压源 + LabVIEW 低温偏置怎么加?
单片机·嵌入式硬件·labview
芦苇电子16 小时前
STM32 驱动 ESP8266 开热点:手机连 WiFi 点 LED,AT 指令逐行拆解
stm32·嵌入式硬件·智能手机
小李不想当小白19 小时前
HAL库之定时器输出比较(STM32 HAL库学习笔记)
笔记·stm32·单片机·嵌入式硬件·学习·嵌入式
LabVIEW开发19 小时前
PAV 电源 + LabVIEW:电压拉偏怎么做?
单片机·嵌入式硬件·labview
都在酒里1 天前
STM32G431 + FreeRTOS 长稳运行实战:看门狗、故障留痕与掉电恢复
stm32·嵌入式硬件·深度学习
郝学胜-神的一滴1 天前
Effective STL 条款 14:用扩容函数避免重新分配
linux·开发语言·网络·数据结构·c++·单片机