Shared Functions()

Discussions and file drops for Auggie
Ya-Nvr-No
Old Timer
Posts: 188
Joined: Wed Sep 08, 2010 11:15 am

Shared Functions()

Post by Ya-Nvr-No »

Here is a down and dirty function, that can create a spiral with some control of shape and size.
called from the script box passing the variables to it.

Makes all that gcode obsolete/waste of time to do something this simple :D

Art will have videos of how to do all this in time but I wanted to show where the main scripts was and how I accessed it.

You might have to use "Configuration/Screen Tools/Fill Screen" at times as I find sometimes it don't resize on its own.

Code: Select all

global Spiral = function( loops, segment, factorX, factorY ) 
{ 
loops=ToInt(loops);
segment=ToFloat(segment);
factorX=ToFloat(factorX);
factorY=ToFloat(factorY);
	for (t = 0; t < Const.PI2 * loops; t += segment)
	{
		x = t * math.cos(t);
		y = t * math.sin(t);
		x=x*factorX;
		y=y*factorY;
		print("x "+x + "\ty "+y); //this gets outputted to the Log file. Access with a button push on button labeled "Log"
		Engine.RapidTo(x,y,0,0); //actual movement in x,y,z,a
		yield(); //give it an out to look whats going on elsewhere.
	};
};
PS: there are a lots of things I could add to this function.
make sure the values passed are valid.
pass it an vector angle to run at.
location of where i want it if not 0,0,0
But this gives you an idea of a simple useful function to drive motion.
Attachments
spiral3c.JPG
spiral3b.JPG
spiral3a.JPG
spiral3.JPG
Last edited by Ya-Nvr-No on Tue Dec 22, 2015 9:57 am, edited 1 time in total.
Ya-Nvr-No
Old Timer
Posts: 188
Joined: Wed Sep 08, 2010 11:15 am

Re: Shared Functions()

Post by Ya-Nvr-No »

here i was messing around with tangential movement, not ready for prime time due to no IO as of yet, but gives you an idea of how powerful this program can be.

Tangential( 5,7,Z,A );

// and it will rotate A to the next drive point then move there. Still some refinement is needed, but I hope it gives you some more ideas of how scripting can be both useful and pretty easy to write, debug and then implement. :)

Code: Select all

global DELTA = .00100; // number of counts to move before calculating angle
global AFACTOR=(180.0f/Const.PI); // converts radians to axis A counts
global LastAngle=0.0;

global Tangential = function( X,Y,Z,A ) 
 { 
	t0=0.0;t1=0.0;dx=0.0;dy=0.0;d=0.0;
	Lastx=0.0; Lasty=0.0;LastReadBit=0;
	Lastx=	GlobalGet("Axis1CurPos");//get where the x axis is
	Lasty=	GlobalGet("Axis2CurPos");//get where the y axis is
	
	while(1) // loop forever
	{
		yield();
		if (IOPin46) &nbsp;// is Tangential control on?
		{
			if (!LastReadBit)
			{
				Lasta=	GlobalGet("Axis3CurPos");
				global LastAngle = Lasta * (1.0f/AFACTOR);
				print("LastAngle: "+LastAngle);
			}		
			LastReadBit=1;
			// check if we moved far enough to determine an angle			

			dx = (X - Lastx);
			dy = (Y - Lasty);
			d = (dx*dx)+(dy*dy);
	
			if (d > DELTA*DELTA)
			{
				//debug();
				// compute new angle
				t0=ToFloat(sysTime());
				global LastAngle = FindAngle(dx,dy);
				print("LastAngle found: "+ LastAngle);
				t1=ToFloat(sysTime());
				t2=(t1-t0)*1e38;
				Z=(LastAngle*AFACTOR)/100;
				print(format("dx=%.4f",dx)+format(" dy=%.4f",dy)+format("\ttheta=%.4f",LastAngle)+format("\tt1= %.1f",t1)+format("\tt0= %.1f",t0)+format(" &nbsp; Z= %.2f",Z));				
				Engine.RapidTo(xx,yy,Z,A);
				yield();
				Engine.RapidTo(X,Y,zz,A);
				yield();
 &nbsp; &nbsp;			break;
			}
		}
	break;
	}
};

