按建议,继续下一步工作
结论:已将 LinuxCNC TP 源码纳入 wasm-port 的可复现 vendor 清单和 native probe 构建,新增真实 tpCreate/tpAddLine/tpRunCycle 线性运动验证,并通过 native probes 全量验证。
This commit is contained in:
146
wasm-port/runtime/core/linuxcnc_wrap/linuxcnc_tp_api_probe.cpp
Normal file
146
wasm-port/runtime/core/linuxcnc_wrap/linuxcnc_tp_api_probe.cpp
Normal file
@@ -0,0 +1,146 @@
|
||||
#include <iostream>
|
||||
|
||||
#include "emc/motion/motion.h"
|
||||
#include "emc/nml_intf/motion_types.h"
|
||||
#include "emc/tp/tp.h"
|
||||
|
||||
namespace {
|
||||
|
||||
emcmot_status_t status{};
|
||||
emcmot_config_t config{};
|
||||
emcmot_joint_t joints[EMCMOT_MAX_JOINTS]{};
|
||||
|
||||
void dio_write(int, char) {}
|
||||
void aio_write(int, double) {}
|
||||
void set_rotary_unlock(int, int) {}
|
||||
int get_rotary_unlock(int) { return 1; }
|
||||
|
||||
double axis_vel_limit(int axis)
|
||||
{
|
||||
return axis >= 0 && axis < EMCMOT_MAX_AXIS ? 10.0 : 0.0;
|
||||
}
|
||||
|
||||
double axis_acc_limit(int axis)
|
||||
{
|
||||
return axis >= 0 && axis < EMCMOT_MAX_AXIS ? 20.0 : 0.0;
|
||||
}
|
||||
|
||||
void init_motion_state()
|
||||
{
|
||||
config.numJoints = 3;
|
||||
config.numSpindles = 1;
|
||||
config.numDIO = 4;
|
||||
config.numAIO = 4;
|
||||
config.arcBlendOptDepth = 0;
|
||||
config.arcBlendEnable = 0;
|
||||
config.arcBlendFallbackEnable = 0;
|
||||
config.arcBlendGapCycles = 4;
|
||||
config.arcBlendRampFreq = 20.0;
|
||||
config.arcBlendTangentKinkRatio = 0.1;
|
||||
config.maxFeedScale = 1.0;
|
||||
|
||||
status.net_feed_scale = 1.0;
|
||||
status.feed_scale = 1.0;
|
||||
status.rapid_scale = 1.0;
|
||||
status.enables_new = FS_ENABLED | SS_ENABLED;
|
||||
status.enables_queued = status.enables_new;
|
||||
status.spindle_status[0].at_speed = 1;
|
||||
status.spindle_status[0].direction = 1;
|
||||
status.spindleSync = 0;
|
||||
status.jerk = 0.0;
|
||||
status.planner_type = 0;
|
||||
|
||||
tpMotData(&status, &config);
|
||||
tpMotFunctions(
|
||||
dio_write,
|
||||
aio_write,
|
||||
set_rotary_unlock,
|
||||
get_rotary_unlock,
|
||||
axis_vel_limit,
|
||||
axis_acc_limit);
|
||||
}
|
||||
|
||||
void run_linear_probe()
|
||||
{
|
||||
init_motion_state();
|
||||
|
||||
TP_STRUCT tp{};
|
||||
EmcPose start{};
|
||||
EmcPose end{};
|
||||
struct state_tag_t tag {};
|
||||
|
||||
end.tran.x = 1.0;
|
||||
|
||||
const int create_rc = tpCreate(&tp, TP_DEFAULT_QUEUE_SIZE, 1);
|
||||
const int set_cycle_rc = tpSetCycleTime(&tp, 0.001);
|
||||
const int set_pos_rc = tpSetPos(&tp, &start);
|
||||
const int set_vmax_rc = tpSetVmax(&tp, 1.0, 1.0);
|
||||
const int set_vlimit_rc = tpSetVlimit(&tp, 1.0);
|
||||
const int set_amax_rc = tpSetAmax(&tp, 10.0);
|
||||
const int set_term_rc = tpSetTermCond(&tp, TC_TERM_COND_STOP, 0.0);
|
||||
const int add_line_rc = tpAddLine(
|
||||
&tp,
|
||||
end,
|
||||
EMC_MOTION_TYPE_FEED,
|
||||
1.0,
|
||||
1.0,
|
||||
10.0,
|
||||
100.0,
|
||||
status.enables_new,
|
||||
0,
|
||||
-1,
|
||||
tag);
|
||||
|
||||
int cycle_rc = 0;
|
||||
int cycles = 0;
|
||||
for (; cycles < 10000 && !tpIsDone(&tp); ++cycles) {
|
||||
cycle_rc = tpRunCycle(&tp, 1000000);
|
||||
if (cycle_rc < 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
EmcPose final_pos{};
|
||||
const int get_pos_rc = tpGetPos(&tp, &final_pos);
|
||||
|
||||
std::cout << "tp_create=" << create_rc << "\n";
|
||||
std::cout << "tp_set_cycle_time=" << set_cycle_rc << "\n";
|
||||
std::cout << "tp_set_pos=" << set_pos_rc << "\n";
|
||||
std::cout << "tp_set_vmax=" << set_vmax_rc << "\n";
|
||||
std::cout << "tp_set_vlimit=" << set_vlimit_rc << "\n";
|
||||
std::cout << "tp_set_amax=" << set_amax_rc << "\n";
|
||||
std::cout << "tp_set_term_cond=" << set_term_rc << "\n";
|
||||
std::cout << "tp_add_line=" << add_line_rc << "\n";
|
||||
std::cout << "tp_cycle_rc=" << cycle_rc << "\n";
|
||||
std::cout << "tp_cycles=" << cycles << "\n";
|
||||
std::cout << "tp_get_pos=" << get_pos_rc << "\n";
|
||||
std::cout << "tp_done_after_line=" << tpIsDone(&tp) << "\n";
|
||||
std::cout << "tp_queue_depth=" << tpQueueDepth(&tp) << "\n";
|
||||
std::cout << "tp_final_pos="
|
||||
<< final_pos.tran.x << ","
|
||||
<< final_pos.tran.y << ","
|
||||
<< final_pos.tran.z << "\n";
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
int main()
|
||||
{
|
||||
TP_STRUCT tp{};
|
||||
TC_STRUCT tc{};
|
||||
EmcPose pose{};
|
||||
|
||||
pose.tran.x = 1.0;
|
||||
pose.tran.y = 2.0;
|
||||
pose.tran.z = 3.0;
|
||||
|
||||
std::cout << "sizeof_TP_STRUCT=" << sizeof(tp) << "\n";
|
||||
std::cout << "sizeof_TC_STRUCT=" << sizeof(tc) << "\n";
|
||||
std::cout << "tp_default_queue_size=" << TP_DEFAULT_QUEUE_SIZE << "\n";
|
||||
std::cout << "tp_err_ok=" << TP_ERR_OK << "\n";
|
||||
std::cout << "tc_linear=" << TC_LINEAR << "\n";
|
||||
std::cout << "tc_circular=" << TC_CIRCULAR << "\n";
|
||||
std::cout << "pose_xyz=" << pose.tran.x << "," << pose.tran.y << "," << pose.tran.z << "\n";
|
||||
run_linear_probe();
|
||||
return 0;
|
||||
}
|
||||
@@ -23,6 +23,13 @@ typedef union {
|
||||
unsigned long long lu;
|
||||
} hal_data_u;
|
||||
|
||||
typedef bool hal_bit_t;
|
||||
typedef double hal_float_t;
|
||||
typedef int hal_s32_t;
|
||||
typedef unsigned int hal_u32_t;
|
||||
typedef long long hal_s64_t;
|
||||
typedef unsigned long long hal_u64_t;
|
||||
|
||||
int hal_init(const char *);
|
||||
int hal_ready(int);
|
||||
int hal_get_pin_value_by_name(const char *, hal_type_t *, hal_data_u **, bool *);
|
||||
|
||||
@@ -19,6 +19,10 @@
|
||||
#define RTAPI_NAME_LEN 31
|
||||
#endif
|
||||
|
||||
#ifndef EXPORT_SYMBOL
|
||||
#define EXPORT_SYMBOL(symbol)
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
RTAPI_MSG_NONE = 0,
|
||||
RTAPI_MSG_ERR,
|
||||
|
||||
Reference in New Issue
Block a user