#ifndef LIBA_PID_H
#define LIBA_PID_H
#include "a.h"
typedef struct a_pid a_pid;
#if defined(__cplusplus)
extern "C" {
#endif
#define a_pid_init(ctx) a_pid_zero(ctx)
A_EXTERN void a_pid_set_kpid(a_pid *ctx, a_float kp, a_float ki, a_float kd);
A_EXTERN a_float a_pid_run(a_pid *ctx, a_float set, a_float fdb);
A_EXTERN a_float a_pid_pos(a_pid *ctx, a_float set, a_float fdb);
A_EXTERN a_float a_pid_inc(a_pid *ctx, a_float set, a_float fdb);
A_EXTERN void a_pid_zero(a_pid *ctx);
#if defined(__cplusplus)
}
namespace a
{
typedef struct a_pid pid;
}
#endif
struct a_pid
{
a_float kp; a_float ki; a_float kd; a_float summax; a_float summin; a_float sum; a_float outmax; a_float outmin; a_float out; a_float var; a_float fdb; a_float err; #if defined(__cplusplus)
A_INLINE void init() { a_pid_init(this); }
A_INLINE void set_kpid(a_float kp_, a_float ki_, a_float kd_)
{
a_pid_set_kpid(this, kp_, ki_, kd_);
}
A_INLINE a_float run(a_float set, a_float fdb_)
{
return a_pid_run(this, set, fdb_);
}
A_INLINE a_float pos(a_float set, a_float fdb_)
{
return a_pid_pos(this, set, fdb_);
}
A_INLINE a_float inc(a_float set, a_float fdb_)
{
return a_pid_inc(this, set, fdb_);
}
A_INLINE void zero() { a_pid_zero(this); }
#endif
};
#endif