Browse code

M19 orient: add 'wait for orient complete' option

Q word: number of seconds to wait until orient completes
condition: motion.spindle.is_oriented becomes true within timeout

Adapt regression test to use Q-.

Thanks to Martin Kaplan for testing.
commit 4d311b0f2a978050e830bcd3617ba37ca24c03fa 1 parent 7fd15a5
authored
4  configs/sim/orient.hal
... ... @@ -6,6 +6,6 @@ net oriented  gladevcp.spindle-is-oriented motion.spindle-is-oriented gladevcp.s
6 6  net locked motion.spindle-locked gladevcp.spindle-locked-led
7 7  
8 8  net angle motion.spindle-orient-angle gladevcp.spindle-orient-angle
9   -net fwd motion.spindle-orient-fwd gladevcp.spindle-orient-fwd-led
  9 +
10 10  net brake motion.spindle-brake  gladevcp.spindle-brake-led
11   -net fault gladevcp.spindle-orient-fault-s motion.spindle-orient-fault 
  11 +net fault gladevcp.spindle-orient-fault-s motion.spindle-orient-fault 
32  configs/sim/orient.ui
... ... @@ -1,7 +1,7 @@
1 1  <?xml version="1.0"?>
2 2  <interface>
3   -  <requires lib="gtk+" version="2.16"/>
4 3    <!-- interface-requires gladevcp 0.0 -->
  4 +  <requires lib="gtk+" version="2.16"/>
5 5    <!-- interface-naming-policy project-wide -->
6 6    <object class="GtkWindow" id="window1">
7 7      <child>
... ... @@ -87,8 +87,8 @@
87 87                  <child>
88 88                    <object class="HAL_Label" id="spindle-orient-angle">
89 89                      <property name="visible">True</property>
90   -                    <property name="label_pin_type">1</property>
91 90                      <property name="text_template">motion.spindle-orient-angle: %f</property>
  91 +                    <property name="label_pin_type">1</property>
92 92                    </object>
93 93                    <packing>
94 94                      <property name="right_attach">2</property>
... ... @@ -97,28 +97,6 @@
97 97                    </packing>
98 98                  </child>
99 99                  <child>
100   -                  <object class="GtkLabel" id="label3">
101   -                    <property name="visible">True</property>
102   -                    <property name="label" translatable="yes">motion.spindle-orient-fwd:</property>
103   -                  </object>
104   -                  <packing>
105   -                    <property name="top_attach">4</property>
106   -                    <property name="bottom_attach">5</property>
107   -                  </packing>
108   -                </child>
109   -                <child>
110   -                  <object class="HAL_LED" id="spindle-orient-fwd-led">
111   -                    <property name="visible">True</property>
112   -                    <property name="led_shape">2</property>
113   -                  </object>
114   -                  <packing>
115   -                    <property name="left_attach">1</property>
116   -                    <property name="right_attach">2</property>
117   -                    <property name="top_attach">4</property>
118   -                    <property name="bottom_attach">5</property>
119   -                  </packing>
120   -                </child>
121   -                <child>
122 100                    <object class="HAL_LED" id="spindle-brake-led">
123 101                      <property name="visible">True</property>
124 102                      <property name="led_shape">2</property>
... ... @@ -164,6 +142,12 @@
164 142                      <property name="bottom_attach">7</property>
165 143                    </packing>
166 144                  </child>
  145 +                <child>
  146 +                  <placeholder/>
  147 +                </child>
  148 +                <child>
  149 +                  <placeholder/>
  150 +                </child>
167 151                </object>
168 152              </child>
169 153            </object>
16  docs/src/gcode/main.txt
... ... @@ -1782,10 +1782,11 @@ regardless of what coolant is on or off.
1782 1782  
1783 1783  To start spindle orientation mode, program `M19`.
1784 1784  
1785   - M19 R- P-
  1785 + M19 R- P- Q-
1786 1786  
1787 1787   - The optional R- word specifies the desired angle in degrees (default 0). 
1788 1788   - The optional P- word specifies the rotation direction (default 0).
  1789 + - The optional Q- word specifies the timeout ins seconds to wait for  orient to complete.
1789 1790  
1790 1791  M19 cancels spindle rotation mode and enters spindle orientation
1791 1792  mode. M19 turns off the spindle, unlocks the spindle brake and then starts the
... ... @@ -1802,7 +1803,18 @@ Any M3,M4,M5 spindle command will cancel spindle orientation mode and
1802 1803  switch back to rotation mode, which is the default.
1803 1804  
1804 1805  The `[RS274NGC]ORIENT_OFFSET` value from the ini file is added to the
1805   -R word to define an aribtrary zero position.
  1806 +R word to define an arbitrary zero position.
  1807 +
  1808 +The Q word commands the spindle orient support to wait for the orient
  1809 +cycle to complete. If no Q word is given, the orient cycle is
  1810 +initiated but not waited for in order to allow parallel operations of
  1811 +e.g. a rapid move and a spindle orient.
  1812 +
  1813 +An `M19` command with just a `Q` word, but no `R` and `P` words will
  1814 +wait for the last M19 cycle to complete, which is considered complete
  1815 +when the HAL logic asserts `motion.spindle-locked`.
  1816 +
  1817 +It is an error to specify a Q value less than 0.
