Skip to content

Commit 1543217

Browse files
committed
homing: Fix race between joint's homing status and state machine done.
1 parent ffc3932 commit 1543217

2 files changed

Lines changed: 27 additions & 2 deletions

File tree

src/emc/motion/control.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2122,7 +2122,19 @@ static void update_status(void)
21222122
}
21232123
#endif
21242124
joint_status->flag = joint->flag;
2125-
joint_status->homing = get_homing(joint_num);
2125+
if(!(joint_status->homing && !get_homing(joint_num) && get_homing_is_active())) {
2126+
// Prevent race condition.
2127+
// (See also emc/motion/homing.c: base_write_homing_out_pins())
2128+
// The homing status variable turns false before get_homing_is_active()
2129+
// turns false. This means that a new homing command on a joint might
2130+
// fail due to the homing state machine being active while all joints
2131+
// already are in the 'not homing' state.
2132+
// Solution:
2133+
// Do not update the homing status when going from homing --> not homing
2134+
// and the state machine is still active. The homing status deassertion
2135+
// must be delayed until the state machine is done.
2136+
joint_status->homing = get_homing(joint_num);
2137+
}
21262138
joint_status->homed = get_homed(joint_num);
21272139
joint_status->pos_cmd = joint->pos_cmd;
21282140
joint_status->pos_fb = joint->pos_fb;
@@ -2209,4 +2221,4 @@ static void update_status(void)
22092221
old_motion_flag = emcmotStatus->motionFlag;
22102222
}
22112223
#endif
2212-
}
2224+
}

src/emc/motion/homing.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,19 @@ static void base_write_homing_out_pins(int njoints)
542542
one_joint_home_data_t *addr;
543543
for (jno = 0; jno < njoints; jno++) {
544544
addr = &(joint_home_data->jhd[jno]);
545+
if(!(*(addr->homing) && !H[jno].homing && homing_active)) {
546+
// Prevent race condition.
547+
// (See also emc/motion/control.c: update_status())
548+
// The homing status variable turns false before homing_active state
549+
// turns false. This means that a new homing command on a joint might
550+
// fail due to the homing state machine being active while all joints
551+
// already are in the 'not homing' state.
552+
// Solution:
553+
// Do not update the homing status when going from homing --> not homing
554+
// and the state machine is still active. The homing status deassertion
555+
// must be delayed until the state machine is done.
556+
*(addr->homing) = H[jno].homing;
557+
}
545558
*(addr->homing) = H[jno].homing; // OUT
546559
*(addr->homed) = H[jno].homed; // OUT
547560
*(addr->home_state) = H[jno].home_state; // OUT

0 commit comments

Comments
 (0)