Permalink
Browse files

modified: assemblies/assembly005/pid.tcl

  • Loading branch information...
1 parent 6281ea2 commit 91c4f2572038da1100ba2d53284b127805034a60 unknown committed Apr 3, 2012
Showing with 29 additions and 0 deletions.
  1. +29 −0 assemblies/assembly005/pid.tcl
@@ -44,6 +44,10 @@ set terrvalues [list]
set timevalues [list]
set rtimevalues [list]
+# Число отсчётов температуры, необходимых для фурье-анализа
+set NUM_OF_FOURIER_READINGS 300
+set tvalues_fourier [list]
+
# Время начала работы, мс
set START_TIME 0
@@ -133,13 +137,32 @@ proc finish {} {
destroyChildren
}
+proc fourierFileName {} {
+ for { set n 1 } { $n < 100 } { incr n } {
+ set fn [format "tf-%03d.txt" $n]
+ if { ![file exists $fn] } {
+ return $fn
+ }
+ }
+ return "tf-000.txt"
+}
+
+proc writeFourierData { data } {
+ set f [open [fourierFileName] w]
+ foreach v $data {
+ puts $f $v
+ }
+ close $f
+}
+
###############################################################################
# Обработчики событий
###############################################################################
# Процедура вызывается модулем измерения температуры
proc setTemperature { t tErr } {
global mutexVar pidState log tvalues terrvalues timevalues rtimevalues NUM_OF_READINGS START_TIME
+ global tvalues_fourier NUM_OF_FOURIER_READINGS
set tm [clock milliseconds]
@@ -162,6 +185,12 @@ proc setTemperature { t tErr } {
set der1 0.0
}
+ lappend tvalues_fourier $t
+ if { [llength $tvalues_fourier] >= $NUM_OF_FOURIER_READINGS } {
+ writeFourierData $tvalues_fourier
+ set tvalues_fourier [list]
+ }
+
# Запишем в состояние ПИДа
set pidState(currentTemperature) $t

0 comments on commit 91c4f25

Please sign in to comment.