Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
9dc04e2
canon: move the NURBS math helpers to nurbs_math.hh
rene-dev Oct 28, 2026
3aaef5b
canon: return whole poses from the position and tool offset queries
rene-dev Oct 28, 2026
c5735e0
canon: pass text as std::string_view, return the parameter file name
rene-dev Oct 28, 2026
51febee
sai: print canon calls with {fmt}
rene-dev Oct 29, 2026
260aa28
interp: remove the unused setup.log_file
rene-dev Oct 29, 2026
91dca07
interp: keep program_prefix and wizard_root in std::string
rene-dev Oct 29, 2026
0a6d48b
interp: keep the error text in the Interp, as a std::string
rene-dev Oct 29, 2026
749c04e
interp: return std::string from the InterpBase text getters
rene-dev Oct 29, 2026
a0cee6b
interp: build file search paths in std::string instead of PATH_MAX bu…
rene-dev Oct 29, 2026
10fb59d
interp: drop fixed buffers from the error stack, REMAP parsing and co…
rene-dev Oct 29, 2026
737af96
interp: build the remap call line in a std::string
rene-dev Oct 29, 2026
b8c9b6d
interp, task: review cleanups
rene-dev Nov 1, 2026
d8fc823
interp: free the wordexp() result after WRDE_NOSPACE
rene-dev Nov 1, 2026
9af83ae
interp: make stack_index read-only from Python
rene-dev Nov 1, 2026
1abfd54
canterp, sai: stop the error stack loop
rene-dev Nov 1, 2026
ba6b810
interp: close the parameter files on every error path
rene-dev Nov 1, 2026
3b7b61e
task: print the current orientation for an RPY comment without values
rene-dev Nov 1, 2026
2bb44bc
interp: reject REMAP lines that would have no effect
rene-dev Nov 1, 2026
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
50 changes: 22 additions & 28 deletions src/emc/canterp/canterp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ static char the_command_args[LINELEN] = { 0 }; // just the args part

