@@ -116,7 +116,7 @@ pin in float rev-dc "Velocity or duty cycle when reverse rotation is desired";
116116pin in float hold-dc "Duty cycle when carousel is in-position (to hold against stop)";
117117pin in float align-dc """Use this pin to set the speed of a slower alignment move once the changer is in position. Such a system almost
118118certainly needs decel-time setting too""";
119- pin in float decel-time "Time to wait for carousel to stop before final alignment";
119+ pin in float decel-time "Time to wait for carousel to stop before final alignment and position check ";
120120pin in signed counts "Connect to the rawcounts of an encoder or a stepgen in 'counts' mode";
121121pin in signed scale = 100 "The number of stepgen or encoder counts between successive pockets";
122122pin in signed width = 0 "How far each side of the exact scale to signal a new pocket";
@@ -167,6 +167,8 @@ int default_dir = 2;
167167int default_sense = 4;
168168int default_parity = 0;
169169
170+ static bool err_once = 0;
171+
170172#define MAX_CHAN 8
171173static int pockets[MAX_CHAN] = {-1};
172174RTAPI_MP_ARRAY_INT(pockets, MAX_CHAN, "The number of pockets in each carousel")
@@ -202,6 +204,7 @@ FUNCTION(_){
202204 for(mask = new_pos >> 1 ; mask != 0 ; mask = mask >> 1){
203205 new_pos ^= mask;
204206 }
207+ if (new_pos == 0) new_pos = inst_pockets; // all zeros != pocket zero
205208 break;
206209 case 'B': // Straight Binary
207210 align_pin = strobe;
@@ -380,7 +383,7 @@ FUNCTION(_){
380383 motor_vel = rev_dc;
381384 timer = rev_pulse;
382385 state = 3;
383- } else if (align_dc != 0) {
386+ } else if (decel_time > 0) {
384387 // stop and prepare for alignment
385388 motor_vel = 0;
386389 timer = decel_time;
@@ -390,7 +393,7 @@ FUNCTION(_){
390393 motor_rev = 0;
391394 motor_vel = hold_dc;
392395 active = 0;
393- if (enable) ready = 1;
396+ if (enable && current_position == mod_pocket ) ready = 1;
394397 state = 9;
395398 }
396399 break;
@@ -407,6 +410,10 @@ FUNCTION(_){
407410 case 5: //Waiting for carousel to stop
408411 timer -= fperiod;
409412 if (timer > 0) return;
413+ if (align_dc == 0){
414+ state = 8;
415+ break;
416+ }
410417 motor_vel = -align_dc;
411418 if (motor_dir == 1) {
412419 state = 6;
@@ -429,11 +436,17 @@ FUNCTION(_){
429436 motor_rev = 0;
430437 motor_vel = hold_dc;
431438 active = 0;
432- if (enable) ready = 1;
439+ // final safety check for in-position
440+ if (enable && current_position == mod_pocket) ready = 1;
433441 state = 9;
434442 break;
435443 case 9: //waiting for enable to go false
444+ if (! ready && ! err_once){
445+ rtapi_print_msg(RTAPI_MSG_ERR, "The toolchanger has failed the final alignment check");
446+ err_once = 1;
447+ }
436448 if (enable) return;
449+ err_once = 0;
437450 state = 0;
438451 break;
439452 case 10: // start of homing
@@ -498,6 +511,8 @@ EXTRA_SETUP(){
498511 if (pockets[extra_arg] > 0) default_pockets = pockets[extra_arg];
499512 if (encoding[extra_arg] == NULL) {
500513 //it's already default_code
514+ } else if (strncmp(encoding[extra_arg], "gray", 4) == 0) {
515+ default_code = 'G';
501516 } else if (strncmp(encoding[extra_arg], "binary", 6) == 0) {
502517 default_code = 'B';
503518 } else if (strncmp(encoding[extra_arg], "bcd", 3) == 0) {
0 commit comments