Subversion Repositories HomeAutomation

Rev

Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed

  1.  
  2. function PID(type, name, id)
  3. {
  4.     this.CanService(type, name, id);
  5.     this.myLastValue = new Array();
  6.     this.registerEventCallback("online", function(args) { _PID_Online(args); });
  7. }
  8.  
  9. function _PID_Online(data) {
  10.     var canMessage = new CanMessage("act", "To_Owner", this.myName, this.myId, "CONFIG_SENSOR");
  11.     sendMessage(canMessage);
  12.     canMessage = new CanMessage("act", "To_Owner", this.myName, this.myId, "CONFIG_ACTUATOR");
  13.     sendMessage(canMessage);
  14.     canMessage = new CanMessage("act", "To_Owner", this.myName, this.myId, "CONFIG_PARAMETER");
  15.     sendMessage(canMessage);
  16.     canMessage = new CanMessage("act", "To_Owner", this.myName, this.myId, "Report_Interval");
  17.     sendMessage(canMessage);
  18. }
  19.  
  20. extend(PID, CanService);
  21.  
  22. PID.prototype.myReportInterval = null;
  23.  
  24. PID.prototype.sensorModuleType = null;
  25. PID.prototype.sensorModuleId = null;
  26. PID.prototype.sensorId = null;
  27.  
  28. PID.prototype.actuatorModuleType = null;
  29. PID.prototype.actuatorModuleId = null;
  30. PID.prototype.actuatorId = null;
  31.  
  32. PID.prototype.K_P= null;
  33. PID.prototype.K_I= null;
  34. PID.prototype.K_D= null;
  35. PID.prototype.TimeUnit= null;
  36. PID.prototype.RegulatorTime = null;
  37.  
  38. PID.prototype.Measurment = null;
  39. PID.prototype.Reference = null;
  40. PID.prototype.PWM = null;
  41. PID.prototype.Sum = null;
  42.  
  43. PID.prototype.canMessageHandler = function(canMessage)
  44. {
  45.     if (canMessage.getDirectionFlag() == "From_Owner")
  46.     {
  47.         switch (canMessage.getCommandName())
  48.         {
  49.         case "DEBUG":
  50.             //<variable name="P_term" type="uint" start_bit="0" bit_length="16" unit="" description=""/>
  51.             //<variable name="I_term" type="uint" start_bit="16" bit_length="16" unit="" description=""/>
  52.             //<variable name="D_term" type="uint" start_bit="32" bit_length="16" unit="" description=""/>
  53.             //<variable name="Sum" type="uint" start_bit="48" bit_length="16" unit="" description=""/>
  54.             //this.myLastValue[canMessage.getData("Id")] = canMessage.getData("Value");
  55.             //this.callEvent("newValue", canMessage.getData("Id"));
  56.         break;
  57.         case "CONFIG_SENSOR":
  58.             this.sensorModuleType= canMessage.getData("sensorModuleType");
  59.             this.sensorModuleId= canMessage.getData("sensorModuleId");
  60.             this.sensorId= canMessage.getData("sensorId");
  61.             //this.callEvent("newValue", canMessage.getData("Id"));
  62.         break;
  63.         case "CONFIG_ACTUATOR":
  64.             this.actuatorModuleType= canMessage.getData("actuatorModuleType");
  65.             this.actuatorModuleId= canMessage.getData("actuatorModuleId");
  66.             this.actuatorId= canMessage.getData("actuatorId");
  67.             //this.callEvent("newValue", canMessage.getData("Id"));
  68.  
  69.         break;
  70.         case "CONFIG_PARAMETER":
  71.             this.K_P= canMessage.getData("K_P");
  72.             this.K_I= canMessage.getData("K_I");
  73.             this.K_D= canMessage.getData("K_D");
  74.             this.TimeUnit= canMessage.getData("TimeUnit");
  75.             this.RegulatorTime= canMessage.getData("RegulatorTime");
  76.             //this.callEvent("newValue", canMessage.getData("Id"));
  77.         break;
  78.         case "PID_STATUS":
  79.             this.Measurment= canMessage.getData("Measurment");
  80.             this.Reference= canMessage.getData("Reference");
  81.             this.PWM= canMessage.getData("PWM");
  82.             this.Sum= canMessage.getData("Sum");
  83.             //this.callEvent("newValue", canMessage.getData("Id"));
  84.         break;
  85.         case "Temperature_Celsius":
  86.             this.Reference= canMessage.getData("Value");
  87.             //this.callEvent("newValue", canMessage.getData("Id"));
  88.         break;
  89.         case "Report_Interval":
  90.             this.myReportInterval = canMessage.getData("Time");
  91.         break;
  92.         }
  93.     }
  94.     this.CanService.prototype.canMessageHandler.call(this, canMessage);
  95. }
  96.  
  97. PID.prototype.setValue = function(temperature)
  98. {
  99.     var canMessage = new CanMessage("act", "To_Owner", this.myName, this.myId, "Temperature_Celsius");
  100.     canMessage.setData("Value", temperature);
  101.     canMessage.setData("SensorId", 0);
  102.     sendMessage(canMessage);
  103. }
  104.  
  105.  
  106. PID.prototype.setReportInterval = function(time)
  107. {
  108.     var canMessage = new CanMessage("act", "To_Owner", this.myName, this.myId, "Report_Interval");
  109.     canMessage.setData("Time", time);
  110.     sendMessage(canMessage);
  111. }
  112.  
  113. PID.prototype.getReportInterval = function(time)
  114. {
  115.    
  116. }
  117.