4 #if A_PREREQ_GNUC(3, 0) || __has_warning("-Wfloat-equal")
5 #pragma GCC diagnostic ignored "-Wfloat-equal"
6 #endif /* -Wfloat-equal */
9 #define L Java_liba_pid
16 JNIEXPORT
void JNICALL
Java_liba_pid_clinit(JNIEnv
*_env
, jclass _cls
)
18 jclass _nbb
= (*_env
)->FindClass(_env
, "Ljava/nio/ByteBuffer;");
19 L
._new
= (*_env
)->GetStaticMethodID(_env
, _nbb
, "allocateDirect", "(I)Ljava/nio/ByteBuffer;");
20 L
.ctx
= (*_env
)->GetFieldID(_env
, _cls
, "ctx", "Ljava/nio/ByteBuffer;");
23 JNIEXPORT
void JNICALL
Java_liba_pid_init(JNIEnv
*_env
, jobject _obj
)
25 jobject _ctx
= (*_env
)->CallObjectMethod(_env
, _obj
, L
._new
, (jint
)sizeof(a_pid
));
26 a_pid
*ctx
= (a_pid
*)(*_env
)->GetDirectBufferAddress(_env
, _ctx
);
27 (*_env
)->SetObjectField(_env
, _obj
, L
.ctx
, _ctx
);
29 ctx
->summax
= +A_FLOAT_INF
;
30 ctx
->summin
= -A_FLOAT_INF
;
31 ctx
->outmax
= +A_FLOAT_INF
;
32 ctx
->outmin
= -A_FLOAT_INF
;
36 JNIEXPORT jdouble JNICALL
Java_liba_pid_kp__(JNIEnv
*_env
, jobject _obj
)
38 jobject _ctx
= (*_env
)->GetObjectField(_env
, _obj
, L
.ctx
);
39 a_pid
*ctx
= (a_pid
*)(*_env
)->GetDirectBufferAddress(_env
, _ctx
);
43 JNIEXPORT jobject JNICALL
Java_liba_pid_kp__D(JNIEnv
*_env
, jobject _obj
, jdouble kp
)
45 jobject _ctx
= (*_env
)->GetObjectField(_env
, _obj
, L
.ctx
);
46 a_pid
*ctx
= (a_pid
*)(*_env
)->GetDirectBufferAddress(_env
, _ctx
);
51 JNIEXPORT jdouble JNICALL
Java_liba_pid_ki__(JNIEnv
*_env
, jobject _obj
)
53 jobject _ctx
= (*_env
)->GetObjectField(_env
, _obj
, L
.ctx
);
54 a_pid
*ctx
= (a_pid
*)(*_env
)->GetDirectBufferAddress(_env
, _ctx
);
58 JNIEXPORT jobject JNICALL
Java_liba_pid_ki__D(JNIEnv
*_env
, jobject _obj
, jdouble ki
)
60 jobject _ctx
= (*_env
)->GetObjectField(_env
, _obj
, L
.ctx
);
61 a_pid
*ctx
= (a_pid
*)(*_env
)->GetDirectBufferAddress(_env
, _ctx
);
66 JNIEXPORT jdouble JNICALL
Java_liba_pid_kd__(JNIEnv
*_env
, jobject _obj
)
68 jobject _ctx
= (*_env
)->GetObjectField(_env
, _obj
, L
.ctx
);
69 a_pid
*ctx
= (a_pid
*)(*_env
)->GetDirectBufferAddress(_env
, _ctx
);
73 JNIEXPORT jobject JNICALL
Java_liba_pid_kd__D(JNIEnv
*_env
, jobject _obj
, jdouble kd
)
75 jobject _ctx
= (*_env
)->GetObjectField(_env
, _obj
, L
.ctx
);
76 a_pid
*ctx
= (a_pid
*)(*_env
)->GetDirectBufferAddress(_env
, _ctx
);
81 JNIEXPORT jdouble JNICALL
Java_liba_pid_summax__(JNIEnv
*_env
, jobject _obj
)
83 jobject _ctx
= (*_env
)->GetObjectField(_env
, _obj
, L
.ctx
);
84 a_pid
*ctx
= (a_pid
*)(*_env
)->GetDirectBufferAddress(_env
, _ctx
);
88 JNIEXPORT jobject JNICALL
Java_liba_pid_summax__D(JNIEnv
*_env
, jobject _obj
, jdouble summax
)
90 jobject _ctx
= (*_env
)->GetObjectField(_env
, _obj
, L
.ctx
);
91 a_pid
*ctx
= (a_pid
*)(*_env
)->GetDirectBufferAddress(_env
, _ctx
);
96 JNIEXPORT jdouble JNICALL
Java_liba_pid_summin__(JNIEnv
*_env
, jobject _obj
)
98 jobject _ctx
= (*_env
)->GetObjectField(_env
, _obj
, L
.ctx
);
99 a_pid
*ctx
= (a_pid
*)(*_env
)->GetDirectBufferAddress(_env
, _ctx
);
103 JNIEXPORT jobject JNICALL
Java_liba_pid_summin__D(JNIEnv
*_env
, jobject _obj
, jdouble summin
)
105 jobject _ctx
= (*_env
)->GetObjectField(_env
, _obj
, L
.ctx
);
106 a_pid
*ctx
= (a_pid
*)(*_env
)->GetDirectBufferAddress(_env
, _ctx
);
107 ctx
->summin
= summin
;
111 JNIEXPORT jdouble JNICALL
Java_liba_pid_sum(JNIEnv
*_env
, jobject _obj
)
113 jobject _ctx
= (*_env
)->GetObjectField(_env
, _obj
, L
.ctx
);
114 a_pid
*ctx
= (a_pid
*)(*_env
)->GetDirectBufferAddress(_env
, _ctx
);
118 JNIEXPORT jdouble JNICALL
Java_liba_pid_outmax__(JNIEnv
*_env
, jobject _obj
)
120 jobject _ctx
= (*_env
)->GetObjectField(_env
, _obj
, L
.ctx
);
121 a_pid
*ctx
= (a_pid
*)(*_env
)->GetDirectBufferAddress(_env
, _ctx
);
125 JNIEXPORT jobject JNICALL
Java_liba_pid_outmax__D(JNIEnv
*_env
, jobject _obj
, jdouble outmax
)
127 jobject _ctx
= (*_env
)->GetObjectField(_env
, _obj
, L
.ctx
);
128 a_pid
*ctx
= (a_pid
*)(*_env
)->GetDirectBufferAddress(_env
, _ctx
);
129 ctx
->outmax
= outmax
;
133 JNIEXPORT jdouble JNICALL
Java_liba_pid_outmin__(JNIEnv
*_env
, jobject _obj
)
135 jobject _ctx
= (*_env
)->GetObjectField(_env
, _obj
, L
.ctx
);
136 a_pid
*ctx
= (a_pid
*)(*_env
)->GetDirectBufferAddress(_env
, _ctx
);
140 JNIEXPORT jobject JNICALL
Java_liba_pid_outmin__D(JNIEnv
*_env
, jobject _obj
, jdouble outmin
)
142 jobject _ctx
= (*_env
)->GetObjectField(_env
, _obj
, L
.ctx
);
143 a_pid
*ctx
= (a_pid
*)(*_env
)->GetDirectBufferAddress(_env
, _ctx
);
144 ctx
->outmin
= outmin
;
148 JNIEXPORT jdouble JNICALL
Java_liba_pid_out(JNIEnv
*_env
, jobject _obj
)
150 jobject _ctx
= (*_env
)->GetObjectField(_env
, _obj
, L
.ctx
);
151 a_pid
*ctx
= (a_pid
*)(*_env
)->GetDirectBufferAddress(_env
, _ctx
);
155 JNIEXPORT jdouble JNICALL
Java_liba_pid_fdb(JNIEnv
*_env
, jobject _obj
)
157 jobject _ctx
= (*_env
)->GetObjectField(_env
, _obj
, L
.ctx
);
158 a_pid
*ctx
= (a_pid
*)(*_env
)->GetDirectBufferAddress(_env
, _ctx
);
162 JNIEXPORT jdouble JNICALL
Java_liba_pid_err(JNIEnv
*_env
, jobject _obj
)
164 jobject _ctx
= (*_env
)->GetObjectField(_env
, _obj
, L
.ctx
);
165 a_pid
*ctx
= (a_pid
*)(*_env
)->GetDirectBufferAddress(_env
, _ctx
);
169 JNIEXPORT jobject JNICALL
Java_liba_pid_kpid(JNIEnv
*_env
, jobject _obj
, jdouble kp
, jdouble ki
, jdouble kd
)
171 jobject _ctx
= (*_env
)->GetObjectField(_env
, _obj
, L
.ctx
);
172 a_pid
*ctx
= (a_pid
*)(*_env
)->GetDirectBufferAddress(_env
, _ctx
);
173 a_pid_kpid(ctx
, kp
, ki
, kd
);
177 JNIEXPORT jdouble JNICALL
Java_liba_pid_run(JNIEnv
*_env
, jobject _obj
, jdouble set
, jdouble fdb
)
179 jobject _ctx
= (*_env
)->GetObjectField(_env
, _obj
, L
.ctx
);
180 a_pid
*ctx
= (a_pid
*)(*_env
)->GetDirectBufferAddress(_env
, _ctx
);
181 return a_pid_run(ctx
, set
, fdb
);
183 JNIEXPORT jdouble JNICALL
Java_liba_pid_pos(JNIEnv
*_env
, jobject _obj
, jdouble set
, jdouble fdb
)
185 jobject _ctx
= (*_env
)->GetObjectField(_env
, _obj
, L
.ctx
);
186 a_pid
*ctx
= (a_pid
*)(*_env
)->GetDirectBufferAddress(_env
, _ctx
);
187 return a_pid_pos(ctx
, set
, fdb
);
190 JNIEXPORT jdouble JNICALL
Java_liba_pid_inc(JNIEnv
*_env
, jobject _obj
, jdouble set
, jdouble fdb
)
192 jobject _ctx
= (*_env
)->GetObjectField(_env
, _obj
, L
.ctx
);
193 a_pid
*ctx
= (a_pid
*)(*_env
)->GetDirectBufferAddress(_env
, _ctx
);
194 return a_pid_inc(ctx
, set
, fdb
);
197 JNIEXPORT jobject JNICALL
Java_liba_pid_zero(JNIEnv
*_env
, jobject _obj
)
199 jobject _ctx
= (*_env
)->GetObjectField(_env
, _obj
, L
.ctx
);
200 a_pid
*ctx
= (a_pid
*)(*_env
)->GetDirectBufferAddress(_env
, _ctx
);