Variable pitch belt driven spindle

More
12 Apr 2020 00:35 - 12 Apr 2020 00:36 #163681 by cmorley
I would put the commands close to the top so you know it called. If you don't see the pins then it's not getting to the command.

I suppose you could use an echo statement too (Bash is not my strong suit)
Anyways the idea of course is to show the flow of the script.

Chris
Last edit: 12 Apr 2020 00:36 by cmorley.

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

More
12 Apr 2020 00:43 #163683 by fungus
Hmm. I just purposely removed the net assignment lines from the main HAL file, which should have caused errors. No errors occurred. Something fishy is going on... It's like the file isn't even running.

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

More
12 Apr 2020 00:52 #163685 by fungus
Yeah, I tried it several places within the script. Nada. I couldn't figure out if I was doing echoes correctly, probably due to the fact that it's not getting executed. I'm a bit baffled by this.

Here's the latest:
M101 (using direct pin assignments)
#!/bin/sh

halcmd show pin

#example usage: M101 P1 (changes variable pitch belt to ratio A)
#uses argument P


#parport.0.pin-11-in-not is input for range A
#parport.0.pin-12-in-not is input for range B
#parport.0.pin-13-in-not is input for range C
#parport.0.pin-2-out is the valve to make RPM lower
#parport.0.pin-5-out is the valve to make RPM higher


range_request = $1

case $range_request in
	#change to ratio 1
	#while the input for ratio 1 is not true, move RPM down until the input is true
	1)
		while ! [halcmd getp parport.0.pin-11-in-not]; do
			if [halcmd getp parport.0.pin-13-in-not] || [halcmd getp parport.0.pin-12-in-not]
			then
				#start the spindle, unscaled
				vfd.speed-command 60
				halcmd setp parport.0.pin-2-out True
			fi
		done

		#once complete, stop the spindle and set both airmotor valves to off
		vfd.speed-command 0.0
		halcmd setp parport.0.pin-2-out False
		halcmd setp parport.0.pin-5-out False
		#set the correct gain for this range
		setp scale.0.gain 0.33
		;;
	#change to ratio 2
	2)
		while ! [halcmd getp parport.0.pin-12-in-not]; do
			if [halcmd getp parport.0.pin-13-in-not]
			then
				vfd.speed-command 60
				halcmd setp parport.0.pin-2-out True
			elif [halcmd getp parport.0.pin-11-in-not]
			then
				vfd.speed-command 60
				halcmd setp parport.0.pin-5-out True
			fi
		done
		vfd.speed-command 0.0
		halcmd setp parport.0.pin-2-out False
		halcmd setp parport.0.pin-5-out False
		setp scale.0.gain 0.66
		;;

	3)
		while ! [halcmd getp parport.0.pin-13-in-not]; do
			if [halcmd getp parport.0.pin-11-in-not] || [halcmd getp parport.0.pin-12-in-not]
			then
				vfd.speed-command 60
				halcmd setp parport.0.pin-5-out True
			fi
		done
		vfd.speed-command 0.0
		halcmd setp parport.0.pin-2-out False
		halcmd setp parport.0.pin-5-out False
		setp scale.0.gain 0.99
		;;
	*)
		halcmd setp parport.0.pin-2-out False
		halcmd setp parport.0.pin-5-out False
		;;
esac
exit 0

M102 (using nets):
#!/bin/sh

halcmd show pin

#example usage: M102 P1 (changes variable pitch belt to ratio A)
#uses argument P


#spin_rnge_a is net for range A
#spin_rnge_b is net for range B
#spin_rnge_c is net for range C
#rpm_dn is the valve to make RPM lower
#rpm_up is the valve to make RPM higher


range_request = $1


case $range_request in
	#change to ratio 1
	#while the input for ratio 1 is not true, move RPM down until the input is true
	1)
		while ! [gets spin_rnge_a]; do
			if [gets spin_rnge_c] || [gets spin_rnge_b]
			then
				#start the spindle, unscaled
				vfd.speed-command 60
				sets rpm_dn True
				halcmd show pin
			fi
		done

		#once complete, stop the spindle and set both airmotor valves to off
		vfd.speed-command 0.0
		sets rpm_dn False
		sets rpm_up False
		#set the correct gain for this range
		setp scale.0.gain 0.33
		;;
	#change to ratio 2
	2)
		while ! [gets spin_rnge_b]; do
			if [gets spin_rnge_a]
			then
				vfd.speed-command 60
				sets rpm_up True
			elif [gets spin_rnge_c]
			then
				vfd.speed-command 60
				sets rpm_dn True
			fi
		done
		vfd.speed-command 0.0
		sets rpm_dn False
		sets rpm_up False
		setp scale.0.gain 0.66
		;;

	3)
		while ! [gets spin_rnge_c]; do
			if [gets spin_rnge_a] || [gets spin_rnge_b]
			then
				vfd.speed-command 60
				sets rpm_up True
			fi
		done
		vfd.speed-command 0.0
		sets rpm_dn False
		sets rpm_up False
		setp scale.0.gain 0.99
		;;
	*)
		sets rpm_dn False
		sets rpm_up False
		;;
