Dahlin控制算法实现

参考 :
https://blog.csdn.net/yin_bu_feng/article/details/85871595

大林控制算法:

#ifndef _DALIN_CONTROLLER_H_
#define _DALIN_CONTROLLER_H_

#ifdef __cplusplus
 extern "C" {
#endif


#ifndef __API__
#define __API__
#endif

#ifndef __STATIC_INLINE__  
#define __STATIC_INLINE__ static inline
#endif

struct DahlinController {
    float last_error;
    float u;
    float last_u;
    float previous_u;
    float a0;
    float a1;
    float b0;
    float b1;
};

__API__ __STATIC_INLINE__ int DahlinController_Init(struct DahlinController *dc)
{
    if (!dc) return -1;

	dc->last_error   = 0;
    dc->u            = 0;
    dc->last_u       = 0;
    dc->previous_u   = 0;
    dc->a0           = 0;
    dc->a1           = 0;
    dc->b0           = 0;
    dc->b1           = 0;
    return 0;
}


__API__ __STATIC_INLINE__ int DahlinController_a0_Set(struct DahlinController *dc, float a0)
{
    if (!dc) return -1;

    dc->a0 = a0;
    return 0;
}


__API__ __STATIC_INLINE__ int DahlinController_a1_Set(struct DahlinController *dc, float a1)
{
    if (!dc) return -1;

    dc->a1 = a1;
    return 0;
}


__API__ __STATIC_INLINE__ int DahlinController_b0_Set(struct DahlinController *dc, float b0)
{
    if (!dc) return -1;

    dc->b0 = b0;
    return 0;
}


__API__ __STATIC_INLINE__ int DahlinController_b1_Set(struct DahlinController *dc, float b1)
{
    if (!dc) return -1;

    dc->b1 = b1;
    return 0;
}


__API__ __STATIC_INLINE__ float DahlinControl(struct DahlinController *dc, float target, float actual)
{
    int result;
    float error;

    error = target - actual;

	dc->u = dc->b0*dc->last_u + dc->b1*dc->previous_u + dc->a0*error + dc->a1*dc->last_error;  /* Dahlin equation */

    dc->last_error = error;
	dc->previous_u = dc->last_u;
	dc->last_u = dc->u;

	return dc->u;
}

#ifdef __cplusplus
}
#endif

#endif /* _DALIN_CONTROLLER_H_ */
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

欲盖弥彰1314

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值