按推荐建议,继续执行

结论:已将 LinuxCNC TRT xyzac/xyzbc 运动学源码纳入 vendored manifest、native probe 和文档验证链,完整 native 验证通过。
This commit is contained in:
2026-06-07 19:21:54 +08:00
parent 1b2f95b3d1
commit e634adfa56
13 changed files with 804 additions and 15 deletions

View File

@@ -54,6 +54,8 @@ The validation fails if:
| `linuxcnc_tp_api_probe` | Validates vendored LinuxCNC trajectory planner calls for linear, arc, and queued motion paths. |
| `linuxcnc_kinematics_probe` | Validates vendored LinuxCNC `trivkins.c` plus `kins_util.c` initialize and perform identity forward/inverse mapping through the standalone HAL/RTAPI boundary. |
| `linuxcnc_5axis_kinematics_probe` | Validates vendored LinuxCNC `5axiskins.c` through `switchkins.c`, including 5-axis forward/inverse round-trip behavior and switching to identity kinematics. |
| `linuxcnc_xyzac_trt_kinematics_probe` | Validates vendored LinuxCNC XYZAC TRT kinematics through `switchkins.c`, including forward/inverse round-trip behavior and switching to identity kinematics. |
| `linuxcnc_xyzbc_trt_kinematics_probe` | Validates vendored LinuxCNC XYZBC TRT kinematics through `switchkins.c`, including forward/inverse round-trip behavior and switching to identity kinematics. |
## Fixture Coverage
@@ -96,7 +98,7 @@ The current fixture expectations validate standalone behavior against the
vendored LinuxCNC source path. They do not yet run a side-by-side native
LinuxCNC executable comparison for each fixture.
The kinematics probes currently cover LinuxCNC identity/trivial kinematics and
the switchable `5axiskins` XYZBCW bridge-mill model. TRT `xyzac`/`xyzbc`,
serial, delta, SCARA, and other machine-specific kinematics still need
dedicated baselines.
The kinematics probes currently cover LinuxCNC identity/trivial kinematics,
the switchable `5axiskins` XYZBCW bridge-mill model, and the TRT `xyzac`/`xyzbc`
table-rotary models. Serial, delta, SCARA, and other machine-specific
kinematics still need dedicated baselines.

View File

@@ -29,7 +29,7 @@ semantic rewrites:
| Python/remap | Python/remap hooks are stubbed at the runtime edge. |
| Dynamic interpreter path | `interp_base.cc` probe uses standalone `EMC2_HOME` compile-time path boundary. |
| Realtime scheduler | TP probes seed deterministic status/config data instead of running LinuxCNC realtime process topology. |
| Kinematics component lifecycle | `trivkins.c` and `5axiskins.c` are initialized through LinuxCNC module entry points while HAL component init/ready/exit, HAL pin allocation, and RTAPI module metadata are handled by standalone shims. |
| Kinematics component lifecycle | `trivkins.c`, `5axiskins.c`, and TRT switchkins modules are initialized through LinuxCNC module entry points while HAL component init/ready/exit, HAL pin allocation, and RTAPI module metadata are handled by standalone shims. |
| Browser storage | OPFS remains outside the native core and is not yet connected. |
## Enforced Non-Drift Rules
@@ -47,11 +47,11 @@ semantic rewrites:
- No browser/WASM parity tests yet.
- No JS SDK validation yet.
- No OPFS persistence validation yet.
- Identity/trivial kinematics and LinuxCNC `5axiskins` now have native
source-probe coverage; TRT `xyzac`/`xyzbc`, serial, delta, SCARA, and other
- Identity/trivial kinematics, LinuxCNC `5axiskins`, and TRT `xyzac`/`xyzbc`
now have native source-probe coverage; serial, delta, SCARA, and other
machine-specific kinematics are not yet extracted.
- Full machine baselines beyond the current identity/trivial and `5axiskins`
probes are not established.
- Full machine baselines beyond the current identity/trivial, `5axiskins`, and
TRT probes are not established.
- Fixture expectations are currently checked against the standalone vendored
source path, not by running a native LinuxCNC binary for every fixture.

View File

@@ -60,6 +60,6 @@ Negative fixture coverage includes:
- missing tool length offset
Machine baseline is still limited to standalone interpreter, trajectory
planner, LinuxCNC identity/trivial kinematics, and the LinuxCNC `5axiskins`
XYZBCW bridge-mill probe. Additional non-trivial kinematics and fuller machine
baselines remain future work.
planner, LinuxCNC identity/trivial kinematics, LinuxCNC `5axiskins` XYZBCW
bridge-mill probing, and LinuxCNC TRT `xyzac`/`xyzbc` probing. Additional
non-trivial kinematics and fuller machine baselines remain future work.

View File

