|
Post by alexfish on Sept 23, 2023 23:35:57 GMT 1
So if can picture what in previous post
then to arrays say draw pixel at x,y
OPTION PARSE FALSE int my_array[3][8] = { {1, 2, 3, 4,5,6,7,8},{9, 10, 11, 12 ,13,14,15,16 },{65, 66, 67, 68,69,70,71,72} } start = 2 FOR t = 0 TO 7 STEP 2 ' get the third element , linux goes from 0 to -> so 2 = third element PRINT "xpos " , my_array[2][t] , " ypos " , my_array[2][t+1] NEXT
if relate the to GCODE then
G01 X=* Y=* int my_array[3][8] = { {1, 2, 3, 4,5,6,7,8},{9, 10, 11, 12 ,13,14,15,16 },{65, 66, 67, 68,69,70,71,72} } start = 2 FOR t = 0 TO 7 STEP 2 PRINT "G01 X" , my_array[2][t] , " Y " , my_array[2][t+1] NEXT
'Scale 2
OPTION PARSE FALSE
int my_array[3][8] = { {1, 2, 3, 4,5,6,7,8},{9, 10, 11, 12 ,13,14,15,16 },{65, 66, 67, 68,69,70,71,72} } start = 2 FOR t = 0 TO 7 STEP 2 PRINT "G01 X" , my_array[2][t] , " Y " , my_array[2][t+1] NEXT
'Scale 2
FOR t = 0 TO 7 STEP 2 PRINT "G01 X" , my_array[2][t]*2 , " Y " , my_array[2][t+1]*2 NEXT
so if think , the gui posted , can sit there and can just draw the raw data to the machine(if say machine is on a PI) OR Send the code , say an arduino with grbl on it
in both cases can save it as *.nc
Alex
|
|
|
Post by alexfish on Sept 24, 2023 17:02:04 GMT 1
float arrays examples circular sin/cos OPTION PARSE FALSE ' Pre defined circle LOCAL t = 0 LOCAL r = 15.0 TYPE float LOCAL Scale = 2.0 TYPE float float array[361*2] 'working sin(rad)/cos(rad) float 3 decimal spaces mantis 0.000111 float mantis = 0.000111
in carving need to pass the start position' or vice versa FOR t= 0 TO 360 STEP 2 array[t] = ((float)COS(RAD(t))*r)+mantis array[t+1] = ((float)SIN(RAD(t))*r)+mantis NEXT
FOR t = 0 TO 359 STEP 2 PRINT "X " , array[t], " Y ", array[t+1] NEXT FOR t= 0 TO 360 array[t] = ((float)COS(RAD(t))*r)+mantis array[t+1] = ((float)SIN(RAD(t))*r)+mantis NEXT
FOR t = 0 TO 359 PRINT "X " , array[t], " Y ", array[t+1] NEXT '' Start an end poins now equal &no nan or e to the power f Start 0 degree
X 15.0001 Y 14.9978 X 14.9978 Y 14.991 X 14.991 Y 14.9796 X 14.9796 Y 14.9636
END
X 14.943 Y 14.9636 X 14.9636 Y 14.9796 X 14.9796 Y 14.991 X 14.991 Y 14.9978 X 14.9978 Y 15.0001 359 degres
0 to 359 = 1 to 360 steps crossing points / transition X -0.261675 Y 0.000111 X 0.000111 Y 0.261897 X 0.261897 Y 0.523603
from that now know which part of the array to pick IE push the y down 1 but in general if within 3 decimal point ? for wood carving with a router one needs to be asking them selves a question that is not good enough for steel , as in engineering what possible suggest one buying a $250,000 bit of kit with the $100,000 controller and tools attached X -0.261675 Y -0.261675 X 0.000111 Y 0.000111 X 0.261897 Y 0.261897 Now try the 1 to 360 post seems bitty :: internet keeps dropping last bit the start and end of 1 to 360 at r=15 pixel 1 pixel = 1mm /machine math first x diff 0.0022 y = 0.009 machine general step ratio = 0.002 on lead8 hence the 0.0022 ,one will Not notice the difference on a hobby cnc using stepper motorslast its = 00001 for both X 14.9978 Y 14.991 X 14.991 Y 14.9796 X 14.9796 Y 14.9636 X 14.9636 Y 14.943 end X 14.9796 Y 14.991 X 14.991 Y 14.9978 X 14.9978 Y 15.0001 X 15.0001 Y 0.000111 BR Alex
|
|
|
Post by alexfish on Sept 24, 2023 19:21:17 GMT 1
Quip of the day Youtube man routers the bits gets a micrometer to check the dims , pulls a face not happy the dims , try again , Argh that is better , but still not what he expected , and quote 'this thing is crap!' Then gets a sheet of sand paper , yes he going to varnish it Sanding away ,each pass takes of 0.1mm or 0.05 , Then puts 3 coats of paint or varnish on it What
|
|
|
Post by alexfish on Sept 25, 2023 21:33:51 GMT 1
And So To the cnc bits
The Machine & the controller
most use things like ugs pronta and bCNC , + a micro controller' the "machine" technical term not a device
so you need a computer at some stage , even to program it
a RPI is quite common i can understand the reason but not the logic at this level especially if you use a PI , and yes I got the facility to do so
so that brings up The Machine and the Controller , that be the bit to talk to the machine.
This come to a method called shared memory .c can do strings an values others need to read at what can not do
I did this method at p2 TO p3 stage , in short at this point could not find the bits posted
downloaded the c example and had a problem , now that is sorted. I found the posting
So , the controller , the machine is same type of gui (Code wise )
one geared up as the Server & one the Client , hence the machine gets on the task without interference + can send back info to be seen in the controller ie (in one instance bCNC ) , yet can be interrupted by the controller.
here need only one device in my case raspberry pi4 , other users ,
same go down the ladder to pi zero h or w . they are in same price range of uno/mega , pico = back to the conventional method although it is a bargain
Back Soon
BR Alex
|
|
|
Post by alexfish on Sept 26, 2023 19:26:54 GMT 1
Back to Circles and making float arrays
normal on a small diy cnc is to pec it pec means a bit at a time
here kept to the original R15
pec 5 layers r 15 ; here look to 3 decimal places
sample of each 90 degress
how close to 15 ? results first
'90 X 0.000111 Y -0.261675 '180 X -14.9999 Y -14.9976 '360 X 15.0001 Y 14.9978 <<---- in maths can get rid of the 0001 and the 14.9978 becomes 14.998 and so on . if want definitive MM apply the integer rule at each quadrant '450 X 0.000111 Y -0.261675 '540 X -14.9999 Y -14.9976
OPTION PARSE FALSE ' Pre defined circle LOCAL t = 0 LOCAL r = 15.0 TYPE float LOCAL Scale = 2.0 TYPE float float array[361*2*5] 'working sin(rad)/cos(rad) float 3 decimal spaces mantis 0.000111 float mantis = 0.000111
FOR t= 1 TO 360 * 5 array[t] = ((float)COS(RAD(t))*r)+mantis array[t+1] = ((float)SIN(RAD(t))*r)+mantis NEXT
FOR t = 1 TO 360 * 5 PRINT "X " , array[t], " Y ", array[t+1] NEXT
OPTION PARSE FALSE ' Pre defined circle LOCAL t = 0 LOCAL r = 15.0 TYPE float LOCAL Scale = 2.0 TYPE float float array[361*2*5] 'working sin(rad)/cos(rad) float 3 decimal spaces mantis 0.000111 float mantis = 0.000111
FOR t= 1 TO 360 * 5 array[t] = ((float)COS(RAD(t))*r)+mantis array[t+1] = ((float)SIN(RAD(t))*r)+mantis NEXT
FOR t = 1 TO 360 * 5 PRINT "X " , array[t], " Y ", array[t+1] NEXT
to be finicky , look through the data to see which axis needs to be triggered first
could be x and then y y then x
not much to work out , then examine to angled lines
BR Alex
|
|
|
Post by alexfish on Sept 26, 2023 20:01:00 GMT 1
Stepper motor code wise need a lib that will run without the constraints of built in homing the axis first , can put in late as an option + has acceleration and de-acceleration built in , same alogo's used in grbl. have tested on the arduino , so attempting a port to c and BaCoNise it, I hope From GITHUBKissStepper KEYWORDS ####################################### # Syntax Coloring Map For kissStepper #######################################
####################################### # Datatypes (KEYWORD1) #######################################
kissStepperNoAccel KEYWORD1 kissStepper KEYWORD1 kissState_t KEYWORD1
####################################### # Methods and Functions (KEYWORD2) #######################################
begin KEYWORD2 enable KEYWORD2 disable KEYWORD2 setMaxSpeed KEYWORD2 getMaxSpeed KEYWORD2 setAccel KEYWORD2 getAccel KEYWORD2 getCurSpeed KEYWORD2 prepareMove KEYWORD2 move KEYWORD2 getState KEYWORD2 decelerate KEYWORD2 stop KEYWORD2 setPos KEYWORD2 getPos KEYWORD2 getTarget KEYWORD2 isEnabled KEYWORD2 isMovingForwards KEYWORD2 calcMaxAccelDist KEYWORD2 calcDecelDist KEYWORD2 getAccelDist KEYWORD2 getRunDist KEYWORD2 getDecelDist KEYWORD2 getDistRemaining KEYWORD2 setForwardLimit KEYWORD2 getForwardLimit KEYWORD2 setReverseLimit KEYWORD2 getReverseLimit KEYWORD2
####################################### # Constants (LITERAL1) #######################################
STATE_STOPPED LITERAL1 STATE_STARTING LITERAL1 STATE_SLEW LITERAL1 STATE_ACCEL LITERAL1 STATE_DECEL LITERAL1 BR Alex
|
|
|
Post by alexfish on Sept 27, 2023 0:23:32 GMT 1
Fun Feature, just started Freehand this collects the mouse clicks into a array the save s the data as g01 or and svg Alex Attachments:
|
|
|
Post by alexfish on Sept 27, 2023 8:09:51 GMT 1
To some math functions + finding type of system float
this relates to some of the Circles / interpolation
these will come from geo2.0.bac
this shows how to convert the values to the 3 decimal places text wise
+ check for a NAN ,
some calcs like distance
as can see from the , making arrays... to pass to the machine
and is a work in progress ie getting the right bits of geo2, ie map the geo bits to bits required here
The BB_MAPBOX = map(bits,foo,bar) where are they . here can relate the likes of hometilelon to $HOME
Radius of , in code has
DEF FN OSM_EQ_RADIUS = 6378137.0 in function likes of (lonmin) is the returned floating point value
The examples from geo math(float) to text(string) including
hence can do things like " X 15.000 Y 30.349 X
BR Alex
code as is :: some bits BEARING = angle in degrees :: and some n s e w , cad wise center circle point
cos(calc) .. sin (calc) ..
'Fix Misc Bug in OPEN file = - WRITTING | + READWRITE OPTION PARSE FALSE INCLUDE "curl.bac" USEH #if FLT_RADIX == 2 #define LOG2(x) (ilogb(x)) #else #define LOG2(x) ((int)floor(log2(abs(x)))) #endif ENDUSEH RECORD BB_MAPBOX LOCAL Cx,Cy LOCAL rem$ TYPE STRING LOCAL hometilelon TYPE int LOCAL hometilelat TYPE int LOCAL north TYPE int LOCAL south TYPE int LOCAL west TYPE int LOCAL east TYPE int LOCAL zoom TYPE int LOCAL degmin$ TYPE STRING LOCAL degsec$ TYPE STRING LOCAL lat TYPE double LOCAL lon TYPE double LOCAL Nposy TYPE double LOCAL Eposx TYPE double LOCAL tile$ TYPE STRING LOCAL provider$ TYPE STRING LOCAL seamark$ TYPE STRING LOCAL cache$ TYPE STRING END RECORD
DEF FN ASINH = asinh DEF FN ATAN = atan 'radius at equater DEF FN OSM_EQ_RADIUS = 6378137.0 DEF FN ISNAN = isnan DEF FN DEG2RAD(deg) = (deg * M_PI / 180.0) DEF FN RAD2DEG(rad) = (rad / M_PI * 180.0)
' =================================== FUNCTION LONDEG2LONMIN ( float lon) TYPE STRING ' =================================== LOCAL lonmin[20] TYPE static char LOCAL degrees TYPE int LOCAL minutes TYPE float
degrees = (abs( (lon>0) ? floor(lon) : ceil(lon) )) minutes = ((fabs(lon) - (float)degrees) * 60)
sprintf (lonmin,"%d°%.3f' %s",degrees,minutes,(lon>0) ? "E" : "W")
RETURN lonmin
END FUNCTION
' ================================= FUNCTION LATDEG2LATMIN (float lat) TYPE STRING ' =================================
LOCAL latmin[20] TYPE static char LOCAL degrees TYPE int LOCAL minutes TYPE float
degrees = (abs( (lat>0) ? floor(lat) : ceil(lat) )) minutes = ((fabs(lat) - (float)degrees) * 60)
sprintf (latmin,"%d°%.3f' %s", degrees,minutes,(lat>0) ? "N" : "S") RETURN latmin
END FUNCTION
' ================================= FUNCTION LATDEG2LATSEC(float lat) TYPE STRING ' =================================
LOCAL latsec[20] TYPE static char LOCAL degrees, full_minutes TYPE int LOCAL minutes, seconds TYPE float
degrees = abs( (lat>0) ? floor(lat) : ceil(lat) ) minutes = (fabs(lat) - (float)degrees) * 60 full_minutes = floor(minutes) seconds = (minutes - (float)full_minutes) * 60
sprintf(latsec,"%d°%d'%.2f\" %s", degrees,full_minutes,seconds,(lat>0) ? "N" : "S")
RETURN latsec END FUNCTION
' ================================== FUNCTION LONDEG2LONSEC ( float lon) TYPE STRING ' ==================================
LOCAL lonmin[20] TYPE static char LOCAL degrees, full_minutes TYPE int LOCAL minutes, seconds TYPE float
degrees = (abs( (lon>0) ? floor(lon) : ceil(lon) )) minutes = ((fabs(lon) - (float)degrees) * 60) full_minutes = (floor(minutes)) seconds = ((minutes - (float)full_minutes) * 60)
sprintf(lonmin,"%d°%d'%.2f\" %s",degrees,full_minutes,seconds,(lon>0) ? "E" : "W")
RETURN lonmin
END FUNCTION
' ========================================================= FUNCTION GET_DISTANCE (double lat1, double lon1, double lat2, double lon2) TYPE float ' =========================================================
LOCAL distance = 0 TYPE double LOCAL tmp TYPE double
tmp = sin(DEG2RAD(lat1)) * sin(DEG2RAD(lat2)) + cos(DEG2RAD(lat1)) * cos(DEG2RAD(lat2)) * cos(DEG2RAD(lon2) - DEG2RAD(lon1))
distance = (6371.0 * acos(tmp))
RETURN distance
END FUNCTION
' ======================================================== FUNCTION GET_BEARING(double lat1, double lon1, double lat2, double lon2) TYPE float ' ======================================================== LOCAL bearing, tmp TYPE double
tmp = atan2(sin(DEG2RAD(lon2)-DEG2RAD(lon1)) * cos(DEG2RAD(lat2)), \ cos(DEG2RAD(lat1)) * sin(DEG2RAD(lat2)) - \ sin(DEG2RAD(lat1)) * cos(DEG2RAD(lat2)) * cos(DEG2RAD(lon2)-DEG2RAD(lon1)) )
bearing = ((tmp < 0) ? tmp + M_PI*2 : tmp)
RETURN RAD2DEG(bearing)
END FUNCTION
|
|
|
Post by alexfish on Sept 27, 2023 23:42:33 GMT 1
Tip Of The Day
suppose want to write / code a svgfile in the editor + see all is as written with quoted strings
IE without escape function
Macro Function MkStrs then svg string
USEH #define MkStrs( x ) #x END USEH
LOCAL svg$
svg$ = MkStrs( \ <svg height="100" width="100"> \ <circle cx="50" cy="50" r="40" stroke="black" stroke-width="3" fill="red" /> \ </svg>) PRINT svg$
SAVE svg$ TO "test.svg"
a bit of bacon and no quotes IE bacon$ = "FOR t = 1 TO 100 STEP 1"
USEH #define MkStrs( x ) #x END USEH
bacon$ = MkStrs(FOR t = 1 TO 100 STEP 1)
PRINT bacon$ Have Fun + BR Alex
|
|
|
Post by alexfish on Sept 28, 2023 0:25:35 GMT 1
IF wanting to write direct to a external machine GCODE wise or need info from the machine or trying to find which port is the connection tty* can look here libserialport
|
|
|
Post by alexfish on Sept 28, 2023 21:50:07 GMT 1
|
|
|
Post by alexfish on Sept 29, 2023 16:48:37 GMT 1
Back to float , why return the value of string
The code example
Need to run as is , to find out the difference
sitting here
94.248 94.248 =========================== 94 ===========================
The example code
OPTION PARSE FALSE
USEH #if FLT_RADIX == 2 #define LOG2(x) (ilogb(x)) #else #define LOG2(x) ((int)floor(log2(abs(x)))) #endif ENDUSEH
DEF FN ASINH = asinh DEF FN ATAN = atan 'radius at equater DEF FN OSM_EQ_RADIUS = 6378137.0 DEF FN ISNAN = isnan DEF FN DEG2RAD(deg) = (deg * M_PI / 180.0) DEF FN RAD2DEG(rad) = (rad / M_PI * 180.0)
'======================================================== FUNCTION circu(float geo_diam) TYPE STRING LOCAL cicum[20] TYPE static char float circur = geo_diam*PI
sprintf(cicum,"%.3f",circur) RETURN cicum
END FUNCTION '======================================================== FUNCTION circu2(float geo_diam) TYPE float float circu = geo_diam*PI RETURN circu
END FUNCTION '======================================================== diameter = 30 a$ = circu(diameter)
float circumference = VAL(a$) PRINT a$ PRINT circumference
PRINT "==========================="
circumference= circu2(diameter)
PRINT circumference
PRINT "==========================="
BR Alex
|
|
|
Post by alexfish on Sept 29, 2023 17:13:10 GMT 1
Q:: diameter is a int value
A :: try
float diameter = 30
when approaching next FULL dimension it can be out be nearly 1 if units are mm = 1mm interpolate x & y that could be 2 mm on a machine
112.783 112.783 =========================== 112 ===========================
demo as in '-------------------------------__________________________"
|
|
|
Post by alexfish on Sept 29, 2023 20:59:41 GMT 1
Recap TEXT
here I use Libre Cad do text
From side menu icon select text , suggest write 1 letter at a time IE of the alphabet
set the font size ,select letter , select font, set letter as close to the center x and y axis ,top right quadrant
select the letter , keep the select box as close to the letter as possible,
from menu select tools/modify/explode
from file menu export/svg , save the file say if a capital Q the Q.svg . ok done
open the Q.svg in a editor, will see each bit as a line
And now BaCon copy code into the MKstr(******)
add the "\" to end of each line ,last line not required
if done with bacon gui the visual is better code wise
Now to the actual svg line to gcode GO1 parser . yes only part text is shown Idea been load the file and the parse with the parser code:: + will have to catch the Last x2/y2
Have Fun + BR Alex
USEH #define MkStrs( x ) #x END USEH
Q$ = MkStrs(<line x1="53" y1="98.44444444" x2="53" y2="98.44444444"/> \ <line x1="53" y1="98.44444444" x2="53" y2="98.44444444"/> \ <line x1="53" y1="98.44444444" x2="56.33333333" y2="104.33333333"/> \ <line x1="56.33333333" y1="104.33333333" x2="60.66666667" y2="109.88888889"/> \ <line x1="60.66666667" y1="109.88888889" x2="65.88888889" y2="115"/> \ <line x1="65.88888889" y1="115" x2="72" y2="119.66666667"/> \ <line x1="72" y1="119.66666667" x2="63.77777778" y2="129.33333333"/> \ <line x1="63.77777778" y1="129.33333333" x2="63.77777778" y2="129.33333333"/>)
Q$ = REPLACE$(Q$,CHR$(34),"") Q$ = REPLACE$(Q$,"<line","G01") Q$ = REPLACE$(Q$,"x1=","X") Q$ = REPLACE$(Q$,"y1=","Y") Q$ = REPLACE$(Q$,"/>",NL$)
SPLIT Q$ BY NL$ TO arr$ SIZE dim Q$ = "" FOR t = 0 TO dim -1 res$ = arr$[t] Q$ = Q$ & MID$(res$,1,INSTR(res$,"x2")-2) & NL$ NEXT PRINT Q$
|
|
|
Post by alexfish on Sept 30, 2023 1:48:46 GMT 1
Coming up, next week GDK pixbuf can there are many instances of converting blagh ,blagh binary ,generally as string decimal hex err: what is hex . those are bytes written to memory etc bits to ponder until next week the can do me do. binary decimal then hex$ if want the binary string , put it into a string OK BR Alex 'computer memory/instance graphics 'pixels rgb = 3bytes rgba= 4bytes 'Or instance any 'my binary comparator bit by bit 'why in array , 8bits = 1byte 16bits = 2... and so on int res[8] = {128,64,32,16,8,4,2,1} int byte[8] = { 1, 0, 1, 0,1,1,0,0} LOCAL total PRINT "First byte" FOR t = 0 TO 7 IF res[t] AND byte[t] THEN total = total+ res[t] PRINT 1, " " ; ELSE PRINT 0, " " ; END IF NEXT PRINT PRINT "==================================" PRINT total PRINT "==================================" PRINT HEX$(total) When I was at Scool we were taught how to count in binary there again some say I cant spell , I blame the keyboard , there again the 'spell check' here, pulls me up for 'comparator', leaving school as it is ADDED will see in the result value as a string AC , the actual NUMBER not the string is PRINT 0xAC for purpose of the pixbuf : example from the libgdk.bac create a pixbuf and init all bytes _fill FUNCTION PIXBUF_NEW(int hug_xsize,hug_ysize) TYPE long LOCAL pixy pixy = gdk_pixbuf_new(0,TRUE,8,hug_xsize,hug_ysize) gdk_pixbuf_fill(pixy,0x00000000) RETURN pixy END FUNCTION In Old School from the above 8 bit sprite 1, 0, 1, 0,1,1,0,0
think of it as Switch for a light and have 8 lights now have first row of the spite ON OFF ON OFF ON ON OFF OFF FINAL bit & time for zzzzzzzzzzzzzzzzzzzzzzz. ' bit by bit mask LOCAL on = 1 LOCAL off=0 PRINT on= NOT(off) PRINT on= NOT(on)
|
|