git.haldean.org sousvide / dd31fff
Add overshoot tracking to UI Will Haldean Brown 8 years ago
3 changed file(s) with 23 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
3333 Gpio GpioParams
3434 DataLock sync.Mutex
3535 AccError float64
36 MaxError float64
3637 lastPOutput float64
3738 lastIOutput float64
3839 lastDOutput float64
4748 Target float64
4849 AbsError float64
4950 AccError float64
51 MaxError float64
5052 Pid PidParams
5153 POutput float64
5254 IOutput float64
8486 Target: float64(s.Target),
8587 AbsError: float64(s.Error()),
8688 AccError: s.AccError,
89 MaxError: s.MaxError,
8790 Pid: s.Pid,
8891 POutput: s.lastPOutput,
8992 IOutput: s.lastIOutput,
103106 }
104107
105108 s.AccError = 0
109 s.MaxError = 0
106110 N := len(s.History)
107111 l := float64(0)
108112 for i := N - 1; i >= N-AccErrorWindow-1 && i >= 0; i-- {
109 s.AccError += math.Abs(s.History[i].AbsError)
113 ae := s.History[i].AbsError
114 s.AccError += math.Abs(ae)
115 if ae < s.MaxError {
116 // find the most negative error
117 s.MaxError = ae
118 }
110119 l++
111120 }
121 s.MaxError *= -1
112122 s.AccError /= l
113123 }
114124
110110 </td>
111111 <td class="val">&plusmn;<span id="acc_err"></span> &deg;C/sample</td>
112112 </tr>
113 <tr>
114 <td class="label">
115 Max overshoot:
116 <span class="subtext">
117 Taken over 32-sample sliding window
118 </span>
119 </td>
120 <td class="val"><span id="max_err"></span> &deg;C</td>
121 </tr>
113122 </table>
114123 <img src="/plot" id="plot">
115124 </section>
00 var tempElem, absErrElem, targetElem, heatingElem, plotElem, accErrElem
11 var targetDisplayElem, targetChangeElem, targetInputElem
22 var pInputElem, iInputElem, dInputElem
3 var enabledElem
3 var enabledElem, maxErrElem
44
55 function getApiData() {
66 $.ajax({
2525 $(targetElem).text(target.toFixed(2));
2626 $(absErrElem).text((err >= 0 ? '+' : '') + err.toFixed(2));
2727 $(accErrElem).text(data.AccError.toFixed(2))
28 $(maxErrElem).text(data.MaxError.toFixed(2))
2829 $(enabledElem).text(data.Enabled ? "ENABLED" : "DISABLED")
2930
3031 pInputElem.setAttribute('value', data.Pid.P)
4950 heatingElem = document.getElementById('heating')
5051 plotElem = document.getElementById('plot')
5152 accErrElem = document.getElementById('acc_err')
53 maxErrElem = document.getElementById('max_err')
5254 enabledElem = document.getElementById('enabled')
5355
5456 targetChangeElem = document.getElementById('target_change')