@@ -37,6 +37,7 @@ Current validation is intentionally mechanical:
| Motion state headers | `src/emc/motion/state_tag.h`, `emcmotcfg.h`, `simple_tp.h`, `motion.h`, `mot_priv.h`, `axis.h` | Copy unchanged | Realtime motion process is not ported; standalone probes seed the small motion status/config state required by TP calls | Vendor byte sync, `linuxcnc_tp_api_probe` |
| Identity/trivial kinematics | `src/emc/kinematics/kinematics.h`, `cubic.h`, `kins_util.c`, `trivkins.c` | Copy unchanged | HAL component lifecycle and RTAPI module metadata are replaced by standalone shims; forward/inverse mapping behavior remains LinuxCNC source | Vendor byte sync, per-file source probes, `linuxcnc_kinematics_probe` |
| Switchable 5-axis bridge kinematics | `src/emc/kinematics/5axiskins.c`, `switchkins.c`, `switchkins.h`, `userkfuncs.c`, plus `src/rtapi/rtapi_ctype.h` | Copy unchanged | HAL pin allocation, HAL component lifecycle, and RTAPI module metadata are standalone runtime edges; switchable 5-axis forward/inverse behavior remains LinuxCNC source | Vendor byte sync, per-file source probes, `linuxcnc_5axis_kinematics_probe` |
| TRT table-rotary kinematics | `src/emc/kinematics/trtfuncs.c`, `xyzac-trt-kins.c`, `xyzbc-trt-kins.c` | Copy unchanged | HAL pin allocation and switchkins lifecycle stay runtime boundaries; XYZAC/XYZBC TRT forward/inverse behavior remains LinuxCNC source | Vendor byte sync, per-file source probes, `linuxcnc_xyzac_trt_kinematics_probe`, `linuxcnc_xyzbc_trt_kinematics_probe` |
| Trajectory planner | `src/emc/tp/tp.c`, `tc.c`, `tcq.c`, `spherical_arc.c`, `blendmath.c`, `sp_scurve.c`, `ruckig_wrapper.c`, plus matching `*.h` files | Copy unchanged | Native realtime scheduling and motion process state are replaced by standalone probe setup | Vendor byte sync, per-file source probes, `linuxcnc_tp_api_probe` |
| Ruckig C planner support | Selected `src/emc/tp/cruckig/*.c` and `*.h` files in the manifest | Copy unchanged | Used as LinuxCNC planner support code through vendored TP sources | Vendor byte sync, per-file source probes |
| Posemath | `src/libnml/posemath/posemath.cc`, `_posemath.c`, `gomath.c`, `sincos.c`, and matching headers | Copy unchanged | `gomath.c` is compiled as C; `rtapi.h` shim is C/C++ compatible for this boundary | Vendor byte sync, per-file source probes, TP probe |
@@ -60,9 +61,8 @@ Current validation is intentionally mechanical:
## Known Gaps
- Additional non-trivial kinematics implementation files, including TRT
`xyzac`/`xyzbc`, serial, delta, SCARA, and other machine-specific modules,
are not yet extracted.
- Additional non-trivial kinematics implementation files, including serial,
delta, SCARA, and other machine-specific modules, are not yet extracted.
- Browser/WASM C ABI and JS SDK layers are not yet built for the full
interpreter/planner core.
- OPFS persistence is not yet connected to INI, tool table, parameter file, or

View File

@@ -0,0 +1,96 @@
#include <cmath>
#include <iostream>
#include "emc/kinematics/kinematics.h"
#include "emc/motion/emcmotcfg.h"
int rtapi_app_main(void);
void rtapi_app_exit(void);
namespace {
int near(double actual, double expected)
{
return std::fabs(actual - expected) < 1e-9;
}
int near_joints(const double *actual, const double *expected)
{
for (int index = 0; index < 5; ++index) {
if (!near(actual[index], expected[index])) {
return 0;
}
}
return 1;
}
int near_identity_pose(const EmcPose &actual, const double *joints)
{
return near(actual.tran.x, joints[0]) &&
near(actual.tran.y, joints[1]) &&
near(actual.tran.z, joints[2]) &&
near(actual.a, joints[3]) &&
near(actual.c, joints[4]);
}
void print_pose(const char *prefix, const EmcPose &pose)
{
std::cout << prefix << "_xyz="
<< pose.tran.x << ","
<< pose.tran.y << ","
<< pose.tran.z << "\n";
std::cout << prefix << "_ac="
<< pose.a << ","
<< pose.c << "\n";
}
void print_joints(const char *prefix, const double *joints)
{
std::cout << prefix << "_xyzac="
<< joints[0] << ","
<< joints[1] << ","
<< joints[2] << ","
<< joints[3] << ","
<< joints[4] << "\n";
}
} // namespace
int main()
{
const int init_rc = rtapi_app_main();
std::cout << "xyzac_trt_init=" << init_rc << "\n";
std::cout << "xyzac_trt_type=" << kinematicsType() << "\n";
std::cout << "xyzac_trt_switchable=" << kinematicsSwitchable() << "\n";
double joints[EMCMOT_MAX_JOINTS]{};
joints[0] = 10.0;
joints[1] = 20.0;
joints[2] = 30.0;
joints[3] = 25.0;
joints[4] = 40.0;
KINEMATICS_FORWARD_FLAGS fflags = 0;
KINEMATICS_INVERSE_FLAGS iflags = 0;
EmcPose forward_pose{};
const int forward_rc = kinematicsForward(joints, &forward_pose, &fflags, &iflags);
std::cout << "xyzac_trt_forward=" << forward_rc << "\n";
print_pose("xyzac_trt_forward", forward_pose);
double inverse_joints[EMCMOT_MAX_JOINTS]{};
const int inverse_rc = kinematicsInverse(&forward_pose, inverse_joints, &iflags, &fflags);
std::cout << "xyzac_trt_inverse=" << inverse_rc << "\n";
print_joints("xyzac_trt_inverse", inverse_joints);
std::cout << "xyzac_trt_roundtrip_joints=" << near_joints(inverse_joints, joints) << "\n";
const int switch_rc = kinematicsSwitch(1);
std::cout << "xyzac_trt_switch_identity=" << switch_rc << "\n";
EmcPose identity_pose{};
const int identity_forward_rc = kinematicsForward(joints, &identity_pose, &fflags, &iflags);
std::cout << "xyzac_trt_identity_forward=" << identity_forward_rc << "\n";
print_pose("xyzac_trt_identity", identity_pose);
std::cout << "xyzac_trt_identity_near=" << near_identity_pose(identity_pose, joints) << "\n";
rtapi_app_exit();
return 0;
}

