Subversion Repositories HomeAutomation

Rev

Rev 2275 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 2275 Rev 2280
Line 6... Line 6...
6
PID_Intervals       = function() { return [ 1, 5, 10, 15, 20 ]; };
6
PID_Intervals       = function() { return [ 1, 5, 10, 15, 20 ]; };
7
//PID_Energy            = function() { return [ 0, 500, 1000, 5000, 10000 ]; };
7
//PID_Energy            = function() { return [ 0, 500, 1000, 5000, 10000 ]; };
8
PID_Temperatures    = function() { return [ 20, 25, 30, 35 ]; };
8
PID_Temperatures    = function() { return [ 20, 25, 30, 35 ]; };
9
PID_Constants       = function() { return [ 0, 0.1, 0.5, 1, 10, 100, 1000 ]; };
9
PID_Constants       = function() { return [ 0, 0.1, 0.5, 1, 10, 100, 1000 ]; };
10
PID_TimeUnits       = function() { return [ "s", "ms"]; };
10
PID_TimeUnits       = function() { return [ "s", "ms"]; };
-
 
11
PID_ControllerDirection = function() { return [ "direct", "reverse"]; };
11
PID_Times       = function() { return [ 1, 5, 10, 15, 20, 40, 60]; };
12
PID_Times       = function() { return [ 1, 5, 10, 15, 20, 40, 60]; };
12
PID_Aliases         = function() { return Module_GetAliasNames(PID_ModuleNames); };
13
PID_Aliases         = function() { return Module_GetAliasNames(PID_ModuleNames); };
13
PID_AvailableIds    = function() { return Module_GetAvailableIds(PID_ModuleNames); };
14
PID_AvailableIds    = function() { return Module_GetAvailableIds(PID_ModuleNames); };
14
PID_SensorAliases   = function() { return Module_GetAliasNames(PID_SensorModuleNames); };
15
PID_SensorAliases   = function() { return Module_GetAliasNames(PID_SensorModuleNames); };
15
PID_ActAliases      = function() { return Module_GetAliasNames(PID_ActModuleNames); };
16
PID_ActAliases      = function() { return Module_GetAliasNames(PID_ActModuleNames); };
Line 235... Line 236...
235
    return true;
236
    return true;
236
}
237
}
237
Console_RegisterCommand(PID_setActuator, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, PID_Aliases(), PID_ActAliases());  });
238
Console_RegisterCommand(PID_setActuator, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, PID_Aliases(), PID_ActAliases());  });
238
 
239
 
239
 
240
 
240
function PID_setParameters(alias_name, KP,KI,KD,Time,Unit)
241
function PID_setParameters(alias_name, KP,KI,KD,Time,Unit,ControllerDirection)
241
{
242
{
242
    if (arguments.length < 6)
243
    if (arguments.length < 6)
243
    {
244
    {
244
        Log("\033[31mNot enough parameters given.\033[0m\n");
245
        Log("\033[31mNot enough parameters given.\033[0m\n");
245
        return false;
246
        return false;
Line 255... Line 256...
255
                    "RegulatorTime"     : Time,
256
                    "RegulatorTime"         : Time,
256
                    "TimeUnit"     : Unit };
257
                    "TimeUnit"          : Unit };
257
        var variables_P_I = {   "K_P"     : KP,
258
        var variables_P_I = {   "K_P"           : KP,
258
                    "K_I"     : KI };
259
                    "K_I"           : KI };
259
        var variables_D_T = {   "K_D"     : KD,
260
        var variables_D_T = {   "K_D"           : KD,
-
 
261
                    "ControllerDirection"   : ControllerDirection,
260
                    "RegulatorTime"     : Time,
262
                    "RegulatorTime"         : Time,
261
                    "TimeUnit"     : Unit };
263
                    "TimeUnit"          : Unit };
262
        if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "CONFIG_PARAMETER", variables))
264
        if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "CONFIG_PARAMETER", variables))
263
        {
265
        {
264
            Log("\033[32mCommand sent successfully to " + name + ".\033[0m");
266
            Log("\033[32mCommand sent successfully to " + name + ".\033[0m");
Line 278... Line 280...
278
            Log("\033[31mFailed to send command to " + name + ".\033[0m\n");
280
            Log("\033[31mFailed to send command to " + name + ".\033[0m\n");
279
        }
281
        }
280
       
282
       
281
        if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "CONFIG_PARAMETER_D_T", variables_D_T))
283
        if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "CONFIG_PARAMETER_D_T", variables_D_T))
282
        {
284
        {
283
            Log("\033[32mK_D = " + KD + "RegTime = " + Time + "Unit = " + Unit + ".\033[0m\n");
285
            Log("\033[32mK_D = " + KD + " RegTime = " + Time + " Unit = " + Unit + " Direction = " + ControllerDirection +".\033[0m\n");
284
        }
286
        }