global FindAngle = function( x,y ) 
 { 
	theta = 0.0;
		if (math.abs(x) < math.abs(y))
	{
		theta = math.atan2(y,x);
 &nbsp;		print("\ttheta0 "+theta);//the \t is a tab over command
		if (theta < 0 and theta > 1) {theta=theta+Const.PI;}
 &nbsp;		print("\ttheta1 "+theta);
	}
	else
	{
		theta = Const.PI2-(math.atan2(x,y));
 &nbsp;		print("\t\ttheta2 "+theta);
	}	
	val= theta ;
	return val;
};
Ya-Nvr-No
Old Timer
Posts: 188
Joined: Wed Sep 08, 2010 11:15 am

Re: Shared Functions()

Post by Ya-Nvr-No »

Here is an obscure code segment I found on the Net and then I adapted for Auggie. Computes the angle and distance between two longitude and latitude locations on the earth, within reason I would think. Just something I was trying. Can be either in metric or imperial with a couple of script modifications.
Shows the power of scripting just to compute spacial information.
Functions just compute the data and can then pass back the results. That's pretty much what we want a computer to do. Most of the time they just piss me off. But here is a functional tool that is pretty easy to use and and at least a dozen times better than Basic.
::)

Code: Select all

global Geo_Angle = function( lat1, lon1, lat2, lon2) 
{&nbsp; 
&nbsp; dLon = math.degtorad(lon2-lon1);
&nbsp; y = math.sin(dLon) * math.cos(math.degtorad(lat2));
&nbsp; x = math.cos(math.degtorad(lat1)) * math.sin(math.degtorad(lat2)) - math.sin(math.degtorad(lat1)) * math.cos(math.degtorad(lat2)) * math.cos(dLon);
&nbsp; brng = math.radtodeg(math.atan2(y, x));
&nbsp; return ((brng + 360) % 360);
};

global Geo_Distance = function( lat1, lon1, lat2, lon2) 
{&nbsp; 
&nbsp; if (lat1 == null or lon1 == null or lat2 == null or lon2 == null) 
&nbsp; {
&nbsp; &nbsp; return null;
&nbsp; }
&nbsp; dlat = math.degtorad(lat2-lat1);
&nbsp; dlon = math.degtorad(lon2-lon1);
&nbsp; sin_dlat = math.sin(dlat/2);
&nbsp; sin_dlon = math.sin(dlon/2);
&nbsp; a = sin_dlat * sin_dlat + math.cos(math.degtorad(lat1)) * math.cos(math.degtorad(lat2)) * sin_dlon * sin_dlon;
&nbsp; c = 2 * math.atan2(math.sqrt(a), math.sqrt(1-a));
&nbsp; // 6378 km is the earth's radius at the equator.
&nbsp; // 6357 km would be the radius at the poles (earth isn't a perfect circle).
&nbsp; // Thus, high latitude distances will be slightly overestimated
&nbsp; // To get miles, use 3963 as the constant (equator again)
&nbsp; d = 6378 * c; //metric
&nbsp; //d = 3963.133 * c; //imperial, I did a little tweaking to this value
&nbsp; return d;
};

print("Bearing between Here and There: " + ToFloat(Geo_Angle(41.759,-85.117,44.65,-63.628))+ " Degrees");
print("Distance between Here and There: " + ToFloat(Geo_Distance(41.759,-85.117,44.65,-63.628)) + " Km");
Ya-Nvr-No
Old Timer
Posts: 188
Joined: Wed Sep 08, 2010 11:15 am

Re: Shared Functions()

Post by Ya-Nvr-No »

here was a routine I had created for drawing a circle and cross hairs on the screen.

Code: Select all

global PatternTool = Graphics("Main_TOOL_0");
PatternTool.DrawMode(1);
PatternTool.SetNorm(Vec3(0,0,1));
PatternTool.MoveTo( Vector3(xc,yc,zc));
PatternTool.Refresh();

