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
 */
相关推荐
眰恦ゞLYF1 小时前
嵌入式硬件——基于IMX6ULL的GPT(通用定时器)实现
单片机·嵌入式硬件·gpt·imx6ull
充哥单片机设计3 小时前
【STM32项目开源】基于STM32的智能老人拐杖
stm32·单片机·嵌入式硬件
10001hours3 小时前
(基于江协科技)51单片机入门:6.串口
科技·嵌入式硬件·51单片机
眰恦ゞLYF4 小时前
嵌入式硬件——基于IMX6ULL的I2C实现
嵌入式硬件·i2c
常州晟凯电子科技17 小时前
君正T32开发笔记之固件烧写
人工智能·笔记·嵌入式硬件·物联网
李永奉17 小时前
51单片机-驱动LCD1602液晶显示屏教程
单片机·嵌入式硬件·51单片机
straw_hat.21 小时前
PCB学习——STM32F103VET6-STM32接口部分
stm32·嵌入式硬件·学习
Hello_wshuo1 天前
记一次手机付费充电设备研究
linux·单片机
点灯小铭1 天前
基于51单片机的手机蓝牙控制8位LED灯亮灭设计
单片机·mongodb·智能手机·毕业设计·51单片机·课程设计