Stylesheet ../dokuwiki/css/_search.css not found, using ../dokuwiki/css/_search.less instead. Please contact developer of "altronic" template.
Stylesheet ../dokuwiki/css/_admin.css not found, using ../dokuwiki/css/_admin.less instead. Please contact developer of "altronic" template.

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
documents:de4000:de4000script [2022/01/25 15:52]
twebster
documents:de4000:de4000script [2022/07/08 13:11] (current)
rjackson
Line 59: Line 59:
  
 **Example:** **Example:**
-<code>+<code lua>
 local suction = get_channel_val(1,1) local suction = get_channel_val(1,1)
 local discharge1 = get_channel_val(1,3) local discharge1 = get_channel_val(1,3)
Line 94: Line 94:
 {{:documents:de4000:scripting_dashboard_modbus_script_2.jpg?400|}} {{:documents:de4000:scripting_dashboard_modbus_script_2.jpg?400|}}
  
-<code>+<code lua>
 defaultModbus() defaultModbus()
 set_modbus(300,diff) set_modbus(300,diff)
Line 103: Line 103:
 40300 Modbus Register 40300 Modbus Register
  
-==== - DE4000 Lua Script API ====+==== - DE-4000 Lua Script API ====
 <markdown> <markdown>
 **CUSTOM FUNCTIONS FOR SCRIPTING** **CUSTOM FUNCTIONS FOR SCRIPTING**
Line 357: Line 357:
 ==== - Master Control Script ==== ==== - Master Control Script ====
  
-{{ :documents:de4000:control.jpg?nolink&800 |}}+{{ :documents:de4000:control.jpg?nolink&600 |}}
  
 When you enter a control setup under the Global Control page the code that runs is called MasterControl. When you enter a control setup under the Global Control page the code that runs is called MasterControl.
  
-If you wish to modify this functionality you can copy this code into the Control Script editor and make your changes to the standard configuration. +If you wish to modify this functionality you can copy this code into the Control Script editor and{{ :documents:de4000:scripting_dashboard_control_script.jpg?nolink|}} make your changes to the standard configuration. 
-{{ :documents:de4000:scripting_dashboard_control_script.jpg?nolink|}}+
  
 <file lua [enable_line_numbers="true"] mastercontrol.lua> <file lua [enable_line_numbers="true"] mastercontrol.lua>
Line 401: Line 401:
     recycleCtrl = true     recycleCtrl = true
   end   end
-  --if recycleCtrl and spSuctType == "linear" and outputLow2 > suctSp then + 
-  --  recycleSuctionRev = true +
-  --end +
-  --if recycleCtrl and spDischType == "linear" and  recycleMax < dischSp then +
-  --  recycleDischargeRev = true +
-  --end +
-  --print("disch: "..tostring(disch).." suct:"..tostring(suct)) +
-  --local suct = 500+
   local dischPct = 100   local dischPct = 100
   local suctPct = 100   local suctPct = 100
Line 513: Line 506:
   end   end
  
-  --print("suctOutput dischOutput: "..math.floor(suctOutput).." "..math.floor(dischOutput)) +  
- +
- +
- +
   local minOutput = 100   local minOutput = 100
   local winning = 0   local winning = 0
Line 576: Line 565:
     end     end
   end   end
- 
- 
- 
- 
- 
- 
---[[ 
-      local idleSpeed = get_gbl("idleSpeed",0) 
-      local lowSpeed = get_gbl("lowSpeed",0) 
-      local highSpeed = get_gbl("highSpeed",0) 
-      local speedPct = 0 
- 
-      if st > highSpeed then st = highSpeed end 
-      if st < lowSpeed then st = lowSpeed end 
-      if get_state() ~= 8 then 
-        --st = idleSpeed 
-      end 
-      set_sVirt("Speed Target",st) 
-      speedPct = (st - lowSpeed) /(highSpeed - lowSpeed) * 100 
-      if speedPct < 0 then speedPct = 0 end 
-      if speedPct > 100 then speedPct = 100 end 
-      st = speedPct 
- 
-      if idleSpeed < lowSpeed then 
-        local speedRpm = speedPct / 100  * (highSpeed - lowSpeed) + lowSpeed 
-        st = (speedRpm - idleSpeed) / (highSpeed - idleSpeed) * 100 
-        --st = (st - idleSpeed) / (highSpeed - idleSpeed) * 100 
-      end 
-]]-- 
- 
- 
  
   --if manMode == 1 and get_state() == 8 then   --if manMode == 1 and get_state() == 8 then