//Pattern =&nbsp; CirclePat(x,y,z,Hole_dia,Pat_dia,stAngle,Hole_num);
global&nbsp; CirclePat = function(xc,yc,zc,dia)
{
//&nbsp; debug();
Max=100;
//dia=10;
&nbsp; l=2; // 1/2 length of cross line
&nbsp; max=Max; // pass the global to the local
&nbsp; PatternTool.SetNorm(Vec3(0,0,1));
&nbsp; PatternTool.DrawColor( COLOR.Blue );
&nbsp; PatternTool.MoveTo( Vector3(xc-l,yc,zc));
&nbsp; PatternTool.LineTo( Vector3(xc+l,yc,zc));
&nbsp; PatternTool.Refresh();
&nbsp; PatternTool.DrawColor( COLOR.Red );
&nbsp; PatternTool.MoveTo( Vector3(xc,yc+l,zc));
&nbsp; PatternTool.LineTo( Vector3(xc,yc-l,zc));
&nbsp; PatternTool.Refresh();
&nbsp; PatternTool.DrawColor( COLOR.Yellow );
&nbsp; PatternTool.CircleAt( Vec3( xc,yc,zc), dia);
&nbsp; PatternTool.Refresh();
&nbsp; PatternTool.MoveTo( Vector3(xc,yc,zc));
//debug();
&nbsp; PatternTool.SetExtents(Vec3(-max,-max,0),Vec3(max,max,0));
&nbsp; PatternTool.Refresh();
};
//CirclePat(0,0,100,10);
Ya-Nvr-No
Old Timer
Posts: 188
Joined: Wed Sep 08, 2010 11:15 am

Re: Shared Functions()

Post by Ya-Nvr-No »

Don't expect to pick this up quick, We all learn at our own pace and somethings flow at time and other times NOT that when I just yell out "ART!" and shake my head. It will start to click just like gcode, basic, subroutines did in time. Dont give up, build a community and share your functions or your need for one. We all can help and learn from each other.

here is an example of my last Gcode using pretty much all variables to make the attached photo's hatching patterns.
(And no it will not run in Auggie due to the pound variables, just an example for those that like the obscure)
just a couple of changes to the variables and I was cutting. It took me years to get to that ability. And pretty much the only way I program anymore. I have routines for turning, boring, facing, threading I just change a few variables touch off the needed locations and hit RUN.
I HATE GCODE. &nbsp;::) &nbsp;but, I love tools, and scripting is a great tool to learn to use.

I would love to beable to do something like that with an Auggie function
So im just learning too.
Art loved to punish me till we found what worked. Been quite a journey to get to this point. &nbsp; :-X

Code: Select all

O7734
#6 = 95 (mill head angle to work at)
#1 = 8 (distance to cut in X)
#3 = 0 (Start location in X)
#4 = 10(cut feed)
#5 = -.12 (depth)
#9 = 60 (rapid feed)
#10 = 1 (number of pecks)
#11 = 36 (# of pattern lines to cut per 360 degrees)
#14 = .7 (ramp height for Z travel in #1 distances)
#15 = [#5 / #10] (Depth of passes)
#77 = .1 (z up from top of part)
#80 = -10 (start angle per 360 degrees)
#81 = 10 (increment plus or minus)
#82 = 120 (angle to rotate A plus or minus)
g0b#6

