component machineactive "decides when the machine is active vs idle"; /* Author: DJ Delorie dj@delorie.com */ /* http://www.delorie.com/cnc/machineactive.comp */ pin out bit active; pin in float velocity = 0 "connect to motion.current_vel"; pin in bit running = 0 "connect to halui.program.is-running"; pin in bit estop = 0 "connect to your estop"; param rw u32 timeout = 1 "idle timeout in seconds"; /* Example usage in a *.hal file: loadrt machineactive count=1 addf machineactive.0 servo-thread net program-running halui.program.is-running => machineactive.0.running net estop => machineactive.0.estop net machine-moving motion.current-vel => machineactive.0.velocity net machine-active <= machineactive.0.active net machine-active => parport.0.pin-01-out */ variable double idle_time; function _; license "GPL"; ;; FUNCTION(_) { if (estop) { active = 0; idle_time = timeout + 1; } if (velocity != 0 || running) { active = 1; idle_time = 0; } else { idle_time += fperiod; if (idle_time > timeout) active = 0; else active = 1; } }