Line 661: Line 619:
   end   end
  
- 
- 
- 
- 
- 
-  --speedTarget = get_sGbl("speedTarget",0) 
   if manSpeed < lowSpeed then   if manSpeed < lowSpeed then
     manSpeed = lowSpeed     manSpeed = lowSpeed
Line 684: Line 636:
   local output2 = 0   local output2 = 0
   if spSuctType == "pid" or spDischType == "pid" then   if spSuctType == "pid" or spDischType == "pid" then
-    --Map minOutput to output1 
     output1 = map_range(outputLow,outputHigh,minOutput)     output1 = map_range(outputLow,outputHigh,minOutput)
     set_sVirt("out1",output1)     set_sVirt("out1",output1)
-    --Map minOutput to ourput2 
     output2 = map_range(outputLow2,outputHigh2,recycleMinOutput)     output2 = map_range(outputLow2,outputHigh2,recycleMinOutput)
     set_sVirt("out2",output2)     set_sVirt("out2",output2)
Line 694: Line 644:
       if hasRPM then       if hasRPM then
         local speedRpm = output1 / 100  * (highSpeed - lowSpeed) + lowSpeed         local speedRpm = output1 / 100  * (highSpeed - lowSpeed) + lowSpeed
-        --set_ao_val(outputTerm,outputChan,(speedRpm - idleSpeed) / (maxSpeed - idleSpeed) * 100) 
         speedTarget = (speedRpm - idleSpeed) / (maxSpeed - idleSpeed) * 100         speedTarget = (speedRpm - idleSpeed) / (maxSpeed - idleSpeed) * 100
       else       else
-        --set_ao_val(outputTerm,outputChan,output1) 
         speedTarget = output1         speedTarget = output1
       end       end
Line 712: Line 660:
     if get_state() < 8 then speedTarget = 0 end     if get_state() < 8 then speedTarget = 0 end
     set_sGbl("speedTarget",speedTarget)     set_sGbl("speedTarget",speedTarget)
-    --set_sGbl("a"..outputChan,speedTarget) 
     set_ao_val(outputTerm,outputChan,speedTarget)     set_ao_val(outputTerm,outputChan,speedTarget)
-    --set_ao_val(outputChan,speedTarget) 
-    --print(suctOutput.." "..dischOutput.." "..speedTarget) 
     set_sVirt("spTarget",speedTarget)     set_sVirt("spTarget",speedTarget)
-    --set_speed_val(1,speedTarget) 
  
     if hasRPM then     if hasRPM then
Line 749: Line 693:
     if recycleCtrl then     if recycleCtrl then
       local recyclePct = map_range(outputLow2,outputHigh2,recycleMinOutput)       local recyclePct = map_range(outputLow2,outputHigh2,recycleMinOutput)
-      --if recycleRevAct == 1 then recyclePct = 100 - recyclePct end 
       if recyclePct <= recycleTarget then       if recyclePct <= recycleTarget then
         recycleTarget = recycleTarget - rampRate2         recycleTarget = recycleTarget - rampRate2
Line 766: Line 709:
         recycleOutput = 100 - recycleOutput         recycleOutput = 100 - recycleOutput
       end       end
-      --set_sGbl("a"..recycleChan,recycleOutput) 
       set_ao_val(recycleTerm,recycleChan,recycleOutput)       set_ao_val(recycleTerm,recycleChan,recycleOutput)
       set_sGbl("recycleTarget",recycleTarget)       set_sGbl("recycleTarget",recycleTarget)
Line 779: Line 721:
     if get_state() < 8 then speedTarget = 0 end     if get_state() < 8 then speedTarget = 0 end
     set_sGbl("speedTarget",speedTarget)     set_sGbl("speedTarget",speedTarget)
-    --set_sGbl("a"..outputChan,speedTarget) 
     set_ao_val(outputTerm,outputChan,speedTarget)     set_ao_val(outputTerm,outputChan,speedTarget)
-    --set_ao_val(outputChan,speedTarget) 
-    --print(suctOutput.." "..dischOutput.." "..speedTarget) 
     set_sVirt("spTarget",speedTarget)     set_sVirt("spTarget",speedTarget)
-    --set_speed_val(1,speedTarget) 
     local sRpm = (speedTarget/100) * maxDiff + idleSpeed     local sRpm = (speedTarget/100) * maxDiff + idleSpeed
     set_sVirt("Speed Target",math.floor(sRpm + 0.5))     set_sVirt("Speed Target",math.floor(sRpm + 0.5))