Skip to content

Commit

Permalink
Spindles: Make spindle velocity limits and plus/minus increments
Browse files Browse the repository at this point in the history
INI-config items.


Signed-off-by: andypugh <andy@bodgesoc.org>
  • Loading branch information
andypugh committed Dec 31, 2021
1 parent 14a02d1 commit 3d005f6
Show file tree
Hide file tree
Showing 12 changed files with 374 additions and 38 deletions.
42 changes: 42 additions & 0 deletions docs/src/config/ini-config.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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_<num>] Section
The <num> 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)))

Expand Down
1 change: 1 addition & 0 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
1 change: 1 addition & 0 deletions src/emc/ini/inihal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
128 changes: 128 additions & 0 deletions src/emc/ini/inispindle.cc
Original file line number Diff line number Diff line change
@@ -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 <unistd.h>
#include <stdio.h> // NULL
#include <stdlib.h> // atol(), _itoa()
#include <string.h> // strcmp()
#include <ctype.h> // isdigit()
#include <sys/types.h>
#include <sys/stat.h>

#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;
}
22 changes: 22 additions & 0 deletions src/emc/ini/inispindle.hh
Original file line number Diff line number Diff line change
@@ -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
58 changes: 50 additions & 8 deletions src/emc/motion/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand All @@ -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");
Expand Down
Loading

0 comments on commit 3d005f6

Please sign in to comment.