1806 1818  
1807 1819  M19 is a modal group 7 command (same as M3,M4,M5). 
1808 1820  
5  src/emc/motion/command.c
... ... @@ -1499,12 +1499,13 @@ void emcmotCommandHandler(void *arg, long period)
1499 1499    case EMCMOT_SPINDLE_ON:
1500 1500        rtapi_print_msg(RTAPI_MSG_DBG, "SPINDLE_ON");
1501 1501  
1502   -      if (*(emcmot_hal_data->spindle_orient))
  1502 +      if (*(emcmot_hal_data->spindle_orient)) 
1503 1503      rtapi_print_msg(RTAPI_MSG_DBG, "SPINDLE_ORIENT cancelled by SPINDLE_ON");
1504 1504        if (*(emcmot_hal_data->spindle_locked))
1505 1505      rtapi_print_msg(RTAPI_MSG_DBG, "spindle-locked cleared by SPINDLE_ON");
1506 1506        *(emcmot_hal_data->spindle_locked) = 0;
1507 1507        *(emcmot_hal_data->spindle_orient) = 0;
  1508 +      emcmotStatus->spindle.orient_state = EMCMOT_ORIENT_NONE;
1508 1509  
1509 1510        /* if (emcmotStatus->spindle.orient) { */
1510 1511        /*   reportError(_("cant turn on spindle during orient in progress")); */
... ... @@ -1535,6 +1536,7 @@ void emcmotCommandHandler(void *arg, long period)
1535 1536      rtapi_print_msg(RTAPI_MSG_DBG, "spindle-locked cleared by SPINDLE_OFF");
1536 1537        *(emcmot_hal_data->spindle_locked) = 0;
1537 1538        *(emcmot_hal_data->spindle_orient) = 0;
  1539 +      emcmotStatus->spindle.orient_state = EMCMOT_ORIENT_NONE;
1538 1540        break;
1539 1541  
1540 1542    case EMCMOT_SPINDLE_ORIENT:
... ... @@ -1548,6 +1550,7 @@ void emcmotCommandHandler(void *arg, long period)
1548 1550      /* tpAbort(&emcmotDebug->queue); */
1549 1551      /* SET_MOTION_ERROR_FLAG(1); */
1550 1552        }
  1553 +      emcmotStatus->spindle.orient_state = EMCMOT_ORIENT_IN_PROGRESS;
1551 1554        emcmotStatus->spindle.speed = 0;
1552 1555        emcmotStatus->spindle.direction = 0;
1553 1556        // so far like spindle stop, except opening brake
2  src/emc/motion/control.c
... ... @@ -572,6 +572,7 @@ static void process_inputs(void)
572 572      // signal error, and cancel the orient
573 573      if (*(emcmot_hal_data->spindle_orient)) {
574 574    if (*(emcmot_hal_data->spindle_orient_fault)) {
  575 +      emcmotStatus->spindle.orient_state = EMCMOT_ORIENT_FAULTED;
575 576        *(emcmot_hal_data->spindle_orient) = 0;
576 577        emcmotStatus->spindle.orient_fault = *(emcmot_hal_data->spindle_orient_fault);
577 578        reportError(_("fault %d during orient in progress"), emcmotStatus->spindle.orient_fault);
... ... @@ -583,6 +584,7 @@ static void process_inputs(void)
583 584        *(emcmot_hal_data->spindle_locked) = 1;
584 585        emcmotStatus->spindle.locked = 1;
585 586        emcmotStatus->spindle.brake = 1;
  587 +      emcmotStatus->spindle.orient_state = EMCMOT_ORIENT_COMPLETE;
586 588        rtapi_print_msg(RTAPI_MSG_DBG, "SPINDLE_ORIENT complete, spindle locked");
587 589    }
588 590      }
11  src/emc/motion/motion.h
... ... @@ -235,6 +235,7 @@ with type (3) items.
235 235          EmcPose tool_offset;        /* TLO */
236 236    double  orientation;    /* angle for spindle orient */
237 237    char    direction;      /* CANON_DIRECTION flag for spindle orient */
  238 +  double  timeout;        /* of wait for spindle orient to complete */
