component toolchanger.comp "refrence to project" //HAL IO Control for ToolChange pin in bit ToolChange "from hal subsystem toolchange request"; pin out bit ToolChanged "pin out to hal subsystem tool change was sucessful"; pin out bit ToolPrepared "send signal to HAL that the next requested tool is avaiable and ready not sure if implemtning in first go round"; pin out bit Estop = false "fatal fault condition disable toolchanger and stop machine"; pin out bit ToolChangerFault = false "IoControlV2 offers toolchanger fault path will investigae for use"; pin in bit s32 ToolNumber "Requested Tool Number from HAL and RS247NGC intepreter"; pin in bit s32 CurrentToolNumber "injection of Current Tool Number in Spindle From Hal"; pin in bit s32 PrepareToolNumber "Tool to have ready next should only be allowable if no tool in spindle not sure f implementing first go round"; // Single Shot Start Flags pin out bit OneShotStart = true "Set to true to be cleared, this prevents fall through execution later on"; pin out bit ToolChanger = false "Contol flag to enable and disable toolchange, we set this true when ToolChange is sent by hal and use it to enable/disable after that"; pin out bit ErrorState = true "Errors allowable only in certain states IE not when carousel is moving etc, mostly used for tool number and pocket errors at start up"; // other warning and error flags to stop message go here // Spindle Orient IO and Timer Functions Here //inputs pin in bit SpindleEnable = false "spinde input MUST be disabled, leave disconncted if your spindle require enabling to stay oriented" pin in bit SpindleBrake = false " use some kind of input to set this pin to true when spindle not moving or locked etc " pin in bit s32 SpindleOrientTimeLimit = 10 "set time limit for spindle orient before faulting out"; pin in bit SpindleOriented = false "input from hal to make sure spindle oriented before starting tool change manuevers"; //outputs pin out bit SpindleTimedOutError = true "Spindle time out error flag and message suppresion"; pin out bit SpindleOrient = false "out to HAL to command spindle to orient"; // inputs for carousel or belt style tool storage along with important things like spinlde commands to lock unlock etc the tool // chose encoding system pin in bit IndexType = false "index encoding schemce 1 pulse per pocket"; pin in bit EncoderType false " sets counting logic to encoder type" // inputs for Index and Home switch style carousel pin in bit IndexPulse = false "index pulse input to count pockets 1 per pocket"; pin in bit IndexHome = false "secondary input to home carousel assembly, ON when pocket 1 is centered in opening etc" // inputs for Encoder with Index feature pin in bit s32 EncoderInput = 0 "encoder input from hal to figure position based on pulse count per pocket"; pin in bit EncoderHome = false "encoder index (home point for pocket 1) input from hal " pin in bit s32 PulsePerPocket = 0 "input divisor to gets pulse per pocket" // external carousel controls pin in bit JogFwd = false "jog forward function"; pin in bit JogRev = false "jog backwar function"; // external control to home the carousel pin in bit HomeCarousel = false "input to home carousel"; pin out bit HomeSensor = false "output for home sensor status"; //decoder outputs from carousel sensors param rw s32 PocketCount = 0 "store the pocket count here and output to hal"; param rw s32 Pocket = 0 "this is the actual value of the pocket output to hal"; param rw s32 PocketRequest = 0 "store this variable here and output to hal for diagnostics"; // carousel motor controls pin out bit MotorFwd = false "carousel motor fwd outpt"; pin out bit MotorRev = false "carousel motor rev output" // will be adding steps and pwm in near future for stepper and other motors types //tool in spindle lock input pin in bit ToolLocked = false "input sensor tool clamp locked"; pin in bit ToolUnlocked = false "input sensor tool clamp unlocked"; // delay timers used to manage the mechanics of the machine, you often need to wait for a mechanical response becuase machine is slower than Computer MUCH MUCH MUCH SLOWER pin in bit float Block01Timer01Setting = 0 " if the output is requested on, before checking to see if the next move can be made, the program stops and waits before moving forward and triggering faults for out of bounds conditions"; pin in bit float Block02Timer01Setting = 0 " if the output is requested on, before checking to see if the next move can be made, the program stops and waits before moving forward and triggering faults for out of bounds conditions"; pin in bit float Block03Timer01Setting = 0 " if the output is requested on, before checking to see if the next move can be made, the program stops and waits before moving forward and triggering faults for out of bounds conditions"; pin in bit float Block04Timer01Setting = 0 " if the output is requested on, before checking to see if the next move can be made, the program stops and waits before moving forward and triggering faults for out of bounds conditions"; pin in bit float Block05Timer01Setting = 0 " if the output is requested on, before checking to see if the next move can be made, the program stops and waits before moving forward and triggering faults for out of bounds conditions"; pin in bit float Block06Timer01Setting = 0 " if the output is requested on, before checking to see if the next move can be made, the program stops and waits before moving forward and triggering faults for out of bounds conditions"; pin in bit float Block07Timer01Setting = 0 " if the output is requested on, before checking to see if the next move can be made, the program stops and waits before moving forward and triggering faults for out of bounds conditions"; pin in bit float Block08Timer01Setting = 0 " if the output is requested on, before checking to see if the next move can be made, the program stops and waits before moving forward and triggering faults for out of bounds conditions"; pin in bit float Block09Timer01Setting = 0 " if the output is requested on, before checking to see if the next move can be made, the program stops and waits before moving forward and triggering faults for out of bounds conditions"; pin in bit float Block10Timer01Setting = 0 " if the output is requested on, before checking to see if the next move can be made, the program stops and waits before moving forward and triggering faults for out of bounds conditions"; // Block monitoring system for execution. these are the BIG cases,these blocks start and end executions blocks. B1count variable operates inside Block 1, etc and so forth. // this is where we will implement the goto and jump logic for different control needs. only need 3 blocks of executiuon, use 3 blocks etc. pin out bit Block01 = false "Logic Control Flag"; pin out bit Block02 = false "Logic Control Flag"; pin out bit Block03 = false "Logic Control Flag"; pin out bit Block04 = false "Logic Control Flag"; pin out bit Block05 = false "Logic Control Flag"; pin out bit Block06 = false "Logic Control Flag"; pin out bit Block07 = false "Logic Control Flag"; pin out bit Block08 = false "Logic Control Flag"; pin out bit Block09 = false "Logic Control Flag"; pin out bit Block10 = false "Logic Control Flag"; // bypass flags to jump over Big Block cases pin in bit JumpBlock01 = false "Logic Control Flag"; pin in bit JumpBlock02 = false "Logic Control Flag"; pin in bit JumpBlock03 = false "Logic Control Flag"; pin in bit JumpBlock04 = false "Logic Control Flag"; pin in bit JumpBlock05 = false "Logic Control Flag"; pin in bit JumpBlock06 = false "Logic Control Flag"; pin in bit JumpBlock07 = false "Logic Control Flag"; pin in bit JumpBlock08 = false "Logic Control Flag"; pin in bit JumpBlock09 = false "Logic Control Flag"; pin in bit JumpBlock10 = false "Logic Control Flag"; // set carousel motion at end of this block, when the proper number of execution steps are reached, then allow for the carousel to change he tool number prior // to inserting into the spindle pin in bit AllowCarouselBlock01 = false "logic to operate carousel at end of a given logic block"; pin in bit AllowCarouselBlock02 = false "logic to operate carousel at end of logic block"; pin in bit AllowCarouselBlock03 = false "logic to operate carousel at end of logic block"; pin in bit AllowCarouselBlock04 = false "logic to operate carousel at end of logic block"; pin in bit AllowCarouselBlock05 = false "logic to operate carousel at end of logic block"; pin in bit AllowCarouselBlock06 = false "logic to operate carousel at end of logic block"; pin in bit AllowCarouselBlock07 = false "logic to operate carousel at end of logic block"; pin in bit AllowCarouselBlock08 = false "logic to operate carousel at end of logic block"; pin in bit AllowCarouselBlock09 = false "logic to operate carousel at end of logic block"; pin in bit AllowCarouselBlock10 = false "logic to operate carousel at end of logic block"; //Program Flow Control for inside the blocks and racking System these turn on and off with each execution step to prevnent fall through execution // and to sequence the logic properly. All viewable in hal to debug execution hangs // Block01 control flags pin out bit B1Count01 = false "Logic Control Flag"; pin out bit B1Count02 = false "Logic Control Flag"; pin out bit B1Count03 = false "Logic Control Flag"; // Block02 control flags pin out bit B2Count01 = false "Logic Control Flag"; pin out bit B2Count02 = false "Logic Control Flag"; pin out bit B2Count03 = false "Logic Control Flag"; // Block03 control flags pin out bit B3Count01 = false "Logic Control Flag"; pin out bit B3Count02 = false "Logic Control Flag"; pin out bit B3Count03 = false "Logic Control Flag"; // Block04 control flags pin out bit B4Count01 = false "Logic Control Flag"; pin out bit B4Count02 = false "Logic Control Flag"; pin out bit B4Count03 = false "Logic Control Flag"; // Block05 control flags pin out bit B5Count01 = false "Logic Control Flag"; pin out bit B5Count02 = false "Logic Control Flag"; pin out bit B5Count03 = false "Logic Control Flag"; // Block06 control flags pin out bit B6Count01 = false "Logic Control Flag"; pin out bit B6Count02 = false "Logic Control Flag"; pin out bit B6Count03 = false "Logic Control Flag"; // Block07 control flags pin out bit B7Count01 = false "Logic Control Flag"; pin out bit B7Count02 = false "Logic Control Flag"; pin out bit B7Count03 = false "Logic Control Flag"; // Block08 control flags pin out bit B8Count01 = false "Logic Control Flag"; pin out bit B8Count02 = false "Logic Control Flag"; pin out bit B8Count03 = false "Logic Control Flag"; // Block09 control flags pin out bit B9Count01 = false "Logic Control Flag"; pin out bit B9Count02 = false "Logic Control Flag"; pin out bit B9Count03 = false "Logic Control Flag"; // Block10 control flags pin out bit B10Count01 = false "Logic Control Flag"; pin out bit B10Count02 = false "Logic Control Flag"; pin out bit B10Count03 = false "Logic Control Flag"; // Digital IO from LogicalBlocks pin out bit Block01OutPut01 "output to turn on of off something digital"; pin in bit Block01InPut01 "input to turn on of off something digital"; pin out bit Block02OutPut01 "output to turn on of off something digital"; pin in bit Block02InPut02 "input to turn on of off something digital"; pin out bit Block03OutPut01 "output to turn on of off something digital"; pin in bit Block03InPut01 "output to turn on of off something digital"; pin out bit Block04OutPut01 "output to turn on of off something digital"; pin in bit Block04InPut01 "input to turn on of off something digital"; pin out bit Block05OutPut01 "output to turn on of off something digital"; pin in bit Block05kInPut01 "input to turn on of off something digital"; pin out bit Block06OutPut01 "output to turn on of off something digital"; pin in bit Block06InPut01 "input to turn on of off something digital"; pin out bit Block07OutPut01 "output to turn on of off something digital"; pin in bit Block07InPut01 "input to turn on of off something digital"; pin out bit Block08OutPut01 "output to turn on of off something digital"; pin in bit Block08InPut01 "input to turn on of off something digital"; pin out bit Block09OutPut01 "output to turn on of off something digital"; pin in bit Block09InPut01 "input to turn on of off something digital"; pin out bit Block10OutPut01 "output to turn on of off something digital"; pin in bit Block10InPut01 "input to turn on of off something digital"; // Block Timer Variables in use these are watchable // Timer Variables use for Motion Timing and Diganostics param rw float Block01Timer01 = 0 "Timer delay variable initialization watchable in HAL uised internally"; param rw float Block02Timer01 = 0 "Timer delay variable initialization watchable in HAL uised internally"; param rw float Block03Timer01 = 0 "Timer delay variable initialization watchable in HAL uised internally"; param rw float Block04Timer01 = 0 "Timer delay variable initialization watchable in HAL uised internally"; param rw float Block05Timer01 = 0 "Timer delay variable initialization watchable in HAL uised internally"; param rw float Block06Timer01 = 0 "Timer delay variable initialization watchable in HAL uised internally"; param rw float Block08Timer01 = 0 "Timer delay variable initialization watchable in HAL uised internally"; param rw float Block09Timer01 = 0 "Timer delay variable initialization watchable in HAL uised internally"; param rw float Block10Timer01 = 0 "Timer delay variable initialization watchable in HAL uised internally"; // output message flood prevention flags pin out bit Block01FloodFlag = false " flag to stop message flooding once error condition met"; pin out bit Block02FloodFlag = false " flag to stop message flooding once error condition met"; pin out bit Block03FloodFlag = false " flag to stop message flooding once error condition met"; pin out bit Block04FloodFlag = false " flag to stop message flooding once error condition met"; pin out bit Block05FloodFlag = false " flag to stop message flooding once error condition met"; pin out bit Block06FloodFlag = false " flag to stop message flooding once error condition met"; pin out bit Block07FloodFlag = false " flag to stop message flooding once error condition met"; pin out bit Block08FloodFlag = false " flag to stop message flooding once error condition met"; pin out bit Block09FloodFlag = false " flag to stop message flooding once error condition met"; pin out bit Block10FloodFlag = false " flag to stop message flooding once error condition met"; // misc error flag flood prevention pin out bit SpindleNotAlignedError = false "message flooding is annoying prevent it here"; Author everybody interested function_;; // declare variable renaming here to stop confusion later !!! Toolchanger = Toolchange; // this is renamed here becuase the incoming pin is not cancelable from the component program PocketRequest = toolnumber; // setup the tool change enviroment in a safe way, we don't wan to crash the machine. if(toolchange == true ){ SpindleOrient = true; } if ( SpindleOrient == true){ SpindleOrientTimer += fperiod; } if (SpindleOrientTimer > SpindleOrientTimeLimit && SpindleOrient == true && toolchange == true ){ Block01 = false; Block01DigitalOut01= false; // disable output ToolChanger = false; // stop toolchange code flow ToolChangerFault= true; // set this error flag Estop = true; if (SpindleTimedOutError == false ){ // block repetitive error messages they are annoying and flood the system rtapi_print_msg(RTAPI_MSG_ERR, "Fault 000 Spindle Took To long to Align For ToolChange ESTOP ON"); SpindleTimedOutError = true; // set flag to block prinint excesive error messages } }else{ if (SpindleOrientTimer < SpindleOrientTimeLimit && SPindleOriented == true) Block1 = true; ToolChanger = false; SpindleOrient = false; } // really demand that all these things are true PRIOR to starting the toolchange MASSIVE IMPORTANCE FOR SAFETY !!!!!!! if (SpindleOriented == true && Toolchange == true && SpindleEnable == false && SpindleBrake == true && Block1 == true ){ SpindleOrient = false; SpindleOrientTimer = 0; Block1 = true }else{ if (SpindleOriented == false && Toolchange == true && Block1 == true ){ Block01DigitalOut01= false; // disable output ToolChanger = false; // stop toolchange code flow ToolChangerFault= true; // set this error flag Estop = true; // disable machine if (SpindleNotAlignedError == false ){ // block repetitive error messages they are annoying and flood the system rtapi_print_msg(RTAPI_MSG_ERR, "Fault 001 Spindle Not Aligned For ToolChange ESTOP ON"); SpindleNotAlignedError = true; // set flag to block prinint excesive error messages } } } // pocket counting logic here to decode pocket position // pocket counting logic, determines count direction from motor command // will implement encoder logic soon if (IndexType == true){ if (MotorFwd) { if (IndexPulse) { Pocket += 1; } }else{ if (MotorRev) { if (IndexPulse) { Pocket -= 1; } } } } if (EncoderType == true){ if (MotorFwd) { if (EncoderInput / PulsePerPocket) { Pocket += 1; } }else{ if (MotorRev) { if (EncoderInput / PulsePerPocket) { Pocket -= 1; } } } } //Carousel Command Code to get desired pocket if (Pocket > PocketRequest && ActivateCarousel == true && toolchanger == true) { // Move tool changer backwards MotorFwd = false; MotorRev = true; } else if (Pocket < PocketRequest && ActivateCarousel == true ToolChanger == true)) { // Move tool changer forwards MotorFwd = true; MotorRev = false; }else if (Pocket == PocketRequest){ // Tool changer is at the correct pocket MotorFwd = false; MotorRev = false; ActivateCarousel = false; } // home carousel function if (IndexHome == true || EncoderHome == true) { HomeSensor = true; } if (HomeCarousel == true && toolchange == false && SpindleEnable == false) { MotorFwd = true; if (HomeSensor == true && CarouselHome == true) { MotorFwd = false; Pocket = 1; } } // logic for jogging the carousel if (JogFwd == true && Block1 == false && SpindleEnable == false && ActivateCarousel == false) { // input from hal to increment pocekt PocketRequest += 1; } if (JogRev == true&& Block1 == false && SpindleEnable == false && ActivateCarousel == false) { // input from hal to decerment pocket PocketRequest -= 1; } /// beginging of Block1 Start of tool change if (Toolchanger == true && OneStartShot == true && toolchanged == false && ActivateCarousel == false){ // getting the execution chain started B1Count01 = true; // first execution step }else{ if (Toolchanger == true && OneStartShot == true && JumpBlock01 == true && ActivateCarousel == false){ // jumpp to next block Block02 = true; } } if (B1Count01 == && Toolchanger == true){ // TurnOnOutPut01 and Block01Count0 start this timer Block01Timer01 += fperiod; // timers are incremented by fperoid in 0.001 second increments B1Count02 = true; Block01OutPut01 = true; // enable a pin out to make a move } if (Block01Timer01 > Block01Timer01Setting && B1Count02 == true && Block01Input01 == true){ // user settable unlock pause before error check Block01Timer01 = 0; B1Count03 = true; // move flow control forward B1Count01 = false; // flow control rest at start of routine Block01Timer01 = 0; // clear timer to clean up }else{ if (Block01Timer01 > Block01Timer01Setting && B1Count02 == true && Block01Input01 == false) // failed to show motion after user set time peroid Block01DigitalOut01= false; // disable output ToolChanger = false; // stop toolchange code flow ToolChangerFault= true; // set this error flag Estop = true; if (Block01FloodFlag01 = false){ // block repetitive error messages they are annoying and flood the system rtapi_print_msg(RTAPI_MSG_ERR, "Fault B01-00 Timer Limit Exceeded Check Machine for Jamming or Other problem"); Block01FloodFlag01 = true; // set flag to block prinint excesive error messages DignosticCount = 0101; // send diagnostic count number, in attempt to find bugs etc. } // diagnosing the problem } if (B1Count03 == true && Block01Input01 == true ){ // clean up and move forward to next block B1Count01 = false; B1Count02 = false; Block02 = true; }else{ if (B1Count03 == true && Block01Input01 == true && AllowCarouselBlock01 == true) { ActivateCarousel = true; } } // end of Block 1, we are going to reuse this code over and over. // Start of Block 2 execution code !!! // setting up jump points and execution in and out of the carousel or belt tool mechanism for the tool pocket if (Toolchanger == true && OneStartShot == true && toolchanged == false && ActivateCarousel == false){ // getting the execution chain started wait for carousel to finish ! B2Count01 = true; // enable first execution step }else{ if (Toolchanger == true && OneStartShot == true && JumpBlock02 == true && ActivateCarousel == false){ // jumpp to next block Block03 = true; } } if (B2Count01 == && Toolchanger == true){ // TurnOnOutPut01 and Block01Count0 start this timer B2ock01Timer01 += fperiod; // timers are incremented by fperoid in 0.001 second increments B2Count02 = true; Block02OutPut01 = true; // enable a pin out to make a move } if (Block02Timer01 > Block02Timer01Setting && B2Count02 == true && Block02Input01 == true){ // user settable unlock pause before error check Block02Timer01 = 0; B2Count03 = true; // move flow control forward B2Count01 = false; // flow control rest at start of routine Block02Timer01 = 0; // clear timer to clean up }else{ if (Block02Timer01 > Block02Timer01Setting && B2Count02 == true && Block02Input01 == false) // failed to show motion after user set time peroid Block02DigitalOut01= false; // disable output ToolChanger = false; // stop toolchange code flow ToolChangerFault= true; // set this error flag Estop = true; if (Block02FloodFlag01 = false){ // block repetitive error messages they are annoying and flood the system rtapi_print_msg(RTAPI_MSG_ERR, "Fault B01-00 Timer Limit Exceeded Check Machine for Jamming or Other problem"); Block02FloodFlag01 = true; // set flag to block prinint excesive error messages DignosticCount = 0101; // send diagnostic count number, in attempt to find bugs etc. } // diagnosing the problem } if (B2Count03 == true && Block02Input01 == true ){ // clean up and move forward to next block B2Count01 = false; B2Count02 = false; B2ock02 = true; }else{ if (B2Count03 == true && Block02Input01 == true && AllowCarouselBlock02 == true) { ActivateCarousel = true; } } // end of Block 2, we are going to reuse this code over and over. // Start of Block 3 execution code !!! // setting up jump points and execution in and out of the carousel or belt tool mechanism for the tool pocket if (Toolchanger == true && OneStartShot == true && toolchanged == false && ActivateCarousel == false){ // getting the execution chain started wait for carousel to finish ! B2Count01 = true; // enable first execution step }else{ if (Toolchanger == true && OneStartShot == true && JumpBlock02 == true && ActivateCarousel == false){ // jumpp to next block Block03 = true; } } if (B2Count01 == && Toolchanger == true){ // TurnOnOutPut01 and Block01Count0 start this timer B2ock01Timer01 += fperiod; // timers are incremented by fperoid in 0.001 second increments B2Count02 = true; Block02OutPut01 = true; // enable a pin out to make a move } if (Block02Timer01 > Block02Timer01Setting && B2Count02 == true && Block02Input01 == true){ // user settable unlock pause before error check Block02Timer01 = 0; B2Count03 = true; // move flow control forward B2Count01 = false; // flow control rest at start of routine Block02Timer01 = 0; // clear timer to clean up }else{ if (Block02Timer01 > Block02Timer01Setting && B2Count02 == true && Block02Input01 == false) // failed to show motion after user set time peroid Block02DigitalOut01= false; // disable output ToolChanger = false; // stop toolchange code flow ToolChangerFault= true; // set this error flag Estop = true; if (Block02FloodFlag01 = false){ // block repetitive error messages they are annoying and flood the system rtapi_print_msg(RTAPI_MSG_ERR, "Fault B01-00 Timer Limit Exceeded Check Machine for Jamming or Other problem"); Block02FloodFlag01 = true; // set flag to block prinint excesive error messages DignosticCount = 0101; // send diagnostic count number, in attempt to find bugs etc. } // diagnosing the problem } if (B2Count03 == true && Block02Input01 == true ){ // clean up and move forward to next block B2Count01 = false; B2Count02 = false; B2ock02 = true; }else{ if (B2Count03 == true && Block02Input01 == true && AllowCarouselBlock02 == true) { ActivateCarousel = true; } } // end of Block 3, we are going to reuse this code over and over.