#ifndef _DOG_PID_H_
#define _DOG_PID_H_

#include "zf_common_headfile.h"
#include "zf_common_debug.h"

#include "DOG_data.h"

struct DOG_PID;

typedef struct DOG_PID{
	/* PID  */
	float Kp;
	float Ki;
	float Kd;
	float output_limit;
	float i_limit;
	
	/* PID  */  
	float now_err;    
	float last_err;    
	float last_last_err;
	float sigma_err;
	float value;
    float value_delta;
	
	/* ģ PID  */
	_fuzzy_subset_ fuzzy_rules[8][8];	// ģ
	 float range[2][3];					// ģ
	
	/* Ա */
	float (*incremental_pid)(struct DOG_PID* this ,float target, float feedback);		// ʽ PID
	float (*positional_pid)(struct DOG_PID* this ,float target, float feedback);		// λʽ PID
	void (*fuzzy_pid_init)(struct DOG_PID* this, _fuzzy_subset_ fuzzy_rules[][8],  float range[][3]);		// ģ PID ʼ
	void (*fuzzy_pid)(struct DOG_PID* this, float* err, float* p, float* i, float* d, float* output_limit, float* i_limit, uint8 order);	// ģ PID
}DOG_PID;

// ʽ PID
float incremental_pid(struct DOG_PID* this ,float target, float feedback);
// λʽ PID
float positional_pid(struct DOG_PID* this ,float target, float feedback);
/*
	ģ PID ʼ
	˵
	fuzzy_rule ģfuzzy_rule[8][8]
	range Χֵrange[2][3] = {{С У }, {С У }}
*/
void fuzzy_pid_init(struct DOG_PID* this, _fuzzy_subset_ fuzzy_rules[][8], float range[][3]);
/* 
	ģ PID
	˵
	err һά/άerr/err[2]
	Kp p[4]
	Ki ֣i[4]
	Kd ΢֣d[4]
	i_limit ޷i_limit[4]
	output_limit ޷output_limit[4]
	order ģ
*/
void fuzzy_pid(struct DOG_PID* this, float* err, float* p, float* i, float* d, float* i_limit, float* output_limit, uint8 order);

// 캯
void pid(struct DOG_PID* this);
// 
void _pid(struct DOG_PID* this);

#endif