rename a_pid_fuzzy_nfuzz to a_pid_fuzzy_bfuzz

This commit is contained in:
tqfx 2024-09-03 23:55:59 +08:00
parent 4e9128eeed
commit 29858d8498
No known key found for this signature in database
GPG Key ID: 54B434B4E27F1DCB
57 changed files with 354 additions and 347 deletions

View File

@ -56,7 +56,7 @@ extern "C" {
@param[in] ki integral constant
@param[in] kd derivative constant
*/
A_EXTERN void a_pid_kpid(a_pid *ctx, a_float kp, a_float ki, a_float kd);
A_EXTERN void a_pid_set_kpid(a_pid *ctx, a_float kp, a_float ki, a_float kd);
/*!
@brief calculate for PID controller
@ -118,9 +118,9 @@ struct a_pid
a_float err; //!< cache error
#if defined(__cplusplus)
A_INLINE void init() { a_pid_init(this); }
A_INLINE void kpid(a_float kp_, a_float ki_, a_float kd_)
A_INLINE void set_kpid(a_float kp_, a_float ki_, a_float kd_)
{
a_pid_kpid(this, kp_, ki_, kd_);
a_pid_set_kpid(this, kp_, ki_, kd_);
}
A_INLINE a_float run(a_float set, a_float fdb_)
{

View File

@ -55,6 +55,27 @@ A_EXTERN a_float (*a_pid_fuzzy_opr(unsigned int opr))(a_float, a_float);
*/
A_EXTERN void a_pid_fuzzy_set_opr(a_pid_fuzzy *ctx, unsigned int opr);
/*!
@brief get memory block for fuzzy PID controller
@param[in,out] ctx points to an instance of fuzzy PID controller
@return memory block for fuzzy PID controller
*/
A_EXTERN void *a_pid_fuzzy_bfuzz(a_pid_fuzzy const *ctx);
/*!
@brief set memory block for fuzzy PID controller
@param[in,out] ctx points to an instance of fuzzy PID controller
@param[in] ptr points to a buffer at least A_PID_FUZZY_BFUZZ(num)
@param[in] num the maximum number triggered by the rule
*/
A_EXTERN void a_pid_fuzzy_set_bfuzz(a_pid_fuzzy *ctx, void *ptr, a_size num);
/*!
@brief compute size of memory block for fuzzy PID controller
@param[in] n the maximum number triggered by the rule
*/
#define A_PID_FUZZY_BFUZZ(n) (sizeof(unsigned int) * (n) * 2 + sizeof(a_float) * (n) * (2 + (n)))
/*!
@brief set rule base for fuzzy PID controller
@param[in,out] ctx points to an instance of fuzzy PID controller
@ -65,29 +86,8 @@ A_EXTERN void a_pid_fuzzy_set_opr(a_pid_fuzzy *ctx, unsigned int opr);
@param[in] mki points to Ki's rule base table which must be a square matrix
@param[in] mkd points to Kd's rule base table which must be a square matrix
*/
A_EXTERN void a_pid_fuzzy_rule(a_pid_fuzzy *ctx, unsigned int nrule, a_float const *me, a_float const *mec,
a_float const *mkp, a_float const *mki, a_float const *mkd);
/*!
@brief compute size of memory block for fuzzy PID controller
@param[in] n the maximum number triggered by the rule
*/
#define A_PID_FUZZY_NFUZZ(n) (sizeof(unsigned int) * (n) * 2 + sizeof(a_float) * (n) * (2 + (n)))
/*!
@brief set memory block for fuzzy PID controller
@param[in,out] ctx points to an instance of fuzzy PID controller
@param[in] ptr points to a buffer at least A_PID_FUZZY_NFUZZ(num)
@param[in] num the maximum number triggered by the rule
*/
A_EXTERN void a_pid_fuzzy_set_nfuzz(a_pid_fuzzy *ctx, void *ptr, a_size num);
/*!
@brief get memory block for fuzzy PID controller
@param[in,out] ctx points to an instance of fuzzy PID controller
@return memory block for fuzzy PID controller
*/
A_EXTERN void *a_pid_fuzzy_nfuzz(a_pid_fuzzy *ctx);
A_EXTERN void a_pid_fuzzy_set_rule(a_pid_fuzzy *ctx, unsigned int nrule, a_float const *me, a_float const *mec,
a_float const *mkp, a_float const *mki, a_float const *mkd);
/*!
@brief set proportional integral derivative constant for fuzzy PID controller
@ -96,7 +96,7 @@ A_EXTERN void *a_pid_fuzzy_nfuzz(a_pid_fuzzy *ctx);
@param[in] ki integral constant
@param[in] kd derivative constant
*/
A_EXTERN void a_pid_fuzzy_kpid(a_pid_fuzzy *ctx, a_float kp, a_float ki, a_float kd);
A_EXTERN void a_pid_fuzzy_set_kpid(a_pid_fuzzy *ctx, a_float kp, a_float ki, a_float kd);
/*!
@brief calculate for fuzzy PID controller
@ -169,18 +169,19 @@ struct a_pid_fuzzy
{
a_pid_fuzzy_set_opr(this, opr_);
}
A_INLINE void set_nfuzz(void *ptr, a_size num)
A_INLINE void *bfuzz() const { return a_pid_fuzzy_bfuzz(this); }
A_INLINE void set_bfuzz(void *ptr, a_size num)
{
a_pid_fuzzy_set_nfuzz(this, ptr, num);
a_pid_fuzzy_set_bfuzz(this, ptr, num);
}
A_INLINE void rule(unsigned int nrule_, a_float const *me_, a_float const *mec_,
a_float const *mkp_, a_float const *mki_, a_float const *mkd_)
A_INLINE void set_rule(unsigned int nrule_, a_float const *me_, a_float const *mec_,
a_float const *mkp_, a_float const *mki_, a_float const *mkd_)
{
a_pid_fuzzy_rule(this, nrule_, me_, mec_, mkp_, mki_, mkd_);
a_pid_fuzzy_set_rule(this, nrule_, me_, mec_, mkp_, mki_, mkd_);
}
A_INLINE void kpid(a_float kp_, a_float ki_, a_float kd_)
A_INLINE void set_kpid(a_float kp_, a_float ki_, a_float kd_)
{
a_pid_fuzzy_kpid(this, kp_, ki_, kd_);
a_pid_fuzzy_set_kpid(this, kp_, ki_, kd_);
}
A_INLINE a_float run(a_float set, a_float fdb)
{

View File

@ -49,7 +49,7 @@ extern "C" {
@param[in] ki integral learning constant
@param[in] kd derivative learning constant
*/
A_EXTERN void a_pid_neuro_kpid(a_pid_neuro *ctx, a_float k, a_float kp, a_float ki, a_float kd);
A_EXTERN void a_pid_neuro_set_kpid(a_pid_neuro *ctx, a_float k, a_float kp, a_float ki, a_float kd);
/*!
@brief set proportional integral derivative weight for single neuron PID controller
@ -58,7 +58,7 @@ A_EXTERN void a_pid_neuro_kpid(a_pid_neuro *ctx, a_float k, a_float kp, a_float
@param[in] wi integral weight
@param[in] wd derivative lweight
*/
A_EXTERN void a_pid_neuro_wpid(a_pid_neuro *ctx, a_float wp, a_float wi, a_float wd);
A_EXTERN void a_pid_neuro_set_wpid(a_pid_neuro *ctx, a_float wp, a_float wi, a_float wd);
/*!
@brief calculate for single neuron PID controller
@ -105,13 +105,13 @@ struct a_pid_neuro
a_float ec; //!< error change
#if defined(__cplusplus)
A_INLINE void init() { a_pid_neuro_init(this); }
A_INLINE void kpid(a_float k_, a_float kp, a_float ki, a_float kd)
A_INLINE void set_kpid(a_float k_, a_float kp, a_float ki, a_float kd)
{
a_pid_neuro_kpid(this, k_, kp, ki, kd);
a_pid_neuro_set_kpid(this, k_, kp, ki, kd);
}
A_INLINE void wpid(a_float wp_, a_float wi_, a_float wd_)
A_INLINE void set_wpid(a_float wp_, a_float wi_, a_float wd_)
{
a_pid_neuro_wpid(this, wp_, wi_, wd_);
a_pid_neuro_set_wpid(this, wp_, wi_, wd_);
}
A_INLINE a_float run(a_float set, a_float fdb)
{

View File

@ -169,10 +169,10 @@ JNIEXPORT jdouble JNICALL Java_liba_pid_err
/*
* Class: liba_pid
* Method: kpid
* Method: set_kpid
* Signature: (DDD)Lliba/pid;
*/
JNIEXPORT jobject JNICALL Java_liba_pid_kpid
JNIEXPORT jobject JNICALL Java_liba_pid_set_1kpid
(JNIEnv *, jobject, jdouble, jdouble, jdouble);
/*

View File

@ -183,14 +183,6 @@ JNIEXPORT jint JNICALL Java_liba_pid_1fuzzy_nrule
JNIEXPORT jobject JNICALL Java_liba_pid_1fuzzy_opr
(JNIEnv *, jobject, jint);
/*
* Class: liba_pid_fuzzy
* Method: rule
* Signature: ([[D[[D[[D[[D[[D)Lliba/pid_fuzzy;
*/
JNIEXPORT jobject JNICALL Java_liba_pid_1fuzzy_rule
(JNIEnv *, jobject, jobjectArray, jobjectArray, jobjectArray, jobjectArray, jobjectArray);
/*
* Class: liba_pid_fuzzy
* Method: nfuzz
@ -209,10 +201,18 @@ JNIEXPORT jobject JNICALL Java_liba_pid_1fuzzy_nfuzz__I
/*
* Class: liba_pid_fuzzy
* Method: kpid
* Method: set_rule
* Signature: ([[D[[D[[D[[D[[D)Lliba/pid_fuzzy;
*/
JNIEXPORT jobject JNICALL Java_liba_pid_1fuzzy_set_1rule
(JNIEnv *, jobject, jobjectArray, jobjectArray, jobjectArray, jobjectArray, jobjectArray);
/*
* Class: liba_pid_fuzzy
* Method: set_kpid
* Signature: (DDD)Lliba/pid_fuzzy;
*/
JNIEXPORT jobject JNICALL Java_liba_pid_1fuzzy_kpid
JNIEXPORT jobject JNICALL Java_liba_pid_1fuzzy_set_1kpid
(JNIEnv *, jobject, jdouble, jdouble, jdouble);
/*

View File

@ -201,18 +201,18 @@ JNIEXPORT jdouble JNICALL Java_liba_pid_1neuro_ec
/*
* Class: liba_pid_neuro
* Method: kpid
* Method: set_kpid
* Signature: (DDDD)Lliba/pid_neuro;
*/
JNIEXPORT jobject JNICALL Java_liba_pid_1neuro_kpid
JNIEXPORT jobject JNICALL Java_liba_pid_1neuro_set_1kpid
(JNIEnv *, jobject, jdouble, jdouble, jdouble, jdouble);
/*
* Class: liba_pid_neuro
* Method: wpid
* Method: set_wpid
* Signature: (DDD)Lliba/pid_neuro;
*/
JNIEXPORT jobject JNICALL Java_liba_pid_1neuro_wpid
JNIEXPORT jobject JNICALL Java_liba_pid_1neuro_set_1wpid
(JNIEnv *, jobject, jdouble, jdouble, jdouble);
/*

View File

@ -162,7 +162,7 @@ public class pid {
* @param kd derivative constant
* @return {@link pid}
*/
public final native pid kpid(double kp, double ki, double kd);
public final native pid set_kpid(double kp, double ki, double kd);
/**
* calculate for PID controller

View File

@ -24,7 +24,7 @@ public class pid_fuzzy {
ByteBuffer mkp;
ByteBuffer mki;
ByteBuffer mkd;
ByteBuffer fuzzy;
ByteBuffer bfuzz;
static {
System.loadLibrary("a");
CAP = 1;
@ -197,18 +197,6 @@ public class pid_fuzzy {
*/
public final native pid_fuzzy opr(int opr);
/**
* set rule base for fuzzy PID controller
*
* @param me membership function parameter table, terminated by {@link mf}
* @param mec membership function parameter table, terminated by {@link mf}
* @param mkp Kp's rule base table which must be a square matrix
* @param mki Ki's rule base table which must be a square matrix
* @param mkd Kd's rule base table which must be a square matrix
* @return {@link pid_fuzzy}
*/
public final native pid_fuzzy rule(double[][] me, double[][] mec, double[][] mkp, double[][] mki, double[][] mkd);
/**
* get maximum number triggered by the rule for fuzzy PID controller
*
@ -224,6 +212,18 @@ public class pid_fuzzy {
*/
public final native pid_fuzzy nfuzz(int num);
/**
* set rule base for fuzzy PID controller
*
* @param me membership function parameter table, terminated by {@link mf}
* @param mec membership function parameter table, terminated by {@link mf}
* @param mkp Kp's rule base table which must be a square matrix
* @param mki Ki's rule base table which must be a square matrix
* @param mkd Kd's rule base table which must be a square matrix
* @return {@link pid_fuzzy}
*/
public final native pid_fuzzy set_rule(double[][] me, double[][] mec, double[][] mkp, double[][] mki, double[][] mkd);
/**
* set proportional integral derivative constant for fuzzy PID controller
*
@ -232,7 +232,7 @@ public class pid_fuzzy {
* @param kd derivative constant
* @return {@link pid_fuzzy}
*/
public final native pid_fuzzy kpid(double kp, double ki, double kd);
public final native pid_fuzzy set_kpid(double kp, double ki, double kd);
/**
* calculate for fuzzy PID controller

View File

@ -195,7 +195,7 @@ public class pid_neuro {
* @param kd derivative learning constant
* @return {@link pid_neuro}
*/
public final native pid_neuro kpid(double k, double kp, double ki, double kd);
public final native pid_neuro set_kpid(double k, double kp, double ki, double kd);
/**
* set proportional integral derivative weight for single neuron PID
@ -206,7 +206,7 @@ public class pid_neuro {
* @param wd derivative weight
* @return {@link pid_neuro}
*/
public final native pid_neuro wpid(double wp, double wi, double wd);
public final native pid_neuro set_wpid(double wp, double wi, double wd);
/**
* calculate for single neuron PID controller

View File

@ -166,11 +166,11 @@ JNIEXPORT jdouble JNICALL Java_liba_pid_err(JNIEnv *Env, jobject Obj)
return ctx->err;
}
JNIEXPORT jobject JNICALL Java_liba_pid_kpid(JNIEnv *Env, jobject Obj, jdouble kp, jdouble ki, jdouble kd)
JNIEXPORT jobject JNICALL Java_liba_pid_set_1kpid(JNIEnv *Env, jobject Obj, jdouble kp, jdouble ki, jdouble kd)
{
jobject Ctx = (*Env)->GetObjectField(Env, Obj, L.ctx);
a_pid *ctx = (a_pid *)(*Env)->GetDirectBufferAddress(Env, Ctx);
a_pid_kpid(ctx, kp, ki, kd);
a_pid_set_kpid(ctx, kp, ki, kd);
return Obj;
}

View File

@ -16,7 +16,7 @@ static struct
jfieldID mkp;
jfieldID mki;
jfieldID mkd;
jfieldID fuzzy;
jfieldID bfuzz;
} L = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
JNIEXPORT void JNICALL Java_liba_pid_1fuzzy_clinit(JNIEnv *Env, jclass Cls)
@ -29,7 +29,7 @@ JNIEXPORT void JNICALL Java_liba_pid_1fuzzy_clinit(JNIEnv *Env, jclass Cls)
L.mkp = (*Env)->GetFieldID(Env, Cls, "mkp", "Ljava/nio/ByteBuffer;");
L.mki = (*Env)->GetFieldID(Env, Cls, "mki", "Ljava/nio/ByteBuffer;");
L.mkd = (*Env)->GetFieldID(Env, Cls, "mkd", "Ljava/nio/ByteBuffer;");
L.fuzzy = (*Env)->GetFieldID(Env, Cls, "fuzzy", "Ljava/nio/ByteBuffer;");
L.bfuzz = (*Env)->GetFieldID(Env, Cls, "bfuzz", "Ljava/nio/ByteBuffer;");
(*Env)->SetStaticIntField(Env, Cls, (*Env)->GetStaticFieldID(Env, Cls, "CAP", "I"), A_PID_FUZZY_CAP);
(*Env)->SetStaticIntField(Env, Cls, (*Env)->GetStaticFieldID(Env, Cls, "CAP_ALGEBRA", "I"), A_PID_FUZZY_CAP_ALGEBRA);
(*Env)->SetStaticIntField(Env, Cls, (*Env)->GetStaticFieldID(Env, Cls, "CAP_BOUNDED", "I"), A_PID_FUZZY_CAP_BOUNDED);
@ -201,6 +201,26 @@ JNIEXPORT jobject JNICALL Java_liba_pid_1fuzzy_opr(JNIEnv *Env, jobject Obj, jin
return Obj;
}
JNIEXPORT jint JNICALL Java_liba_pid_1fuzzy_nfuzz__(JNIEnv *Env, jobject Obj)
{
jobject Ctx = (*Env)->GetObjectField(Env, Obj, L.ctx);
a_pid_fuzzy *ctx = (a_pid_fuzzy *)(*Env)->GetDirectBufferAddress(Env, Ctx);
return (jint)ctx->nfuzz;
}
JNIEXPORT jobject JNICALL Java_liba_pid_1fuzzy_nfuzz__I(JNIEnv *Env, jobject Obj, jint num)
{
jobject Ctx = (*Env)->GetObjectField(Env, Obj, L.ctx);
a_pid_fuzzy *ctx = (a_pid_fuzzy *)(*Env)->GetDirectBufferAddress(Env, Ctx);
if (num > (jint)ctx->nfuzz)
{
jobject Bfuzz = (*Env)->CallObjectMethod(Env, Obj, L.New, (jint)A_PID_FUZZY_BFUZZ((unsigned int)num));
a_pid_fuzzy_set_bfuzz(ctx, (*Env)->GetDirectBufferAddress(Env, Bfuzz), (a_size)num);
(*Env)->SetObjectField(Env, Obj, L.bfuzz, Bfuzz);
}
return Obj;
}
static jobject concat(JNIEnv *Env, jobject Obj, jobjectArray val, jdouble const **out)
{
jsize length = 0;
@ -224,8 +244,8 @@ static jobject concat(JNIEnv *Env, jobject Obj, jobjectArray val, jdouble const
return obj;
}
JNIEXPORT jobject JNICALL Java_liba_pid_1fuzzy_rule(JNIEnv *Env, jobject Obj, jobjectArray me, jobjectArray mec,
jobjectArray mkp, jobjectArray mki, jobjectArray mkd)
JNIEXPORT jobject JNICALL Java_liba_pid_1fuzzy_set_1rule(JNIEnv *Env, jobject Obj, jobjectArray me, jobjectArray mec,
jobjectArray mkp, jobjectArray mki, jobjectArray mkd)
{
jobject Ctx = (*Env)->GetObjectField(Env, Obj, L.ctx);
a_pid_fuzzy *ctx = (a_pid_fuzzy *)(*Env)->GetDirectBufferAddress(Env, Ctx);
@ -243,31 +263,11 @@ JNIEXPORT jobject JNICALL Java_liba_pid_1fuzzy_rule(JNIEnv *Env, jobject Obj, jo
return Obj;
}
JNIEXPORT jint JNICALL Java_liba_pid_1fuzzy_nfuzz__(JNIEnv *Env, jobject Obj)
JNIEXPORT jobject JNICALL Java_liba_pid_1fuzzy_set_1kpid(JNIEnv *Env, jobject Obj, jdouble kp, jdouble ki, jdouble kd)
{
jobject Ctx = (*Env)->GetObjectField(Env, Obj, L.ctx);
a_pid_fuzzy *ctx = (a_pid_fuzzy *)(*Env)->GetDirectBufferAddress(Env, Ctx);
return (jint)ctx->nfuzz;
}
JNIEXPORT jobject JNICALL Java_liba_pid_1fuzzy_nfuzz__I(JNIEnv *Env, jobject Obj, jint num)
{
jobject Ctx = (*Env)->GetObjectField(Env, Obj, L.ctx);
a_pid_fuzzy *ctx = (a_pid_fuzzy *)(*Env)->GetDirectBufferAddress(Env, Ctx);
if (num > (jint)ctx->nfuzz)
{
jobject Fuzzy = (*Env)->CallObjectMethod(Env, Obj, L.New, (jint)A_PID_FUZZY_NFUZZ((unsigned int)num));
a_pid_fuzzy_set_nfuzz(ctx, (*Env)->GetDirectBufferAddress(Env, Fuzzy), (a_size)num);
(*Env)->SetObjectField(Env, Obj, L.fuzzy, Fuzzy);
}
return Obj;
}
JNIEXPORT jobject JNICALL Java_liba_pid_1fuzzy_kpid(JNIEnv *Env, jobject Obj, jdouble kp, jdouble ki, jdouble kd)
{
jobject Ctx = (*Env)->GetObjectField(Env, Obj, L.ctx);
a_pid_fuzzy *ctx = (a_pid_fuzzy *)(*Env)->GetDirectBufferAddress(Env, Ctx);
a_pid_fuzzy_kpid(ctx, kp, ki, kd);
a_pid_fuzzy_set_kpid(ctx, kp, ki, kd);
return Obj;
}

View File

@ -199,19 +199,19 @@ JNIEXPORT jdouble JNICALL Java_liba_pid_1neuro_ec(JNIEnv *Env, jobject Obj)
return ctx->ec;
}
JNIEXPORT jobject JNICALL Java_liba_pid_1neuro_kpid(JNIEnv *Env, jobject Obj, jdouble k, jdouble kp, jdouble ki, jdouble kd)
JNIEXPORT jobject JNICALL Java_liba_pid_1neuro_set_1kpid(JNIEnv *Env, jobject Obj, jdouble k, jdouble kp, jdouble ki, jdouble kd)
{
jobject Ctx = (*Env)->GetObjectField(Env, Obj, L.ctx);
a_pid_neuro *ctx = (a_pid_neuro *)(*Env)->GetDirectBufferAddress(Env, Ctx);
a_pid_neuro_kpid(ctx, k, kp, ki, kd);
a_pid_neuro_set_kpid(ctx, k, kp, ki, kd);
return Obj;
}
JNIEXPORT jobject JNICALL Java_liba_pid_1neuro_wpid(JNIEnv *Env, jobject Obj, jdouble wp, jdouble wi, jdouble wd)
JNIEXPORT jobject JNICALL Java_liba_pid_1neuro_set_1wpid(JNIEnv *Env, jobject Obj, jdouble wp, jdouble wi, jdouble wd)
{
jobject Ctx = (*Env)->GetObjectField(Env, Obj, L.ctx);
a_pid_neuro *ctx = (a_pid_neuro *)(*Env)->GetDirectBufferAddress(Env, Ctx);
a_pid_neuro_wpid(ctx, wp, wi, wd);
a_pid_neuro_set_wpid(ctx, wp, wi, wd);
return Obj;
}

View File

@ -3,7 +3,7 @@ import liba.pid;
class _pid {
public static void main(String[] args) {
pid obj = new pid();
obj.kpid(10, 0.1, 1);
obj.set_kpid(10, 0.1, 1);
System.out.print(obj.zero().pos(1, 0) + " ");
System.out.print(obj.zero().inc(1, 0) + " ");
System.out.println(obj.zero().run(1, 0));

View File

@ -77,8 +77,8 @@ class _pid_fuzzy {
{ NL, NM, NM, NM, NS, NS, NL },
};
pid_fuzzy obj = new pid_fuzzy();
obj.rule(me, mec, mkp, mki, mkd).nfuzz(2);
obj.kpid(10, 0.1, 1);
obj.set_rule(me, mec, mkp, mki, mkd).nfuzz(2);
obj.set_kpid(10, 0.1, 1);
System.out.print(obj.zero().pos(1, 0) + " ");
System.out.print(obj.zero().inc(1, 0) + " ");
System.out.println(obj.run(1, 0));

View File

@ -3,7 +3,7 @@ import liba.pid_neuro;
class _pid_neuro {
public static void main(String[] args) {
pid_neuro obj = new pid_neuro();
obj.kpid(10, 1, 0.1, 1).wpid(1, 0, 0).zero();
obj.set_kpid(10, 1, 0.1, 1).set_wpid(1, 0, 0).zero();
System.out.print(obj.inc(1, 0) + " ");
System.out.println(obj.run(1, 0));
obj.k(obj.k());

10
javascript/liba.d.ts vendored
View File

@ -415,7 +415,7 @@ declare namespace liba {
* @param ki integral constant
* @param kd derivative constant
*/
kpid(kp: number, ki: number, kd: number): pid;
set_kpid(kp: number, ki: number, kd: number): pid;
/**
* calculate for PID controller
* @param set setpoint value
@ -492,14 +492,14 @@ declare namespace liba {
* @param mki Ki's rule base table which must be a square matrix
* @param mkd Kd's rule base table which must be a square matrix
*/
rule(me: number[][], mec: number[][], mkp: number[][], mki: number[][], mkd: number[][]): pid_fuzzy;
set_rule(me: number[][], mec: number[][], mkp: number[][], mki: number[][], mkd: number[][]): pid_fuzzy;
/**
* set proportional integral derivative constant for fuzzy PID controller
* @param kp proportional learning constant
* @param ki integral learning constant
* @param kd derivative learning constant
*/
kpid(kp: number, ki: number, kd: number): pid_fuzzy;
set_kpid(kp: number, ki: number, kd: number): pid_fuzzy;
/**
* calculate for fuzzy PID controller
* @param set setpoint value
@ -579,14 +579,14 @@ declare namespace liba {
* @param ki integral learning constant
* @param kd derivative learning constant
*/
kpid(k: number, kp: number, ki: number, kd: number): pid_neuro;
set_kpid(k: number, kp: number, ki: number, kd: number): pid_neuro;
/**
* set proportional integral derivative weight for single neuron PID controller
* @param wp proportional weight
* @param wi integral weight
* @param wd derivative weight
*/
wpid(wp: number, wi: number, wd: number): pid_neuro;
set_wpid(wp: number, wi: number, wd: number): pid_neuro;
/**
* calculate for single neuron PID controller
* @param set setpoint value

View File

@ -367,9 +367,9 @@ unsigned int const mf::PI = A_MF_PI;
struct pid: public a_pid
{
A_INLINE pid *kpid(a_float kp_, a_float ki_, a_float kd_)
A_INLINE pid *set_kpid(a_float kp_, a_float ki_, a_float kd_)
{
a_pid::kpid(kp_, ki_, kd_);
a_pid::set_kpid(kp_, ki_, kd_);
return this;
}
A_INLINE a_float run(a_float set, a_float fdb_)
@ -424,11 +424,11 @@ struct pid: public a_pid
struct pid_fuzzy: public a_pid_fuzzy
{
A_INLINE pid_fuzzy *rule(emscripten::val const &me_,
emscripten::val const &mec_,
emscripten::val const &mkp_,
emscripten::val const &mki_,
emscripten::val const &mkd_)
A_INLINE pid_fuzzy *set_rule(emscripten::val const &me_,
emscripten::val const &mec_,
emscripten::val const &mkp_,
emscripten::val const &mki_,
emscripten::val const &mkd_)
{
union
{
@ -465,13 +465,13 @@ struct pid_fuzzy: public a_pid_fuzzy
}
A_INLINE pid_fuzzy *set_nfuzz(unsigned int num)
{
void *ptr = a_alloc(a_pid_fuzzy_nfuzz(this), A_PID_FUZZY_NFUZZ(num));
a_pid_fuzzy_set_nfuzz(this, ptr, num);
void *ptr = a_alloc(a_pid_fuzzy::bfuzz(), A_PID_FUZZY_BFUZZ(num));
a_pid_fuzzy::set_bfuzz(ptr, num);
return this;
}
A_INLINE pid_fuzzy *kpid(a_float kp_, a_float ki_, a_float kd_)
A_INLINE pid_fuzzy *set_kpid(a_float kp_, a_float ki_, a_float kd_)
{
a_pid_fuzzy::kpid(kp_, ki_, kd_);
a_pid_fuzzy::set_kpid(kp_, ki_, kd_);
return this;
}
A_INLINE a_float run(a_float set, a_float fdb)
@ -519,7 +519,7 @@ struct pid_fuzzy: public a_pid_fuzzy
a_float const *p;
a_float *o;
} u;
a_alloc(a_pid_fuzzy_nfuzz(this), 0);
a_alloc(a_pid_fuzzy_bfuzz(this), 0);
u.p = me;
a_alloc(u.o, 0);
u.p = mec;
@ -571,14 +571,14 @@ unsigned int const pid_fuzzy::EQU = A_PID_FUZZY_EQU;
struct pid_neuro: public a_pid_neuro
{
A_INLINE pid_neuro *kpid(a_float k_, a_float kp, a_float ki, a_float kd)
A_INLINE pid_neuro *set_kpid(a_float k_, a_float kp, a_float ki, a_float kd)
{
a_pid_neuro::kpid(k_, kp, ki, kd);
a_pid_neuro::set_kpid(k_, kp, ki, kd);
return this;
}
A_INLINE pid_neuro *wpid(a_float wp_, a_float wi_, a_float wd_)
A_INLINE pid_neuro *set_wpid(a_float wp_, a_float wi_, a_float wd_)
{
a_pid_neuro::wpid(wp_, wi_, wd_);
a_pid_neuro::set_wpid(wp_, wi_, wd_);
return this;
}
A_INLINE a_float run(a_float set, a_float fdb)
@ -982,7 +982,7 @@ EMSCRIPTEN_BINDINGS(liba) // NOLINT
.property("output", &lpf::output_r);
emscripten::class_<pid>("pid")
.constructor<>()
.function("kpid", &pid::kpid, emscripten::allow_raw_pointers())
.function("set_kpid", &pid::set_kpid, emscripten::allow_raw_pointers())
.function("zero", &pid::zero, emscripten::allow_raw_pointers())
.function("run", &pid::run)
.function("pos", &pid::pos)
@ -1002,8 +1002,8 @@ EMSCRIPTEN_BINDINGS(liba) // NOLINT
.constructor<>()
.function("set_opr", &pid_fuzzy::set_opr, emscripten::allow_raw_pointers())
.function("set_nfuzz", &pid_fuzzy::set_nfuzz, emscripten::allow_raw_pointers())
.function("rule", &pid_fuzzy::rule, emscripten::allow_raw_pointers())
.function("kpid", &pid_fuzzy::kpid, emscripten::allow_raw_pointers())
.function("set_rule", &pid_fuzzy::set_rule, emscripten::allow_raw_pointers())
.function("set_kpid", &pid_fuzzy::set_kpid, emscripten::allow_raw_pointers())
.function("zero", &pid_fuzzy::zero, emscripten::allow_raw_pointers())
.function("run", &pid_fuzzy::run)
.function("pos", &pid_fuzzy::pos)
@ -1030,8 +1030,8 @@ EMSCRIPTEN_BINDINGS(liba) // NOLINT
.property("nfuzz", &pid_fuzzy::nfuzz_r, &pid_fuzzy::set_nfuzz);
emscripten::class_<pid_neuro>("pid_neuro")
.constructor<>()
.function("kpid", &pid_neuro::kpid, emscripten::allow_raw_pointers())
.function("wpid", &pid_neuro::wpid, emscripten::allow_raw_pointers())
.function("set_kpid", &pid_neuro::set_kpid, emscripten::allow_raw_pointers())
.function("set_wpid", &pid_neuro::set_wpid, emscripten::allow_raw_pointers())
.function("zero", &pid_neuro::zero, emscripten::allow_raw_pointers())
.function("run", &pid_neuro::run)
.function("inc", &pid_neuro::inc)

View File

@ -14,7 +14,7 @@ function do_leak_check() {
}
}
var ctx = new liba.pid();
ctx.kpid(10, 0.1, 1);
ctx.set_kpid(10, 0.1, 1);
console.log(ctx.zero().run(1, 0));
console.log(ctx.zero().pos(1, 0));
console.log(ctx.zero().inc(1, 0));

View File

@ -87,8 +87,8 @@ var mkd = [
[NL, NM, NM, NM, NS, NS, NL],
];
var ctx = new liba.pid_fuzzy();
ctx.rule(me, mec, mkp, mki, mkd).set_nfuzz(2);
ctx.kpid(10, 0.1, 1).set_opr(liba.pid_fuzzy.EQU);
ctx.set_rule(me, mec, mkp, mki, mkd).set_nfuzz(2);
ctx.set_kpid(10, 0.1, 1).set_opr(liba.pid_fuzzy.EQU);
console.log(ctx.zero().run(10, 0));
console.log(ctx.zero().pos(10, 0));
console.log(ctx.zero().inc(10, 0));

View File

@ -14,7 +14,7 @@ function do_leak_check() {
}
}
var ctx = new liba.pid_neuro();
ctx.wpid(1, 0, 0).kpid(10, 1, 0.1, 1);
ctx.set_wpid(1, 0, 0).set_kpid(10, 1, 0.1, 1);
console.log(ctx.zero().run(10, 0));
console.log(ctx.zero().inc(10, 0));
assert("ctx.k != undefined");

View File

@ -838,13 +838,13 @@ function pid:zero() end
---@param ki number
---@param kd number
---@return a.pid
function liba.pid.kpid(ctx, kp, ki, kd) end
function liba.pid.set_kpid(ctx, kp, ki, kd) end
---@param kp number
---@param ki number
---@param kd number
---@return a.pid
function pid:kpid(kp, ki, kd) end
function pid:set_kpid(kp, ki, kd) end
---@param ctx a.pid
---@param set number
@ -918,23 +918,6 @@ function liba.pid_fuzzy.zero(ctx) end
---@return a.pid_fuzzy
function pid_fuzzy:zero() end
---@param ctx a.pid_fuzzy
---@param me table
---@param mec table
---@param mkp table
---@param mki table
---@param mkd table
---@return a.pid_fuzzy
function liba.pid_fuzzy.rule(ctx, me, mec, mkp, mki, mkd) end
---@param me table
---@param mec table
---@param mkp table
---@param mki table
---@param mkd table
---@return a.pid_fuzzy
function pid_fuzzy:rule(me, mec, mkp, mki, mkd) end
liba.pid_fuzzy.CAP = 1
liba.pid_fuzzy.CAP_ALGEBRA = 2
liba.pid_fuzzy.CAP_BOUNDED = 3
@ -960,18 +943,35 @@ function liba.pid_fuzzy.set_nfuzz(ctx, nfuzz) end
---@return a.pid_fuzzy
function pid_fuzzy:set_nfuzz(nfuzz) end
---@param ctx a.pid_fuzzy
---@param me table
---@param mec table
---@param mkp table
---@param mki table
---@param mkd table
---@return a.pid_fuzzy
function liba.pid_fuzzy.set_rule(ctx, me, mec, mkp, mki, mkd) end
---@param me table
---@param mec table
---@param mkp table
---@param mki table
---@param mkd table
---@return a.pid_fuzzy
function pid_fuzzy:set_rule(me, mec, mkp, mki, mkd) end
---@param ctx a.pid_fuzzy
---@param kp number
---@param ki number
---@param kd number
---@return a.pid_fuzzy
function liba.pid_fuzzy.kpid(ctx, kp, ki, kd) end
function liba.pid_fuzzy.set_kpid(ctx, kp, ki, kd) end
---@param kp number
---@param ki number
---@param kd number
---@return a.pid_fuzzy
function pid_fuzzy:kpid(kp, ki, kd) end
function pid_fuzzy:set_kpid(kp, ki, kd) end
---@param ctx a.pid_fuzzy
---@param set number
@ -1051,27 +1051,27 @@ function pid_neuro:zero() end
---@param ki number
---@param kd number
---@return a.pid_neuro
function liba.pid_neuro.kpid(ctx, k, kp, ki, kd) end
function liba.pid_neuro.set_kpid(ctx, k, kp, ki, kd) end
---@param k number
---@param kp number
---@param ki number
---@param kd number
---@return a.pid_neuro
function pid_neuro:kpid(k, kp, ki, kd) end
function pid_neuro:set_kpid(k, kp, ki, kd) end
---@param ctx a.pid_neuro
---@param wp number
---@param wi number
---@param wd number
---@return a.pid_neuro
function liba.pid_neuro.wpid(ctx, wp, wi, wd) end
function liba.pid_neuro.set_wpid(ctx, wp, wi, wd) end
---@param wp number
---@param wi number
---@param wd number
---@return a.pid_neuro
function pid_neuro:wpid(wp, wi, wd) end
function pid_neuro:set_wpid(wp, wi, wd) end
---@param ctx a.pid_neuro
---@param set number

View File

@ -55,9 +55,9 @@ int liba_pid_init(lua_State *L)
@tparam number ki integral constant
@tparam number kd derivative constant
@treturn a.pid PID controller userdata
@function kpid
@function set_kpid
*/
int liba_pid_kpid(lua_State *L)
int liba_pid_set_kpid(lua_State *L)
{
a_pid *const ctx = (a_pid *)lua_touserdata(L, 1);
if (ctx)
@ -65,7 +65,7 @@ int liba_pid_kpid(lua_State *L)
a_float const kp = (a_float)luaL_checknumber(L, 2);
a_float const ki = (a_float)luaL_checknumber(L, 3);
a_float const kd = (a_float)luaL_checknumber(L, 4);
a_pid_kpid(ctx, kp, ki, kd);
a_pid_set_kpid(ctx, kp, ki, kd);
lua_pushvalue(L, 1);
return 1;
}
@ -264,7 +264,7 @@ int luaopen_liba_pid(lua_State *L)
static lua_fun const funcs[] = {
{"new", liba_pid_new},
{"init", liba_pid_init},
{"kpid", liba_pid_kpid},
{"set_kpid", liba_pid_set_kpid},
{"run", liba_pid_run},
{"pos", liba_pid_pos},
{"inc", liba_pid_inc},

View File

@ -47,9 +47,9 @@ int liba_pid_init(lua_State *L);
@tparam number ki integral constant
@tparam number kd derivative constant
@treturn a.pid PID controller userdata
@function kpid
@function set_kpid
*/
int liba_pid_kpid(lua_State *L);
int liba_pid_set_kpid(lua_State *L);
/***
calculate for PID controller

View File

@ -21,7 +21,7 @@ int liba_pid_fuzzy_die(lua_State *L)
lua_alloc(L, ctx->mkp, 0);
lua_alloc(L, ctx->mki, 0);
lua_alloc(L, ctx->mkd, 0);
lua_alloc(L, a_pid_fuzzy_nfuzz(ctx), 0);
lua_alloc(L, a_pid_fuzzy_bfuzz(ctx), 0);
ctx->me = 0;
ctx->mec = 0;
ctx->mkp = 0;
@ -93,7 +93,7 @@ int liba_pid_fuzzy_init(lua_State *L)
@treturn a.pid_fuzzy fuzzy PID controller userdata
@function set_opr
*/
int liba_pid_fuzzy_opr(lua_State *L)
int liba_pid_fuzzy_set_opr(lua_State *L)
{
a_pid_fuzzy *const ctx = (a_pid_fuzzy *)lua_touserdata(L, 1);
if (ctx)
@ -112,14 +112,14 @@ int liba_pid_fuzzy_opr(lua_State *L)
@treturn a.pid_fuzzy fuzzy PID controller userdata
@function set_nfuzz
*/
int liba_pid_fuzzy_nfuzz(lua_State *L)
int liba_pid_fuzzy_set_nfuzz(lua_State *L)
{
a_pid_fuzzy *const ctx = (a_pid_fuzzy *)lua_touserdata(L, 1);
if (ctx)
{
unsigned int const num = (unsigned int)luaL_checkinteger(L, 2);
void *ptr = lua_alloc(L, a_pid_fuzzy_nfuzz(ctx), A_PID_FUZZY_NFUZZ(num));
a_pid_fuzzy_set_nfuzz(ctx, ptr, num);
void *ptr = lua_alloc(L, a_pid_fuzzy_bfuzz(ctx), A_PID_FUZZY_BFUZZ(num));
a_pid_fuzzy_set_bfuzz(ctx, ptr, num);
lua_pushvalue(L, 1);
return 1;
}
@ -135,9 +135,9 @@ int liba_pid_fuzzy_nfuzz(lua_State *L)
@tparam table mki points to Ki's rule base table which must be a square matrix
@tparam table mkd points to Kd's rule base table which must be a square matrix
@treturn a.pid_fuzzy fuzzy PID controller userdata
@function rule
@function set_rule
*/
int liba_pid_fuzzy_rule(lua_State *L)
int liba_pid_fuzzy_set_rule(lua_State *L)
{
a_pid_fuzzy *const ctx = (a_pid_fuzzy *)lua_touserdata(L, 1);
if (ctx)
@ -148,7 +148,7 @@ int liba_pid_fuzzy_rule(lua_State *L)
a_float const *const mkp = lua_table_num_get(L, 4, ctx->mkp, 0);
a_float const *const mki = lua_table_num_get(L, 5, ctx->mki, 0);
a_float const *const mkd = lua_table_num_get(L, 6, ctx->mkd, 0);
a_pid_fuzzy_rule(ctx, num, me, mec, mkp, mki, mkd);
a_pid_fuzzy_set_rule(ctx, num, me, mec, mkp, mki, mkd);
lua_pushvalue(L, 1);
return 1;
}
@ -162,9 +162,9 @@ int liba_pid_fuzzy_rule(lua_State *L)
@tparam number ki integral constant
@tparam number kd derivative constant
@treturn a.pid_fuzzy fuzzy PID controller userdata
@function kpid
@function set_kpid
*/
int liba_pid_fuzzy_kpid(lua_State *L)
int liba_pid_fuzzy_set_kpid(lua_State *L)
{
a_pid_fuzzy *const ctx = (a_pid_fuzzy *)lua_touserdata(L, 1);
if (ctx)
@ -172,7 +172,7 @@ int liba_pid_fuzzy_kpid(lua_State *L)
a_float const kp = (a_float)luaL_checknumber(L, 2);
a_float const ki = (a_float)luaL_checknumber(L, 3);
a_float const kd = (a_float)luaL_checknumber(L, 4);
a_pid_fuzzy_kpid(ctx, kp, ki, kd);
a_pid_fuzzy_set_kpid(ctx, kp, ki, kd);
lua_pushvalue(L, 1);
return 1;
}
@ -288,8 +288,8 @@ static int liba_pid_fuzzy_set(lua_State *L)
case 0x98AE2495: // nfuzz
{
unsigned int const num = (unsigned int)luaL_checkinteger(L, 3);
void *ptr = lua_alloc(L, a_pid_fuzzy_nfuzz(ctx), A_PID_FUZZY_NFUZZ(num));
a_pid_fuzzy_set_nfuzz(ctx, ptr, num);
void *ptr = lua_alloc(L, a_pid_fuzzy_bfuzz(ctx), A_PID_FUZZY_BFUZZ(num));
a_pid_fuzzy_set_bfuzz(ctx, ptr, num);
break;
}
case 0xE8859EEB: // __name
@ -406,10 +406,10 @@ int luaopen_liba_pid_fuzzy(lua_State *L)
static lua_fun const funcs[] = {
{"new", liba_pid_fuzzy_new},
{"init", liba_pid_fuzzy_init},
{"set_opr", liba_pid_fuzzy_opr},
{"set_nfuzz", liba_pid_fuzzy_nfuzz},
{"rule", liba_pid_fuzzy_rule},
{"kpid", liba_pid_fuzzy_kpid},
{"set_opr", liba_pid_fuzzy_set_opr},
{"set_nfuzz", liba_pid_fuzzy_set_nfuzz},
{"set_rule", liba_pid_fuzzy_set_rule},
{"set_kpid", liba_pid_fuzzy_set_kpid},
{"run", liba_pid_fuzzy_run},
{"pos", liba_pid_fuzzy_pos},
{"inc", liba_pid_fuzzy_inc},

View File

@ -53,9 +53,9 @@ int liba_pid_fuzzy_init(lua_State *L);
set fuzzy relational operator for fuzzy PID controller
@tparam int opr enumeration for fuzzy PID controller operator
@treturn a.pid_fuzzy fuzzy PID controller userdata
@function opr
@function set_opr
*/
int liba_pid_fuzzy_opr(lua_State *L);
int liba_pid_fuzzy_set_opr(lua_State *L);
/***
set memory block for fuzzy PID controller
@ -63,7 +63,7 @@ int liba_pid_fuzzy_opr(lua_State *L);
@treturn a.pid_fuzzy fuzzy PID controller userdata
@function set_nfuzz
*/
int liba_pid_fuzzy_nfuzz(lua_State *L);
int liba_pid_fuzzy_set_nfuzz(lua_State *L);
/***
set rule base for fuzzy PID controller
@ -73,9 +73,9 @@ int liba_pid_fuzzy_nfuzz(lua_State *L);
@tparam table mki points to Ki's rule base table which must be a square matrix
@tparam table mkd points to Kd's rule base table which must be a square matrix
@treturn a.pid_fuzzy fuzzy PID controller userdata
@function rule
@function set_rule
*/
int liba_pid_fuzzy_rule(lua_State *L);
int liba_pid_fuzzy_set_rule(lua_State *L);
/***
set proportional integral derivative constant for fuzzy PID controller
@ -83,9 +83,9 @@ int liba_pid_fuzzy_rule(lua_State *L);
@tparam number ki integral constant
@tparam number kd derivative constant
@treturn a.pid_fuzzy fuzzy PID controller userdata
@function kpid
@function set_kpid
*/
int liba_pid_fuzzy_kpid(lua_State *L);
int liba_pid_fuzzy_set_kpid(lua_State *L);
/***
calculate for fuzzy PID controller

View File

@ -63,9 +63,9 @@ int liba_pid_neuro_init(lua_State *L)
@tparam number ki integral learning constant
@tparam number kd derivative learning constant
@treturn a.pid_neuro single neuron PID controller userdata
@function kpid
@function set_kpid
*/
int liba_pid_neuro_kpid(lua_State *L)
int liba_pid_neuro_set_kpid(lua_State *L)
{
a_pid_neuro *const ctx = (a_pid_neuro *)lua_touserdata(L, 1);
if (ctx)
@ -74,7 +74,7 @@ int liba_pid_neuro_kpid(lua_State *L)
a_float const kp = (a_float)luaL_checknumber(L, 3);
a_float const ki = (a_float)luaL_checknumber(L, 4);
a_float const kd = (a_float)luaL_checknumber(L, 5);
a_pid_neuro_kpid(ctx, k, kp, ki, kd);
a_pid_neuro_set_kpid(ctx, k, kp, ki, kd);
lua_pushvalue(L, 1);
return 1;
}
@ -88,9 +88,9 @@ int liba_pid_neuro_kpid(lua_State *L)
@tparam number wi integral weight
@tparam number wd derivative weight
@treturn a.pid_neuro single neuron PID controller userdata
@function wpid
@function set_wpid
*/
int liba_pid_neuro_wpid(lua_State *L)
int liba_pid_neuro_set_wpid(lua_State *L)
{
a_pid_neuro *const ctx = (a_pid_neuro *)lua_touserdata(L, 1);
if (ctx)
@ -98,7 +98,7 @@ int liba_pid_neuro_wpid(lua_State *L)
a_float const wp = (a_float)luaL_checknumber(L, 2);
a_float const wi = (a_float)luaL_checknumber(L, 3);
a_float const wd = (a_float)luaL_checknumber(L, 4);
a_pid_neuro_wpid(ctx, wp, wi, wd);
a_pid_neuro_set_wpid(ctx, wp, wi, wd);
lua_pushvalue(L, 1);
return 1;
}
@ -292,8 +292,8 @@ int luaopen_liba_pid_neuro(lua_State *L)
static lua_fun const funcs[] = {
{"new", liba_pid_neuro_new},
{"init", liba_pid_neuro_init},
{"kpid", liba_pid_neuro_kpid},
{"wpid", liba_pid_neuro_wpid},
{"set_kpid", liba_pid_neuro_set_kpid},
{"set_wpid", liba_pid_neuro_set_wpid},
{"run", liba_pid_neuro_run},
{"inc", liba_pid_neuro_inc},
{"zero", liba_pid_neuro_zero},

View File

@ -50,9 +50,9 @@ int liba_pid_neuro_init(lua_State *L);
@tparam number ki integral learning constant
@tparam number kd derivative learning constant
@treturn a.pid_neuro single neuron PID controller userdata
@function kpid
@function set_kpid
*/
int liba_pid_neuro_kpid(lua_State *L);
int liba_pid_neuro_set_kpid(lua_State *L);
/***
set proportional integral derivative weight for single neuron PID controller
@ -60,9 +60,9 @@ int liba_pid_neuro_kpid(lua_State *L);
@tparam number wi integral weight
@tparam number wd derivative weight
@treturn a.pid_neuro single neuron PID controller userdata
@function wpid
@function set_wpid
*/
int liba_pid_neuro_wpid(lua_State *L);
int liba_pid_neuro_set_wpid(lua_State *L);
/***
calculate for single neuron PID controller

View File

@ -8,12 +8,12 @@ test.dir(getmetatable(a.pid))
local ctx = a.pid.new()
assert(ctx)
test.dir(getmetatable(ctx))
assert(type(a.pid.kpid(ctx, 10, 0.1, 1)) == "userdata")
assert(type(a.pid.set_kpid(ctx, 10, 0.1, 1)) == "userdata")
assert(type(a.pid.run(ctx, 1, 0)) == "number")
assert(type(a.pid.pos(ctx, 1, 0)) == "number")
assert(type(a.pid.inc(ctx, 1, 0)) == "number")
assert(type(a.pid.zero(ctx)) == "userdata")
ctx:kpid(3, 2, 1):zero()
ctx:set_kpid(3, 2, 1):zero()
assert(type(ctx:run(1, 0)) == "number")
assert(type(ctx:pos(1, 0)) == "number")
assert(type(ctx:inc(1, 0)) == "number")

View File

@ -91,14 +91,14 @@ test.dir(getmetatable(a.pid_fuzzy))
local ctx = a.pid_fuzzy.new()
assert(ctx)
test.dir(getmetatable(ctx))
assert(type(a.pid_fuzzy.rule(ctx, me, mec, mkp, mki, mkd)) == "userdata")
assert(type(a.pid_fuzzy.kpid(ctx, 10, 0.1, 1)) == "userdata")
assert(type(a.pid_fuzzy.set_rule(ctx, me, mec, mkp, mki, mkd)) == "userdata")
assert(type(a.pid_fuzzy.set_kpid(ctx, 10, 0.1, 1)) == "userdata")
assert(type(a.pid_fuzzy.set_nfuzz(ctx, 2)) == "userdata")
assert(type(a.pid_fuzzy.run(ctx, 1, 0)) == "number")
assert(type(a.pid_fuzzy.pos(ctx, 1, 0)) == "number")
assert(type(a.pid_fuzzy.inc(ctx, 1, 0)) == "number")
assert(type(a.pid_fuzzy.zero(ctx)) == "userdata")
ctx:rule(me, mec, mkp, mki, mkd):kpid(3, 2, 1):set_nfuzz(2):set_opr(a.pid_fuzzy.EQU):zero()
ctx:set_rule(me, mec, mkp, mki, mkd):set_kpid(3, 2, 1):set_nfuzz(2):set_opr(a.pid_fuzzy.EQU):zero()
assert(type(ctx:run(1, 0)) == "number")
assert(type(ctx:pos(1, 0)) == "number")
assert(type(ctx:inc(1, 0)) == "number")

View File

@ -7,12 +7,12 @@ test.dir(getmetatable(a.pid_neuro))
local ctx = a.pid_neuro.new()
assert(ctx)
test.dir(getmetatable(ctx))
assert(type(a.pid_neuro.kpid(ctx, 4, 3, 2, 1)) == "userdata")
assert(type(a.pid_neuro.wpid(ctx, 3, 2, 1)) == "userdata")
assert(type(a.pid_neuro.set_kpid(ctx, 4, 3, 2, 1)) == "userdata")
assert(type(a.pid_neuro.set_wpid(ctx, 3, 2, 1)) == "userdata")
assert(type(a.pid_neuro.run(ctx, 1, 0)) == "number")
assert(type(a.pid_neuro.inc(ctx, 1, 0)) == "number")
assert(type(a.pid_neuro.zero(ctx)) == "userdata")
ctx:kpid(4, 3, 2, 1):wpid(3, 2, 1):zero()
ctx:set_kpid(4, 3, 2, 1):set_wpid(3, 2, 1):zero()
assert(type(ctx:run(1, 0)) == "number")
assert(type(ctx:inc(1, 0)) == "number")
assert(type(ctx.k) == "number")

View File

@ -274,7 +274,7 @@ class mf:
class pid:
def __init__(self) -> None: ...
def kpid(self, kp: float, ki: float, kd: float) -> pid: ...
def set_kpid(self, kp: float, ki: float, kd: float) -> pid: ...
def run(self, set: float, fdb: float) -> float: ...
def pos(self, set: float, fdb: float) -> float: ...
def inc(self, set: float, fdb: float) -> float: ...
@ -327,7 +327,7 @@ class pid_fuzzy:
def __init__(self) -> None: ...
def set_opr(self, opr: int) -> pid_fuzzy: ...
def set_nfuzz(self, num: int) -> pid_fuzzy: ...
def rule(
def set_rule(
self,
me: Iterable[Iterable[float]],
mec: Iterable[Iterable[float]],
@ -335,7 +335,7 @@ class pid_fuzzy:
mki: Iterable[Iterable[float]],
mkd: Iterable[Iterable[float]],
) -> pid_fuzzy: ...
def kpid(self, kp: float, ki: float, kd: float) -> pid_fuzzy: ...
def set_kpid(self, kp: float, ki: float, kd: float) -> pid_fuzzy: ...
def run(self, set: float, fdb: float) -> float: ...
def pos(self, set: float, fdb: float) -> float: ...
def inc(self, set: float, fdb: float) -> float: ...
@ -395,8 +395,8 @@ class pid_fuzzy:
class pid_neuro:
def __init__(self) -> None: ...
def kpid(self, k: float, kp: float, ki: float, kd: float) -> pid_neuro: ...
def wpid(self, wp: float, wi: float, wd: float) -> pid_neuro: ...
def set_kpid(self, k: float, kp: float, ki: float, kd: float) -> pid_neuro: ...
def set_wpid(self, wp: float, wi: float, wd: float) -> pid_neuro: ...
def run(self, set: float, fdb: float) -> float: ...
def inc(self, set: float, fdb: float) -> float: ...
def zero(self) -> pid_neuro: ...

View File

@ -14,7 +14,7 @@ cdef extern from "a/pid.h":
a_float fdb
a_float err
void a_pid_init(a_pid *ctx)
void a_pid_kpid(a_pid *ctx, a_float kp, a_float ki, a_float kd)
void a_pid_set_kpid(a_pid *ctx, a_float kp, a_float ki, a_float kd)
a_float a_pid_run(a_pid *ctx, a_float set, a_float fdb)
a_float a_pid_pos(a_pid *ctx, a_float set, a_float fdb)
a_float a_pid_inc(a_pid *ctx, a_float set, a_float fdb)

View File

@ -18,14 +18,14 @@ cdef extern from "a/pid_fuzzy.h":
a_float (*opr)(a_float, a_float)
unsigned int nrule
unsigned int nfuzz
void a_pid_fuzzy_init(a_pid_fuzzy *ctx)
a_float (*a_pid_fuzzy_opr(unsigned int opr))(a_float, a_float)
void a_pid_fuzzy_set_opr(a_pid_fuzzy *ctx, unsigned int opr)
void a_pid_fuzzy_init(a_pid_fuzzy *ctx)
void a_pid_fuzzy_rule(a_pid_fuzzy *ctx, unsigned int nrule, const a_float *mec, const a_float *mec, const a_float *mkp, const a_float *mki, const a_float *mkd)
void *a_pid_fuzzy_nfuzz(a_pid_fuzzy *ctx)
void a_pid_fuzzy_set_nfuzz(a_pid_fuzzy *ctx, void *ptr, a_size num)
a_size A_PID_FUZZY_NFUZZ(unsigned int num)
void a_pid_fuzzy_kpid(a_pid_fuzzy *ctx, a_float kp, a_float ki, a_float kd)
void *a_pid_fuzzy_bfuzz(a_pid_fuzzy *ctx)
void a_pid_fuzzy_set_bfuzz(a_pid_fuzzy *ctx, void *ptr, a_size num)
a_size A_PID_FUZZY_BFUZZ(unsigned int num)
void a_pid_fuzzy_set_rule(a_pid_fuzzy *ctx, unsigned int nrule, const a_float *mec, const a_float *mec, const a_float *mkp, const a_float *mki, const a_float *mkd)
void a_pid_fuzzy_set_kpid(a_pid_fuzzy *ctx, a_float kp, a_float ki, a_float kd)
a_float a_pid_fuzzy_run(a_pid_fuzzy *ctx, a_float set, a_float fdb)
a_float a_pid_fuzzy_pos(a_pid_fuzzy *ctx, a_float set, a_float fdb)
a_float a_pid_fuzzy_inc(a_pid_fuzzy *ctx, a_float set, a_float fdb)

View File

@ -9,8 +9,8 @@ cdef extern from "a/pid_neuro.h":
a_float wd
a_float ec
void a_pid_neuro_init(a_pid_neuro *ctx)
void a_pid_neuro_kpid(a_pid_neuro *ctx, a_float k, a_float kp, a_float ki, a_float kd)
void a_pid_neuro_wpid(a_pid_neuro *ctx, a_float wp, a_float wi, a_float wd)
void a_pid_neuro_set_kpid(a_pid_neuro *ctx, a_float k, a_float kp, a_float ki, a_float kd)
void a_pid_neuro_set_wpid(a_pid_neuro *ctx, a_float wp, a_float wi, a_float wd)
a_float a_pid_neuro_run(a_pid_neuro *ctx, a_float set, a_float fdb)
a_float a_pid_neuro_inc(a_pid_neuro *ctx, a_float set, a_float fdb)
void a_pid_neuro_zero(a_pid_neuro *ctx)

View File

@ -613,8 +613,8 @@ cdef class pid:
self.ctx.outmax = +A_FLOAT_INF
self.ctx.outmin = -A_FLOAT_INF
a_pid_init(&self.ctx)
def kpid(self, a_float kp, a_float ki, a_float kd):
a_pid_kpid(&self.ctx, kp, ki, kd)
def set_kpid(self, a_float kp, a_float ki, a_float kd):
a_pid_set_kpid(&self.ctx, kp, ki, kd)
return self
def run(self, a_float set, a_float fdb):
return a_pid_run(&self.ctx, set, fdb)
@ -701,25 +701,25 @@ cdef class pid_fuzzy:
a_pid_fuzzy_set_opr(&self.ctx, opr)
return self
def set_nfuzz(self, unsigned int num):
cdef void *ptr = a_pid_fuzzy_nfuzz(&self.ctx)
ptr = PyMem_Realloc(ptr, A_PID_FUZZY_NFUZZ(num))
a_pid_fuzzy_set_nfuzz(&self.ctx, ptr, num)
cdef void *ptr = a_pid_fuzzy_bfuzz(&self.ctx)
ptr = PyMem_Realloc(ptr, A_PID_FUZZY_BFUZZ(num))
a_pid_fuzzy_set_bfuzz(&self.ctx, ptr, num)
return self
def rule(self, me, mec, mkp, mki, mkd):
def set_rule(self, me, mec, mkp, mki, mkd):
self.me = num_new2(me)
self.mec = num_new2(mec)
self.mkp = num_new2(mkp)
self.mki = num_new2(mki)
self.mkd = num_new2(mkd)
a_pid_fuzzy_rule(&self.ctx, <unsigned int>len(me),
a_pid_fuzzy_set_rule(&self.ctx, <unsigned int>len(me),
num_set2(self.me.data, me),
num_set2(self.mec.data, mec),
num_set2(self.mkp.data, mkp),
num_set2(self.mki.data, mki),
num_set2(self.mkd.data, mkd))
return self
def kpid(self, a_float kp, a_float ki, a_float kd):
a_pid_fuzzy_kpid(&self.ctx, kp, ki, kd)
def set_kpid(self, a_float kp, a_float ki, a_float kd):
a_pid_fuzzy_set_kpid(&self.ctx, kp, ki, kd)
return self
def run(self, a_float set, a_float fdb):
return a_pid_fuzzy_run(&self.ctx, set, fdb)
@ -728,7 +728,7 @@ cdef class pid_fuzzy:
def inc(self, a_float set, a_float fdb):
return a_pid_fuzzy_inc(&self.ctx, set, fdb)
def __dealloc__(self):
PyMem_Free(a_pid_fuzzy_nfuzz(&self.ctx))
PyMem_Free(a_pid_fuzzy_bfuzz(&self.ctx))
def zero(self):
a_pid_fuzzy_zero(&self.ctx)
return self
@ -805,11 +805,11 @@ cdef class pid_neuro:
self.ctx.wi = 0.1
self.ctx.wd = 0.1
a_pid_neuro_init(&self.ctx)
def kpid(self, a_float k, a_float kp, a_float ki, a_float kd):
a_pid_neuro_kpid(&self.ctx, k, kp, ki, kd)
def set_kpid(self, a_float k, a_float kp, a_float ki, a_float kd):
a_pid_neuro_set_kpid(&self.ctx, k, kp, ki, kd)
return self
def wpid(self, a_float wp, a_float wi, a_float wd):
a_pid_neuro_wpid(&self.ctx, wp, wi, wd)
def set_wpid(self, a_float wp, a_float wi, a_float wd):
a_pid_neuro_set_wpid(&self.ctx, wp, wi, wd)
return self
def run(self, a_float set, a_float fdb):
return a_pid_neuro_run(&self.ctx, set, fdb)

View File

@ -37,7 +37,7 @@ ki = 0.01 * Ts
kd = 0.24 / Ts
tf = liba.tf(num, den[1:])
pid = liba.pid().kpid(kp, ki, kd)
pid = liba.pid().set_kpid(kp, ki, kd)
pid.outmax = MAX
pid.outmin = MIN

View File

@ -176,7 +176,10 @@ MIN = -10
MAX = +10
tf = liba.tf(num, den[1:])
pid_fuzzy = (
liba.pid_fuzzy().rule(me, mec, mkp, mki, mkd).set_nfuzz(2).set_opr(liba.pid_fuzzy.CAP_ALGEBRA)
liba.pid_fuzzy()
.set_opr(liba.pid_fuzzy.CAP_ALGEBRA)
.set_rule(me, mec, mkp, mki, mkd)
.set_nfuzz(2)
)
pid_fuzzy.outmax = MAX
pid_fuzzy.outmin = MIN
@ -190,7 +193,7 @@ y = 0.0
tf.zero()
error1 = []
feedback1 = []
pid_fuzzy.kpid(kp, ki, kd)
pid_fuzzy.set_kpid(kp, ki, kd)
for i in data:
y = pid_fuzzy.inc(r, y)
y = tf(y)

View File

@ -51,7 +51,7 @@ y = 0.0
tf.zero()
error1 = []
feedback1 = []
pid_neuro.kpid(k, kp, ki, kd).wpid(wp, wi, wd)
pid_neuro.set_kpid(k, kp, ki, kd).set_wpid(wp, wi, wd)
for i in data:
y = pid_neuro.inc(r, y)
y = tf(y)

View File

@ -22,7 +22,7 @@ num = [6.59492796e-05, 6.54019884e-05]
den = [1.0, -1.97530991, 0.97530991]
tf = liba.tf(num, den[1:])
pid = liba.pid().kpid(kp, ki, kd)
pid = liba.pid().set_kpid(kp, ki, kd)
pid.outmax = MAX
pid.outmin = MIN

View File

@ -108,7 +108,10 @@ den = [1.0, -1.97530991, 0.97530991]
tf = liba.tf(num, den[1:])
pid_fuzzy = (
liba.pid_fuzzy().rule(me, mec, mkp, mki, mkd).set_nfuzz(2).set_opr(liba.pid_fuzzy.CAP_ALGEBRA)
liba.pid_fuzzy()
.set_opr(liba.pid_fuzzy.CAP_ALGEBRA)
.set_rule(me, mec, mkp, mki, mkd)
.set_nfuzz(2)
)
pid_fuzzy.outmax = MAX
pid_fuzzy.outmin = MIN

View File

@ -24,7 +24,7 @@ num = [6.59492796e-05, 6.54019884e-05]
den = [1.0, -1.97530991, 0.97530991]
tf = liba.tf(num, den[1:])
pid_neuro = liba.pid_neuro().kpid(k, kp, ki, kd).wpid(wp, wi, wd)
pid_neuro = liba.pid_neuro().set_kpid(k, kp, ki, kd).set_wpid(wp, wi, wd)
t = 0
x = []

View File

@ -36,7 +36,7 @@ fail:
return JS_EXCEPTION;
}
static JSValue liba_pid_kpid(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
static JSValue liba_pid_set_kpid(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
{
(void)argc;
a_pid *const self = (a_pid *)JS_GetOpaque2(ctx, this_val, liba_pid_class_id);
@ -46,7 +46,7 @@ static JSValue liba_pid_kpid(JSContext *ctx, JSValueConst this_val, int argc, JS
{
if (JS_ToFloat64(ctx, &args[i], argv[i])) { return JS_EXCEPTION; }
}
a_pid_kpid(self, (a_float)args[0], (a_float)args[1], (a_float)args[2]);
a_pid_set_kpid(self, (a_float)args[0], (a_float)args[1], (a_float)args[2]);
return JS_UNDEFINED;
}
@ -170,7 +170,7 @@ static JSCFunctionListEntry const liba_pid_proto[] = {
JS_CGETSET_MAGIC_DEF("out", liba_pid_get, NULL, self_out),
JS_CGETSET_MAGIC_DEF("fdb", liba_pid_get, NULL, self_fdb),
JS_CGETSET_MAGIC_DEF("err", liba_pid_get, NULL, self_err),
JS_CFUNC_DEF("kpid", 3, liba_pid_kpid),
JS_CFUNC_DEF("set_kpid", 3, liba_pid_set_kpid),
JS_CFUNC_DEF("zero", 0, liba_pid_zero),
JS_CFUNC_DEF("run", 2, liba_pid_run),
JS_CFUNC_DEF("pos", 2, liba_pid_pos),

View File

@ -16,7 +16,7 @@ static void liba_pid_fuzzy_finalizer(JSRuntime *rt, JSValue val)
js_free_rt(rt, ((void)(u.p = self->mkp), u.o));
js_free_rt(rt, ((void)(u.p = self->mki), u.o));
js_free_rt(rt, ((void)(u.p = self->mkd), u.o));
js_free_rt(rt, a_pid_fuzzy_nfuzz(self));
js_free_rt(rt, a_pid_fuzzy_bfuzz(self));
js_free_rt(rt, self);
}
@ -49,7 +49,7 @@ fail:
return JS_EXCEPTION;
}
static JSValue liba_pid_fuzzy_opr(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
static JSValue liba_pid_fuzzy_set_opr(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
{
(void)argc;
a_pid_fuzzy *const self = (a_pid_fuzzy *)JS_GetOpaque2(ctx, this_val, liba_pid_fuzzy_class_id);
@ -60,7 +60,7 @@ static JSValue liba_pid_fuzzy_opr(JSContext *ctx, JSValueConst this_val, int arg
return JS_UNDEFINED;
}
static JSValue liba_pid_fuzzy_rule(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
static JSValue liba_pid_fuzzy_set_rule(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
{
(void)argc;
a_pid_fuzzy *const self = (a_pid_fuzzy *)JS_GetOpaque2(ctx, this_val, liba_pid_fuzzy_class_id);
@ -155,30 +155,30 @@ fail:
return JS_UNDEFINED;
}
static int liba_pid_fuzzy_nfuzz_(JSContext *ctx, a_pid_fuzzy *self, unsigned int num)
static int liba_pid_fuzzy_set_nfuzz_(JSContext *ctx, a_pid_fuzzy *self, unsigned int num)
{
void *ptr = a_pid_fuzzy_nfuzz(self);
void *ptr = a_pid_fuzzy_bfuzz(self);
if (num > self->nfuzz)
{
ptr = js_realloc(ctx, ptr, A_PID_FUZZY_NFUZZ(num));
ptr = js_realloc(ctx, ptr, A_PID_FUZZY_BFUZZ(num));
if (!ptr) { return ~0; }
}
a_pid_fuzzy_set_nfuzz(self, ptr, num);
a_pid_fuzzy_set_bfuzz(self, ptr, num);
return 0;
}
static JSValue liba_pid_fuzzy_nfuzz(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
static JSValue liba_pid_fuzzy_set_nfuzz(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
{
(void)argc;
a_pid_fuzzy *const self = (a_pid_fuzzy *)JS_GetOpaque2(ctx, this_val, liba_pid_fuzzy_class_id);
if (!self) { return JS_EXCEPTION; }
a_u32 num;
if (JS_ToUint32(ctx, &num, argv[0])) { return JS_EXCEPTION; }
if (liba_pid_fuzzy_nfuzz_(ctx, self, num)) { return JS_EXCEPTION; }
if (liba_pid_fuzzy_set_nfuzz_(ctx, self, num)) { return JS_EXCEPTION; }
return JS_UNDEFINED;
}
static JSValue liba_pid_fuzzy_kpid(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
static JSValue liba_pid_fuzzy_set_kpid(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
{
(void)argc;
a_pid_fuzzy *const self = (a_pid_fuzzy *)JS_GetOpaque2(ctx, this_val, liba_pid_fuzzy_class_id);
@ -188,7 +188,7 @@ static JSValue liba_pid_fuzzy_kpid(JSContext *ctx, JSValueConst this_val, int ar
{
if (JS_ToFloat64(ctx, &args[i], argv[i])) { return JS_EXCEPTION; }
}
a_pid_fuzzy_kpid(self, (a_float)args[0], (a_float)args[1], (a_float)args[2]);
a_pid_fuzzy_set_kpid(self, (a_float)args[0], (a_float)args[1], (a_float)args[2]);
return JS_UNDEFINED;
}
@ -291,7 +291,7 @@ static JSValue liba_pid_fuzzy_set(JSContext *ctx, JSValueConst this_val, JSValue
if (magic == self_nfuzz)
{
if (JS_ToUint32(ctx, &u, val)) { return JS_EXCEPTION; }
if (liba_pid_fuzzy_nfuzz_(ctx, self, (unsigned int)u)) { return JS_EXCEPTION; }
if (liba_pid_fuzzy_set_nfuzz_(ctx, self, (unsigned int)u)) { return JS_EXCEPTION; }
return JS_UNDEFINED;
}
double x;
@ -325,10 +325,10 @@ static JSCFunctionListEntry const liba_pid_fuzzy_proto[] = {
JS_CGETSET_MAGIC_DEF("err", liba_pid_fuzzy_get, NULL, self_err),
JS_CGETSET_MAGIC_DEF("nrule", liba_pid_fuzzy_get, NULL, self_nrule),
JS_CGETSET_MAGIC_DEF("nfuzz", liba_pid_fuzzy_get, liba_pid_fuzzy_set, self_nfuzz),
JS_CFUNC_DEF("set_opr", 1, liba_pid_fuzzy_opr),
JS_CFUNC_DEF("set_nfuzz", 1, liba_pid_fuzzy_nfuzz),
JS_CFUNC_DEF("rule", 5, liba_pid_fuzzy_rule),
JS_CFUNC_DEF("kpid", 3, liba_pid_fuzzy_kpid),
JS_CFUNC_DEF("set_opr", 1, liba_pid_fuzzy_set_opr),
JS_CFUNC_DEF("set_nfuzz", 1, liba_pid_fuzzy_set_nfuzz),
JS_CFUNC_DEF("set_rule", 5, liba_pid_fuzzy_set_rule),
JS_CFUNC_DEF("set_kpid", 3, liba_pid_fuzzy_set_kpid),
JS_CFUNC_DEF("zero", 0, liba_pid_fuzzy_zero),
JS_CFUNC_DEF("run", 2, liba_pid_fuzzy_run),
JS_CFUNC_DEF("pos", 2, liba_pid_fuzzy_pos),

View File

@ -39,7 +39,7 @@ fail:
return JS_EXCEPTION;
}
static JSValue liba_pid_neuro_kpid(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
static JSValue liba_pid_neuro_set_kpid(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
{
(void)argc;
a_pid_neuro *const self = (a_pid_neuro *)JS_GetOpaque2(ctx, this_val, liba_pid_neuro_class_id);
@ -49,11 +49,11 @@ static JSValue liba_pid_neuro_kpid(JSContext *ctx, JSValueConst this_val, int ar
{
if (JS_ToFloat64(ctx, &args[i], argv[i])) { return JS_EXCEPTION; }
}
a_pid_neuro_kpid(self, (a_float)args[0], (a_float)args[1], (a_float)args[2], (a_float)args[3]);
a_pid_neuro_set_kpid(self, (a_float)args[0], (a_float)args[1], (a_float)args[2], (a_float)args[3]);
return JS_UNDEFINED;
}
static JSValue liba_pid_neuro_wpid(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
static JSValue liba_pid_neuro_set_wpid(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
{
(void)argc;
a_pid_neuro *const self = (a_pid_neuro *)JS_GetOpaque2(ctx, this_val, liba_pid_neuro_class_id);
@ -63,7 +63,7 @@ static JSValue liba_pid_neuro_wpid(JSContext *ctx, JSValueConst this_val, int ar
{
if (JS_ToFloat64(ctx, &args[i], argv[i])) { return JS_EXCEPTION; }
}
a_pid_neuro_wpid(self, (a_float)args[0], (a_float)args[1], (a_float)args[2]);
a_pid_neuro_set_wpid(self, (a_float)args[0], (a_float)args[1], (a_float)args[2]);
return JS_UNDEFINED;
}
@ -182,8 +182,8 @@ static JSCFunctionListEntry const liba_pid_neuro_proto[] = {
JS_CGETSET_MAGIC_DEF("fdb", liba_pid_neuro_get, NULL, self_fdb),
JS_CGETSET_MAGIC_DEF("err", liba_pid_neuro_get, NULL, self_err),
JS_CGETSET_MAGIC_DEF("ec", liba_pid_neuro_get, NULL, self_ec),
JS_CFUNC_DEF("kpid", 4, liba_pid_neuro_kpid),
JS_CFUNC_DEF("wpid", 3, liba_pid_neuro_wpid),
JS_CFUNC_DEF("set_kpid", 4, liba_pid_neuro_set_kpid),
JS_CFUNC_DEF("set_wpid", 3, liba_pid_neuro_set_wpid),
JS_CFUNC_DEF("zero", 0, liba_pid_neuro_zero),
JS_CFUNC_DEF("run", 2, liba_pid_neuro_run),
JS_CFUNC_DEF("inc", 2, liba_pid_neuro_inc),

View File

@ -5,7 +5,7 @@ function assert(expr) {
}
}
var ctx = new a.pid();
ctx.kpid(10, 0.1, 1);
ctx.set_kpid(10, 0.1, 1);
console.log(ctx.run(1, 0));
ctx.zero();
console.log(ctx.pos(1, 0));

View File

@ -78,10 +78,10 @@ var mkd = [
[NL, NM, NM, NM, NS, NS, NL],
];
var ctx = new a.pid_fuzzy();
ctx.rule(me, mec, mkp, mki, mkd);
ctx.set_rule(me, mec, mkp, mki, mkd);
ctx.set_opr(a.pid_fuzzy.EQU);
ctx.set_kpid(10, 0.1, 1);
ctx.set_nfuzz(2);
ctx.kpid(10, 0.1, 1);
console.log(ctx.run(10, 0));
ctx.zero();
console.log(ctx.pos(10, 0));

View File

@ -5,8 +5,8 @@ function assert(expr) {
}
}
var ctx = new a.pid_neuro();
ctx.kpid(10, 1, 0.1, 1);
ctx.wpid(1, 0, 0);
ctx.set_kpid(10, 1, 0.1, 1);
ctx.set_wpid(1, 0, 0);
console.log(ctx.run(10, 0));
ctx.zero();
console.log(ctx.inc(10, 0));

View File

@ -575,7 +575,7 @@ impl Default for pid {
}
extern "C" {
fn a_pid_kpid(ctx: *mut pid, kp: float, ki: float, kd: float);
fn a_pid_set_kpid(ctx: *mut pid, kp: float, ki: float, kd: float);
fn a_pid_run(ctx: *mut pid, set: float, fdb: float) -> float;
fn a_pid_pos(ctx: *mut pid, set: float, fdb: float) -> float;
fn a_pid_inc(ctx: *mut pid, set: float, fdb: float) -> float;
@ -590,8 +590,8 @@ impl pid {
}
/// set proportional integral derivative constant for PID controller
#[inline(always)]
pub fn kpid(&mut self, kp: float, ki: float, kd: float) -> &mut Self {
unsafe { a_pid_kpid(self, kp, ki, kd) };
pub fn set_kpid(&mut self, kp: float, ki: float, kd: float) -> &mut Self {
unsafe { a_pid_set_kpid(self, kp, ki, kd) };
self
}
/// calculate for PID controller
@ -687,7 +687,9 @@ impl Default for pid_fuzzy {
extern "C" {
fn a_pid_fuzzy_opr(opr: c_uint) -> extern "C" fn(float, float) -> float;
fn a_pid_fuzzy_set_opr(ctx: *mut pid_fuzzy, opr: c_uint);
fn a_pid_fuzzy_rule(
fn a_pid_fuzzy_bfuzz(ctx: *const pid_fuzzy) -> *mut u8;
fn a_pid_fuzzy_set_bfuzz(ctx: *mut pid_fuzzy, ptr: *mut u8, num: usize);
fn a_pid_fuzzy_set_rule(
ctx: *mut pid_fuzzy,
num: c_uint,
me: *const float,
@ -696,9 +698,7 @@ extern "C" {
mki: *const float,
mkd: *const float,
);
fn a_pid_fuzzy_nfuzz(ctx: *mut pid_fuzzy) -> *mut u8;
fn a_pid_fuzzy_set_nfuzz(ctx: *mut pid_fuzzy, ptr: *mut u8, num: usize);
fn a_pid_fuzzy_kpid(ctx: *mut pid_fuzzy, kp: float, ki: float, kd: float);
fn a_pid_fuzzy_set_kpid(ctx: *mut pid_fuzzy, kp: float, ki: float, kd: float);
fn a_pid_fuzzy_run(ctx: *mut pid_fuzzy, set: float, fdb: float) -> float;
fn a_pid_fuzzy_pos(ctx: *mut pid_fuzzy, set: float, fdb: float) -> float;
fn a_pid_fuzzy_inc(ctx: *mut pid_fuzzy, set: float, fdb: float) -> float;
@ -711,9 +711,32 @@ impl pid_fuzzy {
pub fn new() -> Self {
Self::default()
}
/// set fuzzy relational operator for fuzzy PID controller
#[inline(always)]
pub fn set_opr(&mut self, opr: c_uint) -> &mut Self {
unsafe { a_pid_fuzzy_set_opr(self, opr) };
self
}
/// compute size of memory block for fuzzy PID controller
#[inline(always)]
#[allow(non_snake_case)]
pub const fn BFUZZ(n: usize) -> usize {
size_of::<c_uint>() * n * 2 + size_of::<float>() * n * (2 + n)
}
/// get memory block for fuzzy PID controller
#[inline(always)]
pub fn bfuzz(&mut self) -> &mut [u8] {
unsafe { from_raw_parts_mut(a_pid_fuzzy_bfuzz(self), Self::BFUZZ(self.nfuzz as usize)) }
}
/// set memory block for fuzzy PID controller
#[inline(always)]
pub fn set_bfuzz(&mut self, ptr: &mut [u8], num: usize) -> &mut Self {
unsafe { a_pid_fuzzy_set_bfuzz(self, ptr.as_mut_ptr(), num) };
self
}
/// set rule base for fuzzy PID controller
#[inline(always)]
pub fn rule(
pub fn set_rule(
&mut self,
col: usize,
me: &[float],
@ -723,7 +746,7 @@ impl pid_fuzzy {
mkd: &[float],
) -> &mut Self {
unsafe {
a_pid_fuzzy_rule(
a_pid_fuzzy_set_rule(
self,
col as c_uint,
me.as_ptr(),
@ -737,31 +760,8 @@ impl pid_fuzzy {
}
/// set proportional integral derivative constant for fuzzy PID controller
#[inline(always)]
pub fn kpid(&mut self, kp: float, ki: float, kd: float) -> &mut Self {
unsafe { a_pid_fuzzy_kpid(self, kp, ki, kd) };
self
}
/// compute size of memory block for fuzzy PID controller
#[inline(always)]
#[allow(non_snake_case)]
pub const fn NFUZZ(n: usize) -> usize {
size_of::<c_uint>() * n * 2 + size_of::<float>() * n * (2 + n)
}
/// get memory block for fuzzy PID controller
#[inline(always)]
pub fn nfuzz(&mut self) -> &mut [u8] {
unsafe { from_raw_parts_mut(a_pid_fuzzy_nfuzz(self), Self::NFUZZ(self.nfuzz as usize)) }
}
/// set memory block for fuzzy PID controller
#[inline(always)]
pub fn set_nfuzz(&mut self, ptr: &mut [u8], num: usize) -> &mut Self {
unsafe { a_pid_fuzzy_set_nfuzz(self, ptr.as_mut_ptr(), num) };
self
}
/// set fuzzy relational operator for fuzzy PID controller
#[inline(always)]
pub fn set_opr(&mut self, opr: c_uint) -> &mut Self {
unsafe { a_pid_fuzzy_set_opr(self, opr) };
pub fn set_kpid(&mut self, kp: float, ki: float, kd: float) -> &mut Self {
unsafe { a_pid_fuzzy_set_kpid(self, kp, ki, kd) };
self
}
/// calculate for fuzzy PID controller
@ -819,8 +819,8 @@ impl Default for pid_neuro {
}
extern "C" {
fn a_pid_neuro_kpid(ctx: *mut pid_neuro, k: float, kp: float, ki: float, kd: float);
fn a_pid_neuro_wpid(ctx: *mut pid_neuro, wp: float, wi: float, wd: float);
fn a_pid_neuro_set_kpid(ctx: *mut pid_neuro, k: float, kp: float, ki: float, kd: float);
fn a_pid_neuro_set_wpid(ctx: *mut pid_neuro, wp: float, wi: float, wd: float);
fn a_pid_neuro_run(ctx: *mut pid_neuro, set: float, fdb: float) -> float;
fn a_pid_neuro_inc(ctx: *mut pid_neuro, set: float, fdb: float) -> float;
fn a_pid_neuro_zero(ctx: *mut pid_neuro);
@ -834,14 +834,14 @@ impl pid_neuro {
}
/// set proportional integral derivative constant for single neuron PID controller
#[inline(always)]
pub fn kpid(&mut self, k: float, kp: float, ki: float, kd: float) -> &mut Self {
unsafe { a_pid_neuro_kpid(self, k, kp, ki, kd) };
pub fn set_kpid(&mut self, k: float, kp: float, ki: float, kd: float) -> &mut Self {
unsafe { a_pid_neuro_set_kpid(self, k, kp, ki, kd) };
self
}
/// set proportional integral derivative weight for single neuron PID controller
#[inline(always)]
pub fn wpid(&mut self, wp: float, wi: float, wd: float) -> &mut Self {
unsafe { a_pid_neuro_wpid(self, wp, wi, wd) };
pub fn set_wpid(&mut self, wp: float, wi: float, wd: float) -> &mut Self {
unsafe { a_pid_neuro_set_wpid(self, wp, wi, wd) };
self
}
/// calculate for single neuron PID controller

View File

@ -1,6 +1,6 @@
#include "a/pid.h"
void a_pid_kpid(a_pid *ctx, a_float kp, a_float ki, a_float kd)
void a_pid_set_kpid(a_pid *ctx, a_float kp, a_float ki, a_float kd)
{
ctx->kp = kp;
ctx->ki = ki;

View File

@ -100,8 +100,8 @@ out:
return counter;
}
void a_pid_fuzzy_rule(a_pid_fuzzy *ctx, unsigned int nrule, a_float const *me, a_float const *mec,
a_float const *mkp, a_float const *mki, a_float const *mkd)
void a_pid_fuzzy_set_rule(a_pid_fuzzy *ctx, unsigned int nrule, a_float const *me, a_float const *mec,
a_float const *mkp, a_float const *mki, a_float const *mkd)
{
ctx->me = me;
ctx->mec = mec;
@ -111,8 +111,8 @@ void a_pid_fuzzy_rule(a_pid_fuzzy *ctx, unsigned int nrule, a_float const *me, a
ctx->nrule = nrule;
}
void *a_pid_fuzzy_nfuzz(a_pid_fuzzy *ctx) { return ctx->idx; }
void a_pid_fuzzy_set_nfuzz(a_pid_fuzzy *ctx, void *ptr, a_size num)
void *a_pid_fuzzy_bfuzz(a_pid_fuzzy const *ctx) { return ctx->idx; }
void a_pid_fuzzy_set_bfuzz(a_pid_fuzzy *ctx, void *ptr, a_size num)
{
ctx->nfuzz = (unsigned int)num;
ctx->idx = (unsigned int *)ptr;
@ -120,9 +120,9 @@ void a_pid_fuzzy_set_nfuzz(a_pid_fuzzy *ctx, void *ptr, a_size num)
ctx->val = (a_float *)ptr;
}
void a_pid_fuzzy_kpid(a_pid_fuzzy *ctx, a_float kp, a_float ki, a_float kd)
void a_pid_fuzzy_set_kpid(a_pid_fuzzy *ctx, a_float kp, a_float ki, a_float kd)
{
a_pid_kpid(&ctx->pid, kp, ki, kd);
a_pid_set_kpid(&ctx->pid, kp, ki, kd);
ctx->kp = kp;
ctx->ki = ki;
ctx->kd = kd;
@ -198,7 +198,7 @@ void a_pid_fuzzy_out_(a_pid_fuzzy *ctx, a_float ec, a_float e)
kd *= inv;
}
pid:
a_pid_kpid(&ctx->pid, ctx->kp + kp, ctx->ki + ki, ctx->kd + kd);
a_pid_set_kpid(&ctx->pid, ctx->kp + kp, ctx->ki + ki, ctx->kd + kd);
}
A_HIDDEN a_float a_pid_run_(a_pid *ctx, a_float set, a_float fdb, a_float err);

View File

@ -1,12 +1,12 @@
#include "a/pid_neuro.h"
void a_pid_neuro_kpid(a_pid_neuro *ctx, a_float k, a_float kp, a_float ki, a_float kd)
void a_pid_neuro_set_kpid(a_pid_neuro *ctx, a_float k, a_float kp, a_float ki, a_float kd)
{
a_pid_kpid(&ctx->pid, kp, ki, kd);
a_pid_set_kpid(&ctx->pid, kp, ki, kd);
ctx->k = k;
}
void a_pid_neuro_wpid(a_pid_neuro *ctx, a_float wp, a_float wi, a_float wd)
void a_pid_neuro_set_wpid(a_pid_neuro *ctx, a_float wp, a_float wi, a_float wd)
{
ctx->wp = wp;
ctx->wi = wi;

View File

@ -3,9 +3,9 @@
#pragma GCC diagnostic ignored "-Wfloat-equal"
#endif /* -Wfloat-equal */
void a_pid_expert_kpid(a_pid_expert *ctx, a_float kp, a_float ki, a_float kd)
void a_pid_expert_set_kpid(a_pid_expert *ctx, a_float kp, a_float ki, a_float kd)
{
a_pid_kpid(&ctx->pid, kp, ki, kd);
a_pid_set_kpid(&ctx->pid, kp, ki, kd);
}
a_float a_pid_expert_iter(a_pid_expert *ctx, a_float set, a_float fdb)

View File

@ -39,7 +39,7 @@ extern "C" {
@param[in] ki integral constant
@param[in] kd derivative constant
*/
A_EXTERN void a_pid_expert_kpid(a_pid_expert *ctx, a_float kp, a_float ki, a_float kd);
A_EXTERN void a_pid_expert_set_kpid(a_pid_expert *ctx, a_float kp, a_float ki, a_float kd);
/*!
@brief calculate for expert PID controller
@ -79,9 +79,9 @@ struct a_pid_expert
a_float loss; //!< loss coefficient
#if defined(__cplusplus)
A_INLINE void init() { a_pid_expert_init(this); }
A_INLINE void kpid(a_float kp, a_float ki, a_float kd)
A_INLINE void set_kpid(a_float kp, a_float ki, a_float kd)
{
a_pid_expert_kpid(this, kp, ki, kd);
a_pid_expert_set_kpid(this, kp, ki, kd);
}
A_INLINE a_float operator()(a_float set, a_float fdb)
{

View File

@ -150,8 +150,8 @@ int main(int argc, char *argv[]) // NOLINT(misc-definitions-in-headers)
pos_pid.mkd = m7kd;
pos_pid.opr = a_pid_fuzzy_opr(A_PID_FUZZY_EQU);
a_pid_fuzzy_init(&pos_pid);
a_byte pos_fuzzy[A_PID_FUZZY_NFUZZ(2)];
a_pid_fuzzy_set_nfuzz(&pos_pid, pos_fuzzy, 2);
a_byte pos_bfuzz[A_PID_FUZZY_BFUZZ(2)];
a_pid_fuzzy_set_bfuzz(&pos_pid, pos_bfuzz, 2);
a_pid_fuzzy inc_pid;
inc_pid.pid.outmax = +10;
inc_pid.pid.outmin = -10;
@ -169,11 +169,11 @@ int main(int argc, char *argv[]) // NOLINT(misc-definitions-in-headers)
inc_pid.mkd = m7kd;
inc_pid.opr = a_pid_fuzzy_opr(A_PID_FUZZY_EQU);
a_pid_fuzzy_init(&inc_pid);
a_byte inc_fuzzy[A_PID_FUZZY_NFUZZ(2)];
a_pid_fuzzy_set_nfuzz(&inc_pid, inc_fuzzy, 2);
a_byte inc_bfuzz[A_PID_FUZZY_BFUZZ(2)];
a_pid_fuzzy_set_bfuzz(&inc_pid, inc_bfuzz, 2);
a_pid_fuzzy_kpid(&pos_pid, 600, A_FLOAT_C(20.0), A_FLOAT_C(6000.0));
a_pid_fuzzy_kpid(&inc_pid, 600, A_FLOAT_C(20.0), A_FLOAT_C(6000.0));
a_pid_fuzzy_set_kpid(&pos_pid, 600, A_FLOAT_C(20.0), A_FLOAT_C(6000.0));
a_pid_fuzzy_set_kpid(&inc_pid, 600, A_FLOAT_C(20.0), A_FLOAT_C(6000.0));
for (unsigned int i = 0; i < 200; ++i)
{
a_float in = input(A_FLOAT_C(0.001) * a_float_c(i));

View File

@ -1,7 +1,7 @@
#[test]
fn pid() {
let mut pid = liba::pid::new();
pid.kpid(10.0, 0.1, 1.0);
pid.set_kpid(10.0, 0.1, 1.0);
std::println!("{}", pid.zero().pos(1.0, 0.0));
std::println!("{}", pid.zero().inc(1.0, 0.0));
}

View File

@ -76,9 +76,9 @@ fn pid_fuzzy() {
[NL, NS, NS, NS, NS, NS, NL],
[NL, NM, NM, NM, NS, NS, NL],
];
let mut fuzzy = [0u8; liba::pid_fuzzy::NFUZZ(2)];
let mut fuzzy = [0u8; liba::pid_fuzzy::BFUZZ(2)];
let mut pid = liba::pid_fuzzy::new();
pid.rule(
pid.set_rule(
me.len(),
&me.concat(),
&mec.concat(),
@ -86,8 +86,8 @@ fn pid_fuzzy() {
&mki.concat(),
&mkd.concat(),
)
.kpid(10.0, 0.1, 1.0)
.set_nfuzz(&mut fuzzy, 2);
.set_kpid(10.0, 0.1, 1.0)
.set_bfuzz(&mut fuzzy, 2);
pid.set_opr(liba::fuzzy::EQU).zero();
std::println!("{} {}", pid.pos(1.0, 0.0), pid.pos(1.0, 0.0));
pid.set_opr(liba::fuzzy::EQU).zero();

View File

@ -1,7 +1,7 @@
#[test]
fn pid_neuro() {
let mut pid = liba::pid_neuro::new();
pid.kpid(10.0, 1.0, 0.1, 1.0).wpid(1.0, 0.0, 0.0);
pid.set_kpid(10.0, 1.0, 0.1, 1.0).set_wpid(1.0, 0.0, 0.0);
std::println!("{}", pid.inc(1.0, 0.0));
pid.zero();
}