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

228
tests/motion/g0/checkresult Executable file
View File

@@ -0,0 +1,228 @@
#!/usr/bin/env python3
import sys
import os
from subprocess import *
#
# read some stuff out of the INI file
#
# servo period in nanoseconds
servo_period_ns = float(Popen(
[
"inivar",
"-var",
"SERVO_PERIOD",
"-sec",
"EMCMOT",
"-ini",
"%s/motion-test.ini" % os.getenv("TEST_DIR")
],
stdout=PIPE
).communicate()[0])
cycles_per_second = 1000000000.0 / servo_period_ns
# max acceleration in inches per second^2
max_acceleration_ips2 = float(Popen(
[
"inivar",
"-var",
"MAX_ACCELERATION",
"-sec",
"AXIS_X",
"-ini",
"%s/motion-test.ini" % os.getenv("TEST_DIR")
],
stdout=PIPE
).communicate()[0])
# max acceleration in inches per second per servo-thread cycle
# A move that never blends (like this lone G0) runs at the full machine
# acceleration; the 1/2 parabolic-blend reservation only applies during an
# actual blend overlap.
max_acceleration_ipspc = (max_acceleration_ips2 / cycles_per_second)
# max velocity in inches per second
max_velocity_ips = float(Popen(
[
"inivar",
"-var",
"MAX_VELOCITY",
"-sec",
"AXIS_X",
"-ini",
"%s/motion-test.ini" % os.getenv("TEST_DIR")
],
stdout=PIPE
).communicate()[0])
max_velocity_ipc = max_velocity_ips / cycles_per_second
# read the samples file and turn it into an array, where index i is an
# array of the floats found on line i of the samples file
samples_filename = sys.argv[1] + ".halsamples"
with open(samples_filename) as f:
lines = f.readlines()
samples = []
for line in lines:
s = [ float(x) for x in line.split() ]
samples.append(s)
#
# here comes the test proper
#
# verify that X starts at 0.000000
if samples[0][1] != 0.000000:
print("error: sample 0: X starts at %.6f, not at 0.000000" % samples[0][1])
sys.exit(1)
#print("line 0: X starts at 0.000000")
# find where X starts moving (X is the second column, column 1)
for i in range(0, len(samples) - 1):
if samples[i][1] != samples[i+1][1]:
break
if len(samples) == i+2:
print("error: no acceleration detected, did linuxcnc take too long to start moving?")
sys.exit(1)
#print("line %d: accel phase starts" % i)
# now i is the sample before it starts moving
# verify accel does not exceed maxaccel
# verify vel does not exceed maxvel
# verify accel phase stops when vel == maxvel
highest_seen_accel_ipc2 = 0
old_accel_ipc2 = 0
old_v_ipc = 0
for i in range(i, len(samples) - 1):
new_v_ipc = samples[i+1][1] - samples[i][1]
accel_ipc2 = new_v_ipc - old_v_ipc
highest_seen_accel_ipc2 = max(accel_ipc2, highest_seen_accel_ipc2)
#print("line %d: X=%.6f, v=%.6f i/c (%.6f i/s), a=%.6f i/c^2 (%.6f i/s^2)" % (i, samples[i][1], new_v_ipc, (new_v_ipc * cycles_per_second), accel_ipc2, (accel_ipc2 * cycles_per_second * cycles_per_second)))
# i hate floating point
if ((accel_ipc2 * cycles_per_second) - max_acceleration_ipspc) > 0.0000001:
print("error: line %d: detected accel constraint violation!" % i)
print("error: detected accel %.6f i/c^2 (%.6f i/s^2)" % (accel_ipc2, (accel_ipc2 * cycles_per_second * cycles_per_second)))
print("error: max accel %.6f i/s^2)" % max_acceleration_ips2)
sys.exit(1)
if (new_v_ipc - max_velocity_ipc) > 0.0000001:
print("error: line %d: detected vel constraint violation!" % i)
print("error: detected vel %.6f i/c (%.6f i/s)" % (new_v_ipc, new_v_ipc * cycles_per_second))
print("error: max vel %.6f i/c (%.6f i/s)" % (max_velocity_ipc, max_velocity_ips))
sys.exit(1)
if accel_ipc2 == 0:
#print("line %d: accel phase over" % i)
break
old_v_ipc = new_v_ipc
# verify highest seen accel is very close to max accel
if abs(max_acceleration_ipspc - (highest_seen_accel_ipc2 * cycles_per_second)) > 0.0000001:
print("error: accel only reached %.6f i/c^2 (%.6f i/s^2)" % (highest_seen_accel_ipc2, (highest_seen_accel_ipc2 * cycles_per_second * cycles_per_second)))
print("error: max accel is %.6f i/s^2" % max_acceleration_ips2)
sys.exit(1)
#print(" accel reached but did not exceed 1/2 of max accel of %.6f i/s^2" % max_acceleration_ips2)
#print("line %d: entering cruise phase, vel=%.6f i/s, max_accel = %.6f i/s^2" % (i, new_v_ipc * cycles_per_second, highest_seen_accel_ipc2 * cycles_per_second * cycles_per_second))
# now i is the first sample of the cruise phase
# wait for vel to drop again
for i in range(i, len(samples) - 1):
new_v_ipc = samples[i+1][1] - samples[i][1]
if abs(new_v_ipc - old_v_ipc) > 0.0000001:
# decel phase starting
break
old_v_ipc = new_v_ipc
#print("line %d: decel phase starting, old_v=%.6f i/s, new_v=%.6f i/s" % (i, old_v_ipc * cycles_per_second, new_v_ipc * cycles_per_second))
# now i is the sample before it starts decel
# verify accel does not exceed maxaccel
# verify vel does not exceed maxvel
# verify decel phase stops when vel == 0
highest_seen_accel_ipc2 = 0
old_accel_ipc2 = 0
for i in range(i, len(samples) - 1):
new_v_ipc = samples[i+1][1] - samples[i][1]
accel_ipc2 = new_v_ipc - old_v_ipc
highest_seen_accel_ipc2 = min(accel_ipc2, highest_seen_accel_ipc2)
#print("line %d: X=%.6f, v=%.6f i/c (%.6f i/s), a=%.6f i/c^2 (%.6f i/s^2)" % (i, samples[i][1], new_v_ipc, (new_v_ipc * cycles_per_second), accel_ipc2, (accel_ipc2 * cycles_per_second * cycles_per_second)))
# i hate floating point
if ((accel_ipc2 * cycles_per_second) - max_acceleration_ipspc) > 0.0000001:
print("error: line %d: detected accel constraint violation!" % i)
print("error: detected accel %.6f i/c^2 (%.6f i/s^2)" % (accel_ipc2, accel_ipc2 * cycles_per_second * cycles_per_second))
print("error: max accel %.6f i/s^2)" % max_acceleration_ips2)
sys.exit(1)
if (new_v_ipc - max_velocity_ipc) > 0.0000001:
print("error: line %d: detected vel constraint violation!" % i)
print("error: detected vel %.6f i/c (%.6f i/s)" % (new_v_ipc, new_v_ipc * cycles_per_second))
print("error: max vel %.6f i/c (%.6f i/s)" % (max_velocity_ipc, max_velocity_ips))
sys.exit(1)
if new_v_ipc < -0.0000001:
print("error: line %d: detected vel undershoot!" % i)
print("error: detected vel %.6f i/c (%.6f i/s)" % (new_v_ipc, new_v_ipc * cycles_per_second))
sys.exit(1)
if new_v_ipc == 0:
# print("line %d: decel phase over" % i)
break
old_v_ipc = new_v_ipc
# verify highest seen accel is very close to max accel
if abs(max_acceleration_ipspc + (highest_seen_accel_ipc2 * cycles_per_second)) > 0.0000001:
print("error: accel only reached %.6f i/c^2 (%.6f i/s^2)" % (highest_seen_accel_ipc2, (highest_seen_accel_ipc2 * cycles_per_second * cycles_per_second)))
print("error: max accel is %.6f i/s^2" % max_acceleration_ips2)
sys.exit(1)
#print(" decel reached but did not exceed 1/2 of max accel of %.6f i/s^2" % max_acceleration_ips2)
# verify X stopped at 1.000000
if samples[i][1] != 1.000000:
print("error: line %d: X stopped at %.6f, not at 1.000000!" % (i, samples[i][1]))
sys.exit(1)
#print(" X reached target of 1.0000")
# verify X doesn't move from now on
for i in range(i, len(samples) - 1):
if samples[i][1] != samples[i+1][1]:
print("error: line %d: X moved!" % i)
sys.exit(1)
#print("line %d: X did not move after reaching target" % i)
sys.exit(0)

