Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/src/man/man9/motion.9.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,9 @@ Note: feed-inhibit applies to G-code commands -- not jogs.
By default, homing is allowed in joint mode whenever motion is enabled.
*motion.is-all-homed* OUT BOOL::
TRUE if all active joints is homed.
*motion.is-homing* OUT BOOL::
TRUE from the start of a homing command until its last joint has finished,
without a break between the HOME_SEQUENCE groups of a "Home All".
*motion.jog-inhibit* IN BOOL::
If this bool is TRUE, jogging of any joint or axis is disallowed and an error is reported.
*motion.jog-stop* IN BOOL::
Expand Down
15 changes: 2 additions & 13 deletions src/emc/motion/control.c
Original file line number Diff line number Diff line change
Expand Up @@ -2509,19 +2509,7 @@ static void update_status(void)
}
#endif
joint_status->flag = joint->flag;
if(!(joint_status->homing && !get_homing(joint_num) && get_homing_is_active())) {
// Prevent race condition.
// (See also emc/motion/homing.c: base_write_homing_out_pins())
// The homing status variable turns false before get_homing_is_active()
// turns false. This means that a new homing command on a joint might
// fail due to the homing state machine being active while all joints
// already are in the 'not homing' state.
// Solution:
// Do not update the homing status when going from homing --> not homing
// and the state machine is still active. The homing status deassertion
// must be delayed until the state machine is done.
joint_status->homing = get_homing(joint_num);
}
joint_status->homing = get_homing(joint_num);
joint_status->homed = get_homed(joint_num);
joint_status->pos_cmd = joint->pos_cmd;
joint_status->pos_fb = joint->pos_fb;
Expand Down Expand Up @@ -2581,6 +2569,7 @@ static void update_status(void)
emcmotStatus->homing_runs++;
}
emcmotStatus->homing_active = get_homing_is_active();
hal_set_bool(emcmot_hal_data->is_homing, emcmotStatus->homing_active);

/*! \todo FIXME - the rest of this function is stuff that was apparently
dropped in the initial move from emcmot.c to control.c. I
Expand Down
52 changes: 29 additions & 23 deletions src/emc/motion/homing.c
Original file line number Diff line number Diff line change
Expand Up @@ -628,19 +628,7 @@ static void base_write_homing_out_pins(int njoints)
one_joint_home_data_t *addr;
for (jno = 0; jno < njoints; jno++) {
addr = &(joint_home_data->jhd[jno]);
if(!(hal_get_bool(addr->homing) && !H[jno].homing && homing_active)) {
// Prevent race condition.
// (See also emc/motion/control.c: update_status())
// The homing status variable turns false before homing_active state
// turns false. This means that a new homing command on a joint might
// fail due to the homing state machine being active while all joints
// already are in the 'not homing' state.
// Solution:
// Do not update the homing status when going from homing --> not homing
// and the state machine is still active. The homing status deassertion
// must be delayed until the state machine is done.
hal_set_bool(addr->homing, H[jno].homing);
}
hal_set_bool(addr->homing, H[jno].homing); // OUT
hal_set_bool(addr->homed, H[jno].homed); // OUT
hal_set_sint(addr->home_state, H[jno].home_state); // OUT
// index_enable is a HAL_IO pin: the encoder driver also writes it
Expand Down Expand Up @@ -1627,10 +1615,35 @@ static int base_1joint_state_machine(int joint_num)
return homing_flag;
} // base_1joint_state_machine()

/* Called after the joint state machines. Move the sequence on in the
cycle its last joint finished, so homing_active drops together with
that joint's homing flag and a new home command is accepted as soon
as no joint reads homing. */
static void update_homing_active(void)
{
int jno;
if (sequence_state == HOME_SEQUENCE_WAIT_JOINTS) {
do_homing_sequence(); // group done => START_JOINTS
if (sequence_state == HOME_SEQUENCE_START_JOINTS) {
do_homing_sequence(); // next group started, or IDLE
}
}
for (jno = 0; jno < all_joints; jno++) {
if (!H[jno].joint_in_sequence) { continue; }
if (!GET_JOINT_ACTIVE_FLAG(&joints[jno])) { continue; }
if (H[jno].home_state != HOME_IDLE) {
homing_active = 1;
return;
}
}
if (sequence_state == HOME_SEQUENCE_IDLE) {
homing_active = 0;
}
}

