double K1 = 50.0 / 300; // Warm up, 5 min, 20 - 70. Subject to change, if wrong
double K2 = -50.0 / 120; // Cool down, 2 min, 20 - 70. Subject to change, if wrong
double T = 20;
const int ON_TIME = 7; // seconds. this should be calculated
const int OFF_TIME = 2; // seconds. this should be calculated
int onCounter = ON_TIME;
int offCounter = 0;
for (int t = 0; t < 1800; t++)
{
if (onCounter > 0)
{
onCounter--;
T += K1;
}
else if(offCounter == 0)
{
onCounter = ON_TIME;
// switch relay off here
}
if (offCounter > 0)
{
T += K2;
offCounter--;
}
else if(onCounter == 0)
{
offCounter = OFF_TIME;
// switch relay on here
}
Console.WriteLine("t: {0}, T: {1:F2}", t, T);
}
这个函数的作用是模拟 30 分钟(Tt)内的烤箱温度线性上升到70C
. 当然,它不会按预期工作。输入参数是两个线性斜率。
- 烤箱温度将在 5 分钟 (Tw) 内从
20C
增加到70C
- 烤箱将在 2 分钟内冷却至
70C
至20C
(Tc) - 步长应为
1C
(Ts)
因此该功能将控制继电器,该继电器将打开或关闭烤箱。我试图只搜索那些 ON/OFF_TIME 常量,但看起来我需要更严肃的方法。
问题是 - 如何计算ON_TIME
和OFF_TIME
。