g55
m100
g1 x[#3]z[#77] a[0] f#9
m3 s2000

g1 x#3 z#77 y0 a[#3] f#9
M98 P010 L#11
g1z[#77*3]f#9
g1 x[#3] f#9
m5
m30

O010
g0a#80
z#77
#80 =[#80 + #81]
M98 P020 L#10
m99

O020
g0a[#80]
#83 =[#80 + #82]
g1 x[#3] z[#77] a[#80] f#9
g1 z[#15] f#4
g1 x[#1] z[#15+#14] a[#83] f#4
z[#77 + #14] f#9
g0 x[#3] a[#80]
g4p7
g0 a[#80]
g0 z[#77]
m99
Happy Holidays

Edit: Sorry, forgot to add a short video clip of a single pass, And thanks for the kind words, I enjoy retirement.&nbsp; ;D

https://www.youtube.com/watch?v=fc_lQRnoDXE
Attachments
candlestickholder.JPG
Last edited by Ya-Nvr-No on Wed Dec 23, 2015 4:07 am, edited 1 time in total.
GlennD
Old Timer
Posts: 80
Joined: Tue Oct 18, 2011 4:19 pm

Re: Shared Functions()

Post by GlennD »

Ya-Nvr-No
Great stuff.
I was thinking for my first attempt, I was going to adapt some python code to create a tabbed box.
These examples will go along way to help.
Thanks
Glenn
User avatar
ArtF
Global Moderator
Global Moderator
Posts: 4592
Joined: Sun Sep 05, 2010 6:14 am
Contact:

Re: Shared Functions()

Post by ArtF »

nice piece of wood that one......

Art
BobL
Global Moderator
Global Moderator
Posts: 466
Joined: Sun Sep 05, 2010 7:18 am

Re: Shared Functions()

Post by BobL »

its ART.
Gearotic Motion
Bob
DanL
Old Timer
Posts: 362
Joined: Wed Sep 10, 2014 1:35 pm

Re: Shared Functions()

Post by DanL »

again Ya-Nvr-No what would we do without you. Merry xmas dude. ;D
Ya-Nvr-No
Old Timer
Posts: 188
Joined: Wed Sep 08, 2010 11:15 am

Re: Shared Functions()

Post by Ya-Nvr-No »

Photo does not do it justice, I'm sure Mom (96) will enjoy it.
thanks again guys

Ho Ho Ho
Merry Christmas. :D
Attachments
ChrismasGift.JPG
User avatar
ArtF
Global Moderator
Global Moderator
Posts: 4592
Joined: Sun Sep 05, 2010 6:14 am
Contact:

Re: Shared Functions()

Post by ArtF »

Nice Job.

Art
Nate
Old Timer
Posts: 107
Joined: Fri May 08, 2015 6:11 am

Re: Shared Functions()

Post by Nate »

Ya-Nvr-No wrote: ...
I HATE GCODE
...
Terrible for programming, but relatively easy to implement on machines and with a nearly universally supported subset.
User avatar
ArtF
Global Moderator
Global Moderator
Posts: 4592
Joined: Sun Sep 05, 2010 6:14 am
Contact:

Re: Shared Functions()

Post by ArtF »

All true. and yet... I too hate GCode.. lol

Art
Ya-Nvr-No
Old Timer
Posts: 188
Joined: Wed Sep 08, 2010 11:15 am

Re: Shared Functions()

Post by Ya-Nvr-No »

Nate wrote:
Ya-Nvr-No wrote: ...
I HATE GCODE
...
Terrible for programming, but relatively easy to implement on machines and with a nearly universally supported subset.
But yet i find no good laser controller just the boring ones that convert raster image into a series of burn marks.
This whole adventure to me is to drive my laser to do the unique, not to follow Gcode not convert raster into a smoke filled box that produces the same as a commercial system. As a hobbyist I strive to create the unusual and spur my imagination.

If I want to use old school Gcode I have 5 other 4 to 6 axis machine builds here that will make me some cool things. But I am ready to blow my mind with the unimaginable items that can be created only thru creative math and thinking beyond the past. I've been coding well over 30 years even taught at the university level. Just because there is a comfortable old seat don't mean you have to use it. It takes years of coding and using hundreds of different controllers to start to fully understand this PLC Gcode environment is old school but of course perfect for industry. We have to realize we have the computer power now to take it to the next level. You can bet that NASA don't use the same code cause it worked to get them to the moon. Just because that old pickup gets you to Wal-Mart does not stop you from dreaming "if only".

As they say "Think outside the box" Have fun, learn and adapt, as we can not live in the past and to develop any coding imagination we have to have the tools that provide it.

I do not forget this is my hobby and I do this out of pure enjoyment. I spent years as Tool & Die Maker and many more as a Manufacturing & contract programming Engineer, now can apply my experience to get a job done for me and have fun at it.

There are a lot of good coders out there that know macro B or even a few that know macro A too, But in all the years of doing this there is a small subset that can write Macro code, know what keeper relays does and then can add them with Fanuc Fapladder logic code, then add Mcodes and additional hardware I/O for loading & unloading and integrating a turnkey system. I can tell you it is a pita and c++ scripting is a breeze next to that. And the best part "Art at this time is providing it FREE" Go out and price the upgrade to a Fanuc controller to add Macro B or to add an Mcode. Call them up and ask if they can write you a special function? Ask your local machine coder what he charges to add that feature. After he gets done laughing you will realize the ability learning scripting can do for you.
GlennD
Old Timer
Posts: 80
Joined: Tue Oct 18, 2011 4:19 pm

Re: Shared Functions()

Post by GlennD »


So I have it doing a actual squares block("MotionStill"); now instead of a squares with radiused corners.
Ya-Nvr-No's code examples in the are very helpful. Thank you!

I am trying to be patient but sometimes a kid in a candy store has a very hard time.

Looking through the Global Func's and constants didn't see a switch case.&nbsp;



Glenn
P.S. Did look up the Game Monkey and it does mention that no switch is available so blocks of if statements it is.&nbsp; :D
Post Reply

Who is online

Users browsing this forum: No registered users and 76 guests