Skip to content
Merged
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
44 changes: 44 additions & 0 deletions lib/python/linuxcnc_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,49 @@ def wait_for_home(self, joints, timeout=10.0):
raise LinuxCNC_Exception("timeout waiting for homing to complete:\nstatus.homed:" + str(self.status.homed) + "\nstatus.position:" + str(self.status.position))


def wait_for_machine_on(self, timeout=10.0):
"""Returns once the machine is on, raises LinuxCNC_Exception if
it did not turn on before the timeout. state(STATE_ON) is done
once task has passed it on, the machine is on some cycles later,
and motion refuses to home until it is."""

start_time = time.time()
while True:
self.status.poll()
if self.status.task_state == linuxcnc.STATE_ON:
return
if (time.time() - start_time) > timeout:
raise LinuxCNC_Exception("timeout waiting for the machine to turn on: task_state %d" % self.status.task_state)
time.sleep(0.01)


def home_all(self, timeout=30.0):
"""Arguments:

'timeout' is a float, the number of seconds to wait for the
machine to turn on and then for the joints to home.

Homes every joint with home(-1) once the machine is on. A
command is done once task has passed it on: the machine is on
and the joints are homed some cycles later, and task refuses
homing and MDI until they are.

Returns once every joint is homed, raises LinuxCNC_Exception if
the machine did not turn on or a joint did not home before the
timeout."""

self.wait_for_machine_on(timeout)
self.command.home(-1)
start_time = time.time()
while True:
self.status.poll()
if all(self.status.homed[:self.status.joints]):
return
if (time.time() - start_time) > timeout:
raise LinuxCNC_Exception("timeout waiting for homing to complete:\nstatus.homed:" + str(self.status.homed) + "\nstatus.position:" + str(self.status.position))
time.sleep(0.01)


def home_joints(self, joints, timeout=10.0):
"""Arguments:

Expand All @@ -118,6 +161,7 @@ def home_joints(self, joints, timeout=10.0):
Returns once all the joints are homed, raises
LinuxCNC_Exception if one did not home before the timeout."""

self.wait_for_machine_on(timeout)
for joint in joints:
self.command.home(joint)
start_time = time.time()
Expand Down
5 changes: 2 additions & 3 deletions tests/kins-limits/box/test-ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# The [AXIS_L] box is the machine frame envelope, the carriage and not the
# tool tip: see README.
import linuxcnc
import linuxcnc_util
import sys
import time

Expand Down Expand Up @@ -84,9 +85,7 @@ def refused(cmd, needle):

c.state(linuxcnc.STATE_ESTOP_RESET)
c.state(linuxcnc.STATE_ON)
c.wait_complete(30)
c.home(-1)
c.wait_complete(60)
linuxcnc_util.LinuxCNC(command=c, status=s).home_all()
c.mode(linuxcnc.MODE_MDI)
c.wait_complete(30)
drain()
Expand Down
4 changes: 2 additions & 2 deletions tests/kins-limits/jog-travel/test-ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# reaches its soft limit, and a jog away from it is free: see README.
import hal
import linuxcnc
import linuxcnc_util
import os
import sys
import time
Expand Down Expand Up @@ -145,8 +146,7 @@ def jog_ended(what):
c.state(linuxcnc.STATE_ESTOP_RESET)
c.state(linuxcnc.STATE_ON)
c.wait_complete(30)
c.home(-1)
c.wait_complete(60)
linuxcnc_util.LinuxCNC(command=c, status=s).home_all()
c.mode(linuxcnc.MODE_MDI)
c.wait_complete(30)
drain()
Expand Down
4 changes: 2 additions & 2 deletions tests/kins-limits/jog/test-ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# own limits: see README.
import hal
import linuxcnc
import linuxcnc_util
import os
import sys
import time
Expand Down Expand Up @@ -124,8 +125,7 @@ def tip_held(what):
c.state(linuxcnc.STATE_ESTOP_RESET)
c.state(linuxcnc.STATE_ON)
c.wait_complete(30)
c.home(-1)
c.wait_complete(60)
linuxcnc_util.LinuxCNC(command=c, status=s).home_all()
c.mode(linuxcnc.MODE_MDI)
c.wait_complete(30)
drain()
Expand Down
4 changes: 2 additions & 2 deletions tests/kins-limits/swing/test-ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# its own limits: see README.
import hal
import linuxcnc
import linuxcnc_util
import os
import sys
import time
Expand Down Expand Up @@ -70,8 +71,7 @@ def log_samples():
c.state(linuxcnc.STATE_ESTOP_RESET)
c.state(linuxcnc.STATE_ON)
c.wait_complete(30)
c.home(-1)
c.wait_complete(60)
linuxcnc_util.LinuxCNC(command=c, status=s).home_all()
c.mode(linuxcnc.MODE_MDI)
c.wait_complete(30)
drain()
Expand Down
4 changes: 2 additions & 2 deletions tests/kins-orient-linear/test-ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# 5axiskins orients with B and C; [AXIS_B] TYPE = LINEAR: see README.

