Import LinuxCNC source tree

This commit is contained in:
Wang Dequan
2026-08-20 06:17:39 +08:00
commit 2c814634c3
9429 changed files with 10556013 additions and 0 deletions

3
tests/single-step/checkresult Executable file
View File

@@ -0,0 +1,3 @@
#!/bin/sh
# Test passes if test-ui.py returns successfully
exit 0

View File

@@ -0,0 +1,4 @@
net Xpos => test-ui.Xpos
net Ypos => test-ui.Ypos
net Zpos => test-ui.Zpos
net counter <= motion.analog-out-00 => test-ui.counter

123
tests/single-step/test-ui.py Executable file
View File

@@ -0,0 +1,123 @@
#!/usr/bin/env python3
import linuxcnc
import linuxcnc_util
import hal
import time
import sys
import os
#
# connect to LinuxCNC
#
c = linuxcnc.command()
s = linuxcnc.stat()
e = linuxcnc.error_channel()
l = linuxcnc_util.LinuxCNC(command=c, status=s, error=e)
#
# Create and connect test feedback comp
#
h = hal.component("test-ui")
h.newpin("Xpos", hal.HAL_FLOAT, hal.HAL_IN)
h.newpin("Ypos", hal.HAL_FLOAT, hal.HAL_IN)
h.newpin("Zpos", hal.HAL_FLOAT, hal.HAL_IN)
h.newpin("counter", hal.HAL_FLOAT, hal.HAL_IN)
h.ready()
os.system("halcmd source ./postgui.hal")
def print_state():
sys.stderr.write(
"line=%d; Xpos=%.2f; Ypos=%.2f; Zpos=%.2f; counter=%d\n" %
(s.current_line, h["Xpos"], h["Ypos"], h["Zpos"], h["counter"]))
#
# Come out of E-stop, turn the machine on, home, and switch to Auto mode.
#
c.state(linuxcnc.STATE_ESTOP_RESET)
c.state(linuxcnc.STATE_ON)
c.home(0)
c.home(1)
c.home(2)
l.wait_for_home([1, 1, 1, 0, 0, 0, 0, 0, 0])
c.mode(linuxcnc.MODE_AUTO)
#
# run the .ngc test file, starting from the special line
#
c.program_open('test.ngc')
epsilon = 0.000001
def mod_5_is_0(x):
return abs((x+epsilon) % 5) < 2*epsilon
def wait_complete_step():
'''The normal `linuxcnc.command.wait_complete()` function does not
understand single-stepping. It waits for the `state` to return to
`RCS_DONE` but this does not happen when single-stepping, `state`
stays at `RCS_EXEC` while waiting for the next step.
This function instead waits for status.task.execState to tell us
that Task is no longer waiting for Motion in any way.'''
timeout = 15.0
start = time.time()
# Wait for the command to be acknowledged by Task (FIXME or is it motion?).
while time.time() - start < timeout:
s.poll()
if s.echo_serial_number >= c.serial:
break
time.sleep(0.1)
# Wait for Task to be done waiting for Motion.
while time.time() - start < timeout:
s.poll()
if s.exec_state not in [ linuxcnc.EXEC_WAITING_FOR_MOTION, linuxcnc.EXEC_WAITING_FOR_MOTION_AND_IO, linuxcnc.EXEC_WAITING_FOR_MOTION_QUEUE ]:
return
time.sleep(0.1)
raise SystemExit(f'error: timeout in wait_complete_step(), {timeout} seconds were not enough')
# Take first three steps (these cause no motion).
c.auto(linuxcnc.AUTO_STEP)
c.auto(linuxcnc.AUTO_STEP)
c.auto(linuxcnc.AUTO_STEP)
wait_complete_step()
count = 0
while True:
s.poll()
if s.interp_state == linuxcnc.INTERP_IDLE:
sys.stderr.write("Finished: Detected program finish\n")
break
(x, y) = (h["Xpos"], h["Ypos"])
if mod_5_is_0(x) and mod_5_is_0(y):
# Both axes on goal; command the next step and wait for it to finish.
sys.stderr.write("Taking step from X%.2f Y%.2f\n" % (x, y))
c.auto(linuxcnc.AUTO_STEP)
wait_complete_step()
print_state()
count += 1
if count >= 1000: # Shouldn't happen, but prevent runaways
sys.stderr.write("Finished: Exceeded max cycles\n")
sys.exit(1)
time.sleep(0.1)
if h["counter"] != 25:
sys.stderr.write("End counter incorrect: %d != 25\n" % h["counter"])
sys.exit(1)
sys.exit(0)

