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 小时前
灵巧手 - 绳驱(钢丝/绳索驱动)、连杆(Linkage)和直驱(Direct Drive)的技术对比
嵌入式硬件·机械·灵巧手
阿拉斯攀登6 小时前
51单片机:点灯程序的底层拆解
单片机·嵌入式硬件·51单片机
网易独家音乐人Mike Zhou6 小时前
【嵌入式模块芯片开发】LP87524电源PMIC芯片配置流程,给雷达供电的延时上电时序及API函数
c语言·stm32·单片机·51单片机·嵌入式·电源·毫米波雷达
小小Fred7 小时前
Cortex-M3的xPSR寄存器介绍
单片机·嵌入式硬件
就是蠢啊7 小时前
51单片机——DS1302 时钟芯片(二)
单片机·嵌入式硬件·51单片机
无人装备硬件开发爱好者7 小时前
深度解析:STM32 MDK 工程 HEX 文件转 BIN 文件 —— 原理、方法、优缺点与实战指南(上)
stm32·嵌入式硬件·hex2bin
up向上up7 小时前
基于51单片机智能家居环境检测设计_烟雾温度GSM短信提示报警器
嵌入式硬件·51单片机·智能家居
Nautiluss8 小时前
一起玩XVF3800麦克风阵列(五)
嵌入式硬件·音频·语音识别·智能音箱
youcans_8 小时前
【动手学电机驱动】 STM32-FOC(11)ST MCSDK6.0 电机控制软件框架
stm32·单片机·嵌入式硬件·foc·电机驱动
rechol8 小时前
cpu异常中断(2)
单片机·嵌入式硬件