static bool base_do_homing(void)
{
int joint_num;
int homing_flag = 0;
bool beginning_allhomed = get_allhomed();

do_homing_sequence();
Expand All @@ -1639,16 +1652,9 @@ static bool base_do_homing(void)
if (!H[joint_num].joint_in_sequence) { continue; }
if (!GET_JOINT_ACTIVE_FLAG(&joints[joint_num])) { continue; }
// DEFAULT joint homing state machine:
homing_flag += base_1joint_state_machine(joint_num);
}
if ( homing_flag > 0 ) { /* one or more joint is homing */
homing_active = 1;
} else { /* is a homing sequence in progress? */
if (sequence_state == HOME_SEQUENCE_IDLE) {
/* no, single joint only, we're done */
homing_active = 0;
}
base_1joint_state_machine(joint_num);
}
update_homing_active();
// return 1 if homing completed this period
if (!beginning_allhomed && get_allhomed()) {homing_active=0; return 1;}
return 0;
Expand Down
1 change: 1 addition & 0 deletions src/emc/motion/mot_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ typedef struct {
hal_bool_t tp_reverse; /* Set true if trajectory planner is running in reverse*/
hal_bool_t motion_enabled; /* RPI: motion enable for all joints */
hal_bool_t is_all_homed; /* RPI: TRUE if all active joints is homed */
hal_bool_t is_homing; /* RPI: TRUE while a homing run is active */
hal_bool_t in_position; /* RPI: all joints are in position */
hal_bool_t coord_mode; /* RPA: TRUE if coord, FALSE if free */
hal_bool_t teleop_mode; /* RPA: TRUE if teleop mode */
Expand Down
1 change: 1 addition & 0 deletions src/emc/motion/motion.c
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,7 @@ static int init_hal_io(void)
// default value of enable is TRUE, so simple machines can leave it disconnected
CALL_CHECK(hal_pin_new_bool(mot_comp_id, HAL_IN, &(emcmot_hal_data->enable), 1, "motion.enable"));
CALL_CHECK(hal_pin_new_bool(mot_comp_id, HAL_OUT, &(emcmot_hal_data->is_all_homed), 0, "motion.is-all-homed"));
CALL_CHECK(hal_pin_new_bool(mot_comp_id, HAL_OUT, &(emcmot_hal_data->is_homing), 0, "motion.is-homing"));

/* state tags pins */
CALL_CHECK(hal_pin_new_real(mot_comp_id, HAL_OUT, &(emcmot_hal_data->feed_upm), 0.0, "motion.feed-upm"));
Expand Down
17 changes: 9 additions & 8 deletions src/emc/usr_intf/emcrsh.cc
Original file line number Diff line number Diff line change
Expand Up @@ -964,18 +964,19 @@ static cmdResponseType setJointWaitHomed(connectionRecType &ctx)
if (!emcStatus->motion.joint[i].homed)
allhome = false;
}
if (allhome) {
if (allhome && !emcStatus->motion.homing_active) {
//replynl(ctx, fmt::format("JOINT_WAIT_HOMED finished in {:.3f} seconds", etime() - st));
// Wait one heartbeat to allow teleop to become set in the
// motion controller.
return doWaitHeartbeat(ctx, 1, WAIT_HEARTBEAT_TIMEOUT);
// Wait for a whole cycle to allow teleop to become set in
// the motion controller.
return doWaitHeartbeat(ctx, 2, WAIT_HEARTBEAT_TIMEOUT);
}
} else {
if (emcStatus->motion.joint[joint].homed && !emcStatus->motion.joint[joint].homing) {
if (emcStatus->motion.joint[joint].homed && !emcStatus->motion.joint[joint].homing
&& !emcStatus->motion.homing_active) {
//replynl(ctx, fmt::format("JOINT_WAIT_HOMED finished in {:.3f} seconds", etime() - st));
// Wait one heartbeat to allow teleop to become set in the
// motion controller.
return doWaitHeartbeat(ctx, 1, WAIT_HEARTBEAT_TIMEOUT);
// Wait for a whole cycle to allow teleop to become set in
// the motion controller.
return doWaitHeartbeat(ctx, 2, WAIT_HEARTBEAT_TIMEOUT);
}
}
double now = etime();
Expand Down
7 changes: 3 additions & 4 deletions src/hal/components/homecomp.comp
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ void write_homing_out_pins(int njoints)

bool do_homing(void)
{
int jno, busy = 0;
int jno;
bool begin_all = base_get_allhomed();
(void)base_do_homing; // replaced by this custom do_homing()
do_homing_sequence();
Expand All @@ -357,11 +357,10 @@ bool do_homing(void)
H[jno].homing = 0;
H[jno].home_state = HOME_IDLE;
} else {
busy += base_1joint_state_machine(jno);
base_1joint_state_machine(jno);
}
}
if (busy > 0) homing_active = 1;
else if (sequence_state == HOME_SEQUENCE_IDLE) homing_active = 0;
update_homing_active();
if (!begin_all && base_get_allhomed()) { homing_active = 0; return 1; }
return 0;
}
Expand Down
26 changes: 26 additions & 0 deletions tests/home-dist/test-ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,32 @@ def check_moved(label, j, start, farthest, dist):
else:
print("%-28s homed" % "working switch")

# Home all: joint 0 (sequence 0), then the pair (sequence -1). A joint
# reads homing only while it homes itself.
sets("j0swpos", pos(0) - 3.0)
sets("j1swpos", pos(1) - 3.0)
sets("j2swpos", pos(2) - 3.0)
errors()
c.home(-1)
c.wait_complete()
seen_pair = False
t0 = time.time()
while time.time() - t0 < 30.0:
homing = [hal.get_value("joint.%d.homing" % j) for j in range(3)]
if homing[1] and homing[2]:
seen_pair = True
if hal.get_value("joint.0.homing") and hal.get_value("joint.1.homing"):
fail("home all: joint 0 still reads homing while the pair homes")
break
if all(hal.get_value("joint.%d.homed" % j) for j in range(3)):
break
time.sleep(0.001)
if not wait_for(lambda: all(s.homed[:3]), 5.0) or not seen_pair:
errors()
fail("home all: homed=%s, pair seen homing=%s" % (s.homed[:3], seen_pair))
else:
print("%-28s homed" % "home all")

c.state(linuxcnc.STATE_ESTOP)
c.wait_complete()

Expand Down