Skip to content
Merged
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
26 changes: 26 additions & 0 deletions src/emc/usr_intf/emcrsh.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ constexpr auto JOINT_WAIT_HOMED_SLEEP = 100ms; // Sleep time between checks
// up and reflect a requested state change in the status
#define WAIT_TASK_STATE_CHANGE_MAX 25

// Maximum wait time for task to receive a command
#define WAIT_TASK_RECEIVED_TIMEOUT 10.0

typedef enum { cmdUnknown, cmdHello, cmdSet, cmdGet, cmdQuit, cmdShutdown, cmdHelp } cmdType;

typedef enum {
Expand Down Expand Up @@ -908,6 +911,23 @@ static cmdResponseType doWaitHeartbeat(connectionRecType &ctx, int periods, doub
return rtError;
}

// Task may be busy for a while before it gets to a command (the interpreter
// syncs the parameter file to disk on a state change) and its status,
// heartbeat included, stands still until then. emcTimeout is 0 (infinite)
// in linuxcncrsh, so bound the wait.
static cmdResponseType waitTaskReceived(connectionRecType &ctx, const std::string &cmd)
{
double saved = emcTimeout;
emcTimeout = WAIT_TASK_RECEIVED_TIMEOUT;
int rv = emcCommandWaitReceived();
emcTimeout = saved;
if (rv) {
errornl(ctx, fmt::format("Task did not receive '{}' within {:.1f} seconds", cmd, WAIT_TASK_RECEIVED_TIMEOUT));
return rtError;
}
return rtOk;
}

static cmdResponseType setJointWaitHomed(connectionRecType &ctx)
{
// SET JOINT_WAIT_HOMED [joint] [timeout]
Expand Down Expand Up @@ -1009,6 +1029,8 @@ static cmdResponseType setMachine(connectionRecType &ctx)
return rtError;
break;
}
if (rtOk != waitTaskReceived(ctx, fmt::format("SET MACHINE {}", onOff(machon))))
return rtError;
// Setting machine on/off takes a moment
// We need to wait for the motion controller to catch up
// and set/clear the motion enable flag internally.
Expand Down Expand Up @@ -1052,6 +1074,8 @@ static cmdResponseType setEStop(connectionRecType &ctx)
break;
}

if (rtOk != waitTaskReceived(ctx, fmt::format("SET ESTOP {}", onOff(estopon))))
return rtError;
// Setting/clearing ESTOP takes a moment
for(unsigned toc = 0; toc < WAIT_TASK_STATE_CHANGE_MAX; toc++) {
// Wait for the motion control to run
Expand Down Expand Up @@ -1445,6 +1469,8 @@ static cmdResponseType setJointHome(connectionRecType &ctx)
return rtError;

if (joint >= 0) {
if (rtOk != waitTaskReceived(ctx, fmt::format("SET JOINT_HOME {}", joint)))
return rtError;
// The motion controller needs a servo-thread run to raise the
// homing flag. Wait for it so that a following command, like
// 'SET JOINT_WAIT_HOMED', can rely on the state being visible.
Expand Down