285
        else
287
        else
286
        {
288
        {
287
            Log("\033[31mFailed to send command to " + name + ".\033[0m\n");
289
            Log("\033[31mFailed to send command to " + name + ".\033[0m\n");
288
        }
290
        }
Line 296... Line 298...
296
        return false;
298
        return false;
297
    }
299
    }
298
 
300
 
299
    return true;
301
    return true;
300
}
302
}
301
Console_RegisterCommand(PID_setParameters, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, PID_Aliases(), PID_Constants(), PID_Constants(), PID_Constants(), PID_Times(), PID_TimeUnits()); });
303
Console_RegisterCommand(PID_setParameters, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, PID_Aliases(), PID_Constants(), PID_Constants(), PID_Constants(), PID_Times(), PID_TimeUnits(), PID_ControllerDirection()); });
302
 
304
 
303
 
305
 
304
function PID_setOutputMaxMin(alias_name, Max,Min)
306
function PID_setOutputMaxMin(alias_name, Max,Min)
305
{
307
{
306
    if (arguments.length < 3)
308
    if (arguments.length < 3)
Line 506... Line 508...
506
                    }
508
                    }
507
                   
509
                   
508
                    last_value["PID_status"] = { "value" : { "Measurment" : variables["Measurment"],"Reference" : variables["Reference"],"PWM" : variables["PWM"],"Sum" : variables["Sum"] }, "timestamp" : get_time() };
510
                    last_value["PID_status"] = { "value" : { "Measurment" : variables["Measurment"],"Reference" : variables["Reference"],"PWM" : variables["PWM"],"Sum" : variables["Sum"] }, "timestamp" : get_time() };
509
                    Storage_SetParameter("LastValues", alias_name, JSON.stringify(last_value));
511
                    Storage_SetParameter("LastValues", alias_name, JSON.stringify(last_value));
510
                }
512
                }
511
    //log("PID status: mea:" + this.Measurment + " ref:" + this.Reference + " pwm:" + this.PWM/100 + " sum:" + this.Sum + "\n");
513
    //Log("PID status: mea:" + this.Measurment + " ref:" + this.Reference + " pwm:" + this.PWM/100 + " sum:" + this.Sum + "\n");
512
                //this.callEvent("newValue", canMessage.getData("Id"));
514
                //this.callEvent("newValue", canMessage.getData("Id"));
513
 
515
 
514
    //var self = this;
516
    //var self = this;
515
    //  this.myHTTP.request(function(result, header, content) { self.httpCallback(result, header, content); }, "linuxz.mine.nu/canlogg/add.php?measurment="+ this.Measurment + "&reference="+this.Reference+"&pwm="+this.PWM/100+"&sum="+this.Sum+"&p="+this.K_P+"&i="+this.K_I+"&d="+this.K_D+"&timeunit="+this.TimeUnit+"&pidtime="+this.RegulatorTime+"");
517
    //  this.myHTTP.request(function(result, header, content) { self.httpCallback(result, header, content); }, "linuxz.mine.nu/canlogg/add.php?measurment="+ this.Measurment + "&reference="+this.Reference+"&pwm="+this.PWM/100+"&sum="+this.Sum+"&p="+this.K_P+"&i="+this.K_I+"&d="+this.K_D+"&timeunit="+this.TimeUnit+"&pidtime="+this.RegulatorTime+"");
516
            break;
518
            break;
Line 529... Line 531...
529
                    Storage_SetParameter("LastValues", alias_name, JSON.stringify(last_value));
531
                    Storage_SetParameter("LastValues", alias_name, JSON.stringify(last_value));
530
                }  
532
                }  
531
                break;
533
                break;
532
            case "Report_Interval":
534
            case "Report_Interval":
533
                this.myReportInterval = canMessage.getData("Time");
535
                this.myReportInterval = canMessage.getData("Time");
-
 
536
                break;
-
 
537
               
-
 
538
            case "CONFIG_PARAMETER_P_I":
-
 
539
                for (var alias_name in aliases_data)
-
 
540
                {
-
 
541
                    var last_value = {};
-
 
542
                    var last_value_string = Storage_GetParameter("LastValues", alias_name);
-
 
543
 
-
 
544
                    if (last_value_string)
-
 
545
                    {
-
 
546
                        last_value = eval("(" + last_value_string + ")");
-
 
547
                    }
-
 
548
                   
-
 
549
                    last_value["Parameters"] = { "value" : { "K_P" : variables["K_P"],"K_I" : variables["K_I"], "K_D" : last_value["Parameters"]["value"]["K_D"],"ControllerDirection" : last_value["Parameters"]["value"]["ControllerDirection"],"TimeUnit" : last_value["Parameters"]["value"]["TimeUnit"],"RegulatorTime" : last_value["Parameters"]["value"]["RegulatorTime"] }, "timestamp" : get_time() };
-
 
550
                    Storage_SetParameter("LastValues", alias_name, JSON.stringify(last_value));
-
 
551
                }  
