Lube Pump
- andypugh
- Offline
- Moderator
Less
More
- Posts: 23170
- Thank you received: 4860
29 Oct 2020 09:01 #187666
by andypugh
Replied by andypugh on topic Lube Pump
I would tend to choose the realtime HAL module for timing reliability, though in this application there probably isn't much advantage over the other approaches.
The realtime HAL module will use a lot less system resources. But I doubt any of them use any significant amount.
The realtime HAL module will use a lot less system resources. But I doubt any of them use any significant amount.
The following user(s) said Thank You: lrak
Please Log in or Create an account to join the conversation.
- lrak
- Offline
- Premium Member
Less
More
- Posts: 113
- Thank you received: 21
03 Nov 2020 04:31 - 03 Nov 2020 04:34 #188172
by lrak
Replied by lrak on topic Lube Pump
Folded fupeama's code around a bit and have it working.
(I'm a bit confused why everything gets added to the servo-thread? Seems things like this and classicladder should be in a lower priority thread? )
Now I need to figure out how to put up a tank low warning in the GUI.
lubrication.comp
From machine.hal :
(I'm a bit confused why everything gets added to the servo-thread? Seems things like this and classicladder should be in a lower priority thread? )
Now I need to figure out how to put up a tank low warning in the GUI.
lubrication.comp
component lubrication ;
pin in float motion "Input pin for motion detect";
pin out bit lube "Output pin for lube pump";
pin out float ctimer "Current value of elapsed cycle time";
// we don't want to pump on an empty lube tank (lube dividers would need priming)
pin in bit lube-tank-ok "input pin - tank has sufficient lube";
//times are in seconds
param rw float waittime=120 "Time for wait";
param rw float lubetime=10 "Time for lube";
variable double totalcycle;
function _;
license "GPL";
author "mk , kps";
//double semicolon below - end of declarations
;;
totalcycle =waittime+lubetime;
// Nothing happens without motion and a tank with oil
if ((motion > 0) && lube_tank_ok){
ctimer+=fperiod;
if (ctimer < waittime) {
lube=0;
}
if (ctimer >= waittime) {
lube=1;
}
if (ctimer > totalcycle ){
lube=0;
ctimer = 0;
}
} else {
lube=0;
}
From machine.hal :
# --- lubrication signals ---
setp lubrication.0.lubetime 2
setp lubrication.0.waittime 8
net lubeon lubrication.0.lube => hm2_7i93.0.7i84.0.0.output-00
#net tankok lubrication.0.lube-tank-ok <= hm2_7i93.0.7i84.0.0.input-04
net motion_detect motion.current-vel => lubrication.0.motion
Last edit: 03 Nov 2020 04:34 by lrak. Reason: typo -2
Please Log in or Create an account to join the conversation.
- rodw
- Offline
- Platinum Member
Less
More
- Posts: 10807
- Thank you received: 3559
03 Nov 2020 05:26 #188175
by rodw
Replied by rodw on topic Lube Pump
Well you can create multiple threads with different time periods which is the purpose of the addf function as it attaches the component to the thread of your choice.
The following user(s) said Thank You: lrak
Please Log in or Create an account to join the conversation.
- lrak
- Offline
- Premium Member
Less
More
- Posts: 113
- Thank you received: 21
12 Nov 2020 02:25 - 24 Nov 2020 03:25 #189081
by lrak
Replied by lrak on topic Lube Pump
I've attached a userspace version -
Updated file - even simpler and no longer burns CPU time.
Updated again - cleaner code..
Posting in line - can't get rid of the old version..
Updated file - even simpler and no longer burns CPU time.
Updated again - cleaner code..
Posting in line - can't get rid of the old version..
component lubrication "lube pump timer" ;
pin in float motion "Input pin for motion detect";
pin out bit lube "Output pin for lube pump";
pin out unsigned ctimer "Current value of elapsed cycle time";
pin out unsigned totalcycle "total cycle time";
// we don't want to pump on an empty lube tank (lube dividers would need priming)
pin in bit lube-tank-ok "input pin - tank has sufficient lube";
//times are in seconds
param rw float waittime=120 "Time for wait";
param rw float lubetime=10 "Time for lube";
option userspace yes;
//option usrinit yes;
license "GPL";
author "mk , kps";
//double semicolon below - end of declarations
;;
#include <unistd.h>
void user_mainloop(void) {
while(1){
sleep(1);
FOR_ALL_INSTS() {
totalcycle =waittime+lubetime;
// Nothing happens without motion and a tank with oil
if((motion > 0) && (lube_tank_ok)){
lube =(++ctimer < lubetime);
if (ctimer >= totalcycle ){
ctimer = 0;
}
}else {
lube = 0;
}
}
}
}
Attachments:
Last edit: 24 Nov 2020 03:25 by lrak. Reason: Bug fix
Please Log in or Create an account to join the conversation.
- endian
- Offline
- Elite Member
Less
More
- Posts: 176
- Thank you received: 45
30 May 2021 14:31 - 31 May 2021 08:47 #210679
by endian
Replied by endian on topic Lube Pump
hello there,
I created cute lube component works on time of moving with alarm message when is low level of lube medium in tank.
check it if it isnt too much for cpu. there was created 1second thread just for it alone.
for first install of this component, you need to go to tour config directory in next step:
then copy to your hal:
and component looks:
not kill me if I am reinveted wheel again
I created cute lube component works on time of moving with alarm message when is low level of lube medium in tank.
check it if it isnt too much for cpu. there was created 1second thread just for it alone.
for first install of this component, you need to go to tour config directory in next step:
- copy component "lubrication.comp" below to /home/cnc/Desktop/******my_cnc******/ then
- open terminal and type: cd /home/cnc/Desktop/******my_cnc******/ then
- in opened terminal install your component to your config: sudo halcompile --install lubrication.comp
then copy to your hal:
###lubrication
loadrt lubrication # load lubrication.comp
loadrt threads name1=lubrication-thread period1=1000000000 # create lubrication "1second" thread
addf lubrication.0 lubrication-thread # add component lubrication to lubrication "1second" thread
loadrt message names=oilLow messages="Low lube level, refill tank!"
addf oilLow servo-thread
#in
setp lubrication.0.lube 15 # seconds 15s of lubrication
setp lubrication.0.wait 1 # minutes 1 waiting for lubrication turn on if it is moving
setp lubrication.0.lowLevelReducer 3 # when is low level, reduce lubrication for save lubrication medium time by value, if not want save set to 1
net motionCurrent motion.current-vel lubrication.0.motion # when machine is moving
net lowOilLevel lubrication.0.lowLevel # here add your # NO signal character sensor, when is low level of lubrication medium == true
#out
net lubeOn lubrication.0.lubeOn
net elapsedTime lubrication.0.lubeTimeElapsed
net lowOilLevel lubrication.0.lowLubeMediumTrigger oilLow.trigger
and component looks:
component lubrication
"""
lubrication component allows lubrication of machine by first
movement of machine, then it works with time of motion and0 with time
memory if machine not moves currently.
when is low level of lubrication medium it can reduce time of lubrication by
denumerator/reducer
""";
pin in float motion "";
pin in bit lowLevel "";
pin in u32 lowLevelReducer "";
pin in u32 wait "";
pin in u32 lube "";
pin out bit lubeOn "";
pin out u32 lubeTimeElapsed "";
pin out bit lowLubeMediumTrigger "";
variable bool motionFisrt=true;
variable unsigned timeElapsed;
variable unsigned timeElapsedLast;
function _;
license "GPL";
author "foxington";
;;
//#include <stdlib.h>
#include <stdio.h>
//#include <string.h>
//#include <math.h>
//#include <assert.h>
//#include <signal.h>
//#include <unistd.h>
//#include <stdarg.h>
unsigned timeCounting(unsigned time, unsigned reduce, bool lubeOnTemp, bool low){
unsigned lWaitingTime;
if(lubeOnTemp){
if(low){
lWaitingTime=(time/reduce);
}
else{
lWaitingTime=(time);
}
}
else{
lWaitingTime=(time*60);
}
return lWaitingTime;
}
FUNCTION(_) {
if(motion){ // in motion
if(!lubeOn){ // not lubing
unsigned lWaitTime=timeCounting(wait, lowLevelReducer, lubeOn, lowLevel);
if((timeElapsed>=(timeElapsedLast+lWaitTime)) || motionFisrt){ // lubing started
timeElapsedLast=timeElapsed;
lubeOn=true;
if(motionFisrt){
motionFisrt=false;
}
} // lubing started
if(lowLubeMediumTrigger){
lowLubeMediumTrigger=false;
}
} // not lubing
else{
unsigned lLubeTime=timeCounting(lube, lowLevelReducer, lubeOn, lowLevel);
if(timeElapsed>=(timeElapsedLast+lLubeTime)){
timeElapsedLast=timeElapsed;
lubeOn=false;
if(motionFisrt){
motionFisrt=false;
}
}
if(lowLevel){
if(!lowLubeMediumTrigger){
lowLubeMediumTrigger=true;
}
}
}
timeElapsed++;
lubeTimeElapsed=timeElapsed;
} // in motion
else{ // not in motion
if(lubeOn){ // when motion stopped and lubing is still active, it will finish job and turn off
unsigned lLubeTime=timeCounting(lube, lowLevelReducer, lubeOn, lowLevel);
if(timeElapsed>=(timeElapsedLast+lLubeTime)){
timeElapsedLast=timeElapsed;
lubeOn=false;
}
if(lubeOn){
timeElapsed++;
lubeTimeElapsed=timeElapsed;
}
else{
timeElapsed=0;
timeElapsedLast=timeElapsed;
if(lowLubeMediumTrigger){
lowLubeMediumTrigger=false;
}
}
}
} // not in motion
}
not kill me if I am reinveted wheel again
Last edit: 31 May 2021 08:47 by endian.
The following user(s) said Thank You: andypugh, anfänger, Sadmeatball
Please Log in or Create an account to join the conversation.
Time to create page: 0.061 seconds