238 239    unsigned char tail;  /* flag count for mutex detect */
239 240      } emcmot_command_t;
240 241  
... ... @@ -426,6 +427,13 @@ with type (3) items.
426 427    HOME_SEQUENCE_WAIT_JOINTS,
427 428      } home_sequence_state_t;
428 429  
  430 +    typedef enum {
  431 +  EMCMOT_ORIENT_NONE = 0,
  432 +  EMCMOT_ORIENT_IN_PROGRESS,
  433 +  EMCMOT_ORIENT_COMPLETE,
  434 +  EMCMOT_ORIENT_FAULTED,
  435 +    } orient_state_t;
  436 +
429 437  /* flags for homing */
430 438  #define HOME_IGNORE_LIMITS  1
431 439  #define HOME_USE_INDEX    2
... ... @@ -559,7 +567,8 @@ with type (3) items.
559 567    int direction;    // 0 stopped, 1 forward, -1 reverse
560 568    int brake;    // 0 released, 1 engaged
561 569    int locked;             // spindle lock engaged after orient
562   -  int orient_fault;
  570 +  int orient_fault;       // fault code from motion.spindle-orient-fault
  571 +  int orient_state;       // orient_state_t
563 572      } spindle_status;
564 573      
565 574  
1  src/emc/nml_intf/canon.hh
... ... @@ -499,6 +499,7 @@ command may be given, but it will have no effect. */
499 499  
500 500  extern void SPINDLE_RETRACT();
501 501  extern void ORIENT_SPINDLE(double orientation, int mode);
  502 +extern void WAIT_SPINDLE_ORIENT_COMPLETE(double timeout);
502 503  extern void LOCK_SPINDLE_Z();
503 504  extern void USE_SPINDLE_FORCE();
504 505  extern void USE_NO_SPINDLE_FORCE();
20  src/emc/nml_intf/emc.cc
... ... @@ -245,6 +245,9 @@ int emcFormat(NMLTYPE type, void *buffer, CMS * cms)
245 245      case EMC_SPINDLE_ORIENT_TYPE:
246 246    ((EMC_SPINDLE_ORIENT *) buffer)->update(cms);
247 247    break;
  248 +    case EMC_SPINDLE_WAIT_ORIENT_COMPLETE_TYPE:
  249 +  ((EMC_SPINDLE_WAIT_ORIENT_COMPLETE *) buffer)->update(cms);
  250 +  break;
248 251      case EMC_SPINDLE_STAT_TYPE:
249 252    ((EMC_SPINDLE_STAT *) buffer)->update(cms);
250 253    break;
... ... @@ -606,6 +609,8 @@ const char *emc_symbol_lookup(long type)
606 609    return "EMC_SPINDLE_SPEED";
607 610      case EMC_SPINDLE_ORIENT_TYPE:
608 611    return "EMC_SPINDLE_ORIENT";
  612 +    case EMC_SPINDLE_WAIT_ORIENT_COMPLETE_TYPE:
  613 +  return "EMC_SPINDLE_WAIT_ORIENT_COMPLETE";
609 614      case EMC_SPINDLE_STAT_TYPE:
610 615    return "EMC_SPINDLE_STAT";
611 616      case EMC_STAT_TYPE:
... ... @@ -1457,7 +1462,8 @@ void EMC_SPINDLE_STAT::update(CMS * cms)
1457 1462      cms->update(brake);
1458 1463      cms->update(increasing);
1459 1464      cms->update(enabled);
1460   -
  1465 +    cms->update(orient_state);
  1466 +    cms->update(orient_fault);
1461 1467  }
1462 1468  
1463 1469  /*
... ... @@ -2115,6 +2121,18 @@ void EMC_SPINDLE_ORIENT::update(CMS * cms)
2115 2121  }
2116 2122  
2117 2123  /*
  2124 +*  NML/CMS Update function for EMC_SPINDLE_WAIT_ORIENT_COMPLETE
  2125 +*  Manually generated by Michael Haberler.
  2126 +*  on Wed Nov  2 18:29:15 CET 2011
  2127 +*/
  2128 +void EMC_SPINDLE_WAIT_ORIENT_COMPLETE::update(CMS * cms)
  2129 +{
  2130 +
  2131 +    EMC_SPINDLE_CMD_MSG::update(cms);
  2132 +    cms->update(timeout);
  2133 +}
  2134 +
  2135 +/*
2118 2136  *  NML/CMS Update function for EMC_TASK_PLAN_END
2119 2137  *  Automatically generated by NML CodeGen Java Applet.
2120 2138  *  on Sat Oct 11 13:45:16 UTC 2003
5  src/emc/nml_intf/emc.hh
... ... @@ -230,6 +230,7 @@ class PM_CARTESIAN;
230 230  /* removed #define EMC_SPINDLE_DISABLE_TYPE                     ((NMLTYPE) 1315) */
231 231  #define EMC_SPINDLE_SPEED_TYPE                       ((NMLTYPE) 1316)
232 232  #define EMC_SPINDLE_ORIENT_TYPE                      ((NMLTYPE) 1317)
  233 +#define EMC_SPINDLE_WAIT_ORIENT_COMPLETE_TYPE        ((NMLTYPE) 1318)
