@@ -537,6 +537,13 @@ int hm2_encoder_parse_md(hostmot2_t *hm2, int md_index) {
537537 goto fail1 ;
538538 }
539539
540+ rtapi_snprintf (name , sizeof (name ), "%s.encoder.%02d.position-interpolated" , hm2 -> llio -> name , i );
541+ r = hal_pin_float_new (name , HAL_OUT , & (hm2 -> encoder .instance [i ].hal .pin .position_interpolated ), hm2 -> llio -> comp_id );
542+ if (r < 0 ) {
543+ HM2_ERR ("error adding pin '%s', aborting\n" , name );
544+ goto fail1 ;
545+ }
546+
540547 rtapi_snprintf (name , sizeof (name ), "%s.encoder.%02d.position-latched" , hm2 -> llio -> name , i );
541548 r = hal_pin_float_new (name , HAL_OUT , & (hm2 -> encoder .instance [i ].hal .pin .position_latch ), hm2 -> llio -> comp_id );
542549 if (r < 0 ) {
@@ -824,6 +831,10 @@ static void hm2_encoder_instance_update_rawcounts_and_handle_index(hostmot2_t *h
824831
825832 e -> zero_offset = prev_rawcounts + reg_count_diff ;
826833 * e -> hal .pin .index_enable = 0 ;
834+ // may need to update interpolated position after index event because
835+ // this _may_ happen without a count but its pretty ugly...
836+ // *e->hal.pin.count = *e->hal.pin.rawcounts - e->zero_offset;
837+ //*e->hal.pin.position_interpolated = *e->hal.pin.count / e->hal.param.scale;
827838 }
828839 } else if (e -> prev_control & HM2_ENCODER_LATCH_ON_PROBE ) {
829840 if (hm2 -> encoder .firmware_supports_probe ) {
@@ -888,6 +899,8 @@ static void hm2_encoder_instance_update_position(hostmot2_t *hm2, int instance)
888899
889900 if (* e -> hal .pin .reset ) {
890901 e -> zero_offset = * e -> hal .pin .rawcounts ;
902+ * e -> hal .pin .position_interpolated = * e -> hal .pin .position ;
903+
891904 }
892905
893906
@@ -1000,6 +1013,7 @@ static void hm2_encoder_instance_process_tram_read(hostmot2_t *hm2, int instance
10001013 if (dT_s >= e -> hal .param .vel_timeout ) {
10011014 * e -> hal .pin .velocity = 0.0 ;
10021015 * e -> hal .pin .velocity_rpm = 0.0 ;
1016+ * e -> hal .pin .position_interpolated = * e -> hal .pin .position ;
10031017 e -> state = HM2_ENCODER_STOPPED ;
10041018 break ;
10051019 }
@@ -1009,6 +1023,8 @@ static void hm2_encoder_instance_process_tram_read(hostmot2_t *hm2, int instance
10091023 } else {
10101024 dS_counts = -1 ;
10111025 }
1026+ // if no counts, calculate interpolated position
1027+ * e -> hal .pin .position_interpolated = * e -> hal .pin .position + (dT_s * * e -> hal .pin .velocity );
10121028
10131029 dS_pos_units = dS_counts / e -> hal .param .scale ;
10141030
@@ -1039,7 +1055,7 @@ static void hm2_encoder_instance_process_tram_read(hostmot2_t *hm2, int instance
10391055
10401056 hm2_encoder_instance_update_rawcounts_and_handle_index (hm2 , instance );
10411057 hm2_encoder_instance_update_position (hm2 , instance );
1042-
1058+ * e -> hal . pin . position_interpolated = * e -> hal . pin . position ;
10431059 time_of_interest = hm2_encoder_get_reg_timestamp (hm2 , instance );
10441060 if (time_of_interest < e -> prev_time_of_interest ) {
10451061 // tsc rollover!
@@ -1059,6 +1075,8 @@ static void hm2_encoder_instance_process_tram_read(hostmot2_t *hm2, int instance
10591075 ) {
10601076 * e -> hal .pin .velocity = 0.0 ;
10611077 * e -> hal .pin .velocity_rpm = 0.0 ;
1078+ * e -> hal .pin .position_interpolated = * e -> hal .pin .position ;
1079+
10621080 } else {
10631081 dT_clocks = (time_of_interest - e -> prev_event_reg_timestamp ) + (e -> tsc_num_rollovers << 16 );
10641082 dT_s = (double )dT_clocks * hm2 -> encoder .seconds_per_tsdiv_clock ;
0 commit comments