代码拉取完成,页面将自动刷新
同步操作将从 luoqi/qfoc 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
/**
* @ Author: luoqi
* @ Create Time: 2024-08-29 21:32
* @ Modified by: luoqi
* @ Modified time: 2024-08-29 21:56
* @ Description:
*/
#include "encoder.h"
int enc_init(Encoder *enc, int32_t eorg, uint32_t tcnt_th, uint32_t ppr, float unit, float interval_ms, EncDir dir)
{
enc->ppr = ppr;
enc->eorg = eorg;
enc->unit = unit;
enc->nms = interval_ms;
enc->dir = dir;
enc->tcnt_th = tcnt_th;
return 0;
}
int enc_zero(Encoder *enc)
{
enc->eorg = 0;
return 0;
}
int enc_update(Encoder *enc, float epos)
{
float abs_epc;
if(enc->dir == ENC_DIR_CCW) {
epos = -epos;
}
enc->epc = epos - enc->epos;
abs_epc = enc->epc > 0.0f ? enc->epc : -enc->epc;
enc->epos = epos;
enc->p = (epos - enc->eorg) * enc->unit;
if(abs_epc < (0.001f * enc->nms * enc->ppr)) {
enc->tcnt++;
enc->tmc += enc->epc;
if(enc->tcnt > enc->tcnt_th) {
enc->tcnt = 0;
enc->v = 1000.0f * ((float)enc->tmc * enc->unit) / (enc->nms * enc->tcnt_th);
enc->tmc = 0;
}
} else {
enc->v = 1000.0f * (enc->epc * enc->unit) / enc->nms;
enc->tcnt = 0;
enc->tmc = 0;
}
return 0;
}
int enc_clear(Encoder *enc)
{
enc->epos = 0.0f;
enc->eorg = 0.0f;
enc->epc = 0.0f;
enc->tcnt = 0;
enc->tmc = 0.0f;
enc->p = 0.0f;
enc->v = 0.0f;
return 0;
}
int enc_zero(Encoder *enc)
{
enc->eorg = enc->epos;
return 0;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。