火影 发表于 2025-4-10 16:32:34

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 range from , 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 */
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;
b = sinTable_f32;

/* Linear interpolation process */
sinVal = (1.0f-fract)*a + fract*b;

/* Return the output value */
return (sinVal);
}

/**
* @} end of sin group
*/

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
页: [1]
查看完整版本: Odrive0.5.1-FOC电机控制 arm_cos_f32.cpp arm_sin_f32.cpp代码实现(二)