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
 */
相关推荐
点灯小铭7 小时前
基于单片机的窗帘、灯光、空调智能家居控制系统设计
单片机·嵌入式硬件·毕业设计·智能家居·课程设计·期末大作业
飞凌嵌入式9 小时前
【玩转多核异构】T153核心板RISC-V核的实时性应用解析
linux·嵌入式硬件·嵌入式·risc-v
怎么就重名了9 小时前
STM32+蓝牙模块+超声波模块+QT
stm32·嵌入式硬件·qt
oshan201210 小时前
小华HC32L136K8TA 单片机新建 MDK5 工程模板(二)
单片机·嵌入式硬件
三品吉他手会点灯11 小时前
STM32F103学习笔记-16-RCC(第4节)-使用 HSI 配置系统时钟并用 MCO 监控系统时钟
笔记·stm32·单片机·嵌入式硬件·学习
Lester_110112 小时前
嵌入式学习笔记 - 关于看门狗定时器的喂狗的操作放在中断还是放在主循环
笔记·单片机·学习
bai54593612 小时前
LED闪烁功能代码详解
单片机·嵌入式硬件
青柚~13 小时前
【鲲鹏服务器麒麟系统arm架构部署docker】
服务器·arm开发·docker·架构
吃货界的硬件攻城狮15 小时前
【STM32】低功耗模式下的IO配置详解(标准库实现)
stm32·单片机·嵌入式硬件
DIY机器人工房16 小时前
嵌入式面试题:物联网协议怎么选?Zigbee/蓝牙/LoRa/4G/WiFi优缺点一文读懂
stm32·嵌入式硬件·嵌入式·diy机器人工房·嵌入式面试题