import linuxcnc
import linuxcnc_util
import os
import sys

Expand All @@ -11,8 +12,7 @@

c.state(linuxcnc.STATE_ESTOP_RESET)
c.state(linuxcnc.STATE_ON)
c.home(-1)
c.wait_complete()
linuxcnc_util.LinuxCNC(command=c, status=s).home_all()
c.mode(linuxcnc.MODE_MDI)
c.wait_complete()

Expand Down
4 changes: 2 additions & 2 deletions tests/kins-switch/test-ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# where the interpreter reads far ahead of the machine.
import hal
import linuxcnc
import linuxcnc_util
import os
import sys
import time
Expand Down Expand Up @@ -88,8 +89,7 @@ def mdi(cmd):
c.state(linuxcnc.STATE_ESTOP_RESET)
c.state(linuxcnc.STATE_ON)
done(30)
c.home(-1)
done(60)
linuxcnc_util.LinuxCNC(command=c, status=s).home_all()
# start in identity every run, the abort's G13.1 may or may not have run yet
c.mode(linuxcnc.MODE_MDI)
done(30)
Expand Down
4 changes: 2 additions & 2 deletions tests/kins-switchkins-core/test-ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# as type 0 and an X offset of 5 as type 1, and switchkins_core does the rest.
import hal
import linuxcnc
import linuxcnc_util
import sys
import time

Expand Down Expand Up @@ -60,8 +61,7 @@ def check(what, got, want):
c.state(linuxcnc.STATE_ESTOP_RESET)
c.state(linuxcnc.STATE_ON)
c.wait_complete(30)
c.home(-1)
c.wait_complete(60)
linuxcnc_util.LinuxCNC(command=c, status=s).home_all()
c.mode(linuxcnc.MODE_MDI)
c.wait_complete(30)
drain()
Expand Down
4 changes: 2 additions & 2 deletions tests/kins-tool-offset/test-ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
# length back out again through motion alone.

import linuxcnc
import linuxcnc_util
import hal
import subprocess
import sys
Expand All @@ -23,8 +24,7 @@

c.state(linuxcnc.STATE_ESTOP_RESET)
c.state(linuxcnc.STATE_ON)
c.home(-1)
c.wait_complete()
linuxcnc_util.LinuxCNC(command=c, status=s).home_all()
c.mode(linuxcnc.MODE_MDI)

errors = 0
Expand Down
4 changes: 2 additions & 2 deletions tests/ptp-machine-frame/test-ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# frame: see README.

import linuxcnc
import linuxcnc_util
import hal
import gcode
import preview_helpers
Expand All @@ -22,8 +23,7 @@

c.state(linuxcnc.STATE_ESTOP_RESET)
c.state(linuxcnc.STATE_ON)
c.home(-1)
c.wait_complete()
linuxcnc_util.LinuxCNC(command=c, status=s).home_all()
c.mode(linuxcnc.MODE_MDI)

errors = 0
Expand Down
4 changes: 2 additions & 2 deletions tests/tool-info/pocket-numbers/shared/abort-ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import time

import linuxcnc
import linuxcnc_util