-
 
552
            case "CONFIG_PARAMETER_D_T":
-
 
553
                for (var alias_name in aliases_data)
-
 
554
                {
-
 
555
                    var last_value = {};
-
 
556
                    var last_value_string = Storage_GetParameter("LastValues", alias_name);
-
 
557
 
-
 
558
                    if (last_value_string)
-
 
559
                    {
-
 
560
                        last_value = eval("(" + last_value_string + ")");
-
 
561
                    }
-
 
562
                    last_value["Parameters"] = { "value" : { "K_P" : last_value["Parameters"]["value"]["K_P"],"K_I" : last_value["Parameters"]["value"]["K_I"], "K_D" : variables["K_D"],"ControllerDirection" : variables["ControllerDirection"],"TimeUnit" : variables["TimeUnit"],"RegulatorTime" : variables["RegulatorTime"] }, "timestamp" : get_time() };
-
 
563
                    Storage_SetParameter("LastValues", alias_name, JSON.stringify(last_value));
-
 
564
                }  
-
 
565
            case "P_I_term":
-
 
566
                for (var alias_name in aliases_data)
-
 
567
                {
-
 
568
                    var last_value = {};
-
 
569
                    var last_value_string = Storage_GetParameter("LastValues", alias_name);
-
 
570
 
-
 
571
                    if (last_value_string)
-
 
572
                    {
-
 
573
                        last_value = eval("(" + last_value_string + ")");
-
 
574
                    }
-
 
575
                   
-
 
576
                    last_value["Debug"] = { "value" : { "P_term" : variables["P_term"],"I_term" : variables["I_term"],"D_term" : last_value["Debug"]["value"]["D_term"],"Output" : last_value["Debug"]["value"]["Output"],"Min" : last_value["Debug"]["value"]["Min"],"Max" : last_value["Debug"]["value"]["Max"] }, "timestamp" : get_time() };
-
 
577
                    Storage_SetParameter("LastValues", alias_name, JSON.stringify(last_value));
-
 
578
                    //Log("Got message DEBUG");
-
 
579
                }
-
 
580
            break; 
-
 
581
            case "D_term_Out":
-
 
582
                for (var alias_name in aliases_data)
-
 
583
                {
-
 
584
                    var last_value = {};
-
 
585
                    var last_value_string = Storage_GetParameter("LastValues", alias_name);
-
 
586
 
-
 
587
                    if (last_value_string)
-
 
588
                    {
-
 
589
                        last_value = eval("(" + last_value_string + ")");
-
 
590
                    }
-
 
591
                   
-
 
592
                    Log("Got message DEBUG");
-
 
593
                   
-
 
594
                    last_value["Debug"] = { "value" : { "P_term" : last_value["Debug"]["value"]["P_term"],"I_term" : last_value["Debug"]["value"]["I_term"],"D_term" : variables["D_term"],"Output" : variables["Output"],"Min" : last_value["Debug"]["value"]["Min"],"Max" : last_value["Debug"]["value"]["Max"] }, "timestamp" : get_time() };
-
 
595
                    Storage_SetParameter("LastValues", alias_name, JSON.stringify(last_value));
-
 
596
                    //Log("Got message DEBUG");
-
 
597
                }
-
 
598
            break;     
-
 
599
            case "OutMinMax":
-
 
600
                for (var alias_name in aliases_data)
-
 
601
                {
-
 
602
                    var last_value = {};
-
 
603
                    var last_value_string = Storage_GetParameter("LastValues", alias_name);
-
 
604
 
-
 
605
                    if (last_value_string)
-
 
606
                    {
-
 
607
                        last_value = eval("(" + last_value_string + ")");
-
 
608
                    }
-
 
609
                   
-
 
610
                    last_value["Debug"] = { "value" : { "P_term" : last_value["Debug"]["value"]["P_term"],"I_term" : last_value["Debug"]["value"]["I_term"],"D_term" : last_value["Debug"]["value"]["D_term"],"Output" : last_value["Debug"]["value"]["Output"], "Min" : variables["Min"],"Max" : variables["Max"] }, "timestamp" : get_time() };
-
 
611
                    Storage_SetParameter("LastValues", alias_name, JSON.stringify(last_value));
-
 
612
                    //Log("Got message DEBUG");
-
 
613
                }
534
                break;
614
            break; 
535
        }
615
        }
536
    }
616
    }
537
}
617
}
538
Module_RegisterToOnMessage("all", PID_OnMessage);
618
Module_RegisterToOnMessage("all", PID_OnMessage);