View File

@@ -0,0 +1,10 @@
# sample where motion tells us to go
loadrt sampler depth=5000 cfg=ff
addf sampler.0 servo-thread
net Xpos => sampler.0.pin.0
net Ypos => sampler.0.pin.1

View File

@@ -0,0 +1,137 @@
[EMC]
VERSION = 1.1
MACHINE = MOTION-TEST
# Debug level, 0 means no messages. See src/emc/nml_int/emcglb.h for others
DEBUG = 0x7FFFFFFF
#DEBUG = 0x10
[DISPLAY]
DISPLAY = linuxcncrsh
#PROGRAM_PREFIX = /home/seb/emc2/nc_files
#MAX_FEED_OVERRIDE = 2.0
[RS274NGC]
# File containing interpreter variables
PARAMETER_FILE = sim.var
[EMCMOT]
EMCMOT = motmod
# Timeout for comm to emcmot, in seconds
COMM_TIMEOUT = 4.0
# BASE_PERIOD is unused in this configuration but specified in LIB:core_sim.hal
BASE_PERIOD = 0
# Servo task period, in nano-seconds
SERVO_PERIOD = 1000000
[TASK]
TASK = milltask
CYCLE_TIME = 0.001
[HAL]
HALFILE = LIB:core_sim.hal
HALFILE = motion-test.hal
[TRAJ]
AXES = 3
COORDINATES = X Y Z
HOME = 0 0 0
LINEAR_UNITS = inch
ANGULAR_UNITS = degree
DEFAULT_LINEAR_VELOCITY = 1.2
MAX_LINEAR_VELOCITY = 4
NO_FORCE_HOMING = 1
# Axes sections ---------------------------------------------------------------
# First axis
[EMCIO]
# tool table file
TOOL_TABLE = simpockets.tbl
TOOL_CHANGE_POSITION = 0 0 2
RANDOM_TOOLCHANGER = 1
[KINS]
KINEMATICS = trivkins
JOINTS = 3
[AXIS_X]
MIN_LIMIT = -40.0
MAX_LIMIT = 40.0
MAX_VELOCITY = 4
MAX_ACCELERATION = 100.0
[JOINT_0]
TYPE = LINEAR
HOME = 0.000
MAX_VELOCITY = 4
MAX_ACCELERATION = 100.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
HOME_OFFSET = 0.0
HOME_SEARCH_VEL = 0.0
HOME_LATCH_VEL = 0.0
HOME_USE_INDEX = NO
HOME_IGNORE_LIMITS = NO
HOME_SEQUENCE = 1
# Second axis
[AXIS_Y]
MIN_LIMIT = -40.0
MAX_LIMIT = 40.0
MAX_VELOCITY = 4
MAX_ACCELERATION = 100.0
[JOINT_1]
TYPE = LINEAR
HOME = 0.000
MAX_VELOCITY = 4
MAX_ACCELERATION = 100.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
HOME_OFFSET = 0.0
HOME_SEARCH_VEL = 0.0
HOME_LATCH_VEL = 0.0
HOME_USE_INDEX = NO
HOME_IGNORE_LIMITS = NO
HOME_SEQUENCE = 1
# Third axis
[AXIS_Z]
MIN_LIMIT = -4.0
MAX_LIMIT = 4.0
MAX_VELOCITY = 4
MAX_ACCELERATION = 100.0
[JOINT_2]
TYPE = LINEAR
HOME = 0.0
MAX_VELOCITY = 4
MAX_ACCELERATION = 100.0
BACKLASH = 0.000
INPUT_SCALE = 4000
OUTPUT_SCALE = 1.000
MIN_LIMIT = -4.0
MAX_LIMIT = 4.0
FERROR = 0.050
MIN_FERROR = 0.010
HOME_OFFSET = 1.0
HOME_SEARCH_VEL = 0.0
HOME_LATCH_VEL = 0.0
HOME_USE_INDEX = NO
HOME_IGNORE_LIMITS = NO
HOME_SEQUENCE = 0

