mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-15 17:02:53 +08:00
more check for fuzzypid
This commit is contained in:
parent
8131137b2c
commit
bbe04c7d93
@ -41,19 +41,16 @@ fuzzy_pid_params = FuzzyPIDParams([
|
||||
[0.65, 0, 0, 0, 0, 0, 1],
|
||||
[-0.34, 0, 0, 0, 0, 0, 1],
|
||||
[-1.1, 0, 0, 0, 0, 0, 1],
|
||||
[-2.4, 0, 0, 0, 0, 0, 1],
|
||||
[1.2, 0, 0, 0, 0, 0, 1],
|
||||
[1.2, 0.05, 0.1, 0, 0, 0, 1],
|
||||
])
|
||||
|
||||
direct = PIDDirect([True, False, False, False, True, True])
|
||||
direct = PIDDirect([True, False, False])
|
||||
|
||||
fuzzy_pid_controller = FuzzyPIDController(
|
||||
rule_base, mf_params, fuzzy_pid_params, direct=direct)
|
||||
|
||||
max_error = 100
|
||||
middle_pwm_output = 500
|
||||
control_id = 5
|
||||
control_id = 2
|
||||
real = 0
|
||||
idea = max_error * 0.9
|
||||
print("idea value: ", idea)
|
||||
|
@ -168,12 +168,19 @@ void _fuzzypid_FuzzyPIDController___init__(PikaObj* self,
|
||||
int* rules = obj_getPtr(rule_base, "rules");
|
||||
int* mf_params_mat = obj_getPtr(mf_params, "mf_params");
|
||||
float* fuzzy_pid_params = obj_getPtr(pid_params, "fuzzy_pid_params");
|
||||
int DOF = obj_getInt(pid_params, "DOF");
|
||||
int DOF_pid_parms = obj_getInt(pid_params, "DOF");
|
||||
int DOF_direct = obj_getInt(direct, "DOF");
|
||||
if (DOF_pid_parms != DOF_direct) {
|
||||
obj_setSysOut(self,
|
||||
"Error: pid_params and direct must have the same length");
|
||||
obj_setErrorCode(self, -__LINE__);
|
||||
return;
|
||||
}
|
||||
struct PID** pid_vector = fuzzy_pid_vector_init(
|
||||
(float(*)[pid_params_count])fuzzy_pid_params, delta_k, mf_type, fo_type,
|
||||
df_type, mf_params_mat, (int(*)[pid_params_count])rules, DOF);
|
||||
df_type, mf_params_mat, (int(*)[pid_params_count])rules, DOF_pid_parms);
|
||||
obj_setPtr(self, "pid_vector", pid_vector);
|
||||
obj_setInt(self, "DOF", DOF);
|
||||
obj_setInt(self, "DOF", DOF_pid_parms);
|
||||
obj_setPtr(self, "direct_vector", obj_getPtr(direct, "direct_vector"));
|
||||
}
|
||||
|
||||
@ -191,6 +198,12 @@ pika_float _fuzzypid_FuzzyPIDController_compute_output(PikaObj* self,
|
||||
pika_float input) {
|
||||
struct PID** pid_vector = obj_getPtr(self, "pid_vector");
|
||||
pika_bool* direct_vector = obj_getPtr(self, "direct_vector");
|
||||
int DOF = obj_getInt(self, "DOF");
|
||||
if (control_id < 0 || control_id >= DOF) {
|
||||
obj_setSysOut(self, "Error: control_id out of range");
|
||||
obj_setErrorCode(self, -__LINE__);
|
||||
return 0;
|
||||
}
|
||||
return fuzzy_pid_motor_pwd_output(real, input, direct_vector[control_id],
|
||||
pid_vector[control_id]);
|
||||
}
|
||||
|
@ -168,12 +168,19 @@ void _fuzzypid_FuzzyPIDController___init__(PikaObj* self,
|
||||
int* rules = obj_getPtr(rule_base, "rules");
|
||||
int* mf_params_mat = obj_getPtr(mf_params, "mf_params");
|
||||
float* fuzzy_pid_params = obj_getPtr(pid_params, "fuzzy_pid_params");
|
||||
int DOF = obj_getInt(pid_params, "DOF");
|
||||
int DOF_pid_parms = obj_getInt(pid_params, "DOF");
|
||||
int DOF_direct = obj_getInt(direct, "DOF");
|
||||
if (DOF_pid_parms != DOF_direct) {
|
||||
obj_setSysOut(self,
|
||||
"Error: pid_params and direct must have the same length");
|
||||
obj_setErrorCode(self, -__LINE__);
|
||||
return;
|
||||
}
|
||||
struct PID** pid_vector = fuzzy_pid_vector_init(
|
||||
(float(*)[pid_params_count])fuzzy_pid_params, delta_k, mf_type, fo_type,
|
||||
df_type, mf_params_mat, (int(*)[pid_params_count])rules, DOF);
|
||||
df_type, mf_params_mat, (int(*)[pid_params_count])rules, DOF_pid_parms);
|
||||
obj_setPtr(self, "pid_vector", pid_vector);
|
||||
obj_setInt(self, "DOF", DOF);
|
||||
obj_setInt(self, "DOF", DOF_pid_parms);
|
||||
obj_setPtr(self, "direct_vector", obj_getPtr(direct, "direct_vector"));
|
||||
}
|
||||
|
||||
@ -191,6 +198,12 @@ pika_float _fuzzypid_FuzzyPIDController_compute_output(PikaObj* self,
|
||||
pika_float input) {
|
||||
struct PID** pid_vector = obj_getPtr(self, "pid_vector");
|
||||
pika_bool* direct_vector = obj_getPtr(self, "direct_vector");
|
||||
int DOF = obj_getInt(self, "DOF");
|
||||
if (control_id < 0 || control_id >= DOF) {
|
||||
obj_setSysOut(self, "Error: control_id out of range");
|
||||
obj_setErrorCode(self, -__LINE__);
|
||||
return 0;
|
||||
}
|
||||
return fuzzy_pid_motor_pwd_output(real, input, direct_vector[control_id],
|
||||
pid_vector[control_id]);
|
||||
}
|
||||
|
@ -41,19 +41,16 @@ fuzzy_pid_params = FuzzyPIDParams([
|
||||
[0.65, 0, 0, 0, 0, 0, 1],
|
||||
[-0.34, 0, 0, 0, 0, 0, 1],
|
||||
[-1.1, 0, 0, 0, 0, 0, 1],
|
||||
[-2.4, 0, 0, 0, 0, 0, 1],
|
||||
[1.2, 0, 0, 0, 0, 0, 1],
|
||||
[1.2, 0.05, 0.1, 0, 0, 0, 1],
|
||||
])
|
||||
|
||||
direct = PIDDirect([True, False, False, False, True, True])
|
||||
direct = PIDDirect([True, False, False])
|
||||
|
||||
fuzzy_pid_controller = FuzzyPIDController(
|
||||
rule_base, mf_params, fuzzy_pid_params, direct=direct)
|
||||
|
||||
max_error = 100
|
||||
middle_pwm_output = 500
|
||||
control_id = 5
|
||||
control_id = 2
|
||||
real = 0
|
||||
idea = max_error * 0.9
|
||||
print("idea value: ", idea)
|
||||
|
Loading…
x
Reference in New Issue
Block a user