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
1 change: 1 addition & 0 deletions docs/src/config/ini-homing.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ If any joint has a *negative* HOME_SEQUENCE value, then all joints with the same
A *negative* HOME_SEQUENCE also applies to commands to home a single joint.
If the HOME_SEQUENCE value is *negative*, all joints having the same absolute value of that HOME_SEQUENCE will be *homed together with a synchronized final move*.
If the HOME_SEQUENCE value is zero or positive, a command to home the joint will home only the specified joint.
A command to home a single joint (or synchronized group) while other joints are homing starts it right away, next to them; during a *HOME ALL* it is refused.

The joints of a synchronized group are treated as rigidly coupled sides of one machine, so no joint moves alone for an unknown distance:
if any joint starts on its home switch, every joint of the group backs off together until every switch is clear, and then every joint searches together;
Expand Down
4 changes: 0 additions & 4 deletions src/emc/motion/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -1765,10 +1765,6 @@ void emcmotCommandHandler_locked(void *arg, long servo_period)
joint_num);
return;
}
if ( get_homing_is_active() ) {
reportError("Homing not possible until current homing process is finished.\n");
return;
}
if (!GET_MOTION_ENABLE_FLAG()) {
break;
}
Expand Down
104 changes: 81 additions & 23 deletions src/emc/motion/homing.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ typedef enum {

static home_sequence_state_t sequence_state;
static int current_sequence = 0;
static bool home_all_run; // the running sequence is a Home All
static bool homing_active;

/* internal states for homing */
Expand Down Expand Up @@ -127,6 +128,7 @@ typedef struct {
int home_sequence; // intfc, updateable
bool volatile_home; // intfc
bool home_is_synchronized;
bool sync_now; // its synchronized group is in step
bool moved; // a move was started in this homing
double move_start; // pos_cmd when the current move began
double move_dist; // its HOME_*_DIST bound, 0 = unbounded
Expand Down Expand Up @@ -346,6 +348,43 @@ static void do_home_all(void)
}
} // do_home_all()

/* Start 'jno', and the joints synchronized with it, while other joints
are homing. They run next to the running joints, outside the
sequence. Not during a Home All, whose sequence decides the order. */
static void join_homing(int jno)
{
int jj;
bool group;
if (home_all_run && sequence_state != HOME_SEQUENCE_IDLE) {
rtapi_print_msg(RTAPI_MSG_ERR,
_("Homing not possible until current homing process is finished.\n"));
return;
}
for (jj = 0; jj < all_joints; jj++) {
group = (jj == jno)
|| ( H[jno].home_sequence < 0
&& ABS(H[jj].home_sequence) == ABS(H[jno].home_sequence));
if (group && H[jj].joint_in_sequence && H[jj].home_state != HOME_IDLE) {
rtapi_print_msg(RTAPI_MSG_ERR,
_("Homing not possible until current homing process is finished.\n"));
return;
}
}
for (jj = 0; jj < all_joints; jj++) {
group = (jj == jno)
|| ( H[jno].home_sequence < 0
&& ABS(H[jj].home_sequence) == ABS(H[jno].home_sequence));
if (!group) {continue;}
if (H[jno].home_sequence < 0) {
H[jj].home_sequence = H[jno].home_sequence;
}
joints[jj].free_tp.enable = 0;
H[jj].joint_in_sequence = 1;
H[jj].home_state = HOME_START;
}
homing_active = 1;
} // join_homing()

static void do_home_one_joint(int jno)
{
//NOTE: if H[jno].home_sequence neg, home all joints in sequence
Expand Down Expand Up @@ -480,6 +519,9 @@ static void do_homing_sequence(void)
}
sequence_is_set = 1;
current_sequence = 0;
home_all_run = 1;
} else {
home_all_run = 0;
}
/* Initializations */
for(i=0; i < all_joints; i++) {
Expand Down Expand Up @@ -554,9 +596,14 @@ static void do_homing_sequence(void)
}
}
if(!seen) {
/* all joints at this step have finished, move on to next step */
current_sequence++;
sequence_state = HOME_SEQUENCE_START_JOINTS;
if (home_all_run) {
/* all joints at this step have finished, move on to next step */
current_sequence++;
sequence_state = HOME_SEQUENCE_START_JOINTS;
} else {
/* a single joint or synchronized group: done */
sequence_state = HOME_SEQUENCE_IDLE;
}
}
break;

Expand Down Expand Up @@ -645,6 +692,15 @@ static void base_write_homing_out_pins(int njoints)
}

