Skip to content

Commit 2d6b598

Browse files
committed
carousel.comp: Add some error detection, decel time and graycode encoding
1) Make it possible to explicity choose graycode encoding tather than rely on default. 2) Interpret graycode all-zeros as max pockets rather than pocket zero (invalid) 3) Allow decel-time to be programmed even without an alignment phase 4) Only set "ready" when everything has stopped, and after a final position check. Signed-off-by: andypugh <andy@bodgesoc.org>
1 parent 5bd26b5 commit 2d6b598

1 file changed

Lines changed: 19 additions & 4 deletions

File tree

src/hal/components/carousel.comp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ pin in float rev-dc "Velocity or duty cycle when reverse rotation is desired";
116116
pin in float hold-dc "Duty cycle when carousel is in-position (to hold against stop)";
117117
pin 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
118118
certainly 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";
120120
pin in signed counts "Connect to the rawcounts of an encoder or a stepgen in 'counts' mode";
121121
pin in signed scale = 100 "The number of stepgen or encoder counts between successive pockets";
122122
pin 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;
167167
int default_sense = 4;
168168
int default_parity = 0;
169169

170+
static bool err_once = 0;
171+
170172
#define MAX_CHAN 8
171173
static int pockets[MAX_CHAN] = {-1};
172174
RTAPI_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

Comments
 (0)