This is my component I used for the 4 speed gearbox on the Blue Cinci. I am not a 'coder', just a machinist.
component gear4 "Select gear range from requested spindle speed"; /* This component if for a 4 speed gearbox with a separate tram shifter. This has 5 solenoids to shift the gears and 4 limit switches to indicate the gearbox state. Tram state is not indicated by limit switch It will sense the spindle speed near zero from the VFD feedback and inhibit the shifting until the spindle is slow enough. It will drive the spindle very slow to allow the gears to mesh. The spindle over ride input stops the shifting when the range boundaries are crossed. */ pin in float spincmd "spindle command from EMC"; pin in float spinspeed "spindle speed from motor encoder"; pin in float spndlinching "gear mesh speed"; pin in float minspeed "lowest spindle speed"; pin in float gear1max "first gear max speed"; pin in float gear2max "second gear max speed"; pin in float gear3max "third gear max speed"; pin in float gear4max "fourth gear max speed"; pin in float gain "numerator of voltage ratio"; pin in float spinovride "spindle over ride percentage"; pin in bit ls31 "solenoid 31 limit switch"; pin in bit ls32 "solenoid 32 limit switch"; pin in bit ls33 "solenoid 33 limit switch"; pin in bit ls34 "solenoid 34 limit switch"; pin in bit tram "tram select input"; pin in bit shiftallow "allow shifting - connect to motion.spindle-brake output"; pin in bit spindlerunin "enable spindle drive request"; pin in bit spindlerevin "spindle reverse request"; pin in bit spinatzero "spindle at zero rpm"; pin in bit drawbar "drawbar in/out"; pin in bit tlchngreset "tool change reset button"; pin out float spinon "spindle speed command to VFD"; pin out float ratio "spindle gear ratio"; pin out float gear "spindle gear range"; pin out float scale "1 divided by ratio"; pin out bit spindlerunout "enable spindle drive command"; pin out bit spindlerevout "spindle reverse command"; pin out bit sol31 "shifting solenoid"; pin out bit sol32 "shifting solenoid"; pin out bit sol33 "tram solenoid"; pin out bit sol34 "shifting solenoid"; pin out bit sol35 "shifting solenoid"; function _; license "GPL"; ;; FUNCTION(_) { int Gear, CurrentGear = 0, InGear = 0; if (tram && shiftallow) { scale = 0.0; ratio = 0; spinon = 0.0; if (spinatzero) { spindlerunout = 0; sol33 = 1; } else { sol33 = 0; } } else { // set requested gear //////////////////// if (abs((spincmd/spinovride)) >= minspeed && abs((spincmd/spinovride)) <= gear4max) { if (abs((spincmd/spinovride)) <= gear1max) { Gear = 1; gear = 1; } else if (abs((spincmd/spinovride)) <= gear2max) { Gear = 2; gear = 2; } else if (abs((spincmd/spinovride)) <= gear3max) { Gear = 3; gear = 3; } else { Gear = 4; gear = 4; } } else { Gear = 0; gear = 0; } /// shift gears if necessary /////////// if (CurrentGear != Gear) { InGear = 0; // shift gears if (spinatzero) { switch (Gear) { case 0: break; case 1: sol31=1; sol32=0; sol33=0; sol34=1; sol35=0; break; case 2: sol31=1; sol32=0; sol33=0; sol34=0; sol35=1; break; case 3: sol31=0; sol32=1; sol33=0; sol34=1; sol35=0; break; case 4: sol31=0; sol32=1; sol33=0; sol34=0; sol35=1; break; case 5: ratio = 0.0; break; } } else { } ////////////////////////////////////////// if (Gear == 1 && ls31 && ls34 && !sol33) { ratio = 15.2; InGear = 1; scale = 1/ratio; } else if (Gear == 2 && ls31 && ls33 && !sol33) { ratio = 8.0; InGear = 1; scale = 1/ratio; } else if (Gear == 3 && ls32 && ls34 && !sol33) { ratio = 1.9; InGear = 1; scale = 1/ratio; } else if (Gear == 4 && ls32 && ls33 && !sol33) { ratio = 1.0; InGear = 1; scale = 1/ratio; } else { InGear = 0; } } else { } ////////////////////////////////////////// if (InGear && !shiftallow && !tram && drawbar && !tlchngreset && spindlerunin) { spindlerevout = spindlerevin; spindlerunout = 1; spinon = abs(spincmd) * ratio * gain; CurrentGear = Gear; } else { if (!InGear && !shiftallow && !tram) { spindlerevout = 0; spindlerunout = 1; ratio = 1; spinon = spndlinching * gain / gear4max; } else { if (spinatzero) { spindlerevout = 0; spindlerunout = 0; ratio = 0.0; spinon = 0.0; } else { spindlerevout = 0; ratio = 0.0; spinon = 0.0; } } } } } On Tue, Jan 28, 2025 at 6:34 PM andy pugh <bodge...@gmail.com> wrote: > On Tue, 28 Jan 2025 at 16:46, Horváth Csaba <hcs....@gmail.com> wrote: > > > I have an old milling machine with a hydraulic spindle speed range > > switch. The hydraulic valve has 2 coils (low and high speed). There are > > 2 feedback inductive sensors (for low and high speed). > > How can I solve this so that when a program needs to change the speed > > range, it does so automatically > > My lathe has a two-speed electronically controlled gearbox, but it > does not have the inductive switches to indicate which gear it is in. > > I use this HAL component (see the halcompile documents for how to use it) > > Note that this works in conjunction with a three-position switch so > that I can lock the spindle in high or low ratio, if I want to. > > > component gearchange "A component to choose spindle gears according to > spindle speed"; > pin in float speed-command; > pin in bit spindle-on; > pin in bit manual-low; > pin in bit manual-high; > pin in bit brake-enable; > pin out float motor-speed; > pin out bit low-gear; > pin out bit high-gear; > pin out bit brake; > param rw float low-ratio=3; > param rw float high-ratio=1; > param rw float max-low = 500; > > author "andy pugh"; > license "GPL"; > function _; > > ;; > > FUNCTION(_){ > static int old_M3; > > if (spindle_on) { > if (!old_M3){ // spindle off to on transition > if (manual_high) { > high_gear = 1; > low_gear = 0; > brake = 0; > } > else if (manual_low){ > high_gear = 0; > low_gear = 1; > brake = 0; > } else if (speed_command <= max_low){ > high_gear = 0; > low_gear = 1; > brake = 0; > } else { > high_gear = 1; > low_gear = 0; > brake = 0; > } > } > } else { //spindle off > high_gear = 0; > low_gear = 0; > brake = brake_enable; > } > > old_M3 = spindle_on; > > if (high_gear){ > motor_speed = speed_command * high_ratio; > } else if (low_gear){ > motor_speed = speed_command * low_ratio; > } > } > > -- > atp > "A motorcycle is a bicycle with a pandemonium attachment and is > designed for the especial use of mechanical geniuses, daredevils and > lunatics." > — George Fitch, Atlanta Constitution Newspaper, 1912 > > > _______________________________________________ > Emc-users mailing list > Emc-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/emc-users > -- Addressee is the intended audience. If you are not the addressee then my consent is not given for you to read this email furthermore it is my wish you would close this without saving or reading, and cease and desist from saving or opening my private correspondence. Thank you for honoring my wish. _______________________________________________ Emc-users mailing list Emc-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/emc-users