esac
exit 0

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

More
12 Apr 2020 01:04 #163691 by fungus
Just tried one of the simple examples:
#!/bin/bash
eog /home/myname/linuxcnc/nc_files/message.png
exit 0

No dice. No errors. The path above is the one referenced in my INI. What the heck?

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

More
12 Apr 2020 02:18 #163706 by fungus
I dug into some windows line endings issues, but it changed nothing in the behavior.
I wrote a python script in place of the bash script, same deal.
I'm frustrated and tired, sounds like a good time to sleep and consider spending time on the realtime version later. Wish I could have the last 7 hours back!
Apparently there are some issues with the scripting side, or at least with the way I'm doing it. If anyone has ideas, I'd love to figure out what's wrong for future use cases.

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

More
13 Apr 2020 04:27 #163843 by fungus
Ok, first C program I've ever written. I'm sure there are issues.

Once I get the encoder fitted I can make sure the counts are above a certain value rather than the "spindle_spinning" bit I'm using right now.

One issue I might see happening is if a request comes through for a float RPM (say 40.5RPM), this might freak out the S32? I'm also probably not using it correctly.
component varipitch "Controls the range of a variable pitch belt";

pin in bit spindle_spinning "spindle is turning";
pin in bit range_0 "range 0 sensor";
pin in bit range_1 "range 1 sensor";
pin in bit range_2 "range 2 sensor";
pin in s32 spindle_rpm_req "requested RPM";
pin out bit speed_up "increases range if too low";
pin out bit speed_down "decreases range if too high";

function _ nofp;
license "GPL";
option singleton yes;
;;

#define ZERO_RANGE 1000
#define ONE_RANGE 2500
#define TWO_RANGE 3500

FUNCTION(_) {
	if(spindle_spinning){
		if(spindle_rpm_req <= ZERO_RANGE){
			while(!range_0){
				speed_down = 1;
			}
			speed_down = 0;
			speed_up = 0;
		}
		else if(spindle_rpm_req > ZERO_RANGE && spindle_rpm_req <= ONE_RANGE){
			while(!range_1){
				if(range_0){
					speed_up = 1;
				}
				else if(range_2){
					speed_down = 1;
				}
			}
			speed_down = 0;
			speed_up = 0;
		}
		else if(spindle_rpm_req > ONE_RANGE && spindle_rpm_req <= TWO_RANGE){
			while(!range_2){
				speed_up = 1;
			}
			speed_down = 0;
			speed_up = 0;
		}
		else {
			speed_down = 0;
			speed_up = 0;
		}
	}
}

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

More
16 Apr 2020 02:33 #164104 by fungus
Potential feature creep ahead...

As it sits right now, I am using the gearchange component to handle my spindle backgear. After I get done with this automated belt adjuster, I will need to externally handle the ratios for gearchange.
I see a couple options to combine this.
I have six potential ratios: LOW 1, LOW 2, LOW 3, HIGH 1, HIGH 2, HIGH 3.
For portability reasons, it would be great to not have these ratios hardcoded into the component.

I could either make 6 float input pins (one for each ratio), then one float output (basically letting you set the ratios external to the realtime component)
~OR~
I could use multiple logic outputs that selected external ratios based on HAL logic (I'm still fuzzy on exactly how I would implement this, probably with mux-gen?)

I'm leaning toward the second option. Any experienced perspectives here?
If I need to start a different thread for the current topic of RT component building, please advise.

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

More
16 Apr 2020 09:01 #164122 by rodw
Have a look at lincurve. It may do what you want.

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

More
16 Apr 2020 14:10 #164140 by fungus
Say, that looks very graceful.
So it looks like I could leave my "varipitch" component as a nofp, and use a single s32 out to drive the x of the "lincurve" component.
~OR~
Completely external to the component, I could drive the x of "lincurve" with the incoming RPM request.

I need to do something, however, to limit the spindle speed during these changes. If I use the first option, I can keep sensible spindle request speeds until the belt drive is in the correct ratio, whereas I would be entirely at the mercy of requested RPM and current belt position in the second option (read: potential overdrive condition)

Thank you rodw for the recommendation, and Andy for another great component!

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

More
23 Apr 2020 03:49 #165180 by fungus
Yahoo! Got it working this evening. Not that what I've done is pretty, but would this be something worth packing up for reuse?
The following user(s) said Thank You: tommylight

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

Time to create page: 0.175 seconds
Powered by Kunena Forum