From 1aa14b1092148da821349a1280b8042327910766 Mon Sep 17 00:00:00 2001
From: Chris Morley <chrisinnanaimo@hotmail.com>
Date: Thu, 5 Jun 2014 23:41:08 -0700
Subject: [PATCH] motion -add a rapid override pin

allows one to override the rapid move from 0 to 100 percent.
Can be connected to halui.feed-override.value to restore the
behaivor of feed override controlling rapids too.
---
 src/emc/kinematics/tp.c   |    4 ++--
 src/emc/motion/control.c  |   12 ++++++++++++
 src/emc/motion/mot_priv.h |    1 +
 src/emc/motion/motion.c   |    3 +++
 src/emc/motion/motion.h   |    1 +
 5 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/src/emc/kinematics/tp.c b/src/emc/kinematics/tp.c
index 46d563c..a8768c6 100644
--- a/src/emc/kinematics/tp.c
+++ b/src/emc/kinematics/tp.c
@@ -1015,9 +1015,9 @@ int tpRunCycle(TP_STRUCT * tp, long period)
     }
     // if this is rapid move, don't use feed override settings (max velocity override is still honoured)
     if(tc->canon_motion_type==EMC_MOTION_TYPE_TRAVERSE) {
-        tc->feed_override = 1.0;
+        tc->feed_override = emcmotStatus->net_rapid_scale;
         if(nexttc) {
-        nexttc->feed_override = 1.0;
+        nexttc->feed_override = emcmotStatus->net_rapid_scale;
         }
     }
     /* handle pausing */
diff --git a/src/emc/motion/control.c b/src/emc/motion/control.c
index 313fab2..3b9e9cc 100644
--- a/src/emc/motion/control.c
+++ b/src/emc/motion/control.c
@@ -486,6 +486,18 @@ static void process_inputs(void)
     /* save the resulting combined scale factor */
     emcmotStatus->net_feed_scale = scale;
 
+	/* set rapid override */
+	/* read and clamp (0.0 to 1.0) adaptive feed HAL pin */
+	tmp = *emcmot_hal_data->rapid_override;
+	if ( tmp > 1.0 ) {
+	    tmp = 1.0;
+	} else if ( tmp < 0.0 ) {
+	    tmp = 0.0;
+	}
+    /* save the resulting scale factor */
+    emcmotStatus->net_rapid_scale = tmp;
+
+
     /* now do spindle scaling */
     scale = 1.0;
     if ( enables & SS_ENABLED ) {
diff --git a/src/emc/motion/mot_priv.h b/src/emc/motion/mot_priv.h
index c1d7638..044e10f 100644
--- a/src/emc/motion/mot_priv.h
+++ b/src/emc/motion/mot_priv.h
@@ -89,6 +89,7 @@ typedef struct {
     hal_float_t *spindle_revs;
     hal_bit_t *spindle_inhibit;	/* RPI: set TRUE to stop spindle (non maskable)*/
     hal_float_t *adaptive_feed;	/* RPI: adaptive feedrate, 0.0 to 1.0 */
+    hal_float_t *rapid_override;	/* RPI: rapid feedrate, 0.0 to 1.0 */
     hal_bit_t *feed_hold;	/* RPI: set TRUE to stop motion maskable with g53 P1*/
     hal_bit_t *feed_inhibit;	/* RPI: set TRUE to stop motion (non maskable)*/
     hal_bit_t *motion_enabled;	/* RPI: motion enable for all joints */
diff --git a/src/emc/motion/motion.c b/src/emc/motion/motion.c
index 48e1bf9..26f1902 100644
--- a/src/emc/motion/motion.c
+++ b/src/emc/motion/motion.c
@@ -327,6 +327,8 @@ static int init_hal_io(void)
     *emcmot_hal_data->spindle_is_atspeed = 1;
     if ((retval = hal_pin_float_newf(HAL_IN, &(emcmot_hal_data->adaptive_feed), mot_comp_id, "motion.adaptive-feed")) < 0) goto error;
     *(emcmot_hal_data->adaptive_feed) = 1.0;
+    if ((retval = hal_pin_float_newf(HAL_IN, &(emcmot_hal_data->rapid_override), mot_comp_id, "motion.rapid-override")) < 0) goto error;
+    *(emcmot_hal_data->rapid_override) = 1.0;
     if ((retval = hal_pin_bit_newf(HAL_IN, &(emcmot_hal_data->feed_hold), mot_comp_id, "motion.feed-hold")) < 0) goto error;
     *(emcmot_hal_data->feed_hold) = 0;
     if ((retval = hal_pin_bit_newf(HAL_IN, &(emcmot_hal_data->feed_inhibit), mot_comp_id, "motion.feed-inhibit")) < 0) goto error;
@@ -906,6 +908,7 @@ static int init_comm_buffers(void)
     emcmotStatus->feed_scale = 1.0;
     emcmotStatus->spindle_scale = 1.0;
     emcmotStatus->net_feed_scale = 1.0;
+    emcmotStatus->net_rapid_scale = 1.0;
     /* adaptive feed is off by default, feed override, spindle 
        override, and feed hold are on */
     emcmotStatus->enables_new = FS_ENABLED | SS_ENABLED | FH_ENABLED;
diff --git a/src/emc/motion/motion.h b/src/emc/motion/motion.h
index 435eac7..69c2d7d 100644
--- a/src/emc/motion/motion.h
+++ b/src/emc/motion/motion.h
@@ -610,6 +610,7 @@ Suggestion: Split this in to an Error and a Status flag register..
 		/* the above set is the enables in effect for new moves */
 	/* the rest are updated every cycle */
 	double net_feed_scale;	/* net scale factor for all motion */
+	double net_rapid_scale;	/* net scale factor for all motion */
 	double net_spindle_scale;	/* net scale factor for spindle */
 	unsigned char enables_queued;	/* flags for FS, SS, etc */
 		/* the above set is the enables in effect for the
-- 
1.7.0.4

