Improved PI control of Hiden XCS

This commit is contained in:
Douglas Clowes
2014-02-28 13:35:26 +11:00
parent de575757e4
commit 1fd74bef01

View File

@ -22,10 +22,10 @@ driver hiden_xcs = {
var flow = {
driveable = flow
readable = 1
read_command = 'None'
fetch_function = fetch_flow
read_function = read_flow
read_command = 'flow1 flow2'
write_function = no_op
write_function = write_flow
lowerlimit = 0
upperlimit = 500
tolerance = 1
@ -33,10 +33,10 @@ driver hiden_xcs = {
property pid_error = 0
property pid_deriv = 0
property pid_integ = 0
property pid_pvalue = 0.05
property pid_ivalue = 0.01
property pid_pvalue = 0.2
property pid_ivalue = 0.1
property pid_dvalue = 0.0
property pid_imax = 1
property pid_imax = 30
}
var flow1
var flow2
@ -47,7 +47,7 @@ driver hiden_xcs = {
readable = 1
read_command = '?ALL DATA'
read_function = read_all_data
write_function = no_op
write_function = write_humidity
checkrange_function = chkrange_function
value = 50
lowerlimit = 10
@ -57,10 +57,10 @@ driver hiden_xcs = {
property pid_error = 0
property pid_deriv = 0
property pid_integ = 0
property pid_pvalue = 0.05
property pid_ivalue = 0.005
property pid_pvalue = 0.2
property pid_ivalue = 0.1
property pid_dvalue = 0.0
property pid_imax = 1
property pid_imax = 30
}
}
#
@ -178,28 +178,15 @@ driver hiden_xcs = {
@ sct geterror "Syntax error for read_all_data in: '${data}'"
@ }
@ if { [hpropexists [sct] target] } {
#@ sct pid_error [expr [sct target] - ${data}]
#@ set p_value [expr [sct pid_pvalue] * [sct pid_error]]
#@ set d_value [expr [sct pid_dvalue] * (${data} - [sct oldval])]
#@ sct pid_deriv [sct pid_error]
#@ sct pid_integ [expr [sct pid_integ] + [sct pid_error]]
#@ if { [sct pid_integ] > [sct pid_imax] } {
#@ sct pid_integ [sct pid_imax]
#@ }
#@ if { [sct pid_integ] < -[sct pid_imax] } {
#@ sct pid_integ -[sct pid_imax]
#@ }
#@ set i_value [expr [sct pid_ivalue] * [sct pid_integ]]
#@ set pid [expr ${p_value} + ${i_value} + ${d_value}]
#@ sct pid_output ${pid}
@ set pid [pid_humidity ${tc_root} [sct target] ${data}]
@ set path [pathname [sct]]
@ foreach node [list analog/sp1 analog/sp2] {
@ set pid [expr -${pid}]
@ hsetprop ${path}/${node} bias_humidity ${pid}
@ if { [hpropexists ${path}/${node} target] } {
@ hset ${path}/${node} [expr [hgetpropval ${path}/${node} target] + ${pid}]
@ hset ${path}/${node} [hgetpropval ${path}/${node} target]
@ } else {
@ hset ${path}/${node} [expr [hval ${path}/${node}] + ${pid}]
@ hset ${path}/${node} [hval ${path}/${node}]
@ }
@ }
@ }
@ -217,26 +204,13 @@ driver hiden_xcs = {
@ }
@ sct targets ${targets}
@ if { [hpropexists [sct] target] } {
#@ sct pid_error [expr [sct target] - [sct result]]
#@ set p_value [expr [sct pid_pvalue] * [sct pid_error]]
#@ set d_value [expr [sct pid_dvalue] * ([sct result] - [sct oldval])]
#@ sct pid_deriv [sct pid_error]
#@ sct pid_integ [expr [sct pid_integ] + [sct pid_error]]
#@ if { [sct pid_integ] > [sct pid_imax] } {
#@ sct pid_integ [sct pid_imax]
#@ }
#@ if { [sct pid_integ] < -[sct pid_imax] } {
#@ sct pid_integ -[sct pid_imax]
#@ }
#@ set i_value [expr [sct pid_ivalue] * [sct pid_integ]]
#@ set pid [expr ${p_value} + ${i_value} + ${d_value}]
#@ sct pid_output ${pid}
@ set pid [pid_flow ${tc_root} [sct target] ${data}]
@ foreach node [list analog/sp1 analog/sp2] {
@ hsetprop ${path}/${node} bias_flow ${pid}
@ if { [hpropexists ${path}/${node} target] } {
@ hset ${path}/${node} [expr [hgetpropval ${path}/${node} target] + ${pid}]
@ hset ${path}/${node} [hgetpropval ${path}/${node} target]
@ } else {
@ hset ${path}/${node} [expr [hval ${path}/${node}] + ${pid}]
@ hset ${path}/${node} [hval ${path}/${node}]
@ }
@ }
@ }
@ -255,16 +229,47 @@ driver hiden_xcs = {
@ } else {
@ set span 500.0
@ }
@ if { [hpropexists [sct] bias_humidity] } {
@ set par [expr ${par} + [sct bias_humidity]]
@ }
@ if { [hpropexists [sct] bias_flow] } {
@ set par [expr ${par} + [sct bias_flow]]
@ }
@ if { ${par} < 0.0 } {
@ set par 0.0
@ }
@ if { ${par} > ${span} } {
@ set par ${span}
@ }
@ set par [expr int(${base} + (4095.0 * ${par} / ${span}))]
@ set cmd "${cmd_str}${par}"
}
code write_function no_op = {
@ if { [hpropexists [sct] driving] } {
@ if { [hpropexists [sct] writestatus] && [sct writestatus] == "start" } {
@ sct driving 1
@ }
code write_function write_flow = {
@ if { [hpropexists ${tc_root}/humidity target] } {
@ set humidity_target [hgetpropval ${tc_root}/humidity target]
@ } else {
@ set humidity_target [hval ${tc_root}/humidity]
@ }
@ return ${nextState}
@ set flow1_target [expr (0.01 * (100.0 - ${humidity_target})) * [sct target]]
@ set flow2_target [expr (0.01 * ( ${humidity_target})) * [sct target]]
@ hset ${tc_root}/analog/sp1 ${flow1_target}
@ hset ${tc_root}/analog/sp2 ${flow2_target}
@ set cmd "@@NOSEND@@"
}
code write_function write_humidity = {
@ if { [hpropexists ${tc_root}/flow target] } {
@ set flow_target [hgetpropval ${tc_root}/flow target]
@ } else {
@ set flow_target [hval ${tc_root}/flow]
@ }
@ set flow1_target [expr (0.01 * (100.0 - [sct target])) * ${flow_target}]
@ set flow2_target [expr (0.01 * ( [sct target])) * ${flow_target}]
@ hset ${tc_root}/analog/sp1 ${flow1_target}
@ hset ${tc_root}/analog/sp2 ${flow2_target}
@ set cmd "@@NOSEND@@"
}
code write_function no_op = {
@ set cmd "@@NOSEND@@"
}
#
# This code is after database creation