|
On 21/11/16 07:55,
[email protected] wrote:
I have changed the component to use hal_bit_t instead of bool. The #defines for true and false are already implemented in comp. I have also changed the other variables whilst I was at it. Params will become deprecated before too long in favour of i/o pins, since the only point of a param, was that you used not to be able to create a pin with an initial default value, but now you can. Other variables should really be hal_typed, int should be either hal_s32_t or hal_u32_t depending upon the requirement, as an integer size can vary. Likewise float should really be hal_float_t, which in fact is double, so that assignments are always correct This compiles for me so hopefully will get you going and you can fine tune the move values required between tools regards -- website: http://www.machinekit.io blog: http://blog.machinekit.io github: https://github.com/machinekit --- You received this message because you are subscribed to the Google Groups "Machinekit" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. Visit this group at https://groups.google.com/group/machinekit. For more options, visit https://groups.google.com/d/optout. |
/*************************************************************************************************************************************EMC2 HAL component to implement ATC toolchanging in Boxford 240(F) CNC lathes (c) ArcEye 09052011 [email protected] All values are metric The same code with possible modification of values in param rw float odd_move = 22.2 param rw float even_move = 24 will work for TCL 160 and TCL 125 and probably other lathes with the same 'move past pawl and reverse to stall against it' methodology. These move figures are only half the actual move in degrees. The scaling takes care of the distance actually moved. There is a very good reason for this. It prevents the stepgen seeing any move as being in excess of 180degrees, therefore all moves between tool stations will be forward moves. If you command a move to a position which is say 270degrees on a angular axis, the stepgen will try to move 90degress backwards to get to the same point by the shortest route. In theory unlinking the stepgen dir signal and using our own should work, but it didn't and the axis wanted to go backwards all the time despite the flag being set at TRUE (FWD). As this worked perfectly, I preserved my sanity and just left well alone. The 240 should have an index proximity switch signalling each station, but mine was U/S along with a lot of other low voltage components My 160 did not have one and as I knew it could be indexed without, I did not replace the expensive Boxford 240 switch If you want to use an index pulse, then you will have to re-write so that the position-cmd is incremented until the signal and then locked back by an appropriate amount These 8 station ATCs do not have the tool and drill stations at perfect 45 degrees as you would expect Stations 1,3,5,7 are tools and 2,4,6,8 are drills or round shank tooling Therefore requires different movement depending upon whether current tool is odd or even number. ######################################################### # .ini file for axis - ATC set up as axis A angular ######################################################### [AXIS_3] TYPE = ANGULAR HOME = 0.0 MAX_VELOCITY = 2.5 MAX_ACCELERATION = 5 STEPGEN_MAXACCEL = 5 SCALE = 80.0 FERROR = 1 MIN_FERROR = .25 MIN_LIMIT = -99999 MAX_LIMIT = 99999 HOME_OFFSET = 0.0 ########################################################## # example Hal linkages required:- ########################################################## setp stepgen.3.position-scale [AXIS_3]SCALE setp stepgen.3.steplen 1 setp stepgen.3.stepspace 0 setp stepgen.3.dirhold 16000 setp stepgen.3.dirsetup 31000 ## make sure accel and velocity are sensibly low or it will take off! setp stepgen.3.maxaccel [AXIS_3]STEPGEN_MAXACCEL ### must unlink these 2 to access stepgen.3.position-cmd ### and prevent continual following errors if motor-pos-fb left linked #net apos-cmd axis.3.motor-pos-cmd => stepgen.3.position-cmd #net apos-fb stepgen.3.position-fb => axis.3.motor-pos-fb net astep <= stepgen.3.step net adir <= stepgen.3.dir net aenable axis.3.amp-enable-out => stepgen.3.enable ########################################################### # loading the toolchange component in .hal file ########################################################### loadrt toolchanger addf toolchanger servo-thread net tool-change iocontrol.0.tool-change => toolchanger.toolchange net tool-changed iocontrol.0.tool-changed <= toolchanger.toolchanged net tool-number iocontrol.0.tool-prep-number => toolchanger.toolnumber net tool-oldnumber iocontrol.0.tool-number => toolchanger.currenttoolnumber net apos-cmd toolchanger.position-cmd => stepgen.3.position-cmd net ahomed axis.3.homed => toolchanger.ishomed net tool-prepare-loopback iocontrol.0.tool-prepare => iocontrol.0.tool-prepared ################################################################################ ***************************************************************************************************************************************/ component toolchanger "This component controls the Boxford 240 Lathe Auto Tool Changer. M6 calls this"; pin in bit toolchange "Receives signal from M6 that tool change required"; pin in s32 toolnumber "Receives Tx data from M6 (tool number requested) Only allows 1-6"; pin in s32 currenttoolnumber "Receives old tool number"; pin out float position_cmd "Sends location required"; pin out bit toolchanged =false "Sends signal when tool change finished"; pin in bit ishomed = false "Status of A axis homing"; pin in bit jog_forward = false "Facilitate jogging of stepgen via component"; pin in bit jog_back = false "Facilitate jogging of stepgen via component"; pin in float jog_move = 0.0 "distance to jog"; // allow parameters to be changed by setp for fine tuning pin io float odd_move = 30 "distance from odd tool station to even one"; pin io float even_move = 30 "distance from even tool station to odd one"; pin io float divisor = 2 "used in calculating reverse move to lock"; pin io float fudge_factor = 1 "additional move to ensure locking"; // internal variables variable hal_s32_t progress_level = 0; // tracks the progress of the toolchange variable hal_s32_t moves = 0; // number of moves to reach tool station variable hal_s32_t index = 0; // Counter used for comparison with moves variable hal_bit_t bEven = false; // Odd or Even station requested variable hal_bit_t bToggle = false; // Status of current move as Odd or Even variable hal_float_t position_req = 0.0; // Where we want to be variable hal_float_t position_accum = 0.0; // Moves are incremental but stepgen is absolute so add them up variable hal_bit_t bWarn = false; // one shot warning no tool set variable hal_s32_t delay = 0; // delay before lock back variable hal_s32_t delay_index = 0; // counter for above variable hal_bit_t fjog = false; // use internal flags for jogging after initial signal to ensure that one command is variable hal_bit_t bjog = false; // carried out at a time - should not be possible to be otherwise but paranoia rules variable hal_float_t jmove = 0.0; option singleton yes; // makes no sense to have more than one of these components running - only one ATC function _; author "ArcEye [email protected]"; license "GPL"; ;; float rnd2(float in) { float num = in; long roundy; num *= 100; if(num >= 0) num += 0.5; else num -= 0.5; roundy = num; num = roundy; num /= 100; return num; } FUNCTION(_) { switch (progress_level) { case 0: // idle waiting for toolchange request if(jog_forward && ! fjog) { fjog = true; bjog = false; jmove = rnd2(jog_move); position_req = jmove; position_req += position_accum; if(position_req > 360) position_req -= 360; position_cmd = position_req; progress_level = 1; break; } else if(jog_back && !bjog) { bjog = true; fjog = false; jmove = rnd2(jog_move); position_req = position_accum - jmove; if(position_req < 0) position_req += 360; position_cmd = position_req; progress_level = 3; break; } else { // axis does not remember the current tool number, so prompt for it when A axis homed if(ishomed && !currenttoolnumber && !bWarn) { bWarn = true; // just warn once, its not an error as such but INFO won't display unless debugging is set 3+ rtapi_print_msg(RTAPI_MSG_ERR, "No tool selected. Use M6Tx to set current tool"); break; } if(toolchange && !toolchanged) // prevent cycling after change done { if(currenttoolnumber && toolnumber != currenttoolnumber && toolnumber > 0 && toolnumber < 7) // if a valid number { if(currenttoolnumber == 2 || currenttoolnumber == 4 || currenttoolnumber == 6) bEven = true; if(currenttoolnumber < toolnumber) moves = toolnumber - currenttoolnumber; else moves = (6 - currenttoolnumber) + toolnumber; bToggle = bEven; while(index < moves) { if(bToggle) position_req += even_move; else position_req += odd_move; index++; bToggle = !bToggle; } if(position_req >= 70) delay = 70; else delay = position_req; position_req += position_accum; if(position_req > 360) position_req -= 360; position_cmd = position_accum; position_cmd = position_req; progress_level = 1; } else // if tool requested is out of range or already selected just set the toolchanged flag and exit progress_level = 5; } if(!toolchange) toolchanged = 0; // reset once toolchange flag reset by system if(toolchange && !currenttoolnumber) // if no tool is set - set to tool requested so that can work next time progress_level = 5; } // end else break; case 1: // Forward move if(position_cmd < position_req) // have we got there yet? { break; } if(!fjog && (delay_index < (delay * 100)) ) // this figure depends upon the speed of the servo thread etc delay_index++; else { if(fjog) { fjog = bjog = false; progress_level = 5; } else { position_req -= ((moves / divisor) + fudge_factor); if(position_req < 0) position_req += 360; position_cmd = position_req; progress_level = 3; } } break; case 3: // Backward locking move or backward jog if(position_cmd > position_req) // have we got there yet? { break; } if(bjog) { bjog = fjog = false; } progress_level = 5; break; case 5: // clean up ready for next toolchange position_accum = position_cmd; position_req = 0; delay_index = 0; moves = 0; index = 0; bEven = false; bToggle = false; progress_level = 0; toolchanged = 1; // signal finished break; case 10: break; // should never get here but if we do then loop endlessly doing nothing default: progress_level = 10; rtapi_print_msg(RTAPI_MSG_ERR, "Error state in toolchanger - now disabled - unload toolchanger"); } }