View File

@@ -0,0 +1,96 @@
#include <cmath>
#include <iostream>
#include "emc/kinematics/kinematics.h"
#include "emc/motion/emcmotcfg.h"
int rtapi_app_main(void);
void rtapi_app_exit(void);
namespace {
int near(double actual, double expected)
{
return std::fabs(actual - expected) < 1e-9;
}
int near_joints(const double *actual, const double *expected)
{
for (int index = 0; index < 5; ++index) {
if (!near(actual[index], expected[index])) {
return 0;
}
}
return 1;
}
int near_identity_pose(const EmcPose &actual, const double *joints)
{
return near(actual.tran.x, joints[0]) &&
near(actual.tran.y, joints[1]) &&
near(actual.tran.z, joints[2]) &&
near(actual.b, joints[3]) &&
near(actual.c, joints[4]);
}
void print_pose(const char *prefix, const EmcPose &pose)
{
std::cout << prefix << "_xyz="
<< pose.tran.x << ","
<< pose.tran.y << ","
<< pose.tran.z << "\n";
std::cout << prefix << "_bc="
<< pose.b << ","
<< pose.c << "\n";
}
void print_joints(const char *prefix, const double *joints)
{
std::cout << prefix << "_xyzbc="
<< joints[0] << ","
<< joints[1] << ","
<< joints[2] << ","
<< joints[3] << ","
<< joints[4] << "\n";
}
} // namespace
int main()
{
const int init_rc = rtapi_app_main();
std::cout << "xyzbc_trt_init=" << init_rc << "\n";
std::cout << "xyzbc_trt_type=" << kinematicsType() << "\n";
std::cout << "xyzbc_trt_switchable=" << kinematicsSwitchable() << "\n";
double joints[EMCMOT_MAX_JOINTS]{};
joints[0] = 10.0;
joints[1] = 20.0;
joints[2] = 30.0;
joints[3] = 35.0;
joints[4] = 40.0;
KINEMATICS_FORWARD_FLAGS fflags = 0;
KINEMATICS_INVERSE_FLAGS iflags = 0;
EmcPose forward_pose{};
const int forward_rc = kinematicsForward(joints, &forward_pose, &fflags, &iflags);
std::cout << "xyzbc_trt_forward=" << forward_rc << "\n";
print_pose("xyzbc_trt_forward", forward_pose);
double inverse_joints[EMCMOT_MAX_JOINTS]{};
const int inverse_rc = kinematicsInverse(&forward_pose, inverse_joints, &iflags, &fflags);
std::cout << "xyzbc_trt_inverse=" << inverse_rc << "\n";
print_joints("xyzbc_trt_inverse", inverse_joints);
std::cout << "xyzbc_trt_roundtrip_joints=" << near_joints(inverse_joints, joints) << "\n";
const int switch_rc = kinematicsSwitch(1);
std::cout << "xyzbc_trt_switch_identity=" << switch_rc << "\n";
EmcPose identity_pose{};
const int identity_forward_rc = kinematicsForward(joints, &identity_pose, &fflags, &iflags);
std::cout << "xyzbc_trt_identity_forward=" << identity_forward_rc << "\n";
print_pose("xyzbc_trt_identity", identity_pose);
std::cout << "xyzbc_trt_identity_near=" << near_identity_pose(identity_pose, joints) << "\n";
rtapi_app_exit();
return 0;
}

View File

@@ -33,6 +33,7 @@ typedef union {
} hal_data_u;
typedef bool hal_bit_t;
typedef double real_t;
typedef double hal_float_t;
typedef int hal_s32_t;
typedef unsigned int hal_u32_t;

View File

