Hello Andy,
while I don't dismiss a separate HAL-component (I just tested the modified home procedure first as I already implemented it) I don't understand how it would help with my current problem. When an index is found the encoder would still reset while the machine being in motion. Unless I would within the HAL-component try to capture the event of the reset instantaneously and artificially generate a 'fake' position signal consistent with the one before the reset (something I would not consider to be very elegant) I still would experience the same behavior. Maybe I'm missing something here....
However in the meantime I have modified the Hostmot2. I added a flag
Code:
hm2_7i92.0.encoder.01.reset-on-index
which is set to 1 by default to be consistent with the original implementation. Further I added an output parameter
Code:
hm2_7i92.0.encoder.01.index-rawcounts
I basically modified the following code in encoder.c (look for *** in the comment)
Code:
if (0 == (latch_ctrl & HM2_ENCODER_LATCH_ON_INDEX)) {
// hm2 reports index event occurred
rtapi_u16 latched_count;
latched_count = (latch_ctrl >> 16) & 0xffff;
reg_count_diff = (rtapi_s32)latched_count - (rtapi_s32)e->prev_reg_count;
if (reg_count_diff > 32768) reg_count_diff -= 65536;
if (reg_count_diff < -32768) reg_count_diff += 65536;
//***Added if-statement to reset the offset only when hal.pin.reset_on_index is true (default)
if(*e->hal.pin.reset_on_index){
e->zero_offset = prev_rawcounts + reg_count_diff;
}
//***Additionally always setting the rawcounts of the last index-position to pin.index_rawcounts
*e->hal.pin.index_rawcounts = prev_rawcounts;
*e->hal.pin.index_enable = 0;
}
The
Code:
if(*e->hal.pin.reset_on_index){ ... }
causes the count and position not to be modfied if
Code:
hm2_7i92.0.encoder.01.reset-on-index
is 0.
The
Code:
*e->hal.pin.index_rawcounts = prev_rawcounts;
is always set to rawcounts value corresponding to the last index signal encountered.
Like that I was able to have the first successful distance-coded homing routines executed which delivered what seemed to be reasonable results

However some more testing and detailed verifying is still needed.
Best regards,
Marc