|
Post by alexfish on Oct 4, 2023 22:13:04 GMT 1
To Gcode or Not
Can now see many SVG cutting files related to design on the web
|
|
|
Post by alexfish on Nov 2, 2023 13:27:58 GMT 1
Just a update REF HUG(3) RE 3.5.3
Now have GOO CANVAS working
Last bits to sort
OPEN GL :: RE gtk GL AREA .
the AREA is now part of the gtk3(API) : hence need to Re Write the Canvas calls to reinstate the "CANVAS GLAREA"
First attempt has failed :
Further Updates relevant to the above posts will be on HUG3 threads
Reason Goo Canvas : possible best canvas for the relevant:: Downer present goo Requires GTK3 + goo2
had look at the Bare libgoocanvas, that now requires GTK4
Also in progress of testing the bits on latest PI OS 'BookWorm'
BR Alex
|
|
|
Post by alexfish on Nov 3, 2023 20:32:38 GMT 1
HUG 3.5.3 almost complete: Release Possible:: Next Week GlArea now in Note Canvas Cairo & Glarea can be used as a WIDGET . Goo = Main Canvas only since all bits are objects Canvases have most of the necessary API imported when defined , hence each type have a get Method IE the preferred draw methods = Native API, so regards DOCS = NONE , = Read the native docs IE cairo see cairo ... anyway Bit of test code to show the Method INCLUDE "hug353.bac"
HUGOPTIONS("NOSCALING") HUGOPTIONS("CANVAS GLAREA")
SUB clear() LOCAL gl gl= GETGLAREA(can) gtk_gl_area_make_current (gl) glClearColor (0, 0, 0, 1) glClear (GL_COLOR_BUFFER_BIT) gtk_gl_area_queue_render(gl) END SUB
SUB TestBits(NUMBER widget) PRINT "Hi Canvas" , MOUSE(0),":", MOUSE(1) LOCAL x, y, i LOCAL angle TYPE FLOATING LOCAL gl gl= GETGLAREA(can) gtk_gl_area_make_current (gl) glLoadIdentity glMatrixMode(GL_PROJECTION) glLoadIdentity glOrtho(0, 600, 550, 0, 0, 1) glMatrixMode(GL_MODELVIEW) glLoadIdentity glTranslatef(0.375, 0.375, 0) glColor3ub(0xFF,0xFF,0x00) glBegin(GL_LINE_LOOP) FOR i = 1 TO 360 angle = 2 * PI * i / 360 x = (200/2)*COS(angle) y = (200/2)*SIN(angle) glVertex2i(MOUSE(0)+(200/2)+x, MOUSE(1)+(200/2)+y) NEXT glEnd gtk_gl_area_queue_render(gl) END SUB win = WINDOW("GLAREA",600,600)
can =GLAREA(600,550)
ATTACH(win,can ,0,50)
but = BUTTON("Clear",100,30) CALLBACK(but,clear) ATTACH(win,but,3,3) CALLBACK(can,TestBits) DISPLAY That's A Wrap Q: Why GOO CANVAS A: GOO CANVAS has built in ANIMATION ++ gtk widgets can be EMBEDDED in the Canvas Hence Goo = Main Canvas only since all bits are objectsQ: How A: HEREAs a foot note Raspi Wise I did code and animated a diy CNC router + using gpio way back in time :: REF used the LIBGFX(GOO CANVAS) + WiringPI Those bits are in the new API 'GOO' wise For Reading See BaConGFXAttachments:
|
|
|
Post by alexfish on Nov 4, 2023 5:08:43 GMT 1
OK Last post GLtext Can use the inbuilt canvas out(gl) Alternate Recommended :: FTGL , it should be in the Repos Quick Bits : reference github.com/frankheckenbach/ftgl'https://github.com/frankheckenbach/ftgl/blob/master/demo/c-demo.c /* FTGLPixmapFont font("Arial.ttf"); font.FaceSize(72); font.Render("Hello World!"); */ +Connection LibreCad :: make Text : export as SVG :: read the svg file: convert data :: pass to machine :: This and other canvasestexture + traceable github.com/matiaslina/font2png/Update : Hershey Font may be in your distro libhersheyfont example code // // hershey-font-example.c - Copyright (C) 2013 Kamal Mostafa <kamal@whence.com> // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along // with this program; if not, write to the Free Software Foundation, Inc., // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. // gcc hersheytest.c -lhersheyfont -o test
#include <hersheyfont.h> #include <stdio.h>
int main( int argc, char **argv ) { const char *render_text = "HELLO";
// // Load a Hershey font with hershey_font_load(). //
const char *fontname = "rowmans"; struct hershey_font *hf = hershey_font_load(fontname); if ( !hf ) { perror(fontname); return 1; }
// // Render each character's line paths with hershey_font_glyph(). //
int x_render_pos = 0;
const char *p; for ( p=render_text; *p; p++ ) {
// get the character c to be rendered int c = *p;
// get the hershey_glyph for character c // and check whether there actually is a glyph for this character struct hershey_glyph *hg = hershey_font_glyph(hf, c); if ( hg->width == 0 ) continue;
printf("# %c\n", c);
// walk the paths-list for this glyph struct hershey_path *hp; for ( hp=hg->paths; hp; hp=hp->next ) { // begin draw path printf("\t"); int i; for ( i=0; i<hp->nverts; i++ ) { short x = hp->verts[i].x + x_render_pos; short y = hp->verts[i].y; printf(" {%d,%d}", x, y); } // end draw path printf("\n"); }
// advance the x_render_pos by the width of this glyph x_render_pos += hg->width; }
// // Destroy the hershey_font with hershey_font_free(). // hershey_font_free(hf);
return 0; } gcc hersheytest.c -lhersheyfont -o test example from term pi@raspberrypi:~ $ gcc hersheytest.c -lhersheyfont -o test pi@raspberrypi:~ $ ./test # H {4,21} {4,0} {18,21} {18,0} {4,11} {18,11} # E {26,21} {26,0} {26,21} {39,21} {26,11} {34,11} {26,0} {39,0} # L {45,21} {45,0} {45,0} {57,0} # L {62,21} {62,0} {62,0} {74,0} # O {84,21} {82,20} {80,18} {79,16} {78,13} {78,8} {79,5} {80,3} {82,1} {84,0} {88,0} {90,1} {92,3} {93,5} {94,8} {94,13} {93,16} {92,18} {90,20} {88,21} {84,21} pi@raspberrypi:~ $ Converting to Bacon ? have not attempted yet:: can start with usec :: then breakdown the bits PRAGMA INCLUDE <hersheyfont.h> PRAGMA LDFLAGS -lhersheyfont OPTION PARSE FALSE
USEC const char *render_text = "HELLO";
// // Load a Hershey font with hershey_font_load(). //
const char *fontname = "rowmans"; struct hershey_font *hf = hershey_font_load(fontname); if ( !hf ) { perror(fontname); return 1; }
// // Render each character's line paths with hershey_font_glyph(). //
int x_render_pos = 0;
const char *p; for ( p=render_text; *p; p++ ) {
// get the character c to be rendered int c = *p;
// get the hershey_glyph for character c // and check whether there actually is a glyph for this character struct hershey_glyph *hg = hershey_font_glyph(hf, c); if ( hg->width == 0 ) continue;
printf("# %c\n", c);
// walk the paths-list for this glyph struct hershey_path *hp; for ( hp=hg->paths; hp; hp=hp->next ) { // begin draw path printf("\t"); int i; for ( i=0; i<hp->nverts; i++ ) { short x = hp->verts[i].x + x_render_pos; short y = hp->verts[i].y; printf(" {%d,%d}", x, y); } // end draw path printf("\n"); }
// advance the x_render_pos by the width of this glyph x_render_pos += hg->width; }
// // Destroy the hershey_font with hershey_font_free(). // hershey_font_free(hf);
END USEC First Attempt + close enough to get the bits for GL fonts 'libhersheyfont.so.0 'libhersheyfont. PRAGMA INCLUDE <hersheyfont.h> PRAGMA LDFLAGS -lhersheyfont OPTION PARSE FALSE
LOCAL render_text$ = "HELLO WORLD"
LOCAL fontname$ = "rowmans" LOCAL hershey_font *hf = hershey_font_load(fontname$) TYPE struct
IF ( NOT(hf) ) THEN perror(fontname$) END END IF
LOCAL x_render_pos = 0
LOCAL p TYPE const char * LOCAL ch
FOR t = 1 TO LEN(render_text$) ch = ASC(MID$(render_text$, t, 1)) LOCAL hershey_glyph *hg = hershey_font_glyph(hf, ch) TYPE struct IF ( hg->width == 0 ) THEN CONTINUE PRINT "* " ,CHR$(ch) LOCAL hershey_path *hp TYPE struct LOCAL i for ( hp=hg->paths; hp; hp=hp->next ) { printf("\t"); for ( i=0; i<hp->nverts; i++ ) { REM the bits short x = hp->verts[i].x + x_render_pos short y = hp->verts[i].y
printf(" {%d,%d}", x, y) } PRINT }
PRINT NEXT
hershey_font_free(hf) Good LUCK + BR Alex List Of Fonts /usr/share/hershey-fonts/astrology.jhf /usr/share/hershey-fonts/cursive.jhf /usr/share/hershey-fonts/cyrilc_1.jhf /usr/share/hershey-fonts/cyrillic.jhf /usr/share/hershey-fonts/futural.jhf /usr/share/hershey-fonts/futuram.jhf /usr/share/hershey-fonts/gothgbt.jhf /usr/share/hershey-fonts/gothgrt.jhf /usr/share/hershey-fonts/gothiceng.jhf /usr/share/hershey-fonts/gothicger.jhf /usr/share/hershey-fonts/gothicita.jhf /usr/share/hershey-fonts/gothitt.jhf /usr/share/hershey-fonts/greek.jhf /usr/share/hershey-fonts/greekc.jhf /usr/share/hershey-fonts/greeks.jhf /usr/share/hershey-fonts/japanese.jhf /usr/share/hershey-fonts/markers.jhf /usr/share/hershey-fonts/mathlow.jhf /usr/share/hershey-fonts/mathupp.jhf /usr/share/hershey-fonts/meteorology.jhf /usr/share/hershey-fonts/music.jhf /usr/share/hershey-fonts/rowmand.jhf /usr/share/hershey-fonts/rowmans.jhf /usr/share/hershey-fonts/rowmant.jhf /usr/share/hershey-fonts/scriptc.jhf /usr/share/hershey-fonts/scripts.jhf /usr/share/hershey-fonts/symbolic.jhf /usr/share/hershey-fonts/timesg.jhf /usr/share/hershey-fonts/timesi.jhf /usr/share/hershey-fonts/timesib.jhf /usr/share/hershey-fonts/timesr.jhf /usr/share/hershey-fonts/timesrb.jhf
|
|
|
Post by alexfish on Dec 25, 2023 11:49:04 GMT 1
From Previous Post The above relate to gcode + communicate with external device IE Arduino to control the stepper drivers Here on a Raspberry PI have gpio pins these pins can be addressed via a mask, so have the advantage of triggering multiple stepper drivers / pins at the same time using ' gpio_put_mask ' Noted: from the Libs PI_GPIO_MASK Small intro to GPIO on PI HEREupdated had a look at linux cnc :: re raspberry pi bits and found some demo code # ------------------outputs----------------- # i use GPIO 2,3,4 for xtep ystep zstep # i use GPIO 12 for spindle motor on # i use GPIO 14,15,18 for xdir ydir zdir
# ------------------inputs----------------- # i use GPIO 17 27 22 for xlim ylim zlim ( used for + and - lims, used for home also )
# gpio pins ( not rpi pins! ) # 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 # 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 (gpio1& 0 not used ) # # 0 0 0 0 0 0 0 0 0 1 0 0 1 1 0 1 0 0 0 0 0 0 0 1 1 1 dir mask (0 means in 1 means out) dec 78855 # 0 1 1 1 1 1 0 1 1 0 0 1 0 0 1 0 1 1 1 1 1 1 1 0 0 0 exclude mask (0 means use 1 means dont use) dec 32918520
loadrt hal_pi_gpio dir=78855 exclude=32918520
# beware gpio 21 and 22 are still reversed, they control rpins 15&50 and are backwards almost everywhere in rpi docs # easy to see and check with 'show pins hal_pi_gpio*
# tjp chg to 3 step dir types,plan on using gekco G540 # was loadrt stepgen step_type=5 ctrl_type=v # make posn loop type loadrt stepgen step_type=0,0,0
# --- begin addf s addf hal_pi_gpio.read base-thread addf stepgen.make-pulses base-thread addf stepgen.capture-position servo-thread addf motion-command-handler servo-thread addf motion-controller servo-thread addf stepgen.update-freq servo-thread addf hal_pi_gpio.write base-thread # --- end addf s
# i use GPIO 2,3,4 for xstep ystep zstep, that's rpin 3,5,7 resp net xstep stepgen.0.step => hal_pi_gpio.pin-03-out net ystep stepgen.1.step => hal_pi_gpio.pin-05-out net zstep stepgen.2.step => hal_pi_gpio.pin-07-out
# i use GPIO 14,15,18 for xdir ydir zdir, that's rpin net xdir stepgen.0.dir => hal_pi_gpio.pin-08-out net ydir stepgen.1.dir => hal_pi_gpio.pin-10-out net zdir stepgen.2.dir => hal_pi_gpio.pin-12-out Found HERENeed your pin out from the terminal Example on PI pi@raspberrypi:~ $ pinout ,--------------------------------. | oooooooooooooooooooo J8 +====== | 1ooooooooooooooooooo PoE | Net | Wi 1o +====== | Fi Pi Model 4B V1.5 oo | | ,----. +---+ +==== | |D| |SoC | |RAM| |USB3 | |S| | | | | +==== | |I| `----' +---+ | | |C| +==== | |S| |USB2 | pwr |hd| |hd| |I||A| +==== `-| |---|m0|---|m1|----|V|-------'
Revision : c03115 SoC : BCM2711 RAM : 4GB Storage : MicroSD USB ports : 4 (of which 2 USB3) Ethernet ports : 1 (1000Mbps max. speed) Wi-fi : True Bluetooth : True Camera ports (CSI) : 1 Display ports (DSI): 1
J8: 3V3 (1) (2) 5V GPIO2 (3) (4) 5V GPIO3 (5) (6) GND GPIO4 (7) (8) GPIO14 GND (9) (10) GPIO15 GPIO17 (11) (12) GPIO18 GPIO27 (13) (14) GND GPIO22 (15) (16) GPIO23 3V3 (17) (18) GPIO24 GPIO10 (19) (20) GND GPIO9 (21) (22) GPIO25 GPIO11 (23) (24) GPIO8 GND (25) (26) GPIO7 GPIO0 (27) (28) GPIO1 GPIO5 (29) (30) GND GPIO6 (31) (32) GPIO12 GPIO13 (33) (34) GND GPIO19 (35) (36) GPIO16 GPIO26 (37) (38) GPIO20 GND (39) (40) GPIO21
POE: TR01 (1) (2) TR00 TR03 (3) (4) TR02
For further information, please refer to https://pinout.xyz/ pi@raspberrypi:~ $ BR Alex
|
|
|
Post by alexfish on Dec 26, 2023 5:18:51 GMT 1
A Bresenham's Circle example
stepper step to mm = 0.02
CONST red = "#FF0000"
SUB drawCircle(double xc, double yc, double x, double y) 'TODO store in array then ' right half ' [anticlock] PIXEL("#FF0000", xc+x, yc+y) SYNC 'PRINT xc+x, ":", yc+y ' [clock] PIXEL("#FFFF00", xc+y, yc+x) SYNC ' [anticlock] PIXEL(red, xc+y, yc-x) SYNC ' [clock] PIXEL("#FFFF00", xc+x, yc-y) SYNC 'left half ' [anticlock] PIXEL(red, xc-x, yc-y) SYNC ' [clock] PIXEL("#FFFF00", xc-y, yc-x) SYNC ' [anticlock] PIXEL(red, xc-y, yc+x) SYNC ' [clock] PIXEL("#FFFF00", xc-x, yc+y) SYNC
'PIXEL(red, x, y)
'PRINT x, ":y ",y
END SUB
REM ------------------------------------- LOCAL ptr SUB circleBres(double xc, double yc, double r)
LOCAL x1 , y2, d TYPE double y2 = r d = 3.0 - 2.0 * r drawCircle(xc, yc, x1, y2) ' WHILE (y2 >= x1) DO INCR ptr INCR x1, 0.02
IF (d > 0) THEN
DECR y2, 0.02 d = d + 4.0 * (x1 - y2) + 10.0 ELSE d = d + 4.0 * x1 + 6.0 END IF drawCircle(xc, yc, x1, y2) 'IF x1 > 45 THEN BREAK WEND
END SUB '=================================== SUB Draw SQUARE("#000000",0,0,800,750,1) SYNC circleBres(150,150,150)
END SUB win = WINDOW("Bresenam", 800, 800, 0) but= BUTTON("Draw",100,35) ATTACH (win,but,6,6) CALLBACK(but,Draw)
can = CANVAS(800,750) ATTACH(win,can,0,50)
DISPLAY
Have put the bits in sequential : Hence last Job is to sort into Arrays : look at the print statements
That will fill in the holidays if your board games make you bored
Have Fun Alex
|
|
|
Post by alexfish on Dec 26, 2023 23:37:18 GMT 1
How do MASKS work
Some BIT 's to Play With :: REF hug.bac
CONST GDK_EXPOSURE_MASK = 1 << 1 CONST GDK_POINTER_MOTION_MASK = 1 << 2 CONST GDK_POINTER_MOTION_HINT_MASK = 1 << 3 CONST GDK_BUTTON_MOTION_MASK = 1 << 4 CONST GDK_BUTTON1_MOTION_MASK = 1 << 5 CONST GDK_BUTTON2_MOTION_MASK = 1 << 6 CONST GDK_BUTTON3_MOTION_MASK = 1 << 7 CONST GDK_BUTTON_PRESS_MASK = 1 << 8 CONST GDK_BUTTON_RELEASE_MASK = 1 << 9 CONST GDK_KEY_PRESS_MASK = 1 << 10 CONST GDK_KEY_RELEASE_MASK = 1 << 11 CONST GDK_ENTER_NOTIFY_MASK = 1 << 12 CONST GDK_LEAVE_NOTIFY_MASK = 1 << 13 CONST GDK_FOCUS_CHANGE_MASK = 1 << 14 CONST GDK_STRUCTURE_MASK = 1 << 15 CONST GDK_PROPERTY_CHANGE_MASK = 1 << 16 CONST GDK_VISIBILITY_NOTIFY_MASK = 1 << 17 CONST GDK_PROXIMITY_IN_MASK = 1 << 18 CONST GDK_PROXIMITY_OUT_MASK = 1 << 19 CONST GDK_SUBSTRUCTURE_MASK = 1 << 20 CONST GDK_SCROLL_MASK = 1 << 21 CONST GDK_ALL_EVENTS_MASK = 0x3FFFFE LOCAL unsigned int mask mask = GDK_POINTER_MOTION_MASK PRINT mask mask = GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK PRINT mask
REM The Point of NOTE NO CHANGE since all BIT,s in ESSENCE are a 'location' see two posts up
mask = GDK_POINTER_MOTION_MASK | GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK PRINT mask
Have Fun
+ BR Alex
|
|
|
Post by alexfish on Dec 27, 2023 4:00:38 GMT 1
you want to see the bits
Well:: improved version : BIT Viewer
CONST GDK_EXPOSURE_MASK = 1 << 1 CONST GDK_POINTER_MOTION_MASK = 1 << 2 CONST GDK_POINTER_MOTION_HINT_MASK = 1 << 3 CONST GDK_BUTTON_MOTION_MASK = 1 << 4 CONST GDK_BUTTON1_MOTION_MASK = 1 << 5 CONST GDK_BUTTON2_MOTION_MASK = 1 << 6 CONST GDK_BUTTON3_MOTION_MASK = 1 << 7 CONST GDK_BUTTON_PRESS_MASK = 1 << 8 CONST GDK_BUTTON_RELEASE_MASK = 1 << 9 CONST GDK_KEY_PRESS_MASK = 1 << 10 CONST GDK_KEY_RELEASE_MASK = 1 << 11 CONST GDK_ENTER_NOTIFY_MASK = 1 << 12 CONST GDK_LEAVE_NOTIFY_MASK = 1 << 13 CONST GDK_FOCUS_CHANGE_MASK = 1 << 14 CONST GDK_STRUCTURE_MASK = 1 << 15 CONST GDK_PROPERTY_CHANGE_MASK = 1 << 16 CONST GDK_VISIBILITY_NOTIFY_MASK = 1 << 17 CONST GDK_PROXIMITY_IN_MASK = 1 << 18 CONST GDK_PROXIMITY_OUT_MASK = 1 << 19 CONST GDK_SUBSTRUCTURE_MASK = 1 << 20 CONST GDK_SCROLL_MASK = 1 << 21 CONST GDK_ALL_EVENTS_MASK = 0x3FFFFE
REM ================================================ FUNCTION DecToBinary$(unsigned int n) TYPE STRING LOCAL binaryNum[1000] LOCAL i LOCAL bin$
WHILE (n > 0) DO binaryNum[i] = n % 2 bin$ = bin$ & STR$(binaryNum[i]) n = n / 2 INCR i WEND RETURN bin$ END FUNCTION
LOCAL bin$ LOCAL unsigned int mask
mask = GDK_SCROLL_MASK bin$= DecToBinary$(mask) PRINT mask PRINT bin$
mask = GDK_POINTER_MOTION_MASK | GDK_KEY_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_SCROLL_MASK PRINT mask bin$= DecToBinary$(mask) PRINT bin$
mask = mask & GDK_SCROLL_MASK PRINT mask bin$= DecToBinary$(mask) PRINT bin$
'BLINK A BIT
mask = GDK_POINTER_MOTION_MASK | GDK_KEY_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_SCROLL_MASK PRINT mask bin$= DecToBinary$(mask) PRINT bin$
mask = mask ^ GDK_BUTTON_RELEASE_MASK
PRINT mask bin$= DecToBinary$(mask) PRINT bin$
mask = mask ^ GDK_BUTTON_RELEASE_MASK
PRINT mask bin$= DecToBinary$(mask) PRINT bin$
Have Fun
BR Alex
|
|
|
Post by alexfish on Dec 29, 2023 6:08:53 GMT 1
Finally:: Filling in the hole Reading and writing complex GCODE Here will see similar functions in HUG and high performance canvas.bac whether it be a circle of an ellipse suggested macro function #1=100 (X RADIUS) #2=50 (Y RADIUS) #3=0 (START ANGLE) #4=50 (NUM OF POINTS) #5=360/#4(ANGLE INCREMENT) #6=0 (COUNTER) #24=#1*COS[#3] #25=#2*SIN[#3] G00 X#24 Y#25 G43 Z10.000 H01 G01 Z1.000 F1000.0 G01 Z-5.000 F100.0 #6=#6+1 #3=#3+#5 WHILE [#6 LE [#4] ] DO1 #24=#1*COS[#3] #25=#2*SIN[#3] G01 X#24 Y#25 F300.0 #6=#6+1 #3=#3+#5 END1
Yes the COS and SIN as use by BaCon BASIC WHILE [#6 LE [#4] ] DO1 #24=#1*COS[#3] #25=#2*SIN[#3] G01 X#24 Y#25 F300.0 #6=#6+1 #3=#3+#5 END1
variables #* WHILE . WHILE loop LE . LE less than equal <= DO1 . DO eg #6=#6+1 INCR END1 . WEND AMAZING no holes to fill in BR Alex
|
|
|
Post by Pjot on Dec 29, 2023 9:20:43 GMT 1
Hi Alex, Looks interesting! Never heard of G-Code before, I mean not before you started talking about it, nor from the LinuxCNC project. BR Peter
|
|
|
Post by alexfish on Dec 29, 2023 22:42:33 GMT 1
Hi Peter and All
Well in GCODE most complex stuff is done in Macro yet these bits are more like Basic
here is part of example with SUB and END SUB Also Has IF and END IF
O0 sub (#1=radius) F100 G0 X-100.000000 Y-100.000000 O1 if [#1 NE 0] G41.1 D#1 O1 endif g90 g1 y-102.000000 G2 I1.095697 J-0.097206 X-99.562609 Y-102.978473 G1 X-97.562609 Y-99.978473 G1 X-91.562609 Y-97.978473 G3 I-1.365837 J-2.212349 X-90.369054 Y-100.648542 G40 G1 X-80.369054 Y-95.648542 O0 endsub F100 G21 O0 call [0] O0 call [-.5] O0 call [.5] O2 sub (#1=radius) F100 G0 X-100.000000 Y-50.000000 O3 if [#1 NE 0] G41.1 D#1 O3 endif
I did a simple parser that changes in then vars + in the code Comments are in brackets
note that G1 = LINE G2 & G3 are arc/ circles
a quick demo of output of previous code
var1=100 (X RADIUS) var2=50 (Y RADIUS) var3=0 (START ANGLE) var4=50 (NUM OF POINTS) var5=360/var4(ANGLE INCREMENT) var6=0 (COUNTER) var24=var1*COS[var3] var25=var2*SIN[var3] G00 Xvar24 Yvar25 G43 Z10.000 H01 G01 Z1.000 F1000.0 G01 Z-5.000 F100.0 var6=var6+1 var3=var3+var5 WHILE [var6 LE [var4] ] DO var24=var1*COS[var3] var25=var2*SIN[var3] G01 Xvar24 Yvar25 F300.0 var6=var6+1 var3=var3+var5 WEND
since here in BaCon & Hug Canvas wise one knows what these functions are doing Hence can interpret what they are and draw the bits + controll the CNC
Not that one can use Uppercase Keywords and Lowercase Keywords + I think says he Linux CNC uses Python/ for the gui much the same as bCNC
BR Alex
|
|
|
Post by alexfish on Dec 30, 2023 6:58:41 GMT 1
HENCE the Title of the thread
and what is relevant is the type of file IE gcode can have .nc .txt .*whatever here it is .bac file or a .hug.bac
To hence my comment To GCODE or NOT when in terms of GCODE macro functions it is
Now to the Raspberry PI the CNC Device Motion controller , of seen Controller & OFFLINE IE GRBL offline controller one does not need this set up if Have Raspberry pi device , exception been the Raspberry PI Pico
as regards the Pico one can program the Pico directly from a Raspberry PI other than the Pico
And So To the controller as in Raspberry PI device with gpio pins
Example of a stepper function
Yes it be Very Raw and does JSN and So we have done the Drawing and calculate the motions relative to the Drawing , call it Cam if you wish
The Example
REM Stepper constants.
CONST stepper_pin_1A = 12 CONST stepper_pin_1B = 13 CONST stepper_pin_2A = 14 CONST stepper_pin_2B = 15 CONST stepper_steps_per_revolution = 200 CONST stepping_mode = 1 DECLARE speed = 20
REM ========================================== FUNCTION INIT_STEPPER(NUMBER stepper, int pin1, int pin2,int pin3,int pin4, int stepsrpm,int stepmode)
RETURN TRUE
END FUNCTION
REM ========================================== SUB SETSPEED(NUMBER stepper,int stepspeed)
END SUB
REM ========================================== SUB ROTATE_STEPPER(NUMBER stepper, double steprot) REM ========================================== END SUB
REM ========================================== SUB RELEASE(NUMBER stepper)
END SUB
REM MAIN
LOCAL stepper
REM Initialise the stepper INIT_STEPPER (stepper, stepper_pin_1A, stepper_pin_1B, \ stepper_pin_2A, stepper_pin_2B, \ stepper_steps_per_revolution, stepping_mode)
SETSPEED(stepper, speed)
REM test stepper WHILE (1) DO REM Rotate 3/4 of a turn. ROTATE_STEPPER(stepper, 270) SLEEP 500
REM Now rotate these many steps in the oposite direction ROTATE_STEPPER (stepper, -45) SLEEP 500
REM Increase the speed and rotate 360 degrees speed = 50 SETSPEED(stepper, speed) ROTATE_STEPPER(stepper, 360) /* Release the coils and sleep for a while. You can check that the coils are not energised by moving the rotor manually: there should be little resistance. */ RELEASE(stepper) SLEEP 4000
REM Decrease the speed speed = 15 SETSPEED(stepper, speed) WEND
Back Soon + BR Alex
|
|
|
Post by alexfish on Dec 30, 2023 7:12:39 GMT 1
Troubling Shooting
True
I once owned a CNC machine , bit of a Beast in terms of CNC
Anyway it broke down
Engineer arrives to fix it
Engineer says this is the problem
I say EH , that bit is a Sinclair QL board
|
|
|
Post by alexfish on Dec 30, 2023 15:28:01 GMT 1
Q: mentioned, gpio masking to interpolate the axis A: WiringPi
void digitalWriteByte (int value) ; This writes the 8-bit byte supplied to the 8 GPIO pins. It’s the fastest way to set all 8 bits at once to a particular value, although it still takes twi write operations to the GPIO hardware.
Applied use stepper drive 4988 or similar can be configured to use 1 pin to step it
'3axis squence 'enable pins LOCAL steppers_enable[3] = {0, 0, 0} TYPE int 'direction pins LOCAL steppers_direction[3] = {0 ,0 , 0} TYPE int 'step pins LOCAL steppers_step [3] = {0, 0, 0} TYPE int
HTH alex
|
|
|
Post by alexfish on Dec 30, 2023 19:41:17 GMT 1
|
|