diff --git a/docs/src/config/ini-config.adoc b/docs/src/config/ini-config.adoc index cec25ceff4c..9ae221b218b 100644 --- a/docs/src/config/ini-config.adoc +++ b/docs/src/config/ini-config.adoc @@ -284,17 +284,22 @@ On multi spindle machine there will be entries for each spindle number. Qtvcp on * 'DEFAULT_SPINDLE_SPEED = 100' - The default spindle RPM when the spindle is started in manual mode. if this setting is not present, this defaults to 1 RPM for AXIS and 300 RPM for gmoccapy. + - deprecated - use the [SPINDLE_n] section instead * 'DEFAULT_SPINDLE_0_SPEED = 100' - The default spindle RPM when the spindle is started in manual mode. On multi spindle machine there will be entries for each spindle number. Qtvcp only + - deprecated - use the [SPINDLE_n] section instead * 'SPINDLE_INCREMENT = 200' - The increment used when clicking increase/decrease buttons Qtvcp only +- deprecated - use the [SPINDLE_n] section instead * 'MIN_SPINDLE_0_SPEED = 1000' - The minimum RPM that can be manually selected. On multi spindle machine there will be entries for each spindle number. Qtvcp only +- deprecated - use the [SPINDLE_n] section instead * 'MAX_SPINDLE_0_SPEED = 20000' - The maximum RPM that can be manually selected. On multi spindle machine there will be entries for each spindle number. Qtvcp only +- deprecated - use the [SPINDLE_n] section instead * 'PROGRAM_PREFIX = ~/linuxcnc/nc_files' - The default location for g-code files and the location for user-defined M-codes. This location is searched @@ -1585,6 +1590,43 @@ image::images/encoder-scale.png[align="center"] than the joint MAX_VELOCITY. Subsequent testing has shown that use of STEPGEN_MAXVEL does not improve the tuning of stepgen's position loop. +[[sec:spindle-section]](((INI File, SPINDLE Section))) + +=== [SPINDLE_] Section +The specifies the spindle number 0 ... (num_spindles-1) +The value of 'num_spindles' is set by [TRAJ]SPINDLES= + +* 'MAX_VELOCITY = 20000' + The maximum spindle speed (in rpm) for the specified spindle. Optional. + +* 'MIN_VELOCITY = 3000' + The minimum spindle speed (in rpm) for the specified spindle. Optional. + Many spindles have a minimum speed below which they should not be run. + Any spindle speed command below this limit will be /increased/ to this + limit. + +* 'MAX_REVERSE_VELOCITY = 20000' + This setting will default to MAX_VELOCITY if omitted. It can be used + in cases where the spindle speed is limited in reverse. Set to zero + for spindles which must not be run in reverse. + In this context "max" refers to the abslute magnitude of the spindle + speed. + +* 'MIN_REVERSE_VELOCITY = 3000' + This setting is equivalent to MIN_VELOCITY but for reverse spindle + rotation. It will default to the MIN_VELOCITY if omitted. + +* 'HOME_SEARCH_VELOCITY = 100' - FIXME: Spindle homing not yet working + Sets the homing speed (rpm) for the spindle. The spindle will rotate + at this velocity during the homing sequence until the spindle index + is located, at which point the spindle position will be set to zero. + Note that it makes no sense for the spindle home position to be any + value other than zero, and so there is no provision to do so. + +* 'HOME_SEQUENCE = 0' - FIXME: Spindle homing not yet working + Controls where in the general homing sequence the spindle homing + rotations occur. Set the HOME_SEARCH_VELOCITY to zero to avoid spindle + rotation during the homing sequence [[sec:emcio-section]](((INI File, EMCIO Section))) diff --git a/src/Makefile b/src/Makefile index e27dd13a4dd..aefef056cd8 100644 --- a/src/Makefile +++ b/src/Makefile @@ -314,6 +314,7 @@ HEADERS := \ emc/ini/emcIniFile.hh \ emc/ini/iniaxis.hh \ emc/ini/inijoint.hh \ + emc/ini/inispindle.hh \ emc/ini/initraj.hh \ emc/ini/inihal.hh \ emc/kinematics/cubic.h \ diff --git a/src/emc/ini/inihal.cc b/src/emc/ini/inihal.cc index f15013aa900..01ddc240e19 100644 --- a/src/emc/ini/inihal.cc +++ b/src/emc/ini/inihal.cc @@ -26,6 +26,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "rtapi.h" #include "inihal.hh" #include "iniaxis.hh" +#include "inispindle.hh" static int debug=0; static int comp_id; diff --git a/src/emc/ini/inispindle.cc b/src/emc/ini/inispindle.cc new file mode 100644 index 00000000000..7855dddaed3 --- /dev/null +++ b/src/emc/ini/inispindle.cc @@ -0,0 +1,128 @@ +/******************************************************************** +* Description: inispindle.cc +* INI file initialization routines for spindle NML +* +* Derived from a work by Fred Proctor & Will Shackleford +* +* Author: Andy Pugh +* License: GPL Version 2+ +* System: Linux +* +* Copyright (c) 2021 All rights reserved. +* +* Last change: created 30/12/21 +********************************************************************/ + +#include +#include // NULL +#include // atol(), _itoa() +#include // strcmp() +#include // isdigit() +#include +#include + +#include "emc.hh" +#include "rcs_print.hh" +#include "emcIniFile.hh" +#include "inispindle.hh" // these decls +#include "emcglb.h" // EMC_DEBUG +#include "emccfg.h" // default values for globals + +#include "inihal.hh" + +extern value_inihal_data old_inihal_data; + +/* + loadSpindls(int spindle) + + Loads ini file params for the specified spindle + spindle max and min velocities + */ + +static int loadSpindle(int spindle, EmcIniFile *spindleIniFile) +{ + int num_spindles = 1; + char spindleString[11]; + double max_pos = 1e99; + double max_neg = 0; + double min_pos = 0; + double min_neg = -1e99; + int home_sequence = 0; + double search_vel = 0; + double home_angle = 0; + double increment = 100; + double limit; + + spindleIniFile->EnableExceptions(EmcIniFile::ERR_CONVERSION); + + if (spindleIniFile->Find(&num_spindles, "SPINDLES", "TRAJ") < 0){ + num_spindles = 1; } + if (spindle > num_spindles) return -1; + + snprintf(spindleString, sizeof(spindleString), "SPINDLE_%i", spindle); + + // set max positive speed limit + if (spindleIniFile->Find(&limit, "MAX_VELOCITY", spindleString) == 0){ + max_pos = limit; + min_neg = limit; + } + // set min positive speed limit + if (spindleIniFile->Find(&limit, "MIN_VELOCITY", spindleString) == 0){ + min_pos = limit; + max_neg = limit; + } + // set min negative speed limit + if (spindleIniFile->Find(&limit, "MIN_REVERSE_VELOCITY", spindleString) == 0){ + max_neg = -1.0 * fabs(limit); + } + // set max negative speed limit + if (spindleIniFile->Find(&limit, "MAX_REVERSE_VELOCITY", spindleString) == 0){ + min_neg = -1.0 * fabs(limit); + } + // set home sequence + if (spindleIniFile->Find(&limit, "HOME_SEQUENCE", spindleString) == 0){ + home_sequence = (int)limit; + } + // set home velocity + if (spindleIniFile->Find(&limit, "HOME_SEARCH_VELOCITY", spindleString) == 0){ + search_vel = (int)limit; + } + /* set home angle - I believe this is a bad idea - andypugh 30/12/21 + if (spindleIniFile->Find(&limit, "HOME", spindleString) >= 0){ + home_angle = (int)limit; + }*/ + home_angle = 0; + // set spindle increment + if (spindleIniFile->Find(&limit, "INCREMENT", spindleString) == 0){ + increment = limit; + } + + if (0 != emcSpindleSetParams(spindle, max_pos, min_pos, max_neg, + min_neg, search_vel, home_angle, home_sequence, increment)) { + return -1; + } + return 0; +} + +/* + iniAxis(int axis, const char *filename) + + Loads ini file parameters for specified axis, [0 .. AXES - 1] + + */ +int iniSpindle(int spindle, const char *filename) +{ + EmcIniFile spindleIniFile(EmcIniFile::ERR_TAG_NOT_FOUND | + EmcIniFile::ERR_SECTION_NOT_FOUND | + EmcIniFile::ERR_CONVERSION); + + if (spindleIniFile.Open(filename) == false) { + return -1; + } + + // load its values + if (0 != loadSpindle(spindle, &spindleIniFile)) { + return -1; + } + return 0; +} diff --git a/src/emc/ini/inispindle.hh b/src/emc/ini/inispindle.hh new file mode 100644 index 00000000000..95c2e684e16 --- /dev/null +++ b/src/emc/ini/inispindle.hh @@ -0,0 +1,22 @@ +/******************************************************************** +* Description: inispindle.hh +* +* Derived from a work by Fred Proctor & Will Shackleford +* +* Author: +* License: GPL Version 2 +* System: Linux +* +* Copyright (c) 2021 All rights reserved. +* +* Last change: file created by andypugh 30/12/21 +********************************************************************/ +#ifndef INISPINDLE_HH +#define INISPINDLE_HH + +#include "emc.hh" // EMC_AXIS_STAT + +/* initializes spindle modules from ini file */ +extern int iniSpindle(int spindle, const char *filename); + +#endif diff --git a/src/emc/motion/command.c b/src/emc/motion/command.c index c9d5a0944a0..fef832655d8 100644 --- a/src/emc/motion/command.c +++ b/src/emc/motion/command.c @@ -193,6 +193,16 @@ void refresh_jog_limits(emcmot_joint_t *joint, int joint_num) } } +void apply_spindle_limits(spindle_status_t *s){ + if (s->speed > 0) { + if (s->speed > s->max_pos_speed) s->speed = s->max_pos_speed; + if (s->speed < s->min_pos_speed) s->speed = s->min_pos_speed; + } else if (s->speed < 0) { + if (s->speed < s->min_neg_speed) s->speed = s->min_neg_speed; + if (s->speed > s->max_neg_speed) s->speed = s->max_neg_speed; + } +} + static int check_axis_constraint(double target, int id, char *move_type, int axis_no, char axis_name) { int in_range = 1; @@ -1738,6 +1748,27 @@ void emcmotCommandHandler(void *arg, long servo_period) } break; + case EMCMOT_SET_SPINDLE_PARAMS: + rtapi_print_msg(RTAPI_MSG_DBG, "SPINDLE_SETUP: spindle %d/%d max_pos %f min_pos %f" + "max_neg %f min_neg %f, home: %f, %f, %d\n", + emcmotCommand->spindle, emcmotConfig->numSpindles, emcmotCommand->maxLimit, + emcmotCommand->min_pos_speed, emcmotCommand->max_neg_speed, emcmotCommand->minLimit, + emcmotCommand->search_vel, emcmotCommand->home, emcmotCommand->home_sequence); + spindle_num = emcmotCommand->spindle; + if (spindle_num >= emcmotConfig->numSpindles){ + reportError(_("Attempt to configure non-existent spindle")); + emcmotStatus->commandStatus = EMCMOT_COMMAND_INVALID_COMMAND; + break; + } + emcmotStatus->spindle_status[spindle_num].max_pos_speed = emcmotCommand->maxLimit; + emcmotStatus->spindle_status[spindle_num].min_neg_speed = emcmotCommand->minLimit; + emcmotStatus->spindle_status[spindle_num].max_neg_speed = emcmotCommand->max_neg_speed; + emcmotStatus->spindle_status[spindle_num].min_pos_speed = emcmotCommand->min_pos_speed; + emcmotStatus->spindle_status[spindle_num].home_search_vel = emcmotCommand->search_vel; + emcmotStatus->spindle_status[spindle_num].home_sequence = emcmotCommand->home_sequence; + emcmotStatus->spindle_status[spindle_num].increment = emcmotCommand->offset; + + break; case EMCMOT_SPINDLE_ON: rtapi_print_msg(RTAPI_MSG_DBG, "SPINDLE_ON: spindle %d/%d speed %d\n", emcmotCommand->spindle, emcmotConfig->numSpindles, (int) emcmotCommand->vel); @@ -1780,6 +1811,7 @@ void emcmotCommandHandler(void *arg, long servo_period) emcmotStatus->spindle_status[n].direction = -1; } emcmotStatus->spindle_status[n].brake = 0; //disengage brake + apply_spindle_limits(&emcmotStatus->spindle_status[n]); } emcmotStatus->atspeed_next_feed = emcmotCommand->wait_for_spindle_at_speed; @@ -1882,10 +1914,11 @@ void emcmotCommandHandler(void *arg, long servo_period) } for (n = s0; n<=s1; n++){ if (emcmotStatus->spindle_status[n].speed > 0) { - emcmotStatus->spindle_status[n].speed += 100; //FIXME - make the step a HAL parameter + emcmotStatus->spindle_status[n].speed += emcmotStatus->spindle_status[n].increment; } else if (emcmotStatus->spindle_status[n].speed < 0) { - emcmotStatus->spindle_status[n].speed -= 100; + emcmotStatus->spindle_status[n].speed -= emcmotStatus->spindle_status[n].increment; } + apply_spindle_limits(&emcmotStatus->spindle_status[n]); } break; @@ -1897,12 +1930,21 @@ void emcmotCommandHandler(void *arg, long servo_period) emcmotStatus->commandStatus = EMCMOT_COMMAND_INVALID_COMMAND; break; } - if (emcmotStatus->spindle_status[spindle_num].speed > 100) { - emcmotStatus->spindle_status[spindle_num].speed -= 100; //FIXME - make the step a HAL parameter - } else if (emcmotStatus->spindle_status[spindle_num].speed < -100) { - emcmotStatus->spindle_status[spindle_num].speed += 100; - } - break; + s0 = spindle_num; + s1 = spindle_num; + if (spindle_num ==-1){ + s0 = 0; + s1 = motion_num_spindles - 1; + } + for (n = s0; n<=s1; n++){ + if (emcmotStatus->spindle_status[n].speed > emcmotStatus->spindle_status[n].increment) { + emcmotStatus->spindle_status[n].speed -= emcmotStatus->spindle_status[n].increment; + } else if (emcmotStatus->spindle_status[n].speed < -1.0 * emcmotStatus->spindle_status[n].increment) { + emcmotStatus->spindle_status[n].speed += emcmotStatus->spindle_status[n].increment; + } + apply_spindle_limits(&emcmotStatus->spindle_status[n]); + } + break; case EMCMOT_SPINDLE_BRAKE_ENGAGE: rtapi_print_msg(RTAPI_MSG_DBG, "SPINDLE_BRAKE_ENGAGE"); diff --git a/src/emc/motion/control.c b/src/emc/motion/control.c index 8f3c521494a..ff72e386a24 100644 --- a/src/emc/motion/control.c +++ b/src/emc/motion/control.c @@ -1940,10 +1940,10 @@ static void output_to_hal(void) } for (spindle_num = 0; spindle_num < emcmotConfig->numSpindles; spindle_num++){ + double speed; if(emcmotStatus->spindle_status[spindle_num].css_factor) { double denom = fabs(emcmotStatus->spindle_status[spindle_num].xoffset - emcmotStatus->carte_pos_cmd.tran.x); - double speed; double maxpositive; if(denom > 0) speed = emcmotStatus->spindle_status[spindle_num].css_factor / denom; else speed = emcmotStatus->spindle_status[spindle_num].speed; @@ -1955,32 +1955,38 @@ static void output_to_hal(void) speed = -maxpositive; if(speed > maxpositive) speed = maxpositive; - - *(emcmot_hal_data->spindle[spindle_num].spindle_speed_out) = speed; - *(emcmot_hal_data->spindle[spindle_num].spindle_speed_out_rps) = speed/60.; } else { - *(emcmot_hal_data->spindle[spindle_num].spindle_speed_out) = - emcmotStatus->spindle_status[spindle_num].speed * + speed = emcmotStatus->spindle_status[spindle_num].speed * emcmotStatus->spindle_status[spindle_num].net_scale; - *(emcmot_hal_data->spindle[spindle_num].spindle_speed_out_rps) = - emcmotStatus->spindle_status[spindle_num].speed * - emcmotStatus->spindle_status[spindle_num].net_scale / 60.; } - *(emcmot_hal_data->spindle[spindle_num].spindle_speed_out_abs) = - fabs(*(emcmot_hal_data->spindle[spindle_num].spindle_speed_out)); - *(emcmot_hal_data->spindle[spindle_num].spindle_speed_out_rps_abs) = - fabs(*(emcmot_hal_data->spindle[spindle_num].spindle_speed_out_rps)); - *(emcmot_hal_data->spindle[spindle_num].spindle_speed_cmd_rps) = + + // Limit to spindle velocity limits + if (speed > 0){ + if (speed > emcmotStatus->spindle_status[spindle_num].max_pos_speed) { + speed = emcmotStatus->spindle_status[spindle_num].max_pos_speed; + } else if (speed < emcmotStatus->spindle_status[spindle_num].min_pos_speed) { + speed = emcmotStatus->spindle_status[spindle_num].min_pos_speed; + } + } else if (speed < 0) { + if (speed < emcmotStatus->spindle_status[spindle_num].min_neg_speed) { + speed = emcmotStatus->spindle_status[spindle_num].min_neg_speed; + } else if (speed > emcmotStatus->spindle_status[spindle_num].max_neg_speed) { + speed = emcmotStatus->spindle_status[spindle_num].max_neg_speed; + } + } + + *(emcmot_hal_data->spindle[spindle_num].spindle_speed_out) = speed; + *(emcmot_hal_data->spindle[spindle_num].spindle_speed_out_rps) = speed/60.; + *(emcmot_hal_data->spindle[spindle_num].spindle_speed_out_abs) = fabs(speed); + *(emcmot_hal_data->spindle[spindle_num].spindle_speed_out_rps_abs) = fabs(speed / 60); + *(emcmot_hal_data->spindle[spindle_num].spindle_on) = (speed != 0) ? 1 : 0; + *(emcmot_hal_data->spindle[spindle_num].spindle_forward) = (speed > 0) ? 1 : 0; + *(emcmot_hal_data->spindle[spindle_num].spindle_reverse) = (speed < 0) ? 1 : 0; + *(emcmot_hal_data->spindle[spindle_num].spindle_brake) = + (emcmotStatus->spindle_status[spindle_num].brake != 0) ? 1 : 0; + // What is this for? Docs don't say + *(emcmot_hal_data->spindle[spindle_num].spindle_speed_cmd_rps) = emcmotStatus->spindle_status[spindle_num].speed / 60.; - *(emcmot_hal_data->spindle[spindle_num].spindle_on) = - ((emcmotStatus->spindle_status[spindle_num].state * - emcmotStatus->spindle_status[spindle_num].net_scale) != 0) ? 1 : 0; - *(emcmot_hal_data->spindle[spindle_num].spindle_forward) = - (*emcmot_hal_data->spindle[spindle_num].spindle_speed_out > 0) ? 1 : 0; - *(emcmot_hal_data->spindle[spindle_num].spindle_reverse) = - (*emcmot_hal_data->spindle[spindle_num].spindle_speed_out < 0) ? 1 : 0; - *(emcmot_hal_data->spindle[spindle_num].spindle_brake) = - (emcmotStatus->spindle_status[spindle_num].brake != 0) ? 1 : 0; } *(emcmot_hal_data->program_line) = emcmotStatus->id; diff --git a/src/emc/motion/motion.h b/src/emc/motion/motion.h index 06d6e70d325..f894403b482 100644 --- a/src/emc/motion/motion.h +++ b/src/emc/motion/motion.h @@ -189,6 +189,8 @@ extern "C" { EMCMOT_SET_AXIS_ACC_LIMIT, /* set the max axis acc */ EMCMOT_SET_AXIS_LOCKING_JOINT, /* set the axis locking joint */ + EMCMOT_SET_SPINDLE_PARAMS, /* One command to set all spindle params */ + } cmd_code_t; /* this enum lists the possible results of a command */ @@ -220,6 +222,8 @@ extern "C" { double motor_offset; /* offset from joint to motor position */ double maxLimit; /* pos value for position limit, output */ double minLimit; /* neg value for position limit, output */ + double min_pos_speed; /* spindle minimum positive speed */ + double max_neg_speed; /* spindle maximum negative speed */ EmcPose pos; /* line/circle endpt, or teleop vector */ PmCartesian center; /* center for circle */ PmCartesian normal; /* normal vec for circle */ @@ -541,11 +545,19 @@ Suggestion: Split this in to an Error and a Status flag register.. int locked; // spindle lock engaged after orient int orient_fault; // fault code from motion.spindle-orient-fault int orient_state; // orient_state_t - int spindle_index_enable; /* hooked to a canon encoder index-enable */ - double spindleRevs; /* position of spindle in revolutions */ - double spindleSpeedIn; /* velocity of spindle in revolutions per minute */ - int at_speed; + int spindle_index_enable; /* hooked to a canon encoder index-enable */ + double spindleRevs; /* position of spindle in revolutions */ + double spindleSpeedIn; /* velocity of spindle in revolutions per minute */ + int at_speed; int fault; /* amplifier fault */ + double max_pos_speed; /* spindle speed limits */ + double min_pos_speed; /* signed values, so max_neg = 0 */ + double max_neg_speed; /* and min_neg = -1e99 indicates no limit */ + double min_neg_speed; + double home_angle; + double home_search_vel; + int home_sequence; + double increment; } spindle_status_t; typedef struct { diff --git a/src/emc/nml_intf/Submakefile b/src/emc/nml_intf/Submakefile index 115e84b40e0..60f6027b695 100644 --- a/src/emc/nml_intf/Submakefile +++ b/src/emc/nml_intf/Submakefile @@ -11,6 +11,7 @@ LIBEMCSRCS := \ emc/ini/emcIniFile.cc \ emc/ini/iniaxis.cc \ emc/ini/inijoint.cc \ + emc/ini/inispindle.cc \ emc/ini/initraj.cc \ emc/ini/inihal.cc \ emc/nml_intf/interpl.cc diff --git a/src/emc/nml_intf/emc.hh b/src/emc/nml_intf/emc.hh index 2353b72201f..2e311ffafd3 100644 --- a/src/emc/nml_intf/emc.hh +++ b/src/emc/nml_intf/emc.hh @@ -384,6 +384,12 @@ extern int emcJogAbs(int nr, double pos, double vel, int jjogmode); extern int emcJointUpdate(EMC_JOINT_STAT stat[], int numJoints); + +// implementation functions for EMC_SPINDLE types + +extern int emcSpindleSetParams(int spindle, double max_pos, double min_pos, double max_neg, + double min_neg, double search_vel, double home_angle, int sequence, double increment); + // implementation functions for EMC_TRAJ types extern int emcTrajSetJoints(int joints); diff --git a/src/emc/nml_intf/emcglb.h b/src/emc/nml_intf/emcglb.h index 94f65c64250..868afbdd8cf 100644 --- a/src/emc/nml_intf/emcglb.h +++ b/src/emc/nml_intf/emcglb.h @@ -77,6 +77,16 @@ typedef struct AxisConfig_t { double MaxLimit; } AxisConfig_t; +typedef struct SpindleConfig_t { + int Inited; + double max_pos_speed; + double max_neg_speed; + double min_pos_speed; + double min_neg_speed; + int home_sequence; + double home_search_velocity; +} SpindleConfig_t; + typedef struct TrajConfig_t { int Inited; // non-zero means traj called init int Joints; diff --git a/src/emc/task/taskintf.cc b/src/emc/task/taskintf.cc index 000d203750b..7da9897d5b3 100644 --- a/src/emc/task/taskintf.cc +++ b/src/emc/task/taskintf.cc @@ -31,6 +31,7 @@ #include "inifile.hh" #include "iniaxis.hh" #include "inijoint.hh" +#include "inispindle.hh" #include "initraj.hh" #include "inihal.hh" @@ -72,6 +73,7 @@ static emcmot_status_t emcmotStatus; static struct TrajConfig_t TrajConfig; static struct JointConfig_t JointConfig[EMCMOT_MAX_JOINTS]; static struct AxisConfig_t AxisConfig[EMCMOT_MAX_AXIS]; +static struct SpindleConfig_t SpindleConfig[EMCMOT_MAX_SPINDLES]; static emcmot_command_t emcmotCommand; @@ -586,13 +588,18 @@ int emcAxisUpdate(EMC_AXIS_STAT stat[], int axis_mask) static int JointOrTrajInited(void) { - int joint; + int joint, spindle; for (joint = 0; joint < EMCMOT_MAX_JOINTS; joint++) { if (JointConfig[joint].Inited) { return 1; } } + for (spindle = 0; spindle < EMCMOT_MAX_SPINDLES; spindle++) { + if (SpindleConfig[spindle].Inited) { + return 1; + } + } if (TrajConfig.Inited) { return 1; } @@ -640,6 +647,27 @@ int emcAxisInit(int axis) return retval; } +int emcSpindleInit(int spindle) +{ + int retval = 0; + + if (spindle < 0 || spindle >= EMCMOT_MAX_SPINDLES) { + return 0; + } + // init emcmot interface + if (!JointOrTrajInited()) { + usrmotIniLoad(emc_inifile); + if (0 != usrmotInit("emc2_task")) { + return -1; + } + } + SpindleConfig[spindle].Inited = 1; + if (0 != iniSpindle(spindle, emc_inifile)) { + retval = -1; + } + return retval; +} + int emcJointHalt(int joint) { if (joint < 0 || joint >= EMCMOT_MAX_JOINTS) { @@ -1708,7 +1736,7 @@ int emcPositionSave() { int emcMotionInit() { int r; - int joint, axis; + int joint, axis, spindle; r = emcTrajInit(); // we want to check Traj first, the sane defaults for units are there // it also determines the number of existing joints, and axes @@ -1731,7 +1759,15 @@ int emcMotionInit() return -1; } } - } + } + + for (spindle = 0; spindle < TrajConfig.Spindles; spindle++) { + if (0 != emcSpindleInit(spindle)) { + rcs_print("%s: emcSpindleInit(%d) failed\n", __FUNCTION__, spindle); + return -1; + } + } + // Ignore errors from emcPositionLoad(), because what are you going to do? (void)emcPositionLoad(); @@ -1834,6 +1870,35 @@ int emcMotionSetDout(unsigned char index, unsigned char start, return usrmotWriteEmcmotCommand(&emcmotCommand); } +int emcSpindleSetParams(int spindle, double max_pos, double min_pos, double max_neg, + double min_neg, double search_vel, double home_angle, int sequence, double increment) +{ + + if (spindle < 0 || spindle >= EMCMOT_MAX_SPINDLES) { + return 0; + } + + emcmotCommand.command = EMCMOT_SET_SPINDLE_PARAMS; + emcmotCommand.spindle = spindle; + emcmotCommand.maxLimit = max_pos; + emcmotCommand.minLimit = min_neg; + emcmotCommand.min_pos_speed = min_pos; + emcmotCommand.max_neg_speed = max_neg; + emcmotCommand.home = home_angle; + emcmotCommand.search_vel = search_vel; + emcmotCommand.home_sequence = sequence; + emcmotCommand.offset = increment; + + int retval = usrmotWriteEmcmotCommand(&emcmotCommand); + + if (emc_debug & EMC_DEBUG_CONFIG) { + rcs_print("%s(%d, %.4f, %.4f, %.4f, %.4f, %.4f, %.4f, %i, %.4f) returned %d\n", + __FUNCTION__, spindle, max_pos, min_pos, max_neg, min_neg, search_vel, home_angle, + sequence, increment, retval); + } + return retval; +} + int emcSpindleAbort(int spindle) { return emcSpindleOff(spindle);