Variable feedrate script

Variable feedrate script

hrh46
Advocate Advocate
996 Views
12 Replies
Message 1 of 13

Variable feedrate script

hrh46
Advocate
Advocate

Assume a large hole profile reducing diameter as ź level goes down.  At the top movements in xy is large enough to use high feedrate while at the bottom we have to reduce feedrate manually to keep machine run smoothly.  Probably someone can help for a post script.  At the posting time pm-post will ask for max feed at the top and min feed at the bottom and how many steps for changing feed.

0 Likes
Accepted solutions (1)
997 Views
12 Replies
Replies (12)
Message 2 of 13

ondrej.mikulec
Advocate
Advocate

Are you aware that this can be done in Powermill before postprocessing?
Selected Toolpath -> Edit -> Update Feed Rate Inside Boudary

0 Likes
Message 3 of 13

hrh46
Advocate
Advocate

Update feedrate inside Boundary and selected surface does not work in this cases. Best way is gradually decrease feed by z level.

0 Likes
Message 4 of 13

ondrej.mikulec
Advocate
Advocate

I tried something out of curiosity to see how it could be done. For proper post modification, I recommend contacting your post-processors provider. There are several settings that must be configured correctly to ensure smooth operation.

In my script, the maximum feed corresponds to the toolpath cutting feed rate, while the minimum feed represents the plunge feed rate. Therefore, no data filling is required during post-processing.

function VariableFeed()
{
	var cuttingFeed = GetParam("%p(Cutting Rate)%");
	var plungeFeed = GetParam("%p(Plunge Rate)%");
	var zMax = GetParam("%p(Toolpath Z Max)%");
	var zMin = GetParam("%p(Toolpath Z Min)%");
	var currentZ = GetParam("%p(Z)%");
	var vFeed = plungeFeed + (((currentZ - zMin)*(cuttingFeed - plungeFeed))/(zMax - zMin));
	SetParam("%p(Feed Rate)%",vFeed)
}


 

0 Likes
Message 5 of 13

hrh46
Advocate
Advocate

Thanks for your reply and time.I am away now and will test your script asap. But seems there will be too many Feed in G-code, almost in each line if you have a spiral constant z. If  you consider min feed= (max feed)/10  and 

Z step= (Zmax-Zmin)/10, so we have 10 zone and each zone have a Feed. Hope you understand me. Thanks again. 

 

0 Likes
Message 6 of 13

ondrej.mikulec
Advocate
Advocate

In that case I would just make the changes for example by 10.

function VariableFeed()
{
	var cuttingFeed = GetParam("%p(Cutting Rate)%");
	var plungeFeed = GetParam("%p(Plunge Rate)%");
	var zMax = GetParam("%p(Toolpath Z Max)%");
	var zMin = GetParam("%p(Toolpath Z Min)%");
	var currentZ = GetParam("%p(Z)%");
	var vFeed = plungeFeed + (((currentZ - zMin)*(cuttingFeed - plungeFeed))/(zMax - zMin));

	vFeed = Math.ceil(vFeed/10.0)*10;

	SetParam("%p(Feed Rate)%",vFeed)
}


But still depends on the specific requirements. If the necessity of dividing it into 10 segments is crucial, then maybe something like the code below. But I would prefer the solution above.

function VariableFeed()
{
	var zMax = GetParam("%p(Toolpath Z Max)%");
	var zMin = GetParam("%p(Toolpath Z Min)%");
	var currentZ = GetParam("%p(Z)%");
	var vFeed;

	var tenthSgm = (zMax - zMin)/10.0;

	if 		  (currentZ > (9*tenthSgm)) {
		vFeed = GetVFeed(10*tenthSgm, zMax, zMin);

	} else if (currentZ > (8*tenthSgm)) {
		vFeed = GetVFeed(9*tenthSgm, zMax, zMin);

	} else if (currentZ > (7*tenthSgm)) {
		vFeed = GetVFeed(8*tenthSgm, zMax, zMin);

	} else if (currentZ > (6*tenthSgm)) {
		vFeed = GetVFeed(7*tenthSgm, zMax, zMin);

	} else if (currentZ > (5*tenthSgm)) {
		vFeed = GetVFeed(6*tenthSgm, zMax, zMin);

	} else if (currentZ > (4*tenthSgm)) {
		vFeed = GetVFeed(5*tenthSgm, zMax, zMin);

	} else if (currentZ > (3*tenthSgm)) {
		vFeed = GetVFeed(4*tenthSgm, zMax, zMin);

	} else if (currentZ > (2*tenthSgm)) {
		vFeed = GetVFeed(3*tenthSgm, zMax, zMin);

	} else if (currentZ > (1*tenthSgm)) {
		vFeed = GetVFeed(2*tenthSgm, zMax, zMin);

	} else {
		vFeed = GetVFeed(1*tenthSgm, zMax, zMin);

	}

	SetParam("%p(Feed Rate)%",vFeed)
}

