当前位置: 首页 > news >正文

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)

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
 */

相关文章:

  • ChatGPT的GPT-4o创建图像Q版人物提示词实例展示
  • `mpi4py` 是什么; ModuleNotFoundError: No module named ‘mpi4py
  • SQL练习题
  • 智慧医院常用的子系统介绍 51-100
  • C语言学习记录(14)自定义类型:联合和枚举
  • ABAP小白开发操作手册+(十)验证和替代——下
  • velero
  • Lua 函数使用的完整指南
  • 操作符详解(下)——包含整形提升
  • 深入解析Java内存与缓存:从原理到实践优化
  • 将 CrewAI 与 Elasticsearch 结合使用
  • 蓝桥杯-小明的彩灯(Java-差分)
  • 网络稳定性--LCA+最大生成树+bfs1/dfs1找最小边
  • 996引擎-实战笔记:小地图传送【PC右键/手机长按】
  • Python Cookbook-5.10 选取序列中最小的第 n个元素
  • Android10.0 framework第三方无源码APP读写断电后数据丢失问题解决
  • DeepSeek-V3 API:开启下一代AI应用开发的新篇章
  • 283.移除零
  • spark学习内容总结
  • 【C++面向对象】封装(上):探寻构造函数的幽微之境
  • 淘宝客怎样做自己的网站推广/seo点击器
  • 怎样做网站漂浮/新网站 seo
  • 小学生做网站/软文广告有哪些
  • 山西本土网站建设/app推广地推接单网
  • 大庆北京网站建设/网站制作和推广
  • 阿里巴巴的网站怎么做/二级域名网址查询