static void base_do_home_joint(int jno) {
if (homing_active) {
if (jno == -1) {
rtapi_print_msg(RTAPI_MSG_ERR,
_("Homing not possible until current homing process is finished.\n"));
} else {
join_homing(jno);
}
return;
}
if (jno == -1) {
H[0].homed = 0; // ensure at least one unhomed
do_home_all();
Expand Down Expand Up @@ -791,25 +847,31 @@ static bool base_get_homing_at_index_search_wait(int jno) {
return H[jno].home_state == HOME_INDEX_SEARCH_WAIT ? 1 : 0;
}

static bool sync_now = 0;
static void sync_reset(void) { sync_now=0; return; }
// a joint of the same synchronized group
static bool same_group(int joint_num, int jno)
{
if (!H[jno].joint_in_sequence) {return 0;}
if (H[jno].home_sequence >= 0) {return 0;}
if (ABS(H[jno].home_sequence) != ABS(H[joint_num].home_sequence)) {return 0;}
if (H[jno].home_flags & HOME_ABSOLUTE_ENCODER) {return 0;}
return 1;
}

static bool sync_ready(int joint_num)
{
// defer a move until all joints in sequence are at current state
if ( ( ABS(H[joint_num].home_sequence) == current_sequence)
&& !sync_now) {
int jno;
for (jno = 0; jno < all_joints; jno++) {
if (!H[jno].joint_in_sequence) {continue;}
if (ABS(H[jno].home_sequence) != current_sequence) {continue;}
if (H[jno].home_flags & HOME_ABSOLUTE_ENCODER) {continue;}
if (H[jno].home_state != H[joint_num].home_state) {
sync_now = 0; return 0; // not ready
}
// defer a move until all joints of the group are at current state
int jno;
if (H[joint_num].sync_now) {return 1;}
for (jno = 0; jno < all_joints; jno++) {
if (!same_group(joint_num, jno)) {continue;}
if (H[jno].home_state != H[joint_num].home_state) {
return 0; // not ready
}
sync_now = 1;
}
for (jno = 0; jno < all_joints; jno++) {
if (same_group(joint_num, jno)) {H[jno].sync_now = 1;}
}
H[joint_num].sync_now = 1;
return 1; // ready
} // sync_ready()

Expand All @@ -822,11 +884,7 @@ static bool sync_ready(int joint_num)
static bool sync_partner(int joint_num, int jno)
{
if (jno == joint_num) {return 0;}
if (!H[jno].joint_in_sequence) {return 0;}
if (ABS(H[jno].home_sequence) != current_sequence) {return 0;}
if (ABS(H[joint_num].home_sequence) != current_sequence) {return 0;}
if (H[jno].home_flags & HOME_ABSOLUTE_ENCODER) {return 0;}
return 1;
return same_group(joint_num, jno);
}

// a partner sits on its switch before having searched for it
Expand Down Expand Up @@ -926,7 +984,7 @@ static int base_1joint_state_machine(int joint_num)
H[joint_num].homed = 0;
}
joint->free_tp.enable = 0; /* stop any existing motion */
sync_reset(); /* stop any interrupted/canceled sync */
H[joint_num].sync_now = 0; /* stop any interrupted/canceled sync */
H[joint_num].pause_timer = 0; /* reset delay counter */
/* figure out exactly what homing sequence is needed */
if (H[joint_num].home_flags & HOME_ABSOLUTE_ENCODER) {
Expand Down
9 changes: 5 additions & 4 deletions src/emc/usr_intf/axis/scripts/axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -2010,10 +2010,11 @@ def all_homed():

def go_home(num):
s.poll()
for j in range(s.joints):
if s.joint[j]["homing"]:
print(_("Homing not possible until current homing process is finished."))
return
if any(s.joint[j]["homing"] for j in range(s.joints)):
# already in joint mode; waiting here would block until the
# homing joints stop
c.home(num)
return
set_motion_teleop(0)
c.home(num)
c.wait_complete()
Expand Down
10 changes: 5 additions & 5 deletions src/emc/usr_intf/gmoccapy/gmoccapy.py
Original file line number Diff line number Diff line change
Expand Up @@ -4416,10 +4416,7 @@ def _on_btn_home_clicked(self, widget):
# home axis or joint?
LOG.debug("on button home clicked = {0}".format(widget.get_property("name")))
self.stat.poll()
for j in range(self.stat.joints):
if self.stat.joint[j]["homing"]:
self._show_error((linuxcnc.OPERATOR_DISPLAY, _("Homing not possible until current homing process is finished.")))
return
homing = any(self.stat.joint[j]["homing"] for j in range(self.stat.joints))
if "axis" in widget.get_property("name"):
value = widget.get_property("name")[-1]
# now get the joint from directory by the value
Expand All @@ -4429,7 +4426,10 @@ def _on_btn_home_clicked(self, widget):
elif "all" in widget.get_property("name"):
joint_or_axis = -1

self._set_motion_mode(0)
# while homing, already in joint mode; waiting would block until
# the homing joints stop
if not homing:
self._set_motion_mode(0)
self.command.home(joint_or_axis)

def _unhome_signal(self, object, joint):
Expand Down
23 changes: 23 additions & 0 deletions tests/home-dist/test-ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,29 @@ def check_moved(label, j, start, farthest, dist):
else:
print("%-28s homed" % "home all")

# Homing the pair while joint 0 is still homing starts it next to joint
# 0, and all three finish homed (#3314).
sets("j0swpos", pos(0) - 3.0)
sets("j1swpos", pos(1) - 3.0)
sets("j2swpos", pos(2) - 3.0)
errors()
c.teleop_enable(0)
c.wait_complete()
c.home(0)
c.wait_complete()
if not wait_for(lambda: s.joint[0]["homing"], 5.0):
fail("concurrent: joint 0 did not start homing")
c.home(1)
if not wait_for(lambda: s.joint[0]["homing"] and s.joint[1]["homing"] and s.joint[2]["homing"], 5.0):
fail("concurrent: the pair did not start while joint 0 was homing")
if not wait_for(lambda: all(s.homed[:3]) and not any(j["homing"] for j in s.joint[:3]), 30.0):
fail("concurrent: homed=%d,%d,%d" % tuple(s.homed[:3]))
else:
print("%-28s homed" % "pair joins joint 0")
msgs = errors()
if msgs:
fail("concurrent: unexpected errors %s" % msgs)

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

Expand Down