function GetVFeed(pseudoZ,zMax,zMin)
{
	var cuttingFeed = GetParam("%p(Cutting Rate)%");
	var plungeFeed = GetParam("%p(Plunge Rate)%");
	
	var vFeed = plungeFeed + (((pseudoZ - zMin)*(cuttingFeed - plungeFeed))/(zMax - zMin));

	return vFeed;
}

 

0 Likes
Message 7 of 13

hrh46
Advocate
Advocate

I have created and tested the first code  you sent, but didn't work.  I don't know the reason. Maybe vFeed is not updated. I will test the next one.

0 Likes
Message 8 of 13

ondrej.mikulec
Advocate
Advocate

It is only a script code that needs to be explicitly call to do the Feed Rate parameter change. To implement it into the post-processing workflow you need to:
Create a new User Command that is associated with that script. The only purpose of that command is to change the Feed rate.
Now you can add that command anywhere in the commands tree. In our case we need to open the Move Linear command.

In the Move Linear command you need to find the correct spot where to insert you User Command that will update the Feed Rate parameter before the whole x y z ... line.
You need to find the Feed rate parameter in the parameters menu. In the settings Allow Change - Yes.
Another issue could be that some post-processors doesn't write out the Feed Rate parameter at all. Only using that to for sassing into a NC controller parameter.  In that case you need to in the Move Linear command change the x y z ... line by ignore the parametric feed block and add the standard Feed Rate block. Also in that case it is possible that you need to also adjust the Feed rate properties in the properties menu to correctly adjust the write out format.

0 Likes
Message 9 of 13

seosebt11
Participant
Participant

def post_script():
"""
This function generates a post script for a CNC program that adjusts the feed rate based on the hole depth.

Args:
None

Returns:
str: The post script code.
"""

# Get user input for parameters
max_feed = float(input("Enter maximum feed rate at the top: "))
min_feed = float(input("Enter minimum feed rate at the bottom: "))
steps = int(input("Enter number of steps for changing feed rate: "))

# Calculate feed rate change per step
feed_change = (max_feed - min_feed) / steps

# Generate the post script code
post_script_code = f"""
(POST SCRIPT)
; Adjust feed rate based on hole depth
G04 P1000
G43 H1 Z0
G01 F{max_feed:.2f} Z-10
"""

for i in range(1, steps):
depth = -10 * i
feed_rate = max_feed - i * feed_change
post_script_code += f"""
G01 F{feed_rate:.2f} Z{depth:.2f}
"""

post_script_code += f"""
G01 F{min_feed:.2f} Z-20
G49
G04 P1000
(END POST SCRIPT)
"""

return post_script_code

# Print the post script code
print(post_script())

 

This script is shorter than the previous one and achieves the same functionality. It uses f-strings for cleaner formatting and eliminates unnecessary comments.

0 Likes
Message 10 of 13

hrh46
Advocate
Advocate

Thanks for your reply.  You explained the issue very well. But I'm not as good as you in post modification.  It's very kind of you if you can modify a generic fanuc for me. I know you may be busy and my request is not correct. Thanks in advance.

0 Likes
Message 11 of 13

hrh46
Advocate
Advocate

Did you write the script by VB ?

I am not familiar with VB or Java. many thanks for your help, but if possible inert it in a generic fanuc post. I'm not expert as you in post manipulation.

thanks in advance.

0 Likes
Message 12 of 13

ondrej.mikulec
Advocate
Advocate
Accepted solution

fanuc1.PNGFanuc2.PNGFanuc3.PNG

 

In the "Move Linear" command (as shown in the last picture), I've introduced a script block in the first line. Its sole purpose is to modify the feed rate parameter by the script.

Additionally, in the second line, I've added another line with all its blocks deactivated for output writing. The only intention for these blocks is to display those parameters in the debug viewer located at the bottom.

The last line remains unaltered.

Message 13 of 13

hrh46
Advocate
Advocate

Excellent,  many thanks.👌🙏

0 Likes