Page 1 of 4
Shared Functions()
Posted: Tue Dec 22, 2015 8:28 pm
by Amazon [Bot]
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
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.
Re: Shared Functions()
Posted: Tue Dec 22, 2015 9:14 pm
by Amazon [Bot]
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) // 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(" Z= %.2f",Z));
Engine.RapidTo(xx,yy,Z,A);
yield();
Engine.RapidTo(X,Y,zz,A);
yield();
break;
}
}
break;
}
};
global FindAngle = function( x,y )
{
theta = 0.0;
if (math.abs(x) < math.abs(y))
{
theta = math.atan2(y,x);
print("\ttheta0 "+theta);//the \t is a tab over command
if (theta < 0 and theta > 1) {theta=theta+Const.PI;}
print("\ttheta1 "+theta);
}
else
{
theta = Const.PI2-(math.atan2(x,y));
print("\t\ttheta2 "+theta);
}
val= theta ;
return val;
};
Re: Shared Functions()
Posted: Tue Dec 22, 2015 9:45 pm
by Amazon [Bot]
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)
{
dLon = math.degtorad(lon2-lon1);
y = math.sin(dLon) * math.cos(math.degtorad(lat2));
x = math.cos(math.degtorad(lat1)) * math.sin(math.degtorad(lat2)) - math.sin(math.degtorad(lat1)) * math.cos(math.degtorad(lat2)) * math.cos(dLon);
brng = math.radtodeg(math.atan2(y, x));
return ((brng + 360) % 360);
};
global Geo_Distance = function( lat1, lon1, lat2, lon2)
{
if (lat1 == null or lon1 == null or lat2 == null or lon2 == null)
{
return null;
}
dlat = math.degtorad(lat2-lat1);
dlon = math.degtorad(lon2-lon1);
sin_dlat = math.sin(dlat/2);
sin_dlon = math.sin(dlon/2);
a = sin_dlat * sin_dlat + math.cos(math.degtorad(lat1)) * math.cos(math.degtorad(lat2)) * sin_dlon * sin_dlon;
c = 2 * math.atan2(math.sqrt(a), math.sqrt(1-a));
// 6378 km is the earth's radius at the equator.
// 6357 km would be the radius at the poles (earth isn't a perfect circle).
// Thus, high latitude distances will be slightly overestimated
// To get miles, use 3963 as the constant (equator again)
d = 6378 * c; //metric
//d = 3963.133 * c; //imperial, I did a little tweaking to this value
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");
Re: Shared Functions()
Posted: Tue Dec 22, 2015 9:56 pm
by Amazon [Bot]
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 = CirclePat(x,y,z,Hole_dia,Pat_dia,stAngle,Hole_num);
global CirclePat = function(xc,yc,zc,dia)
{
// debug();
Max=100;
//dia=10;
l=2; // 1/2 length of cross line
max=Max; // pass the global to the local
PatternTool.SetNorm(Vec3(0,0,1));
PatternTool.DrawColor( COLOR.Blue );
PatternTool.MoveTo( Vector3(xc-l,yc,zc));
PatternTool.LineTo( Vector3(xc+l,yc,zc));
PatternTool.Refresh();
PatternTool.DrawColor( COLOR.Red );
PatternTool.MoveTo( Vector3(xc,yc+l,zc));
PatternTool.LineTo( Vector3(xc,yc-l,zc));
PatternTool.Refresh();
PatternTool.DrawColor( COLOR.Yellow );
PatternTool.CircleAt( Vec3( xc,yc,zc), dia);
PatternTool.Refresh();
PatternTool.MoveTo( Vector3(xc,yc,zc));
//debug();
PatternTool.SetExtents(Vec3(-max,-max,0),Vec3(max,max,0));
PatternTool.Refresh();
};
//CirclePat(0,0,100,10);
Re: Shared Functions()
Posted: Tue Dec 22, 2015 10:27 pm
by Amazon [Bot]
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. ::) 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. :-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. ;D
https://www.youtube.com/watch?v=fc_lQRnoDXE
Re: Shared Functions()
Posted: Tue Dec 22, 2015 11:22 pm
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
Re: Shared Functions()
Posted: Wed Dec 23, 2015 1:43 am
by ArtF
nice piece of wood that one......
Art
Re: Shared Functions()
Posted: Wed Dec 23, 2015 4:31 am
by BobL
its ART.
Re: Shared Functions()
Posted: Wed Dec 23, 2015 4:42 am
by DanL
again Ya-Nvr-No what would we do without you. Merry xmas dude. ;D
Re: Shared Functions()
Posted: Wed Dec 23, 2015 5:01 pm
by Amazon [Bot]
Photo does not do it justice, I'm sure Mom (96) will enjoy it.
thanks again guys
Ho Ho Ho
Merry Christmas.
