From: Michael H. <gi...@gi...> - 2011-10-21 08:52:56
|
M19 orient spindle: improve usefulness of the P word 0: rotate clockwise or counterclockwise for smallest angular movement 1: always rotate clockwise 2: always rotate counterclockwise Adapt interpretation of the ORIEN_SPINDLE second parameter. Add range check in interp_check.cc Adapt regression test output. Adapt docs. http://git.linuxcnc.org/?p=emc2.git;a=commitdiff;h=a2ab876 --- docs/man/man9/motion.9 | 14 +++++++------- docs/src/config/emc2hal.txt | 25 ++++++++++++++++++------- docs/src/gcode/main.txt | 9 +++++++-- src/emc/motion/command.c | 2 +- src/emc/motion/mot_priv.h | 2 +- src/emc/motion/motion.c | 4 ++-- src/emc/nml_intf/canon.hh | 2 +- src/emc/nml_intf/emc.cc | 2 +- src/emc/nml_intf/emc_nml.hh | 2 +- src/emc/rs274ngc/interp_check.cc | 11 +++++++---- src/emc/rs274ngc/interp_convert.cc | 3 +-- src/emc/rs274ngc/interp_queue.cc | 8 ++++---- src/emc/rs274ngc/interp_queue.hh | 4 ++-- src/emc/sai/saicanon.cc | 6 ++---- src/emc/task/emccanon.cc | 4 ++-- src/emc/task/emctaskmain.cc | 2 +- src/emc/task/taskintf.cc | 4 ++-- tests/interp/m19/expected | 10 +++++----- 18 files changed, 65 insertions(+), 49 deletions(-) diff --git a/docs/man/man9/motion.9 b/docs/man/man9/motion.9 index e95e0a3..9d6b2bc 100644 --- a/docs/man/man9/motion.9 +++ b/docs/man/man9/motion.9 @@ -204,29 +204,29 @@ Desired spindle speed in rotations per minute Desired spindle speed in rotations per second .TP -\fBspindle-orient-angle\fR OUT float +\fBmotion.spindle-orient-angle\fR OUT float Desired spindle orientation for M19. Value of the M19 R word parameter plus the value of the [RS274NGC]ORIENT_OFFSET ini parameter. .TP -\fBspindle-orient-fwd\fR OUT bit -Desired spindle rotation direction for M19. Default 1. Set to zero if M19 P1 is given. +\fBmotion.spindle-orient-mode\fR OUT bit +Desired spindle rotation mode. Reflects M19 P parameter word. .TP -\fBspindle-orient\fR OUT bit +\fBmotion.spindle-orient\fR OUT bit Indicates start of spindle orient cycle. Set by M19. Cleared by any of M3,M4,M5. If spindle-orient-fault is not zero during spindle-orient true, the M19 command fails with an error message. .TP -\fBspindle-is-oriented\fR IN bit +\fBmotion.spindle-is-oriented\fR IN bit Acknowledge pin for spindle-orient. Completes orient cycle. If spindle-orient was true when spindle-is-oriented was asserted, the spindle-orient pin is cleared and the spindle-locked pin is asserted. Also, the spindle-brake pin is asserted. .TP -\fBspindle-orient-fault\fR IN s32 +\fBmotion.spindle-orient-fault\fR IN s32 Fault code input for orient cycle. Any value other than zero will cause the orient cycle to abort. .TP -\fBspindle-locked\fR OUT bit +\fBmotion.pindle-locked\fR OUT bit Spindle orient complete pin. Cleared by any of M3,M4,M5. .TP diff --git a/docs/src/config/emc2hal.txt b/docs/src/config/emc2hal.txt index 3052b61..a43c403 100644 --- a/docs/src/config/emc2hal.txt +++ b/docs/src/config/emc2hal.txt @@ -154,30 +154,30 @@ motion.tooloffset.x ... motion.tooloffset.w:: it could come from the tool table (`G43` active), or it could come from the gcode (`G43.1` active) -spindle-orient-angle:: +motion.spindle-orient-angle:: (float,out) Desired spindle orientation for M19. Value of the M19 R word parameter plus the value of the [RS274NGC]ORIENT_OFFSET ini parameter. -spindle-orient-fwd:: - (bit,out) Desired spindle rotation direction for M19. Default 1. Set to zero if M19 P1 is given. +motion.spindle-orient-mode:: + (s32,out) Desired spindle rotation mode M19. Default 0. -spindle-orient:: +motion.spindle-orient:: (out,bit) Indicates start of spindle orient cycle. Set by M19. Cleared by any of M3,M4,M5. If spindle-orient-fault is not zero during spindle-orient true, the M19 command fails with an error message. -spindle-is-oriented:: +motion.spindle-is-oriented:: (in, bit) Acknowledge pin for spindle-orient. Completes orient cycle. If spindle-orient was true when spindle-is-oriented was asserted, the spindle-orient pin is cleared and the spindle-locked pin is asserted. Also, the spindle-brake pin is asserted. -spindle-orient-fault:: +motion.spindle-orient-fault:: (s32, in) Fault code input for orient cycle. Any value other than zero will cause the orient cycle to abort. -spindle-lock:: +motion.spindle-lock:: (bit, out) Spindle orient complete pin. Cleared by any of M3,M4,M5. ==== HAL pin usage for M19 orient spindle @@ -213,6 +213,17 @@ Also, any of the M3,M4 or M5 commands cancel either 'searching for desired orientation' or 'orientation complete' mode. This is indicated by deasserting both the `spindle-orient` and `spindle-locked` pins. +The `spindle-orient-mode` pin reflects the M19 P word and shall be +interpreted as follows: + + - 0: rotate clockwise or counterclockwise for smallest angular movement + - 1: always rotate clockwise + - 2: always rotate counterclockwise + +It can be used with the `orient` HAL component which provides a PID +command value based on spindle encoder positon, `spindle-orient-angle` +and `spindle-orient-mode`. + === Parameters Many of these parameters serve as debugging aids, and are subject to diff --git a/docs/src/gcode/main.txt b/docs/src/gcode/main.txt index 5ee0313..2e046b1 100644 --- a/docs/src/gcode/main.txt +++ b/docs/src/gcode/main.txt @@ -1770,14 +1770,19 @@ To start spindle orientation mode, program `M19`. M19 R- P- - The optional R- word specifies the desired angle in degrees (default 0). - - The optional P- word specifies the rotation direction (default clockwise, - a value of 1 specifies counterclockwise rotation). + - The optional P- word specifies the rotation direction (default 0). M19 cancels spindle rotation mode and enters spindle orientation mode. M19 turns off the spindle, unlocks the spindle brake and then starts the orientation HAL pin protocol. See the motion manpage for the pin description. +The P parameter is interpreted as follows: + + - 0: rotate clockwise or counterclockwise for smallest angular movement + - 1: always rotate clockwise + - 2: always rotate counterclockwise + Any M3,M4,M5 spindle command will cancel spindle orientation mode and switch back to rotation mode, which is the default. diff --git a/src/emc/motion/command.c b/src/emc/motion/command.c index 52e8918..ec260f9 100644 --- a/src/emc/motion/command.c +++ b/src/emc/motion/command.c @@ -1554,7 +1554,7 @@ check_stuff ( "before command_handler()" ); emcmotStatus->spindle.brake = 0; // open brake *(emcmot_hal_data->spindle_orient_angle) = emcmotCommand->orientation; - *(emcmot_hal_data->spindle_orient_fwd) = emcmotCommand->direction; + *(emcmot_hal_data->spindle_orient_mode) = emcmotCommand->mode; *(emcmot_hal_data->spindle_locked) = 0; *(emcmot_hal_data->spindle_orient) = 1; diff --git a/src/emc/motion/mot_priv.h b/src/emc/motion/mot_priv.h index f4a3892..2ff910e 100644 --- a/src/emc/motion/mot_priv.h +++ b/src/emc/motion/mot_priv.h @@ -143,7 +143,7 @@ typedef struct { // spindle orient hal_float_t *spindle_orient_angle; /* out: desired spindle angle, degrees */ - hal_bit_t *spindle_orient_fwd; /* out: search cw if true, else ccw */ + hal_s32_t *spindle_orient_mode; /* out: 0: least travel; 1: cw; 2: ccw */ hal_bit_t *spindle_orient; /* out: signal orient in progress */ hal_bit_t *spindle_locked; /* out: signal orient complete, spindle locked */ hal_bit_t *spindle_is_oriented; /* in: orientation completed */ diff --git a/src/emc/motion/motion.c b/src/emc/motion/motion.c index bf88a15..34d9d19 100644 --- a/src/emc/motion/motion.c +++ b/src/emc/motion/motion.c @@ -303,13 +303,13 @@ static int init_hal_io(void) // spindle orient pins if ((retval = hal_pin_float_newf(HAL_OUT, &(emcmot_hal_data->spindle_orient_angle), mot_comp_id, "motion.spindle-orient-angle")) < 0) goto error; - if ((retval = hal_pin_bit_newf(HAL_OUT, &(emcmot_hal_data->spindle_orient_fwd), mot_comp_id, "motion.spindle-orient-fwd")) < 0) goto error; + if ((retval = hal_pin_s32_newf(HAL_OUT, &(emcmot_hal_data->spindle_orient_mode), mot_comp_id, "motion.spindle-orient-mode")) < 0) goto error; if ((retval = hal_pin_bit_newf(HAL_OUT, &(emcmot_hal_data->spindle_orient), mot_comp_id, "motion.spindle-orient")) < 0) goto error; if ((retval = hal_pin_bit_newf(HAL_OUT, &(emcmot_hal_data->spindle_locked), mot_comp_id, "motion.spindle-locked")) < 0) goto error; if ((retval = hal_pin_bit_newf(HAL_IN, &(emcmot_hal_data->spindle_is_oriented), mot_comp_id, "motion.spindle-is-oriented")) < 0) goto error; if ((retval = hal_pin_s32_newf(HAL_IN, &(emcmot_hal_data->spindle_orient_fault), mot_comp_id, "motion.spindle-orient-fault")) < 0) goto error; *(emcmot_hal_data->spindle_orient_angle) = 0.0; - *(emcmot_hal_data->spindle_orient_fwd) = 1; + *(emcmot_hal_data->spindle_orient_mode) = 0; *(emcmot_hal_data->spindle_orient) = 0; diff --git a/src/emc/nml_intf/canon.hh b/src/emc/nml_intf/canon.hh index 1e32e21..812dbfd 100644 --- a/src/emc/nml_intf/canon.hh +++ b/src/emc/nml_intf/canon.hh @@ -498,7 +498,7 @@ extern void STOP_SPINDLE_TURNING(); command may be given, but it will have no effect. */ extern void SPINDLE_RETRACT(); -extern void ORIENT_SPINDLE(double orientation, CANON_DIRECTION direction); +extern void ORIENT_SPINDLE(double orientation, int mode); extern void LOCK_SPINDLE_Z(); extern void USE_SPINDLE_FORCE(); extern void USE_NO_SPINDLE_FORCE(); diff --git a/src/emc/nml_intf/emc.cc b/src/emc/nml_intf/emc.cc index 576bee3..1aeb580 100644 --- a/src/emc/nml_intf/emc.cc +++ b/src/emc/nml_intf/emc.cc @@ -2082,7 +2082,7 @@ void EMC_SPINDLE_ORIENT::update(CMS * cms) EMC_SPINDLE_CMD_MSG::update(cms); cms->update(orientation); - cms->update(direction); + cms->update(mode); } /* diff --git a/src/emc/nml_intf/emc_nml.hh b/src/emc/nml_intf/emc_nml.hh index f5b6a92..f2cc895 100644 --- a/src/emc/nml_intf/emc_nml.hh +++ b/src/emc/nml_intf/emc_nml.hh @@ -1681,7 +1681,7 @@ class EMC_SPINDLE_ORIENT:public EMC_SPINDLE_CMD_MSG { // For internal NML/CMS use only. void update(CMS * cms); double orientation; // desired spindle position - int direction; // CANON_DIRECTION + int mode; }; diff --git a/src/emc/rs274ngc/interp_check.cc b/src/emc/rs274ngc/interp_check.cc index 28a67a6..e892ea1 100644 --- a/src/emc/rs274ngc/interp_check.cc +++ b/src/emc/rs274ngc/interp_check.cc @@ -298,10 +298,13 @@ int Interp::check_other_codes(block_pointer block) //!< pointer to a block (block->m_modes[7] != 19) && (block->user_m != 1)), _("P word with no G2 G3 G4 G10 G64 G5 G5.2 G76 G82 G86 G88 G89" " or M50 M51 M52 M53 M62 M63 M64 M65 M66 or user M code to use it")); - CHKS((block->p_flag && (motion == G_2 || motion == G_3 || (block->m_modes[7] == 19)) && - fabs(round_to_int(block->p_number) - block->p_number) > 0.001), - _("P value not an integer with M19 G2 or G3")); - CHKS((block->p_flag && (motion == G_2 || motion == G_3) && round_to_int(block->p_number) < 1), + int p_value = round_to_int(block->p_number); + CHKS(((motion == G_2 || motion == G_3 || (block->m_modes[7] == 19)) && + fabs(p_value - block->p_number) > 0.001), + _("P value not an integer with M19 G2 or G3")); + CHKS((block->m_modes[7] == 19) && ((p_value > 2) || p_value < 0), + _("P value must be 0,1,or 2 with M19")); + CHKS(((motion == G_2 || motion == G_3) && round_to_int(block->p_number) < 1), _("P value should be 1 or greater with G2 or G3")); } diff --git a/src/emc/rs274ngc/interp_convert.cc b/src/emc/rs274ngc/interp_convert.cc index 3f5ba39..3470219 100644 --- a/src/emc/rs274ngc/interp_convert.cc +++ b/src/emc/rs274ngc/interp_convert.cc @@ -3021,8 +3021,7 @@ int Interp::convert_m(block_pointer block, //!< pointer to a block of RS27 } else if (block->m_modes[7] == 19) { settings->spindle_turning = CANON_STOPPED; enqueue_ORIENT_SPINDLE(block->r_flag ? (block->r_number + settings->orient_offset) : settings->orient_offset, - block->p_flag ? (block->p_number > 0.0 ? CANON_COUNTERCLOCKWISE : CANON_CLOCKWISE) : - CANON_CLOCKWISE); + block->p_flag ? block->p_number : 0); } else if ((block->m_modes[7] == 70) || (block->m_modes[7] == 73)) { // save state in current stack frame. We borrow the o-word call stack diff --git a/src/emc/rs274ngc/interp_queue.cc b/src/emc/rs274ngc/interp_queue.cc index 6cba961..a380403 100644 --- a/src/emc/rs274ngc/interp_queue.cc +++ b/src/emc/rs274ngc/interp_queue.cc @@ -186,16 +186,16 @@ void enqueue_STOP_SPINDLE_TURNING(void) { qc().push_back(q); } -void enqueue_ORIENT_SPINDLE(double orientation, CANON_DIRECTION direction) { +void enqueue_ORIENT_SPINDLE(double orientation, int mode) { if(qc().empty()) { if(debug_qc) printf("immediate spindle orient\n"); - ORIENT_SPINDLE(orientation,direction); + ORIENT_SPINDLE(orientation,mode); return; } queued_canon q; q.type = QORIENT_SPINDLE; q.data.orient_spindle.orientation = orientation; - q.data.orient_spindle.direction = direction; + q.data.orient_spindle.mode = mode; if(debug_qc) printf("enqueue spindle orient\n"); qc().push_back(q); } @@ -528,7 +528,7 @@ void dequeue_canons(setup_pointer settings) { break; case QORIENT_SPINDLE: if(debug_qc) printf("issuing orient spindle\n"); - ORIENT_SPINDLE(q.data.orient_spindle.orientation, q.data.orient_spindle.direction); + ORIENT_SPINDLE(q.data.orient_spindle.orientation, q.data.orient_spindle.mode); break; } } diff --git a/src/emc/rs274ngc/interp_queue.hh b/src/emc/rs274ngc/interp_queue.hh index d38f3aa..0b84307 100644 --- a/src/emc/rs274ngc/interp_queue.hh +++ b/src/emc/rs274ngc/interp_queue.hh @@ -68,7 +68,7 @@ struct mcommand { struct orient_spindle { double orientation; - int direction; + int mode; }; struct queued_canon { @@ -122,7 +122,7 @@ void enqueue_ARC_FEED(setup_pointer settings, int l, double u, double v, double w); void enqueue_M_USER_COMMAND(int index,double p_number,double q_number); void enqueue_START_CHANGE(void); -void enqueue_ORIENT_SPINDLE(double orientation, CANON_DIRECTION direction); +void enqueue_ORIENT_SPINDLE(double orientation, int mode); void dequeue_canons(setup_pointer settings); void set_endpoint(double x, double y); void set_endpoint_zx(double z, double x); diff --git a/src/emc/sai/saicanon.cc b/src/emc/sai/saicanon.cc index 95887fa..609b41f 100644 --- a/src/emc/sai/saicanon.cc +++ b/src/emc/sai/saicanon.cc @@ -606,10 +606,8 @@ void STOP_SPINDLE_TURNING() void SPINDLE_RETRACT() {PRINT0("SPINDLE_RETRACT()\n");} -void ORIENT_SPINDLE(double orientation, CANON_DIRECTION direction) -{PRINT2("ORIENT_SPINDLE(%.4f, %s)\n", orientation, - (direction == CANON_CLOCKWISE) ? "CANON_CLOCKWISE" : - "CANON_COUNTERCLOCKWISE"); +void ORIENT_SPINDLE(double orientation, int mode) +{PRINT2("ORIENT_SPINDLE(%.4f, %d)\n", orientation,mode); } void USE_NO_SPINDLE_FORCE() diff --git a/src/emc/task/emccanon.cc b/src/emc/task/emccanon.cc index d301da2..69cb704 100644 --- a/src/emc/task/emccanon.cc +++ b/src/emc/task/emccanon.cc @@ -1738,13 +1738,13 @@ void SPINDLE_RETRACT() /*! \todo FIXME-- unimplemented */ } -void ORIENT_SPINDLE(double orientation, int direction) +void ORIENT_SPINDLE(double orientation, int mode) { EMC_SPINDLE_ORIENT o; flush_segments(); o.orientation = orientation; - o.direction = direction; + o.mode = mode; interp_list.append(o); } diff --git a/src/emc/task/emctaskmain.cc b/src/emc/task/emctaskmain.cc index 7df6311..26330b7 100644 --- a/src/emc/task/emctaskmain.cc +++ b/src/emc/task/emctaskmain.cc @@ -1874,7 +1874,7 @@ static int emcTaskIssueCommand(NMLmsg * cmd) case EMC_SPINDLE_ORIENT_TYPE: spindle_orient_msg = (EMC_SPINDLE_ORIENT *) cmd; - retval = emcSpindleOrient(spindle_orient_msg->orientation, spindle_orient_msg->direction); + retval = emcSpindleOrient(spindle_orient_msg->orientation, spindle_orient_msg->mode); break; case EMC_SPINDLE_ON_TYPE: diff --git a/src/emc/task/taskintf.cc b/src/emc/task/taskintf.cc index 0af3c16..157206f 100644 --- a/src/emc/task/taskintf.cc +++ b/src/emc/task/taskintf.cc @@ -1392,11 +1392,11 @@ int emcSpindleSpeed(double speed, double css_factor, double offset) return -1; //can't have negative speeds } -int emcSpindleOrient(double orientation, int direction) +int emcSpindleOrient(double orientation, int mode) { emcmotCommand.command = EMCMOT_SPINDLE_ORIENT; emcmotCommand.orientation = orientation; - emcmotCommand.direction = (direction == CANON_CLOCKWISE); + emcmotCommand.mode = mode; return usrmotWriteEmcmotCommand(&emcmotCommand); } diff --git a/tests/interp/m19/expected b/tests/interp/m19/expected index c949e8d..01ff1e3 100644 --- a/tests/interp/m19/expected +++ b/tests/interp/m19/expected @@ -3,11 +3,11 @@ N..... SET_G92_OFFSET(0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000) N..... SET_XY_ROTATION(0.0000) N..... SET_FEED_REFERENCE(CANON_XYZ) - N..... ORIENT_SPINDLE(42.0000, CANON_CLOCKWISE) - N..... ORIENT_SPINDLE(87.0000, CANON_CLOCKWISE) - N..... ORIENT_SPINDLE(42.0000, CANON_COUNTERCLOCKWISE) - N..... ORIENT_SPINDLE(132.0000, CANON_CLOCKWISE) - N..... ORIENT_SPINDLE(132.0000, CANON_COUNTERCLOCKWISE) + N..... ORIENT_SPINDLE(42.0000, 0) + N..... ORIENT_SPINDLE(87.0000, 0) + N..... ORIENT_SPINDLE(42.0000, 1) + N..... ORIENT_SPINDLE(132.0000, 0) + N..... ORIENT_SPINDLE(132.0000, 1) N..... SET_G5X_OFFSET(1, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000) N..... SET_XY_ROTATION(0.0000) N..... SET_FEED_MODE(0) |