class Canterp : public InterpBase {
public:
Canterp () : f(NULL), filename{} {}
char *error_text(int errcode, char *buf, size_t buflen) override;
char *stack_name(int index, char *buf, size_t buflen) override;
char *line_text(char *buf, size_t buflen) override;
char *file_name(char *buf, size_t buflen) override;
Canterp () : f(NULL) {}
std::string error_text(int errcode) override;
std::string stack_name(int index) override;
std::string line_text() override;
std::string file_name() override;
size_t line_length() override;
int sequence_number() override;
int ini_load(const char *inifile) override;
Expand All @@ -87,8 +87,8 @@ class Canterp : public InterpBase {
int reset() override;
int line() override;
int call_level() override;
char *command(char *buf, size_t buflen) override;
char *file(char *buf, size_t buflen) override;
std::string command() override;
std::string file() override;
int on_abort(int reason, const char *message) override;
void active_g_codes(int active_gcodes[ACTIVE_G_CODES]) override;
void active_m_codes(int active_mcodes[ACTIVE_M_CODES]) override;
Expand All @@ -103,18 +103,16 @@ class Canterp : public InterpBase {
void set_loop_on_main_m99(bool state) override;
FILE* get_stdout() override { return NULL; };
FILE *f;
char filename[PATH_MAX];
std::string filename;
};

char *Canterp::error_text(int errcode, char *buf, size_t buflen) {
if(errcode < INTERP_MIN_ERROR) snprintf(buf, buflen, "OK %d", errcode);
else snprintf(buf, buflen, "ERROR %d", errcode);
return buf;
std::string Canterp::error_text(int errcode) {
return (errcode < INTERP_MIN_ERROR ? "OK " : "ERROR ") + std::to_string(errcode);
}

char *Canterp::stack_name(int index, char *buf, size_t buflen) {
snprintf(buf, buflen, "<stack %d>", index);
return buf;
// canterp has no call stack; an empty name ends the caller's loop
std::string Canterp::stack_name(int /*index*/) {
return {};
}

int Canterp::ini_load(const char * /*inifile*/) {
Expand Down Expand Up @@ -697,7 +695,7 @@ int Canterp::execute() {
int Canterp::open(const char *newfilename) {
if(f) fclose(f);
f = fopen(newfilename, "r");
if(f) snprintf(filename, sizeof(filename), "%s", newfilename);
if(f) filename = newfilename;
return f ? INTERP_OK : INTERP_ERROR;
}

Expand All @@ -715,27 +713,23 @@ int Canterp::reset() { return 0; }
int Canterp::line() { return 0; }
int Canterp::call_level() { return 0; }

char *Canterp::line_text(char *buf, size_t bufsize) {
snprintf(buf, bufsize, "<Canterp::line_text>");
return buf;
std::string Canterp::line_text() {
return "<Canterp::line_text>";
}
char *Canterp::file_name(char *buf, size_t bufsize) {
snprintf(buf, bufsize, "%s", filename);
return buf;
std::string Canterp::file_name() {
return filename;
}
char *Canterp::file(char *buf, size_t bufsize) {
snprintf(buf, bufsize, "%s", filename);
return buf;
std::string Canterp::file() {
return filename;
}
int Canterp::on_abort(int reason, const char *message)
{
fprintf(stderr, "Canterp::on_abort reason=%d message='%s'", reason, message);
reset();
return INTERP_OK;
}
char *Canterp::command(char *buf, size_t bufsize) {
snprintf(buf, bufsize, "<Canterp::command>");
return buf;
std::string Canterp::command() {
return "<Canterp::command>";
}
size_t Canterp::line_length() {
return 0;
Expand Down
152 changes: 18 additions & 134 deletions src/emc/nml_intf/canon.hh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#define CANON_HH

#include <stdio.h> // FILE
#include <string>
#include <string_view>
#include <vector>

#include <emcpos.h>
Expand Down Expand Up @@ -522,80 +524,6 @@ extern void STRAIGHT_FEED(int lineno,
double a, double b, double c,
double u, double v, double w);

/* Additional functions needed to calculate nurbs G5 points */

extern std::vector<unsigned int> nurbs_G5_knot_vector_creator(unsigned int n, unsigned int k);

extern double nurbs_G5_Nmix(unsigned int i, unsigned int k, double u, const std::vector<unsigned int>& knot_vector);

extern double nurbs_G5_Rden(double u, unsigned int k,
const std::vector<NURBS_CONTROL_POINT>& nurbs_control_points,
const std::vector<unsigned int>& knot_vector);

extern NURBS_PLANE_POINT nurbs_G5_point(double u, unsigned int k,
const std::vector<NURBS_CONTROL_POINT>& nurbs_control_points,
const std::vector<unsigned int>& knot_vector);

extern NURBS_PLANE_POINT nurbs_G5_tangent(double u, unsigned int k,
const std::vector<NURBS_CONTROL_POINT>& nurbs_control_points,
const std::vector<unsigned int>& knot_vector);

/* Additional functions needed to calculate nurbs points G_6_2*/

extern std::vector<double> nurbs_g6_knot_vector_creator(unsigned int n, unsigned int k, const std::vector<NURBS_G6_CONTROL_POINT>& nurbs_control_points);

std::vector<double> nurbs_interval_span_knot_vector_creator(unsigned int n, unsigned int k, const std::vector<double>& knot_vector_);

extern double nurbs_lderv(double u, unsigned int k, const std::vector<NURBS_G6_CONTROL_POINT>& nurbs_control_points, const std::vector<double>& knot_vector_);

extern double nurbs_Sa1_b1_length_(double a1, double b1, unsigned int k, const std::vector<NURBS_G6_CONTROL_POINT>& nurbs_control_points, const std::vector<double>& knot_vector_);

extern std::vector<double> nurbs_lenght_vector_creator(unsigned int k, const std::vector<NURBS_G6_CONTROL_POINT>& nurbs_control_points, const std::vector<double>& knot_vector_, const std::vector<double>& span_knot_vector);

extern double nurbs_lenght_tot(int j, const std::vector<double>& span_knot_vector, const std::vector<double>& lenght_vector);

extern double nurbs_lenght_l_u(double u, unsigned int k, const std::vector<NURBS_G6_CONTROL_POINT>& nurbs_control_points, const std::vector<double>& knot_vector_, const std::vector<double>& span_knot_vector, const std::vector<double>& lenght_vector);

extern std::vector<double> nurbs_Du_span_knot_vector_creator(unsigned int k, const std::vector<NURBS_G6_CONTROL_POINT>& nurbs_control_points, const std::vector<double>& knot_vector_, const std::vector<double>& span_knot_vector);

extern std::vector<double> nurbs_costant_crator(const std::vector<double>& span_knot_vector, const std::vector<double>& lenght_vector, const std::vector<double>& Du_span_knot_vector);

extern double nurbs_uj_l(double l, const std::vector<double>& span_knot_vector, const std::vector<double>& lenght_vector, const std::vector<double>& nurbs_costant);

/* Funzioni di supporto all'algoritmo di suddivisione */
extern std::vector<double> nurbs_G6_new_control_point_nurbs1(double u, unsigned int k, const std::vector<NURBS_G6_CONTROL_POINT>& nurbs_control_points, const std::vector<double>& knot_vector_ );

extern std::vector<double> nurbs_G6_new_control_point_nurbs2(double u, unsigned int k, const std::vector<NURBS_G6_CONTROL_POINT>& nurbs_control_points, const std::vector<double>& knot_vector_ );

extern std::vector<double> nurbs_G6_knot_vector_new_creator_sgment(unsigned int k, const std::vector<NURBS_G6_CONTROL_POINT>& nurbs_control_points);
/* ... */

extern double nurbs_G6_Nmix(unsigned int i, unsigned int k, double u, const std::vector<double>& knot_vector_);

extern std::vector< std::vector<double> > nurbs_G6_Nmix_creator(double u, unsigned int k, double n, const std::vector<double>& knot_vector_);

extern double nurbs_G6_Rden(double u, unsigned int k, const std::vector<NURBS_G6_CONTROL_POINT>& nurbs_control_points, const std::vector<double>& knot_vector_);

extern NURBS_PLANE_POINT nurbs_G6_point(double u, unsigned int k, const std::vector<NURBS_G6_CONTROL_POINT>& nurbs_control_points, const std::vector<double>& knot_vector_);

extern double nurbs_G6_Rdenx(double u, unsigned int k, const std::vector<NURBS_G6_CONTROL_POINT>& nurbs_control_points, const std::vector<double>& knot_vector_, const std::vector< std::vector<double> >& A6);

extern NURBS_PLANE_POINT nurbs_G6_pointx(double u, unsigned int k, const std::vector<NURBS_G6_CONTROL_POINT>& nurbs_control_points, const std::vector<double>& knot_vector_, const std::vector< std::vector<double> >& A6);

extern NURBS_PLANE_POINT nurbs_G6_point_x(double u, unsigned int k, const std::vector<NURBS_G6_CONTROL_POINT>& nurbs_control_points, const std::vector<double>& knot_vector_);

extern NURBS_PLANE_POINT nurbs_G6_tangent_x(double u, unsigned int k, const std::vector<NURBS_G6_CONTROL_POINT>& nurbs_control_points, const std::vector<double>& knot_vector_);

/*Funzioni di supporto all'algoritmo di suddivisione********************************************************************/
extern std::vector<double> nurbs_G6_new_control_point_nurbs1(double u, unsigned int k, const std::vector<NURBS_G6_CONTROL_POINT>& nurbs_control_points, const std::vector<double>& knot_vector_ );

extern std::vector<double> nurbs_G6_new_control_point_nurbs2(double u, unsigned int k, const std::vector<NURBS_G6_CONTROL_POINT>& nurbs_control_points, const std::vector<double>& knot_vector_ );

extern std::vector<double> nurbs_G6_knot_vector_new_creator_sgment(unsigned int k, const std::vector<NURBS_G6_CONTROL_POINT>& nurbs_control_points);

/* End of NURBS functions*/


/* Canon calls */

extern void NURBS_G5_FEED(int lineno, const std::vector<NURBS_CONTROL_POINT>& nurbs_control_points, unsigned int nurbs_order, CANON_PLANE plane);
Expand All @@ -606,8 +534,6 @@ extern void NURBS_G5_FEED(int lineno, const std::vector<NURBS_CONTROL_POINT>& nu
extern void NURBS_G6_FEED(int lineno, const std::vector<NURBS_G6_CONTROL_POINT>& nurbs_control_points, unsigned int k, double feedrate, int l, CANON_PLANE plane);
// this is for G6xx

extern double alpha_finder(double dx, double dy);


/********************************************************************************************************************/

Expand Down Expand Up @@ -737,7 +663,7 @@ controller.
An attempt to move an axis while it is clamped should result in an
error condition in the controller. */

extern void COMMENT(const char *s);
extern void COMMENT(std::string_view s);

/* This function has no physical effect. If commands are being printed or
logged, the comment command is printed or logged, including the string
Expand Down Expand Up @@ -768,11 +694,11 @@ extern void FLOOD_OFF();
extern void FLOOD_ON();
/* Turn flood coolant on. */

extern void MESSAGE(char *s);
extern void MESSAGE(std::string_view s);

extern void LOG(char *s);
extern void LOGOPEN(char *s);
extern void LOGAPPEND(char *s);
extern void LOG(std::string_view s);
extern void LOGOPEN(std::string_view filename);
extern void LOGAPPEND(std::string_view filename);
extern void LOGCLOSE();

extern void MIST_OFF();
Expand Down Expand Up @@ -969,55 +895,22 @@ extern double GET_EXTERNAL_ORIGIN_Z();

*/

// returns nothing but copies the name of the parameter file into
// the filename array, stopping at max_size if the name is longer
// An empty string may be placed in filename.
extern void GET_EXTERNAL_PARAMETER_FILE_NAME(char *filename, int max_size);
// returns the name of the parameter file, or an empty string if none is set
extern std::string GET_EXTERNAL_PARAMETER_FILE_NAME();

extern void SET_PARAMETER_FILE_NAME(const char *name);
extern void SET_PARAMETER_FILE_NAME(std::string_view name);

// returns the currently active plane
extern CANON_PLANE GET_EXTERNAL_PLANE();

// returns the current a-axis position
extern double GET_EXTERNAL_POSITION_A();

// returns the current b-axis position
extern double GET_EXTERNAL_POSITION_B();

// returns the current c-axis position
extern double GET_EXTERNAL_POSITION_C();

// returns the current x-axis position
extern double GET_EXTERNAL_POSITION_X();

// returns the current y-axis position
extern double GET_EXTERNAL_POSITION_Y();

// returns the current z-axis position
extern double GET_EXTERNAL_POSITION_Z();

// returns the current u-axis position
extern double GET_EXTERNAL_POSITION_U();

// returns the current v-axis position
extern double GET_EXTERNAL_POSITION_V();

// returns the current w-axis position
extern double GET_EXTERNAL_POSITION_W();
// returns the current position of all nine axes, in program units
// and the current work coordinate system
extern CANON_POSITION GET_EXTERNAL_POSITION();


// Returns the position of the specified axis at the last probe trip,
// Returns the position of all axes at the last probe trip,
// in the current work coordinate system.
extern double GET_EXTERNAL_PROBE_POSITION_A();
extern double GET_EXTERNAL_PROBE_POSITION_B();
extern double GET_EXTERNAL_PROBE_POSITION_C();
extern double GET_EXTERNAL_PROBE_POSITION_X();
extern double GET_EXTERNAL_PROBE_POSITION_Y();
extern double GET_EXTERNAL_PROBE_POSITION_Z();
extern double GET_EXTERNAL_PROBE_POSITION_U();
extern double GET_EXTERNAL_PROBE_POSITION_V();
extern double GET_EXTERNAL_PROBE_POSITION_W();
extern CANON_POSITION GET_EXTERNAL_PROBE_POSITION();

// Returns the value for any analog non-contact probing.
extern double GET_EXTERNAL_PROBE_VALUE();
Expand All @@ -1035,16 +928,8 @@ extern double GET_EXTERNAL_SPEED(int spindle);
// Returns the system value for direction of spindle turning
extern CANON_DIRECTION GET_EXTERNAL_SPINDLE(int spindle);

// returns current tool length offset
extern double GET_EXTERNAL_TOOL_LENGTH_XOFFSET();
extern double GET_EXTERNAL_TOOL_LENGTH_YOFFSET();
extern double GET_EXTERNAL_TOOL_LENGTH_ZOFFSET();
extern double GET_EXTERNAL_TOOL_LENGTH_AOFFSET();
extern double GET_EXTERNAL_TOOL_LENGTH_BOFFSET();
extern double GET_EXTERNAL_TOOL_LENGTH_COFFSET();
extern double GET_EXTERNAL_TOOL_LENGTH_UOFFSET();
extern double GET_EXTERNAL_TOOL_LENGTH_VOFFSET();
extern double GET_EXTERNAL_TOOL_LENGTH_WOFFSET();
// returns current tool length offset, in program units
extern EmcPose GET_EXTERNAL_TOOL_LENGTH_OFFSET();

// Returns the system value for the carousel slot in which the tool
// currently in the spindle belongs. Return value zero means there is no
Expand Down Expand Up @@ -1089,7 +974,6 @@ extern double GET_EXTERNAL_ANALOG_INPUT(int index, double def);
extern int GET_EXTERNAL_AXIS_MASK();


#define PARAMETER_FILE_NAME_LENGTH 100

#define USER_DEFINED_FUNCTION_NUM 100
typedef void (*USER_DEFINED_FUNCTION_TYPE) (int num, double arg1,
Expand All @@ -1108,7 +992,7 @@ extern void FINISH(void);
extern void ON_RESET(void);

// expose CANON_ERROR
extern void CANON_ERROR(const char *fmt, ...) __attribute__((format(printf,1,2)));
extern void CANON_ERROR(std::string_view message);

extern int GET_EXTERNAL_OFFSET_APPLIED();
extern EmcPose GET_EXTERNAL_OFFSETS();
Expand Down
Loading
Loading