c = linuxcnc.command()
s = linuxcnc.stat()
Expand Down Expand Up @@ -59,8 +60,7 @@ def report():
print("=== begin")
c.state(linuxcnc.STATE_ESTOP_RESET)
c.state(linuxcnc.STATE_ON)
c.home(-1)
c.wait_complete()
linuxcnc_util.LinuxCNC(command=c, status=s).home_all()
c.mode(linuxcnc.MODE_MDI)
c.wait_complete()
drain()
Expand Down
4 changes: 2 additions & 2 deletions tests/tool-info/pocket-numbers/shared/table-ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import time

import linuxcnc
import linuxcnc_util

c = linuxcnc.command()
s = linuxcnc.stat()
Expand Down Expand Up @@ -53,8 +54,7 @@ def table():
table()
c.state(linuxcnc.STATE_ESTOP_RESET)
c.state(linuxcnc.STATE_ON)
c.home(-1)
c.wait_complete()
linuxcnc_util.LinuxCNC(command=c, status=s).home_all()

print("tool_offset(1, z=7, x=0.25)")
c.tool_offset(1, 7.0, 0.25, 0.0, 0.0, 0.0, 0)
Expand Down
4 changes: 2 additions & 2 deletions tests/tool-info/pocket-numbers/shared/test-ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import gcode
import hal
import linuxcnc
import linuxcnc_util
from rs274.interpret import StatMixin

c = linuxcnc.command()
Expand Down Expand Up @@ -113,8 +114,7 @@ def preview():
print("=== begin")
c.state(linuxcnc.STATE_ESTOP_RESET)
c.state(linuxcnc.STATE_ON)
c.home(-1)
c.wait_complete()
linuxcnc_util.LinuxCNC(command=c, status=s).home_all()
c.mode(linuxcnc.MODE_MDI)
c.wait_complete()
drain()
Expand Down
15 changes: 13 additions & 2 deletions tests/twp-native/native.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@


import linuxcnc
import linuxcnc_util
import hal
import sys
import os
Expand All @@ -29,8 +30,7 @@ def error(self, *a): print("oracle:", a)

c.state(linuxcnc.STATE_ESTOP_RESET)
c.state(linuxcnc.STATE_ON)
c.home(-1)
c.wait_complete()
linuxcnc_util.LinuxCNC(command=c, status=s).home_all()
c.mode(linuxcnc.MODE_MDI)

errors = 0
Expand Down Expand Up @@ -68,6 +68,17 @@ def done(timeout=60):
time.sleep(0.002)
error("timed out waiting for task")

# poll status until cond() holds
def until(cond, what, timeout=60):
deadline = time.time() + timeout
while time.time() < deadline:
s.poll()
if cond():
return True
time.sleep(0.002)
error("timed out waiting for " + what)
return False

# the move has ended when task has nothing left to run and motion is at
# rest; in position with an empty queue alone is also true before task has
# sent the move on. Status is a copy task writes once a cycle, so it only
Expand Down
6 changes: 3 additions & 3 deletions tests/twp-native/test-ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,11 +313,11 @@ def pose_near(pairs, b_now, c_now, limited):
error("%s was accepted while a plane is active" % cmd)
else:
print("refused as expected:", m[1])
# the abort's cancel goes through task's queue: status has it some
# cycles after the error
until(lambda: not s.g68_active, "the abort after %s to cancel the plane" % cmd, 30)
c.mode(linuxcnc.MODE_MDI)
done()
s.poll()
if s.g68_active:
error("the abort after %s left the plane active" % cmd)
mdi("G69")

# --- stopping a program that has a plane ---------------------------------
Expand Down
4 changes: 2 additions & 2 deletions tests/twp-table/test-ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# G53.1 P1 and P2 on the xyzac-trt sim: see README.

import linuxcnc
import linuxcnc_util
import sys
import os
import time
Expand All @@ -16,8 +17,7 @@

c.state(linuxcnc.STATE_ESTOP_RESET)
c.state(linuxcnc.STATE_ON)
c.home(-1)
c.wait_complete()
linuxcnc_util.LinuxCNC(command=c, status=s).home_all()
c.mode(linuxcnc.MODE_MDI)

errors = 0
Expand Down