component syringe2 "syringe control"; // syringe2.comp - control syringe for 2gbp // // modes: // 0: idle // en=0 // o-hvon = 0 // // 1: extruding <- mode0 && running && m68==1 // en=1 // o-hvon = 0 // vel-cmd = extrvel // // 2: spinning <- mode0 && running && m68==2 // en=1 // o-hvon = hv_arm // vel-cmd = spinvel // // 3: jogging <- mode0 && !running && (retract || depress) // en=1 // o-hvon = 0 // vel-cmd=1.0 or -1.0 // pin in float i-extrrate "extrusion velocity"; pin in float i-vectrate "vector rate"; pin in float i-m68 "M67/68 E0 Qvalue"; pin in float i-hvlevel "M68 E2 Qvalue"; pin in bit i-running "running G-code or MDI"; pin in bit i-hv_arm "arm HV"; pin in bit i-retract "syringe retract"; pin in bit i-depress "syringe depress"; pin out float o-velcmd "velocity command for stepgen"; pin out bit o-en "enable stepgen"; pin out bit o-hvon "HV is on"; pin out bit o-spinning "is spinning"; pin out bit o-extruding "is extruding"; pin out bit o-retract "syringe retract command"; pin out bit o-depress "syringe depress command"; pin out float o-mode "debug - current mode"; function _; option singleton yes; license "GPL"; author "Ralph Stirling"; // Date: 2020-11-12 variable int mode = 0; ;; #include FUNCTION(_) { o_mode = mode; switch (mode) { default: mode = 0; case 0: // idle o_en = 0; o_spinning = 0; o_extruding = 0; o_retract = o_depress = 0; o_velcmd = 0; o_hvon = 0; if (i_running && i_m68==1) mode = 1; // start velocity proportional extruding if (i_running && i_m68==2) mode = 2; // start constant extruding if (!i_running && (i_retract != i_depress)) mode = 3; // start jogging break; case 1: // extruding o_en = 1; o_spinning = 0; o_extruding = 1; o_velcmd = i_extrrate * i_vectrate; if ((i_hvlevel > 0.01) || (i_hvlevel < -0.01)) o_hvon = i_hv_arm; else o_hvon = 0; if ((i_running && i_m68==0) || (!i_running)) mode = 0; if (i_running && i_m68==2) mode = 2; break; case 2: // spinning o_en = 1; o_spinning = 1; o_extruding = 0; o_velcmd = i_extrrate/3600; o_hvon = i_hv_arm; if ((i_running && i_m68==0) || (!i_running)) mode = 0; if (i_running && i_m68==1) mode = 1; break; case 3: // jogging o_en = 1; o_spinning = 0; o_extruding = 0; o_hvon = 0; if (i_retract) { o_retract = 1; o_depress = 0; o_velcmd = -0.1; } else if (i_depress) { o_retract = 0; o_depress = 1; o_velcmd = 0.1; } if (i_retract == i_depress) mode = 0; break; } }