233 234  
234 235  #define EMC_SPINDLE_STAT_TYPE                        ((NMLTYPE) 1399)
235 236  
... ... @@ -306,7 +307,8 @@ enum EMC_TASK_EXEC_ENUM {
306 307      EMC_TASK_EXEC_WAITING_FOR_PAUSE = 6,
307 308      EMC_TASK_EXEC_WAITING_FOR_MOTION_AND_IO = 7,
308 309      EMC_TASK_EXEC_WAITING_FOR_DELAY = 8,
309   -    EMC_TASK_EXEC_WAITING_FOR_SYSTEM_CMD = 9
  310 +    EMC_TASK_EXEC_WAITING_FOR_SYSTEM_CMD = 9,
  311 +    EMC_TASK_EXEC_WAITING_FOR_SPINDLE_ORIENTED = 10
310 312  };
311 313  
312 314  // types for EMC_TASK interpState
... ... @@ -527,6 +529,7 @@ extern int emcSpindleAbort();
527 529  extern int emcSpindleSpeed(double speed, double factor, double xoffset);
528 530  extern int emcSpindleOn(double speed, double factor, double xoffset);
529 531  extern int emcSpindleOrient(double orientation, int direction);
  532 +extern int emcSpindleWaitOrientComplete(double timout);
530 533  extern int emcSpindleOff();
531 534  extern int emcSpindleIncrease();
532 535  extern int emcSpindleDecrease();
13  src/emc/nml_intf/emc_nml.hh
... ... @@ -1129,6 +1129,8 @@ class EMC_SPINDLE_STAT:public EMC_SPINDLE_STAT_MSG {
1129 1129      int brake;      // 0 released, 1 engaged
1130 1130      int increasing;    // 1 increasing, -1 decreasing, 0 neither
1131 1131      int enabled;    // non-zero means enabled
  1132 +    int orient_state;
  1133 +    int orient_fault;
1132 1134  };
1133 1135  
1134 1136  class EMC_MOTION_STAT:public EMC_MOTION_STAT_MSG {
... ... @@ -1684,6 +1686,17 @@ class EMC_SPINDLE_ORIENT:public EMC_SPINDLE_CMD_MSG {
1684 1686      int    mode;   
1685 1687  };
1686 1688  
  1689 +class EMC_SPINDLE_WAIT_ORIENT_COMPLETE:public EMC_SPINDLE_CMD_MSG {
  1690 +  public:
  1691 +    EMC_SPINDLE_WAIT_ORIENT_COMPLETE():EMC_SPINDLE_CMD_MSG(EMC_SPINDLE_WAIT_ORIENT_COMPLETE_TYPE,
  1692 +              sizeof(EMC_SPINDLE_WAIT_ORIENT_COMPLETE)) {
  1693 +    };
  1694 +
  1695 +    // For internal NML/CMS use only.
  1696 +    void update(CMS * cms);
  1697 +    double timeout;   // how long to wait until spindle orient completes; > 0
  1698 +};
  1699 +
1687 1700  
1688 1701  class EMC_SPINDLE_ON:public EMC_SPINDLE_CMD_MSG {
1689 1702    public:
1  src/emc/rs274ngc/gcodemodule.cc
... ... @@ -405,6 +405,7 @@ void SET_SPINDLE_MODE(double) {}
405 405  void STOP_SPINDLE_TURNING() {}
406 406  void SET_SPINDLE_SPEED(double rpm) {}
407 407  void ORIENT_SPINDLE(double d, int i) {}
  408 +void WAIT_SPINDLE_ORIENT_COMPLETE(double timeout) {}
408 409  void PROGRAM_STOP() {}
409 410  void PROGRAM_END() {}
410 411  void FINISH() {}
7  src/emc/rs274ngc/interp_check.cc
... ... @@ -320,9 +320,10 @@ int Interp::check_other_codes(block_pointer block)       //!< pointer to a block
320 320  
321 321    if (block->q_number != -1.0) {
322 322        CHKS((motion != G_83) && (motion != G_73) && (motion != G_5) && (block->user_m != 1) && (motion != G_76) &&
323   -          (block->m_modes[5] != 66) && (block->m_modes[5] != 67) && (block->m_modes[5] != 68) && 
324   -          (block->g_modes[0] != G_10) && (block->m_modes[6] != 61) && (block->g_modes[13] != G_64), 
325   -          _("Q word with no G5, G10, G64, G73, G76, G83, M66, M67, M68 or user M code that uses it"));
  323 +     (block->m_modes[5] != 66) && (block->m_modes[5] != 67) && (block->m_modes[5] != 68) && 
  324 +     (block->g_modes[0] != G_10) && (block->m_modes[6] != 61) && (block->g_modes[13] != G_64) && 
  325 +     (block->m_modes[7] != 19), 
  326 +     _("Q word with no G5, G10, G64, G73, G76, G83, M19, M66, M67, M68 or user M code that uses it"));
326 327    }
327 328  
328 329    if (block->r_flag) {
5  src/emc/rs274ngc/interp_convert.cc
... ... @@ -3078,8 +3078,13 @@ int Interp::convert_m(block_pointer block,       //!< pointer to a block of RS27
3078 3078      settings->spindle_turning = CANON_STOPPED;
3079 3079    } else if ((block->m_modes[7] == 19) && ONCE_M(7)) {
3080 3080        settings->spindle_turning = CANON_STOPPED;
  3081 +      if (block->r_flag || block->p_flag)
3081 3082        enqueue_ORIENT_SPINDLE(block->r_flag ? (block->r_number + settings->orient_offset) : settings->orient_offset, 
3082 3083             block->p_flag ? block->p_number : 0);
  3084 +      if (block->q_flag) {
  3085 +    CHKS((block->q_number <= 0.0),(_("Q word with M19 requires a value > 0")));
  3086 +    enqueue_WAIT_ORIENT_SPINDLE_COMPLETE(block->q_number);
  3087 +      }
3083 3088    } else if ((block->m_modes[7] == 70) || (block->m_modes[7] == 73)) {
3084 3089  
3085 3090       // save state in current stack frame. We borrow the o-word call stack
17  src/emc/rs274ngc/interp_queue.cc
... ... @@ -201,6 +201,19 @@ void enqueue_ORIENT_SPINDLE(double orientation, int mode) {
201 201      qc().push_back(q);
202 202  }
203 203  
  204 +void enqueue_WAIT_ORIENT_SPINDLE_COMPLETE(double timeout) {
  205 +    if(qc().empty()) {
  206 +        if(debug_qc) printf("immediate wait spindle orient complete\n");
  207 +        WAIT_SPINDLE_ORIENT_COMPLETE(timeout);
  208 +        return;
  209 +    }
  210 +    queued_canon q;
  211 +    q.type = QWAIT_ORIENT_SPINDLE_COMPLETE;
  212 +    q.data.wait_orient_spindle_complete.timeout = timeout;
  213 +    if(debug_qc) printf("enqueue wait spindle orient complete\n");
  214 +    qc().push_back(q);
  215 +}
  216 +
204 217  void enqueue_SET_SPINDLE_MODE(double mode) {
205 218      if(qc().empty()) {
206 219          if(debug_qc) printf("immediate spindle mode %f\n", mode);
... ... @@ -531,6 +544,10 @@ void dequeue_canons(setup_pointer settings) {
531 544              if(debug_qc) printf("issuing orient spindle\n");
532 545              ORIENT_SPINDLE(q.data.orient_spindle.orientation, q.data.orient_spindle.mode);
533 546              break;
  547 +  case QWAIT_ORIENT_SPINDLE_COMPLETE:
  548 +            if(debug_qc) printf("issuing wait orient spindle complete\n");
  549 +            WAIT_SPINDLE_ORIENT_COMPLETE(q.data.wait_orient_spindle_complete.timeout);
  550 +            break;
534 551          }
535 552      }
536 553      qc().clear();
9  src/emc/rs274ngc/interp_queue.hh
... ... @@ -14,7 +14,8 @@ enum queued_canon_type {QSTRAIGHT_TRAVERSE, QSTRAIGHT_FEED, QARC_FEED, QSET_FEED
14 14                                  QMIST_ON, QMIST_OFF, QFLOOD_ON, QFLOOD_OFF,
15 15                                  QSTART_SPINDLE_CLOCKWISE, QSTART_SPINDLE_COUNTERCLOCKWISE, QSTOP_SPINDLE_TURNING,
16 16                                  QSET_SPINDLE_MODE, QSET_SPINDLE_SPEED,
17   -      QCOMMENT, QM_USER_COMMAND,QSTART_CHANGE, QORIENT_SPINDLE};
  17 +      QCOMMENT, QM_USER_COMMAND,QSTART_CHANGE, 
  18 +      QORIENT_SPINDLE, QWAIT_ORIENT_SPINDLE_COMPLETE};
18 19  
19 20  struct straight_traverse {
20 21      int line_number;
... ... @@ -71,6 +72,10 @@ struct orient_spindle {
71 72      int mode;
72 73  };
73 74  
  75 +struct wait_orient_spindle_complete {
  76 +    double timeout;
  77 +};
  78 +
74 79  struct queued_canon {
75 80      queued_canon_type type;
76 81      union {
... ... @@ -85,6 +90,7 @@ struct queued_canon {
85 90          struct comment comment;
86 91          struct mcommand mcommand;
87 92    struct orient_spindle orient_spindle;
  93 +  struct wait_orient_spindle_complete wait_orient_spindle_complete;
88 94      } data;
89 95  };
90 96  
... ... @@ -123,6 +129,7 @@ void enqueue_ARC_FEED(setup_pointer settings, int l,
123 129  void enqueue_M_USER_COMMAND(int index,double p_number,double q_number);
124 130  void enqueue_START_CHANGE(void);
125 131  void enqueue_ORIENT_SPINDLE(double orientation, int mode);
  132 +void enqueue_WAIT_ORIENT_SPINDLE_COMPLETE(double timeout);
126 133  void dequeue_canons(setup_pointer settings);
127 134  void set_endpoint(double x, double y);
128 135  void set_endpoint_zx(double z, double x);
5  src/emc/sai/saicanon.cc
... ... @@ -609,6 +609,11 @@ void ORIENT_SPINDLE(double orientation, int mode)
609 609  {PRINT2("ORIENT_SPINDLE(%.4f, %d)\n", orientation,mode);
610 610  }
611 611  
  612 +void WAIT_SPINDLE_ORIENT_COMPLETE(double timeout) 
  613 +{
  614 +  PRINT1("SPINDLE_WAIT_ORIENT_COMPLETE(%.4f)\n", timeout);
  615 +}
  616 +
612 617  void USE_NO_SPINDLE_FORCE()
613 618  {PRINT0("USE_NO_SPINDLE_FORCE()\n");}
614 619  
9  src/emc/task/emccanon.cc
... ... @@ -1748,6 +1748,15 @@ void ORIENT_SPINDLE(double orientation, int mode)
1748 1748      interp_list.append(o);
1749 1749  }
1750 1750  
  1751 +void WAIT_SPINDLE_ORIENT_COMPLETE(double timeout)
  1752 +{
  1753 +    EMC_SPINDLE_WAIT_ORIENT_COMPLETE o;
  1754 +
  1755 +    flush_segments();
  1756 +    o.timeout = timeout;
  1757 +    interp_list.append(o);
  1758 +}
  1759 +
1751 1760  void USE_SPINDLE_FORCE(void)
1752 1761  {
1753 1762      /*! \todo FIXME-- unimplemented */
66  src/emc/task/emctaskmain.cc
... ... @@ -79,6 +79,7 @@
79 79  #include "nml_oi.hh"
80 80  #include "task.hh"    // emcTaskCommand etc
81 81  #include "taskclass.hh"
  82 +#include "motion.h"             // EMCMOT_ORIENT_*
82 83  
83 84  /* time after which the user interface is declared dead
84 85   * because it would'nt read any more messages
... ... @@ -392,6 +393,7 @@ int emcSystemCmd(char *s)
392 393  
393 394  static EMC_SPINDLE_SPEED *spindle_speed_msg;
394 395  static EMC_SPINDLE_ORIENT *spindle_orient_msg;
  396 +static EMC_SPINDLE_WAIT_ORIENT_COMPLETE *wait_spindle_orient_complete_msg;
395 397  static EMC_SPINDLE_ON *spindle_on_msg;
396 398  static EMC_TOOL_PREPARE *tool_prepare_msg;
397 399  static EMC_TOOL_LOAD_TOOL_TABLE *load_tool_table_msg;
... ... @@ -1004,6 +1006,7 @@ static int emcTaskPlan(void)
1004 1006      case EMC_TRAJ_SET_SO_ENABLE_TYPE:
1005 1007      case EMC_SPINDLE_SPEED_TYPE:
1006 1008      case EMC_SPINDLE_ORIENT_TYPE:
  1009 +    case EMC_SPINDLE_WAIT_ORIENT_COMPLETE_TYPE:
1007 1010      case EMC_SPINDLE_ON_TYPE:
1008 1011      case EMC_SPINDLE_OFF_TYPE:
1009 1012      case EMC_SPINDLE_BRAKE_RELEASE_TYPE:
... ... @@ -1163,6 +1166,7 @@ static int emcTaskPlan(void)
1163 1166      case EMC_TRAJ_SET_SO_ENABLE_TYPE:
1164 1167      case EMC_SPINDLE_SPEED_TYPE:
1165 1168      case EMC_SPINDLE_ORIENT_TYPE:
  1169 +    case EMC_SPINDLE_WAIT_ORIENT_COMPLETE_TYPE:
1166 1170      case EMC_SPINDLE_ON_TYPE:
1167 1171      case EMC_SPINDLE_OFF_TYPE:
1168 1172      case EMC_SPINDLE_BRAKE_RELEASE_TYPE:
... ... @@ -1315,6 +1319,7 @@ static int emcTaskPlan(void)
1315 1319        case EMC_TRAJ_SET_SO_ENABLE_TYPE:
1316 1320        case EMC_SPINDLE_SPEED_TYPE:
1317 1321        case EMC_SPINDLE_ORIENT_TYPE:
  1322 +      case EMC_SPINDLE_WAIT_ORIENT_COMPLETE_TYPE:
1318 1323        case EMC_SPINDLE_ON_TYPE:
1319 1324        case EMC_SPINDLE_OFF_TYPE:
1320 1325        case EMC_SPINDLE_BRAKE_RELEASE_TYPE:
... ... @@ -1413,6 +1418,7 @@ static int emcTaskCheckPreconditions(NMLmsg * cmd)
1413 1418      case EMC_TRAJ_RIGID_TAP_TYPE: //and this
1414 1419      case EMC_TRAJ_CLEAR_PROBE_TRIPPED_FLAG_TYPE:  // and this
1415 1420      case EMC_AUX_INPUT_WAIT_TYPE:
  1421 +    case EMC_SPINDLE_WAIT_ORIENT_COMPLETE_TYPE:
1416 1422    return EMC_TASK_EXEC_WAITING_FOR_MOTION_AND_IO;
1417 1423    break;
1418 1424  
... ... @@ -1511,6 +1517,7 @@ static int emcTaskCheckPreconditions(NMLmsg * cmd)
1511 1517    return EMC_TASK_EXEC_DONE;
1512 1518    break;
1513 1519  
  1520 +
1514 1521      default:
1515 1522    // unrecognized command
1516 1523    if (EMC_DEBUG & EMC_DEBUG_TASK_ISSUE) {
... ... @@ -1823,6 +1830,11 @@ static int emcTaskIssueCommand(NMLmsg * cmd)
1823 1830    }
1824 1831    break;
1825 1832  
  1833 +    case EMC_SPINDLE_WAIT_ORIENT_COMPLETE_TYPE:
  1834 +  wait_spindle_orient_complete_msg = (EMC_SPINDLE_WAIT_ORIENT_COMPLETE *) cmd;
  1835 +  taskExecDelayTimeout = etime() + wait_spindle_orient_complete_msg->timeout;
  1836 +  break;
  1837 +
1826 1838      case EMC_TRAJ_RIGID_TAP_TYPE:
1827 1839    retval = emcTrajRigidTap(((EMC_TRAJ_RIGID_TAP *) cmd)->pos,
1828 1840            ((EMC_TRAJ_RIGID_TAP *) cmd)->vel,
... ... @@ -1886,7 +1898,7 @@ static int emcTaskIssueCommand(NMLmsg * cmd)
1886 1898    retval = emcSpindleOrient(spindle_orient_msg->orientation, spindle_orient_msg->mode);
1887 1899    break;
1888 1900  
1889   -    case EMC_SPINDLE_ON_TYPE:
  1901 +   case EMC_SPINDLE_ON_TYPE:
1890 1902    spindle_on_msg = (EMC_SPINDLE_ON *) cmd;
1891 1903    retval = emcSpindleOn(spindle_on_msg->speed, spindle_on_msg->factor, spindle_on_msg->xoffset);
1892 1904    break;
... ... @@ -2323,6 +2335,10 @@ static int emcTaskCheckPostconditions(NMLmsg * cmd)
2323 2335    return EMC_TASK_EXEC_DONE;
2324 2336    break;
2325 2337  
  2338 +    case EMC_SPINDLE_WAIT_ORIENT_COMPLETE_TYPE:
  2339 +  return EMC_TASK_EXEC_WAITING_FOR_SPINDLE_ORIENTED;
  2340 +  break;
  2341 +
2326 2342      case EMC_TRAJ_DELAY_TYPE:
2327 2343      case EMC_AUX_INPUT_WAIT_TYPE:
2328 2344    return EMC_TASK_EXEC_WAITING_FOR_DELAY;
... ... @@ -2540,6 +2556,37 @@ static int emcTaskExecute(void)
2540 2556    }
2541 2557    break;
2542 2558  
  2559 +    case EMC_TASK_EXEC_WAITING_FOR_SPINDLE_ORIENTED:
  2560 +  STEPPING_CHECK(); // not sure
  2561 +  switch (emcStatus->motion.spindle.orient_state) {
  2562 +  case EMCMOT_ORIENT_NONE:
  2563 +  case EMCMOT_ORIENT_COMPLETE:
  2564 +      emcStatus->task.execState = EMC_TASK_EXEC_DONE;
  2565 +      emcStatus->task.delayLeft = 0;
  2566 +      emcTaskEager = 1;
  2567 +      rcs_print("wait for orient complete: nothing to do\n");
  2568 +      break;
  2569 +
  2570 +  case EMCMOT_ORIENT_IN_PROGRESS:
  2571 +      emcStatus->task.delayLeft = taskExecDelayTimeout - etime();
  2572 +      if (etime() >= taskExecDelayTimeout) {
  2573 +    emcStatus->task.execState = EMC_TASK_EXEC_ERROR;
  2574 +    emcStatus->task.delayLeft = 0;
  2575 +    emcTaskEager = 1;
  2576 +    emcOperatorError(0, "wait for orient complete: TIMED OUT");
  2577 +      }
  2578 +      break;
  2579 +
  2580 +  case EMCMOT_ORIENT_FAULTED:
  2581 +      // actually the code in main() should trap this before we get here
  2582 +      emcStatus->task.execState = EMC_TASK_EXEC_ERROR;
  2583 +      emcStatus->task.delayLeft = 0;
  2584 +      emcTaskEager = 1;
  2585 +      emcOperatorError(0, "wait for orient complete: FAULTED code=%d", 
  2586 +           emcStatus->motion.spindle.orient_fault);
  2587 +  }
  2588 +  break;
  2589 +
2543 2590      case EMC_TASK_EXEC_WAITING_FOR_DELAY:
2544 2591    STEPPING_CHECK();
2545 2592    // check if delay has passed
... ... @@ -3230,6 +3277,7 @@ int main(int argc, char *argv[])
3230 3277        }
3231 3278  
3232 3279    }
  3280 +
3233 3281    // check for subordinate errors, and halt task if so
3234 3282    if (emcStatus->motion.status == RCS_ERROR ||
3235 3283        ((emcStatus->io.status == RCS_ERROR) &&
... ... @@ -3249,10 +3297,18 @@ int main(int argc, char *argv[])
3249 3297          emcOperatorError(0, io_error, emcStatus->io.reason);
3250 3298      }
3251 3299        }
3252   -      // abort everything
3253   -      emcTaskAbort();
3254   -      emcIoAbort(EMC_ABORT_MOTION_OR_IO_RCS_ERROR);
3255   -      emcSpindleAbort();
  3300 +      // motion already should have reported this condition (and set RCS_ERROR?)
  3301 +      // an M19 orient failed to complete within timeout
  3302 +      // if ((emcStatus->motion.status == RCS_ERROR) && 
  3303 +      //   (emcStatus->motion.spindle.orient_state == EMCMOT_ORIENT_FAULTED) &&
  3304 +      //   (emcStatus->motion.spindle.orient_fault != 0)) {
  3305 +      //   emcOperatorError(0, "wait for orient complete timed out");
  3306 +      // }
  3307 +
  3308 +        // abort everything
  3309 +        emcTaskAbort();
  3310 +        emcIoAbort(EMC_ABORT_MOTION_OR_IO_RCS_ERROR);
  3311 +        emcSpindleAbort();
3256 3312        mdi_execute_abort();
3257 3313        // without emcTaskPlanClose(), a new run command resumes at
3258 3314        // aborted line-- feature that may be considered later
2  src/emc/task/taskintf.cc
... ... @@ -1500,6 +1500,8 @@ int emcMotionUpdate(EMC_MOTION_STAT * stat)
1500 1500      stat->spindle.speed = emcmotStatus.spindle.speed;
1501 1501      stat->spindle.brake = emcmotStatus.spindle.brake;
1502 1502      stat->spindle.direction = emcmotStatus.spindle.direction;
  1503 +    stat->spindle.orient_state = emcmotStatus.spindle.orient_state;
  1504 +    stat->spindle.orient_fault = emcmotStatus.spindle.orient_fault;
1503 1505  
1504 1506      for (dio = 0; dio < EMC_MAX_DIO; dio++) {
1505 1507    stat->synch_di[dio] = emcmotStatus.synch_di[dio];
3  tests/interp/m19/expected
... ... @@ -3,11 +3,12 @@
3 3   N..... SET_G92_OFFSET(0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000)
4 4   N..... SET_XY_ROTATION(0.0000)
5 5   N..... SET_FEED_REFERENCE(CANON_XYZ)
6   - N..... ORIENT_SPINDLE(42.0000, 0)
7 6   N..... ORIENT_SPINDLE(87.0000, 0)
  7 + N..... SPINDLE_WAIT_ORIENT_COMPLETE(2.0000)
8 8   N..... ORIENT_SPINDLE(42.0000, 1)
9 9   N..... ORIENT_SPINDLE(132.0000, 0)
10 10   N..... ORIENT_SPINDLE(132.0000, 1)
  11 + N..... SPINDLE_WAIT_ORIENT_COMPLETE(1.0000)
11 12   N..... SET_G5X_OFFSET(1, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000)
12 13   N..... SET_XY_ROTATION(0.0000)
13 14   N..... SET_FEED_MODE(0)
3  tests/interp/m19/test.ngc
... ... @@ -1,7 +1,8 @@
1 1  M19
2   -M19 R45
  2 +M19 R45 Q2
3 3  M19 P1
4 4  M19 R90 P0
5 5  M19 R90 P1
  6 +M19 Q1
6 7  
7 8  M2

0 notes on commit 4d311b0

Please sign in to comment.
Something went wrong with that request. Please try again.