100
tests/single-step/test.ini Normal file
View File

@@ -0,0 +1,100 @@
[EMC]
VERSION = 1.1
#DEBUG = 0xffffffff
DEBUG = 0x0
[DISPLAY]
DISPLAY = ./test-ui.py
[TASK]
TASK = milltask
CYCLE_TIME = 0.001
[RS274NGC]
LOG_LEVEL = 999
[EMCMOT]
EMCMOT = motmod
COMM_TIMEOUT = 4.0
BASE_PERIOD = 0
SERVO_PERIOD = 1000000
[EMCIO]
TOOL_TABLE = simpockets.tbl
TOOL_CHANGE_QUILL_UP = 1
RANDOM_TOOLCHANGER = 0
[HAL]
HALFILE = LIB:core_sim.hal
[TRAJ]
NO_FORCE_HOMING = 1
AXES = 3
COORDINATES = X Y Z
HOME = 0 0 0
LINEAR_UNITS = inch
ANGULAR_UNITS = degree
DEFAULT_LINEAR_VELOCITY = 1200
MAX_LINEAR_VELOCITY = 4000
[KINS]
KINEMATICS = trivkins
JOINTS = 3
[AXIS_X]
MIN_LIMIT = -40.0
MAX_LIMIT = 40.0
MAX_VELOCITY = 4000
MAX_ACCELERATION = 10000.0
[JOINT_0]
TYPE = LINEAR
HOME = 0.000
MAX_VELOCITY = 4000
MAX_ACCELERATION = 10000.0
BACKLASH = 0.000
INPUT_SCALE = 4000
OUTPUT_SCALE = 1.000
MIN_LIMIT = -40.0
MAX_LIMIT = 40.0
FERROR = 0.050
MIN_FERROR = 0.010
[AXIS_Y]
MIN_LIMIT = -40.0
MAX_LIMIT = 40.0
MAX_VELOCITY = 4000
MAX_ACCELERATION = 10000.0
[JOINT_1]
TYPE = LINEAR
HOME = 0.000
MAX_VELOCITY = 4000
MAX_ACCELERATION = 10000.0
BACKLASH = 0.000
INPUT_SCALE = 4000
OUTPUT_SCALE = 1.000
MIN_LIMIT = -40.0
MAX_LIMIT = 40.0
FERROR = 0.050
MIN_FERROR = 0.010
[AXIS_Z]
MIN_LIMIT = -40
MAX_LIMIT = 40
MAX_VELOCITY = 4000
MAX_ACCELERATION = 10000.0
[JOINT_2]
TYPE = LINEAR
HOME = 0.0
MAX_VELOCITY = 4000
MAX_ACCELERATION = 10000.0
BACKLASH = 0.000
INPUT_SCALE = 4000
OUTPUT_SCALE = 1.000
MIN_LIMIT = -40
MAX_LIMIT = 40
FERROR = 0.050
MIN_FERROR = 0.010

View File

@@ -0,0 +1,12 @@
#1 = 0
O100 repeat [6]
M67 E0 Q[#1]
(DEBUG, 1)
G1 F500 X[5 + #1]
(DEBUG, 2)
G1 F500 Y[5 + #1]
(DEBUG, 3)
G1 F500 X[10 + #1]
#1 = [#1 + 5]
O100 endrepeat
M2

3
tests/single-step/test.sh Executable file
View File

@@ -0,0 +1,3 @@
#!/bin/bash -e
linuxcnc -r test.ini