Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #492 from blazini36/patch-1
Create Spindle_monitor.comp
- Loading branch information
Showing
1 changed file
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
component spindle_monitor "spindle at-speed and underspeed detection"; | ||
pin in bit spindle-is-on; | ||
pin in float spindle-command; | ||
pin in float spindle-feedback; | ||
|
||
pin out bit spindle-at-speed; | ||
pin out bit spindle-underspeed; | ||
|
||
param rw unsigned level "state machine state"; | ||
param rw float threshold; | ||
|
||
function _; | ||
license "gpl v2 or higher"; | ||
|
||
;; | ||
|
||
#include <rtapi_math.h> | ||
|
||
FUNCTION(_) { | ||
|
||
switch (level){ | ||
case 0: // idle | ||
spindle_at_speed = 0; | ||
spindle_underspeed = 0; | ||
if (spindle_is_on) level = 1; | ||
break; | ||
case 1: // waiting for spindle-at-speed | ||
if ( ! spindle_is_on ) { | ||
level = 0; | ||
return; } | ||
if (fabs(spindle_command - spindle_feedback) < threshold) { | ||
level = 2; | ||
spindle_at_speed = 1; | ||
return; } | ||
break; | ||
case 2: // monitoring speed | ||
if ( ! spindle_is_on ) { | ||
level = 0; | ||
return; } | ||
if ((spindle_command - spindle_feedback) > threshold) { | ||
spindle_underspeed = 1; } | ||
break; | ||
default: | ||
// not sure how we got here, but fix the situation | ||
level = 0; | ||
} | ||
} |