74
tests/motion/g0/test.sh Executable file
View File

@@ -0,0 +1,74 @@
#!/bin/bash
#export PATH=$PATH:$EMC2_HOME/tests/helpers
#source $EMC2_HOME/tests/helpers/test-functions.sh
wait_for_pin() {
pin="$1"
value="$2"
maxwait=10 # seconds
while [ 0 -lt $maxwait ] \
&& [ "$value" != "$(halcmd -s show pin "$pin" | awk '{print $4}')" ]; do
sleep 1
maxwait=$((maxwait - 1))
done
if [ 0 -eq $maxwait ] ; then
echo "E: waiting for pin $pin timed out"
kill "$linuxcncpid"
kill "$samplerpid"
exit 1
fi
}
linuxcnc motion-test.ini &
linuxcncpid=$!
# let linuxcnc come up
TOGO=80
while [ $TOGO -gt 0 ]; do
echo "I: trying to connect to linuxcncrsh TOGO=$TOGO"
if nc -z localhost 5007; then
break
fi
sleep 0.25
TOGO=$((TOGO - 1))
done
if [ $TOGO -eq 0 ]; then
echo "I: connection to linuxcncrsh timed out"
exit 1
fi
wait_for_pin motion.in-position TRUE
echo "I: starting to capture data"
halsampler -t >| result.halsamples &
samplerpid=$!
(
echo "hello EMC mt 1.0"
echo "set enable EMCTOO"
echo "set estop off"
echo "set machine on"
echo "set mode mdi"
dist=1
echo "set mdi g0x$dist"
# Wait for movement to complete
wait_for_pin joint.0.pos-fb $dist
wait_for_pin joint.0.in-position TRUE
wait_for_pin joint.1.in-position TRUE
echo "shutdown"
) | nc localhost 5007
kill "$samplerpid"
wait "$samplerpid"
echo "I: finished capturing data"
# wait for linuxcnc to finish
wait "$linuxcncpid"
exit 0