ezeio2:scriptref:pid_new

Differences

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

Link to this comparison view

Next revision
Previous revision
ezeio2:scriptref:pid_new [2020-08-14 23:20] – created andrehezeio2:scriptref:pid_new [2022-03-30 23:44] (current) andreh
Line 5: Line 5:
 === Description === === Description ===
  
-<code>PID_new( pid[], Float:in, Float:out )</code> +<code>PID_new( pid[], Float:set, Float:out ) // set up new PID</code> 
-<code>PID_dir( pid[], direction )</code> +<code>PID_dir( pid[], direction ) // set direction of control</code> 
-<code>PID_set( pid[], Float:set )</code> +<code>PID_set( pid[], Float:set ) // adjust the target value</code> 
-<code>PID_tune( pid[], Float:Kp, Float:Ki, Float:Kd )</code> +<code>PID_tune( pid[], Float:Kp, Float:Ki, Float:Kd ) // set the P, I, D parameters</code> 
-<code>PID_tune( pid[], Float:min, Float:max )</code> +<code>PID_limits( pid[], Float:min, Float:max ) // set the control range</code> 
-<code>PID_update( pid[], Float:in )</code>+<code>PID_update( pid[], Float:in ) // update PID with feedback, and return new control value</code>
  
 === Parameters === === Parameters ===
  
-| ''in''Feedback value |+| ''set''setpoint / target |
 | ''out'' | Initial output value | | ''out'' | Initial output value |
 | ''direction'' | 1 (normal) or -1 (reverse) | | ''direction'' | 1 (normal) or -1 (reverse) |
-| ''set'' | setpoint / target | 
 | ''Kp'' | Proportional component | | ''Kp'' | Proportional component |
 | ''Ki'' | Integral response component | | ''Ki'' | Integral response component |
Line 36: Line 35:
    main()     main() 
    {    {
-      // Initialize the PID with mid range input and no output+      // Initialize the PID with target and no output
       PID_new(p, 50.0, 0.0);       PID_new(p, 50.0, 0.0);
              
Line 55: Line 54:
              
       // Read and scale a sensor input (0-100psi from 4-20mA sensor)       // Read and scale a sensor input (0-100psi from 4-20mA sensor)
-      psi = 100.0 * ((GetInputValue(1)-4000)/16000);+      psi = 100.0 * ((GetInputValue(1, INVAL_RAW)-4000)/16000);
              
       // Update the PID with the feedback value       // Update the PID with the feedback value
Line 66: Line 65:
 </code> </code>
  
-NOTE: The values used in the above example are not takes from a real world setup. Please make sure you understand how PID works and how to correctly tune them if you use any of the PID functions.+NOTE: The values used in the above example are not from a real world setup. Please make sure you understand how PID works and how to correctly tune the variables if you use any of the PID functions.
  
  
  • ezeio2/scriptref/pid_new.1597447223.txt.gz
  • Last modified: 2020-08-14 23:20
  • by andreh