Trigger output per distance moved (Auto Oiler)

More
13 Oct 2014 08:27 #51990 by pippin88
I've converted my benchtop mill and it's working reasonably. I can never remember to oil it.

So I'm building an oiler with a bunch of pneumatic parts. I'm going to use a peristaltic pump to move the oil.

I see two ways to do this:
1. via LinuxCNC (preferred)
Ideally this would be triggered when a certain distance is moved.
- is this possible?
- I've searched and I can't find a solution
I've got spare outputs on my G540 to drive a relay.
The other possibility is a timer within LinuxCNC, preferably with a separate (priming) event on start

2. Independent of LinuxCNC - arduino (or similar)
In which case I would implement a timer than pumps for x seconds every y minutes
But this results in the same amount of oil if the machine is sitting on doing nothing or if it's moving non-stop.

Has anyone done this?
Can anyone shed any light?
Help is appreciated.

Please Log in or Create an account to join the conversation.

More
13 Oct 2014 13:44 #51995 by emcPT
We do it with a timer. Like turn it on for 5 seconds in intervals of 10 minutes.
If you find this solution suitable, I can send more details, as I am not near a machine.

Please Log in or Create an account to join the conversation.

More
13 Oct 2014 15:40 - 14 Oct 2014 16:43 #51999 by ArcEye
Hi

There will be a few ways to do this regards distance moved, but probably most readily from a component.

motion.in-position will tell you when a move has stopped

motion.distance-to-go will tell you the distance remaining in a move

www.linuxcnc.org/docs/html/config/emc2hal.html

So if your component uses motion.in-position as a trigger to tell it that a move has begun, it can then add motion.distance-to-go to a cumulative total,
then reset when motion.in-position becomes true again, ready for the next move.

When the cumulative total reaches a preset value, the oiler is switched on, cumulative total reset and off you go again.

Probably need override pins for a reset and on demand oiler activation too.

This is a 'back-of-an-envelope' example of what I mean
It compiles but is not tested. DTG should always be a positive number, irrespective of the direction of movement, so that bit should be fine

Minimum connection requirements, something like:

loadrt oilactivate
addf oilactivate servo-thread
net dtg motion.distance-to-go => oilactivate.distancetogo
net inpos motion.in-position => oilactivate.inposition
net oil oilactivate.oilon => {your-lube-activation-pin}

component oilactivate;

pin in bit inposition = 1;
pin in float distancetogo = 0;

pin in bit reset = 0;
pin in bit oilnow = 0;

pin out bit oilon = 0;

// internal variables

variable int progress_level = 0;        //  switches execution according to state 
variable float cumtotal = 0;
    // flags to prevent cycling
variable int hasreset = 0;
variable int hasoilnow = 0;

param rw s32 oiltime = 2000;
param rw float disttotal = 30000;  // oil every 30 metres of movement for example

variable int delaytime = 0;

option singleton yes;
function _;
author "ArcEye <arceyeATmgwareDOTcoDOTuk>";
license "GPL";
;;

FUNCTION(_)
{
    switch (progress_level)
        {
        case 0: if(!inposition)
                    {
                    progress_level = 1;
                    break;
                    }
                if(oilnow && !hasoilnow)
                    {
                    hasoilnow = 1;
                    progress_level = 3;
                    break;
                    }
                if(!oilnow && hasoilnow)    
                    hasoilnow = 0; // reset when pin cleared
                    
                if(reset && !hasreset)
                    {
                    hasreset = 1;
                    cumtotal = 0;
                    }
                if(!reset && hasreset)
                    hasreset = 0; // reset when pin cleared
                    
                break;
                
        case 1: cumtotal += distancetogo;
                progress_level = 2;
                break;
                
        case 2: // delay to prevent overrun
                if(inposition)
                    {
                    if(cumtotal >= disttotal)
                        progress_level = 3;
                    else
                        progress_level = 0;
                    }            
                break; 

       case 3:  oilon = 1;
                progress_level = 4;
                break;
       
       case 4: if(delaytime < oiltime) 
                    {
                    delaytime++;  
                    break;
                    }
                delaytime = 0;
                oilon = 0;
                progress_level = 0;        
                break; 

        
        case 30: 
                break;  // should never get here but if we do then loop endlessly doing nothing
                
        default:    
                progress_level = 30;
                rtapi_print_msg(RTAPI_MSG_ERR, "Unsupported state in oilactivate - now disabled ");            
        
        }
 
}

regards
Last edit: 14 Oct 2014 16:43 by ArcEye.
The following user(s) said Thank You: andypugh

Please Log in or Create an account to join the conversation.

More
13 Oct 2014 17:52 #52014 by pippin88
emcPT: I'm interested in seeing your timer implementation. No rush, it will be a while before I can get this done.

ArcEye: Thanks a lot for that. I'll have a look through and try it with a dummy setup at least.

The other possible way that occurred to me is to run the pump very slowly but constantly while motion is occurring. This would be very easy to implement from a software point of view. Then a button or script for priming / initial oiling - preferably prime on startup if hasn't Ben primed for x hours.

Please Log in or Create an account to join the conversation.

More
13 Oct 2014 19:37 - 13 Oct 2014 19:42 #52019 by jtc
By emcPT request there is the component(s) that we use:
/**********************************************************************************************************************
***********************************************************************************************************************/

component spwm                       "slow pwm";

pin in u32 OnDuty;
pin in u32 OffDuty;
pin in u32 Seconds;
pin out bit Out;
//pin out u32 acc;

variable int time = 0;
variable int acc = 0;


option singleton yes;              
function _;
author "jtc";
license "GPL";
;;
#include <rtapi_math.h>


FUNCTION(_)
{ 
	if(Seconds!=time){
		time=Seconds;
		acc++;
	}
	
	if(acc<=OnDuty){
		Out=true;
	}else{
		Out=false;
	}
	
	if(acc==(OnDuty+OffDuty)){
		acc=0;
	}
	
}


in the hal file:
###	Software pwm for lub pump
loadrt spwm
addf spwm servo-thread
###	Time component to lub pump
loadrt time count=1
addf time.0 servo-thread
setp time.0.start true


###################################	Lub pump	#########################
net sec time.0.seconds => spwm.Seconds
setp spwm.OnDuty  [lube]OnDuty
setp spwm.OffDuty  [lube]OffDuty
setp hm2_5i20.0.gpio.043.is_output true
setp hm2_5i20.0.gpio.043.invert_output true

net LubPump spwm.Out => hm2_5i20.0.gpio.043.out
#########################################################################

and at last in the ini file:
[lube]
OnDuty = 2
OffDuty = 1200


João
Last edit: 13 Oct 2014 19:42 by jtc.

Please Log in or Create an account to join the conversation.

Time to create page: 0.189 seconds
Powered by Kunena Forum