@@ -83,6 +83,10 @@ check_exitcode linuxcnc_kinematics_probe
check_exitcode linuxcnc_kinematics_probe.run
check_exitcode linuxcnc_5axis_kinematics_probe
check_exitcode linuxcnc_5axis_kinematics_probe.run
check_exitcode linuxcnc_xyzac_trt_kinematics_probe
check_exitcode linuxcnc_xyzac_trt_kinematics_probe.run
check_exitcode linuxcnc_xyzbc_trt_kinematics_probe
check_exitcode linuxcnc_xyzbc_trt_kinematics_probe.run
for name in \
linuxcnc_tp_tp_source_probe \
linuxcnc_tp_tc_source_probe \
@@ -128,6 +132,9 @@ check_exitcode linuxcnc_trivkins_source_probe
check_exitcode linuxcnc_switchkins_source_probe
check_exitcode linuxcnc_userkfuncs_source_probe
check_exitcode linuxcnc_5axiskins_source_probe
check_exitcode linuxcnc_trtfuncs_source_probe
check_exitcode linuxcnc_xyzac_trt_kins_source_probe
check_exitcode linuxcnc_xyzbc_trt_kins_source_probe
check_exitcode linuxcnc_interp_convert_source_probe
check_exitcode linuxcnc_interp_read_source_probe
check_exitcode linuxcnc_interp_check_source_probe
@@ -234,6 +241,28 @@ grep -Fq "fiveaxis_switch_identity=0" "$FIVEAXIS_KINEMATICS_STDOUT"
grep -Fq "fiveaxis_identity_forward=0" "$FIVEAXIS_KINEMATICS_STDOUT"
grep -Fq "fiveaxis_identity_near=1" "$FIVEAXIS_KINEMATICS_STDOUT"
XYZAC_TRT_KINEMATICS_STDOUT="$BUILD_DIR/linuxcnc_xyzac_trt_kinematics_probe.run.stdout.log"
grep -Fq "xyzac_trt_init=0" "$XYZAC_TRT_KINEMATICS_STDOUT"
grep -Fq "xyzac_trt_type=4" "$XYZAC_TRT_KINEMATICS_STDOUT"
grep -Fq "xyzac_trt_switchable=1" "$XYZAC_TRT_KINEMATICS_STDOUT"
grep -Fq "xyzac_trt_forward=0" "$XYZAC_TRT_KINEMATICS_STDOUT"
grep -Fq "xyzac_trt_inverse=0" "$XYZAC_TRT_KINEMATICS_STDOUT"
grep -Fq "xyzac_trt_roundtrip_joints=1" "$XYZAC_TRT_KINEMATICS_STDOUT"
grep -Fq "xyzac_trt_switch_identity=0" "$XYZAC_TRT_KINEMATICS_STDOUT"
grep -Fq "xyzac_trt_identity_forward=0" "$XYZAC_TRT_KINEMATICS_STDOUT"
grep -Fq "xyzac_trt_identity_near=1" "$XYZAC_TRT_KINEMATICS_STDOUT"
XYZBC_TRT_KINEMATICS_STDOUT="$BUILD_DIR/linuxcnc_xyzbc_trt_kinematics_probe.run.stdout.log"
grep -Fq "xyzbc_trt_init=0" "$XYZBC_TRT_KINEMATICS_STDOUT"
grep -Fq "xyzbc_trt_type=4" "$XYZBC_TRT_KINEMATICS_STDOUT"
grep -Fq "xyzbc_trt_switchable=1" "$XYZBC_TRT_KINEMATICS_STDOUT"
grep -Fq "xyzbc_trt_forward=0" "$XYZBC_TRT_KINEMATICS_STDOUT"
grep -Fq "xyzbc_trt_inverse=0" "$XYZBC_TRT_KINEMATICS_STDOUT"
grep -Fq "xyzbc_trt_roundtrip_joints=1" "$XYZBC_TRT_KINEMATICS_STDOUT"
grep -Fq "xyzbc_trt_switch_identity=0" "$XYZBC_TRT_KINEMATICS_STDOUT"
grep -Fq "xyzbc_trt_identity_forward=0" "$XYZBC_TRT_KINEMATICS_STDOUT"
grep -Fq "xyzbc_trt_identity_near=1" "$XYZBC_TRT_KINEMATICS_STDOUT"
check_fixture_output() {
local fixture="$1"
local expected="$2"

View File

@@ -362,6 +362,26 @@ FIVEAXIS_KINEMATICS_PROBE_SOURCES=(
"$WRAP_DIR/linuxcnc_5axis_kinematics_probe.cpp"
)
XYZAC_TRT_KINEMATICS_PROBE_SOURCES=(
"$VENDOR_DIR/src/emc/kinematics/kins_util.c"
"$VENDOR_DIR/src/emc/kinematics/switchkins.c"
"$VENDOR_DIR/src/emc/kinematics/userkfuncs.c"
"$VENDOR_DIR/src/emc/kinematics/trtfuncs.c"
"$VENDOR_DIR/src/emc/kinematics/xyzac-trt-kins.c"
"$WRAP_DIR/linuxcnc_hal_adapter.cpp"
"$WRAP_DIR/linuxcnc_xyzac_trt_kinematics_probe.cpp"
)
XYZBC_TRT_KINEMATICS_PROBE_SOURCES=(
"$VENDOR_DIR/src/emc/kinematics/kins_util.c"
"$VENDOR_DIR/src/emc/kinematics/switchkins.c"
"$VENDOR_DIR/src/emc/kinematics/userkfuncs.c"
"$VENDOR_DIR/src/emc/kinematics/trtfuncs.c"
"$VENDOR_DIR/src/emc/kinematics/xyzbc-trt-kins.c"
"$WRAP_DIR/linuxcnc_hal_adapter.cpp"
"$WRAP_DIR/linuxcnc_xyzbc_trt_kinematics_probe.cpp"
)
TP_CORE_SOURCES=(
"$VENDOR_DIR/src/emc/tp/tp.c"
"$VENDOR_DIR/src/emc/tp/tc.c"
@@ -549,6 +569,20 @@ build_binary_target \
FIVEAXIS_KINEMATICS_PROBE_SOURCES \
NO_LINK_FLAGS
build_binary_target \
linuxcnc_xyzac_trt_kinematics_probe \
"$BUILD_DIR/linuxcnc_xyzac_trt_kinematics_probe" \
TP_FLAGS \
XYZAC_TRT_KINEMATICS_PROBE_SOURCES \
NO_LINK_FLAGS
build_binary_target \
linuxcnc_xyzbc_trt_kinematics_probe \
"$BUILD_DIR/linuxcnc_xyzbc_trt_kinematics_probe" \
TP_FLAGS \
XYZBC_TRT_KINEMATICS_PROBE_SOURCES \
NO_LINK_FLAGS
if [[ "$(tr -d '[:space:]' < "$BUILD_DIR/linuxcnc_kinematics_probe.exitcode")" == "0" ]]; then
set +e
"$BUILD_DIR/linuxcnc_kinematics_probe" \
@@ -579,6 +613,36 @@ else
"$BUILD_DIR/linuxcnc_5axis_kinematics_probe.run.stderr.log"
fi
if [[ "$(tr -d '[:space:]' < "$BUILD_DIR/linuxcnc_xyzac_trt_kinematics_probe.exitcode")" == "0" ]]; then
set +e
"$BUILD_DIR/linuxcnc_xyzac_trt_kinematics_probe" \
>"$BUILD_DIR/linuxcnc_xyzac_trt_kinematics_probe.run.stdout.log" \
2>"$BUILD_DIR/linuxcnc_xyzac_trt_kinematics_probe.run.stderr.log"
XYZAC_TRT_KINEMATICS_RUN_RC=$?
set -e
echo "$XYZAC_TRT_KINEMATICS_RUN_RC" > "$BUILD_DIR/linuxcnc_xyzac_trt_kinematics_probe.run.exitcode"
else
rm -f \
"$BUILD_DIR/linuxcnc_xyzac_trt_kinematics_probe.run.exitcode" \
"$BUILD_DIR/linuxcnc_xyzac_trt_kinematics_probe.run.stdout.log" \
"$BUILD_DIR/linuxcnc_xyzac_trt_kinematics_probe.run.stderr.log"
fi
if [[ "$(tr -d '[:space:]' < "$BUILD_DIR/linuxcnc_xyzbc_trt_kinematics_probe.exitcode")" == "0" ]]; then
set +e
"$BUILD_DIR/linuxcnc_xyzbc_trt_kinematics_probe" \
>"$BUILD_DIR/linuxcnc_xyzbc_trt_kinematics_probe.run.stdout.log" \
2>"$BUILD_DIR/linuxcnc_xyzbc_trt_kinematics_probe.run.stderr.log"
XYZBC_TRT_KINEMATICS_RUN_RC=$?
set -e
echo "$XYZBC_TRT_KINEMATICS_RUN_RC" > "$BUILD_DIR/linuxcnc_xyzbc_trt_kinematics_probe.run.exitcode"
else
rm -f \
"$BUILD_DIR/linuxcnc_xyzbc_trt_kinematics_probe.run.exitcode" \
"$BUILD_DIR/linuxcnc_xyzbc_trt_kinematics_probe.run.stdout.log" \
"$BUILD_DIR/linuxcnc_xyzbc_trt_kinematics_probe.run.stderr.log"
fi
if [[ "$(tr -d '[:space:]' < "$BUILD_DIR/linuxcnc_tp_api_probe.exitcode")" == "0" ]]; then
set +e
"$BUILD_DIR/linuxcnc_tp_api_probe" \
@@ -707,6 +771,24 @@ build_object_target \
"$VENDOR_DIR/src/emc/kinematics/5axiskins.c" \
TP_FLAGS
build_object_target \
linuxcnc_trtfuncs_source_probe \
"$BUILD_DIR/linuxcnc_trtfuncs_source_probe.o" \
"$VENDOR_DIR/src/emc/kinematics/trtfuncs.c" \
TP_FLAGS
build_object_target \
linuxcnc_xyzac_trt_kins_source_probe \
"$BUILD_DIR/linuxcnc_xyzac_trt_kins_source_probe.o" \
"$VENDOR_DIR/src/emc/kinematics/xyzac-trt-kins.c" \
TP_FLAGS
build_object_target \
linuxcnc_xyzbc_trt_kins_source_probe \
"$BUILD_DIR/linuxcnc_xyzbc_trt_kins_source_probe.o" \
"$VENDOR_DIR/src/emc/kinematics/xyzbc-trt-kins.c" \
TP_FLAGS
build_object_target \
linuxcnc_interp_convert_source_probe \
"$BUILD_DIR/linuxcnc_interp_convert_source_probe.o" \

View File

@@ -37,6 +37,9 @@ src/emc/kinematics/switchkins.h
src/emc/kinematics/switchkins.c
src/emc/kinematics/userkfuncs.c
src/emc/kinematics/5axiskins.c
src/emc/kinematics/trtfuncs.c
src/emc/kinematics/xyzac-trt-kins.c
src/emc/kinematics/xyzbc-trt-kins.c
src/emc/tp/tp.h
src/emc/tp/tp_types.h
src/emc/tp/tc.h

View File

@@ -0,0 +1,366 @@
/**************************************************************************
* Copyright 2016 Rudy du Preez <rudy@asmsa.co.za>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
**************************************************************************/
/********************************************************************
* Kinematics functions (forward,inverse) for:
* 1) 5 axis mill (XYZAC)
* This mill has a tilting table (A axis) and horizontal rotary
* mounted to the table (C axis).
* 2) 5 axis mill (XYZBC)
* This mill has a tilting table (B axis) and horizontal rotary
* mounted to the table (C axis).
*
* Note: The directions of the rotational axes are the opposite of the
* conventional axis directions. See
* https://linuxcnc.org/docs/html/gcode/machining-center.html
********************************************************************/
#include <rtapi_math.h>
#include <rtapi_string.h>
#include <rtapi_ctype.h>
#include <hal.h>
#include <emcmotcfg.h>
#include <kinematics.h>
static int trtfuncs_max_joints;
// joint number assignments (-1 ==> not assigned)
static int JX = -1;
static int JY = -1;
static int JZ = -1;
static int JA = -1;
static int JB = -1;
static int JC = -1;
static int JU = -1;
static int JV = -1;
static int JW = -1;
struct haldata {
hal_float_t *x_rot_point;
hal_float_t *y_rot_point;
hal_float_t *z_rot_point;
hal_float_t *x_offset;
hal_float_t *y_offset;
hal_float_t *z_offset;
hal_float_t *tool_offset;
hal_bit_t *conventional_directions; // default: false
} *haldata;
int trtKinematicsSetup(const int comp_id,
const char* coordinates,
kparms* kp)
{
int i,jno,res=0;
int axis_idx_for_jno[EMCMOT_MAX_JOINTS];
int rqdjoints = strlen(kp->required_coordinates);
if (rqdjoints > kp->max_joints) {
rtapi_print_msg(RTAPI_MSG_ERR,
"ERROR %s: supports %d joints, <%s> requires %d\n",
kp->kinsname,
kp->max_joints,
coordinates,
rqdjoints);
goto error;
}
trtfuncs_max_joints = kp->max_joints;
if (map_coordinates_to_jnumbers(coordinates,
kp->max_joints,
kp->allow_duplicates,
axis_idx_for_jno)) {
goto error;
}
// require all chars in reqd_coords (order doesn't matter)
for (i=0; i < rqdjoints; i++) {
char reqd_char;
reqd_char = *(kp->required_coordinates + i);
if ( !strchr(coordinates,toupper(reqd_char))
&& !strchr(coordinates,tolower(reqd_char)) ) {
rtapi_print_msg(RTAPI_MSG_ERR,
"ERROR %s:\nrequired coordinates:%s\n"
"specified coordinates:%s\n",
kp->kinsname, kp->required_coordinates, coordinates);
goto error;
}
}
// assign principal joint numbers (first found in coordinates map)
// duplicates are handled by position_to_mapped_joints()
for (jno=0; jno < EMCMOT_MAX_JOINTS; jno++) {
if (axis_idx_for_jno[jno] == 0 && JX==-1) {JX = jno;}
if (axis_idx_for_jno[jno] == 1 && JY==-1) {JY = jno;}
if (axis_idx_for_jno[jno] == 2 && JZ==-1) {JZ = jno;}
if (axis_idx_for_jno[jno] == 3 && JA==-1) {JA = jno;}
if (axis_idx_for_jno[jno] == 4 && JB==-1) {JB = jno;}
if (axis_idx_for_jno[jno] == 5 && JC==-1) {JC = jno;}
if (axis_idx_for_jno[jno] == 6 && JU==-1) {JU = jno;}
if (axis_idx_for_jno[jno] == 7 && JV==-1) {JV = jno;}
if (axis_idx_for_jno[jno] == 8 && JW==-1) {JW = jno;}
}
rtapi_print("%s coordinates=%s assigns:\n", kp->kinsname,coordinates);
for (jno=0; jno<EMCMOT_MAX_JOINTS; jno++) {
if (axis_idx_for_jno[jno] == -1) break; //fini
rtapi_print(" Joint %d ==> Axis %c\n",
jno,"XYZABCUVW"[axis_idx_for_jno[jno]]);
}
haldata = hal_malloc(sizeof(struct haldata));
if (!haldata) {goto error;}
res += hal_pin_float_newf(HAL_IN, &(haldata->x_rot_point), comp_id,
"%s.x-rot-point",kp->halprefix);
res += hal_pin_float_newf(HAL_IN, &(haldata->y_rot_point), comp_id,
"%s.y-rot-point",kp->halprefix);
res += hal_pin_float_newf(HAL_IN, &(haldata->z_rot_point), comp_id,
"%s.z-rot-point",kp->halprefix);
res += hal_pin_float_newf(HAL_IN, &(haldata->x_offset), comp_id,
"%s.x-offset",kp->halprefix);
res += hal_pin_float_newf(HAL_IN, &(haldata->y_offset), comp_id,
"%s.y-offset",kp->halprefix);
res += hal_pin_float_newf(HAL_IN, &(haldata->z_offset), comp_id,
"%s.z-offset",kp->halprefix);
res += hal_pin_float_newf(HAL_IN, &(haldata->tool_offset), comp_id,
"%s.tool-offset",kp->halprefix);
res += hal_pin_bit_newf(HAL_IN, &(haldata->conventional_directions), comp_id,
"%s.conventional-directions", kp->halprefix);
if (res) {goto error;}
return 0;
error:
rtapi_print_msg(RTAPI_MSG_ERR,"trtKinematicsSetup() FAIL\n");
return -1;
} // trtKinematicsSetup()
int xyzacKinematicsForward(const double *joints,
EmcPose * pos,
const KINEMATICS_FORWARD_FLAGS * fflags,
KINEMATICS_INVERSE_FLAGS * iflags)
{
(void)fflags;
(void)iflags;
const double x_rot_point = *(haldata->x_rot_point);
const double y_rot_point = *(haldata->y_rot_point);
const double z_rot_point = *(haldata->z_rot_point);
const double dt = *(haldata->tool_offset);
const double dy = *(haldata->y_offset);
const double dz = *(haldata->z_offset) + dt;
const double a_rad = joints[JA]*TO_RAD;
const double c_rad = joints[JC]*TO_RAD;
const real_t con = *(haldata->conventional_directions) ? 1.0 : -1.0;
pos->tran.x = + cos(c_rad) * (joints[JX] - x_rot_point)
- con * sin(c_rad) * cos(a_rad) * (joints[JY] - dy - y_rot_point)
+ sin(c_rad) * sin(a_rad) * (joints[JZ] - dz - z_rot_point)
- con * sin(c_rad) * dy
+ x_rot_point;
pos->tran.y = + con * sin(c_rad) * (joints[JX] - x_rot_point)
+ cos(c_rad) * cos(a_rad) * (joints[JY] - dy - y_rot_point)
- con * cos(c_rad) * sin(a_rad) * (joints[JZ] - dz - z_rot_point)
+ cos(c_rad) * dy
+ y_rot_point;
pos->tran.z = + 0
+ con * sin(a_rad) * (joints[JY] - dy - y_rot_point)
+ cos(a_rad) * (joints[JZ] - dz - z_rot_point)
+ dz
+ z_rot_point;
pos->a = joints[JA];
pos->c = joints[JC];
// optional letters (specify with coordinates module parameter)
pos->b = (JB != -1)? joints[JB] : 0;
pos->u = (JU != -1)? joints[JU] : 0;
pos->v = (JV != -1)? joints[JV] : 0;
pos->w = (JW != -1)? joints[JW] : 0;
return 0;
} // xyzacKinematicsForward()
int xyzacKinematicsInverse(const EmcPose * pos,
double *joints,
const KINEMATICS_INVERSE_FLAGS * iflags,
KINEMATICS_FORWARD_FLAGS * fflags)
{
(void)iflags;
(void)fflags;
const double x_rot_point = *(haldata->x_rot_point);
const double y_rot_point = *(haldata->y_rot_point);
const double z_rot_point = *(haldata->z_rot_point);
const double dy = *(haldata->y_offset);
const double dt = *(haldata->tool_offset);
const double dz = *(haldata->z_offset) + dt;
const double a_rad = pos->a*TO_RAD;
const double c_rad = pos->c*TO_RAD;
const real_t con = *(haldata->conventional_directions) ? 1.0 : -1.0;
EmcPose P; // computed position
P.tran.x = + cos(c_rad) * (pos->tran.x - x_rot_point)
+ con * sin(c_rad) * (pos->tran.y - y_rot_point)
+ x_rot_point;
P.tran.y = - con * sin(c_rad) * cos(a_rad) * (pos->tran.x - x_rot_point)
+ cos(c_rad) * cos(a_rad) * (pos->tran.y - y_rot_point)
+ con * sin(a_rad) * (pos->tran.z - z_rot_point)
- cos(a_rad) * dy
- con * sin(a_rad) * dz
+ dy
+ y_rot_point;
P.tran.z = + sin(c_rad) * sin(a_rad) * (pos->tran.x - x_rot_point)
- con * cos(c_rad) * sin(a_rad) * (pos->tran.y - y_rot_point)
+ cos(a_rad) * (pos->tran.z - z_rot_point)
+ con * sin(a_rad) * dy
- cos(a_rad) * dz
+ dz
+ z_rot_point;
P.a = pos->a;
P.c = pos->c;
// optional letters (specify with coordinates module parameter)
P.b = (JB != -1)? pos->b : 0;
P.u = (JU != -1)? pos->u : 0;
P.v = (JV != -1)? pos->v : 0;
P.w = (JW != -1)? pos->w : 0;
// update joints with support for
// multiple-joints per-coordinate letter:
// based on computed position
position_to_mapped_joints(trtfuncs_max_joints,
&P,
joints);
return 0;
} // xyzacKinematicsInverse()
int xyzbcKinematicsForward(const double *joints,
EmcPose * pos,
const KINEMATICS_FORWARD_FLAGS * fflags,
KINEMATICS_INVERSE_FLAGS * iflags)
{
(void)fflags;
(void)iflags;
// Note: 'principal' joints are used
const double x_rot_point = *(haldata->x_rot_point);
const double y_rot_point = *(haldata->y_rot_point);
const double z_rot_point = *(haldata->z_rot_point);
const double dx = *(haldata->x_offset);
const double dt = *(haldata->tool_offset);
const double dz = *(haldata->z_offset) + dt;
const double b_rad = joints[JB]*TO_RAD;
const double c_rad = joints[JC]*TO_RAD;
const real_t con = *(haldata->conventional_directions) ? 1.0 : -1.0;
pos->tran.x = cos(c_rad) * cos(b_rad) * (joints[JX] - dx - x_rot_point)
- con * sin(c_rad) * (joints[JY] - y_rot_point)
+ con * cos(c_rad) * sin(b_rad) * (joints[JZ] - dz - z_rot_point)
+ cos(c_rad) * dx
+ x_rot_point;
pos->tran.y = + con * sin(c_rad) * cos(b_rad) * (joints[JX] - dx - x_rot_point)
+ cos(c_rad) * (joints[JY] - y_rot_point)
+ sin(c_rad) * sin(b_rad) * (joints[JZ] - dz - z_rot_point)
+ con * sin(c_rad) * dx
+ y_rot_point;
pos->tran.z = - con * sin(b_rad) * (joints[JX] - dx - x_rot_point)
+ cos(b_rad) * (joints[JZ] - dz - z_rot_point)
+ dz
+ z_rot_point;
pos->b = joints[JB];
pos->c = joints[JC];
// optional letters (specify with coordinates module parameter)
pos->a = (JA != -1)? joints[JA] : 0;
pos->u = (JU != -1)? joints[JU] : 0;
pos->v = (JV != -1)? joints[JV] : 0;
pos->w = (JW != -1)? joints[JW] : 0;
return 0;
} // xyzbcKinematicsForward()
int xyzbcKinematicsInverse(const EmcPose * pos,
double *joints,
const KINEMATICS_INVERSE_FLAGS * iflags,
KINEMATICS_FORWARD_FLAGS * fflags)
{
(void)iflags;
(void)fflags;
const double x_rot_point = *(haldata->x_rot_point);
const double y_rot_point = *(haldata->y_rot_point);
const double z_rot_point = *(haldata->z_rot_point);
const double dx = *(haldata->x_offset);
const double dt = *(haldata->tool_offset);
const double dz = *(haldata->z_offset) + dt;
const double b_rad = pos->b*TO_RAD;
const double c_rad = pos->c*TO_RAD;
const double dpx = -cos(b_rad)*dx + sin(b_rad)*dz + dx;
const double dpz = -sin(b_rad)*dx - cos(b_rad)*dz + dz;
const real_t con = *(haldata->conventional_directions) ? 1.0 : -1.0;
EmcPose P; // computed position
P.tran.x = + cos(c_rad) * cos(b_rad) * (pos->tran.x - x_rot_point)
+ con * sin(c_rad) * cos(b_rad) * (pos->tran.y - y_rot_point)
- con * sin(b_rad) * (pos->tran.z - z_rot_point)
+ dpx
+ x_rot_point;
P.tran.y = - con * sin(c_rad) * (pos->tran.x - x_rot_point)
+ cos(c_rad) * (pos->tran.y - y_rot_point)
+ y_rot_point;
P.tran.z = + con * cos(c_rad) * sin(b_rad) * (pos->tran.x - x_rot_point)
+ sin(c_rad) * sin(b_rad) * (pos->tran.y - y_rot_point)
+ cos(b_rad) * (pos->tran.z - z_rot_point)
+ dpz
+ z_rot_point;
P.b = pos->b;
P.c = pos->c;
// optional letters (specify with coordinates module parameter)
P.a = (JA != -1)? pos->a : 0;
P.u = (JU != -1)? pos->u : 0;
P.v = (JV != -1)? pos->v : 0;
P.w = (JW != -1)? pos->w : 0;
// update joints with support for
// multiple-joints per-coordinate letter:
// based on computed position
position_to_mapped_joints(trtfuncs_max_joints,
&P,
joints);
return 0;
} // xyzbcKinematicsInverse()

View File

@@ -0,0 +1,57 @@
/********************************************************************
* xyzac-trt-kins.c employing switchkins.[ch]
* License: GPL Version 2
*
* NOTEs:
* 1) specify all kparms items
* 2) specify 3 KS,KF,KI functions for switchkins_type=0,1,2
* 3) the 0th switchkins_type is the startup default
* 4) sparm is a module string parameter for configuration
* 5) The directions of the rotational axes are the opposite of the
* conventional axis directions.
*/
#include <rtapi.h>
#include <rtapi_string.h>
#include <emcmotcfg.h>
#include "switchkins.h"
int switchkinsSetup(kparms* kp,
KS* kset0, KS* kset1, KS* kset2,
KF* kfwd0, KF* kfwd1, KF* kfwd2,
KI* kinv0, KI* kinv1, KI* kinv2
)
{
kp->kinsname = "xyzac-trt-kins"; // !!! must agree with filename
kp->halprefix = "xyzac-trt-kins"; // hal pin names
kp->required_coordinates = "xyzac";
kp->allow_duplicates = 1;
kp->max_joints = EMCMOT_MAX_JOINTS;
if (kp->sparm && strstr(kp->sparm,"identityfirst")) {
rtapi_print("\n!!! switchkins-type 0 is IDENTITY\n");
*kset0 = identityKinematicsSetup;
*kfwd0 = identityKinematicsForward;
*kinv0 = identityKinematicsInverse;
*kset1 = trtKinematicsSetup; // trt: xyzac,xyzbc
*kfwd1 = xyzacKinematicsForward;
*kinv1 = xyzacKinematicsInverse;
} else {
rtapi_print("\n!!! switchkins-type 0 is %s\n",kp->kinsname);
*kset0 = trtKinematicsSetup; // trt: xyzac,xyzbc
*kfwd0 = xyzacKinematicsForward;
*kinv0 = xyzacKinematicsInverse;
*kset1 = identityKinematicsSetup;
*kfwd1 = identityKinematicsForward;
*kinv1 = identityKinematicsInverse;
}
*kset2 = userkKinematicsSetup;
*kfwd2 = userkKinematicsForward;
*kinv2 = userkKinematicsInverse;
return 0;
}

View File

@@ -0,0 +1,57 @@
/********************************************************************
* xyzbc-trt-kins.c employing switchkins.[ch]
* License: GPL Version 2
*
* NOTEs:
* 1) specify all kparms items
* 2) specify 3 KS,KF,KI functions for switchkins_type=0,1,2
* 3) the 0th switchkins_type is the startup default
* 4) sparm is a module string parameter for configuration
* 5) The directions of the rotational axes are the opposite of the
* conventional axis directions.
*/
#include <rtapi.h>
#include <rtapi_string.h>
#include <emcmotcfg.h>
#include "switchkins.h"
int switchkinsSetup(kparms* kp,
KS* kset0, KS* kset1, KS* kset2,
KF* kfwd0, KF* kfwd1, KF* kfwd2,
KI* kinv0, KI* kinv1, KI* kinv2
)
{
kp->kinsname = "xyzbc-trt-kins"; // !!! must agree with filename
kp->halprefix = "xyzbc-trt-kins"; // hal pin names
kp->required_coordinates = "xyzbc";
kp->allow_duplicates = 1;
kp->max_joints = EMCMOT_MAX_JOINTS;
if (kp->sparm && strstr(kp->sparm,"identityfirst")) {
rtapi_print("\n!!! switchkins-type 0 is IDENTITY\n");
*kset0 = identityKinematicsSetup;
*kfwd0 = identityKinematicsForward;
*kinv0 = identityKinematicsInverse;
*kset1 = trtKinematicsSetup; // trt: xyzac,xyzbc
*kfwd1 = xyzbcKinematicsForward;
*kinv1 = xyzbcKinematicsInverse;
} else {
rtapi_print("\n!!! switchkins-type 0 is %s\n",kp->kinsname);
*kset0 = trtKinematicsSetup; // trt: xyzac,xyzbc
*kfwd0 = xyzbcKinematicsForward;
*kinv0 = xyzbcKinematicsInverse;
*kset1 = identityKinematicsSetup;
*kfwd1 = identityKinematicsForward;
*kinv1 = identityKinematicsInverse;
}
*kset2 = userkKinematicsSetup;
*kfwd2 = userkKinematicsForward;
*kinv2 = userkKinematicsInverse;
return 0;
}