|
Post by mikewilsonfletcherok on Apr 5, 2024 19:53:27 GMT -5
Good internet time greating of the day to you as you read this. I have been exposed to and used Liberty Basic for roughly 27 years now since 1997 and I know it's power is pretty far out there way above expectations of most programmers who arent looking to control hardware in minimum codesets. I learned of its power back when Pseudo Code was still taught in the classroom back before structure was "common sense" to programmers. Tonight I experience a "Wow" moment with LB. I wrote a program in 130 lines of code this week, now 172, that will load a default image "cutimage.bmp" 480x640 pixels that can generate a 5 inch by 9 inch set of lines in G-Code to run my archaic CNC plasma cutter. Seriously, I'm less than 100 lines of code away from having a very simple CNC Plasma Cutter G-Code generator that can cut 5x9 inch plates, and I'm temporarly stuck trying to figure out how to open a custom bitmap. The most important part is I am literally using an extremely easy to use language to write CNC software. Have any of you ever stopped to think, "Carl really smashed the crap out of this ball and sent it a mile in this ballgame"? I'm still fluent in 13 programming languages for multiple uses web, CGI, database, GUI/Linux, GUI/Windows, command line (BSD, DOS, Linux, Windows). Every now an then someone hits me with a windows challenge, and now I am programming a CAM program on a standalone Windows PC connected to an archaic Plasma cutter, but Liberty Basic made a workable example in 18 minutes of FreeForm and now a shareable example in less than 6 hours of working time. Do any of you get stuck thinking "oh my gosh, that was too easy" --Mike Wilson Fletcher, OK P.S. For the record, I will share this code freely when I don't think it will break a computer or machine.
|
|
|
Post by tenochtitlanuk on Apr 6, 2024 4:00:27 GMT -5
Hi Mike Welcome( back) I agree entirely on LB's ease of use and utility especially in applications involving interfacing to hardware. I look forward to more details of the plasma cutter interface. It's something I've been very tempted to play with.
|
|
|
Post by mikewilsonfletcherok on Apr 26, 2024 14:47:47 GMT -5
I have a working simple CAD program that does line commands on an 8x8 inch plate. It's not fancy, but it is clicky and I have been able to create real work with it. I need to figout out how to attach a source file and jpg image to share this.
|
|
|
Post by mikewilsonfletcherok on Apr 26, 2024 14:49:33 GMT -5
This is the actual sign fronts I made on the CNC plasma cutter using my own G-Code generator. Now to attach the current level of the code for you to tinker with.
|
|
|
Post by Rod on Apr 27, 2024 4:14:03 GMT -5
Nicely written code. I wish I had a CNC machine to play. If you search you will find some examples of accessing the contents of .bmp files and manipulating or finding the color. That might let you extract shapes or intersects automatically.
|
|
|
Post by tenochtitlanuk on Apr 27, 2024 14:48:35 GMT -5
I look forward to hearing more! My last experience with 2D plotters was with Acorn/BBC computers 40 years ago. Image format then was HPGL. I've since played a bit creating svg vector files programmatically in LB, but only for screen display- and also to run on home-built egg-plotters. ( see link ) I use InkScape, which can convert bitmap images to vector dxf, hpgl, etc. I've also experimented with simplifying bitmap outlines and tracing them as vectors. Is your intention to trace outlines automatically? A lot of your project therefore resonates with me. Perhaps I can justify getting hold of a CNC laser-cutter or CNC router... I'm not up to building one now.
|
|
|
Post by mikewilsonfletcherok on Apr 27, 2024 17:20:18 GMT -5
Nicely written code. I wish I had a CNC machine to play. If you search you will find some examples of accessing the contents of .bmp files and manipulating or finding the color. That might let you extract shapes or intersects automatically. Thank you for the compliment on code. I try to stop every few versions and fix formatting, variable names and comment accurately. I was specifically looking to avoid automated because I'm not overly familiar with G-Code and I am dealing huge margin of error with 1/8" accuracy and I want to learn more about G-Code other than uploading and downloading files at converter sites. I've already ran into the stray pixel errors were a cut point becomes off the table and that can be a headache. Hopefully I will be able to control the port and use a cable to start doing design and cutting in one window, not 4 programs.
|
|
|
Post by mikewilsonfletcherok on Apr 27, 2024 17:39:07 GMT -5
I look forward to hearing more! My last experience with 2D plotters was with Acorn/BBC computers 40 years ago. Image format then was HPGL. I've since played a bit creating svg vector files programmatically in LB, but only for screen display- and also to run on home-built egg-plotters. ( see link ) I use InkScape, which can convert bitmap images to vector dxf, hpgl, etc. I've also experimented with simplifying bitmap outlines and tracing them as vectors. Is your intention to trace outlines automatically? A lot of your project therefore resonates with me. Perhaps I can justify getting hold of a CNC laser-cutter or CNC router... I'm not up to building one now. I am specfically looking for manual plotting using short lines. There are countless converters out there that will plot images into DXF files, but I'm looking to convert to G-Code in the shortest way possible and a point and click program is the easiest. I've tried converting any image to DXF, importing that into my CAD program, exporting that to G-Code, and then auditing that line by line because there are so many unintennded actions or commands it is rediculous. So this really solves my problem in the easiest manner.Also by performing all the manual controls, it makes it easier to explain CNC tasks using visual representation. I smashed out a lot of code last night, and even had the print function working to create a paper copy of the graphics box which is a unbelieveble simple native function. In the future I might look at other options for importing G-Code or being able to send raw G-Code to a plasma cutter directly. I'm ready to start opening the ports and playing with actually talking directly to the plasma cutter.
|
|
|
Post by Brandon Parker on Apr 28, 2024 6:46:33 GMT -5
Mike, You have a nice starting point here...
I would suggest you clear the Graphic Box before loading the image.
So this section here:
[main.Menu.File.LoadImage] 'use file image to load a bitmap named "CUTIMAGE" FILEDIALOG "OPEN FILE", "*.bmp", fileName$ 'error check for "Cancel" button in filedialog IF fileName$ ="" THEN WAIT ' zero toolpath positions startXTorchPos=0 startYTorchPos=0 isFeedRateSet=0 'clear the whole GCode window PRINT #main.GCode, "!CLS" PRINT #main.GCode, "("; fileName$;")" LOADBMP "CUTIMAGE", "";fileName$ PRINT #main.Graphics, "drawbmp CUTIMAGE 0 0; flush" WAIT
Would be changed to this...where a "CLS" is placed in the Graphic Box command just before the "DrawBmp" command.
[main.Menu.File.LoadImage] 'use file image to load a bitmap named "CUTIMAGE" FILEDIALOG "OPEN FILE", "*.bmp", fileName$ 'error check for "Cancel" button in filedialog IF fileName$ ="" THEN WAIT ' zero toolpath positions startXTorchPos=0 startYTorchPos=0 isFeedRateSet=0 'clear the whole GCode window PRINT #main.GCode, "!CLS" PRINT #main.GCode, "("; fileName$;")" LOADBMP "CUTIMAGE", "";fileName$ PRINT #main.Graphics, "cls; drawbmp CUTIMAGE 0 0; flush" WAIT
Not only will this clear the Graphic Box of any old image used, but it also removes all flushed segments and allows the memory they consumed to be released.
{:0)
Brandon R. Parker
|
|
|
Post by mikewilsonfletcherok on Apr 29, 2024 21:27:47 GMT -5
Thats a great point. Thank you for the help on that one. I just added it in. Little things like that will eventually take a toll on the old machine I will be moving this to. Right now I'm battling a UART serial port with LB that is picky about when it accepts commands. I don't get it, it will open the connection 50 times, and then randomly accept a command. Right now I can create stable G-Code and run it on a CNC plasma cutter using Mach3 commercial software, but I'm looking to simplify everything into a 1 stop shop. I'm just hoping to send the textbox commands out the USB/COM port and control the machine directly. Once I get this part, then I can start advancing the software into more advanced functions.
|
|
|
Post by Rod on Apr 30, 2024 1:46:43 GMT -5
Be sure to have a browse here before you go much further. It covers the serial port and issues in Liberty. alycesrestaurant.com/lbpe/AccessingSerialPort.htmlKeeping pace and breathing are likely the issues. Keep the port open , don't open and close it. Send an action but be aware of the time the cnc machine is likely to take to complete it and send you any response.
|
|
|
Post by mikewilsonfletcherok on Apr 30, 2024 20:23:53 GMT -5
That clarified a ton for me. It wasn't too far off from what I already knew and had been using, but the order of my opening statement was wrong causing most of my problems. Right now and going to smash together something that will allow me to send and recieve data and once I have that, I'll start looking at what this controller wants for input. It's a big box with a little one of these controllerin it.
|
|
|
Post by mikewilsonfletcherok on Apr 30, 2024 21:51:17 GMT -5
' set all the variables first
comportOpen=0
raw.Port$="COM4"
raw.Baud$="115200"
raw.Data$="N"
raw.Parity$="8"
raw.StopBits$="1"
raw.Options$="ds0,cs0,rs"
comPortToOpen$ ="";raw.Port$;":";raw.Baud$;",";raw.Data$;",";raw.Parity$;",";raw.StopBits$;",";raw.Options$
comPort$(1) = "COM4"
comPort$(2) = "COM2"
comPort$(3) = "COM3"
comPort$(4) = "COM4"
baudRate$(1) = "9600"
baudRate$(2) = "19200"
baudRate$(3) = "38400"
baudRate$(4) = "57600"
baudRate$(5) = "115200"
dataBits$(1) = "N"
partiy$(1)= "8"
stopBits$(1 )= "1"
options$ = "ds0,cs0,rs"
[setup.terminal.Window]
nomainwin
WindowWidth = 840
WindowHeight = 400
UpperLeftX=int((DisplayWidth-WindowWidth)/2)
UpperLeftY=int((DisplayHeight-WindowHeight)/2)
'-----Begin GUI objects code
TexteditorColor$ = "white"
ListboxColor$ = "white"
TextboxColor$ = "white"
texteditor #terminal.recievedRawDatatextedit, 5, 132, 820, 205
listbox #terminal.comPortList, comPort$(, [comPortSelect], 5, 5, 100, 20
listbox #terminal.baudRateList, baudRate$(, [baudRateSelect], 110, 5, 100, 20
listbox #terminal.dataBitsList, dataBits$(, [dataBitsSelect], 215, 5, 100, 20
listbox #terminal.partiyList, partiy$(, [paritySelect], 320, 5, 100, 20
listbox #terminal.stopBitsList, stopBits$(, [stopBitsSelect], 425, 5, 100, 20
textbox #terminal.options, 530, 5, 100, 20
button #terminal.openPortButton,"Open Port",[openPort], UL, 640, 2, 90, 25
button #terminal.closePortButton,"Close Port",[closePort], UL, 735, 2, 90, 25
statictext #terminal.commandToSendLabel, "Command To Send", 5, 47, 117, 20
textbox #terminal.commandToSendBox, 130, 42, 500, 25
button #terminal.sendCommandButton,"Send Command",[sendCommand], UL, 640, 37, 185, 25
statictext #terminal.recievedRawDataLabel, "Recieved Raw Data", 5, 102, 121, 20
'-----End GUI objects code
open "Serial Terminal for testing" for window_nf as #terminal
print #terminal, "font ms_sans_serif 10"
print #terminal, "trapclose [quit.terminal]"
'load our presets
print #terminal.comPortList, "select "; raw.Port$
print #terminal.baudRateList, "select "; raw.Baud$
print #terminal.dataBitsList, "select "; raw.Data$
print #terminal.partiyList, "select "; raw.Parity$
print #terminal.stopBitsList, "select "; raw.StopBits$
print #terminal.options, "";options$
[terminal.inputLoop] 'wait here for input event
wait
[comPortSelect] 'Perform action for the listbox named 'comPortList'
print #terminal.comPortList, "selection? comPort$"
wait
[baudRateSelect] 'Perform action for the listbox named 'baudRateList'
print #terminal.baudRateList, "selection? baudRate$"
wait
[dataBitsSelect] 'Perform action for the listbox named 'dataBitsList'
print #terminal.dataBitsList, "selection? dataBits$"
wait
[paritySelect] 'Perform action for the listbox named 'partiyList'
print #terminal.partiyList, "selection? partiy$"
wait
[stopBitsSelect] 'Perform action for the listbox named 'stopBitsList'
print #terminal.stopBitsList, "selection? stopBits$"
wait
[openPort] 'Perform action for the button named 'openPortButton'
'select all of the port data to open
print #terminal.comPortList, "selection? comPort$"
print #terminal.baudRateList, "selection? baudRate$"
print #terminal.dataBitsList, "selection? dataBits$"
print #terminal.partiyList, "selection? partiy$"
print #terminal.stopBitsList, "selection? stopBits$"
print #terminal.options, "!contents? options$"
comPortToOpen$ ="";comPort$;":";baudRate$;",";dataBits$;",";partiy$;",";stopBits$;",";options$
PRINT #terminal.recievedRawDatatextedit, "Opening port ----> ";comPortToOpen$
open comPortToOpen$ for random as #openComPort
wait
[closePort] 'Perform action for the button named 'closePortButton'
CLOSE #openComPort
PRINT #terminal.recievedRawDatatextedit, "Port Closed ######## "
wait
[sendCommand] 'Perform action for the button named 'sendCommandButton'
'read and display anything inbound before sending
dataRead$ = input$(#openComPort, 1024) '
print #terminal.recievedRawDatatextedit, ""; dataRead$
'get info from command box then send at CR and LF
print #terminal.commandToSendBox, "!contents? dataSent$"
print #terminal.recievedRawDatatextedit, ""; dataSent$
print #openComPort, dataSent$
[getFeedback]
dataRead$ = input$(#openComPort, 1024) '
print #terminal.recievedRawDatatextedit, ""; dataRead$
wait
[quit.terminal] 'End the program
close #terminal
end
'-------------DO NOT DELETE--------------------
' open comPortToOpen$ for random as #cncOutPut'
' print #cncOutPut, "G1 f3 X1 Y1" '
' print comPortToOpen$
' dataRead$ = input$(#cncOutPut, 10) '
' print dataRead$ '
' CLOSE #cncOutPut '
' print "complete" '
' '
' PRODUCES THIS OUTPUT '
' '
' COM4:9600,n,8,1,ds0,cs0,rs '
' Úds€æd '
' complete '
' '
'-------------DO NOT DELETE--------------------
'-------------DO NOT DELETE--------------------
'this is raw data from the GUI '
' '
'Opening port ----> COM4:9600,N,8,1,ds0,cs0,rs'
'g0 x10 '
'ägæäÆiKƒ '
'g0 x9 '
'gÄfgȶ2« '
'g0 x10 '
'¨»¾ð³mÚ '
'Port Closed ######## '
' '
' '
'Opening port ----> COM4:9600,N,8,1,ds0,cs0,rs'
'm21 '
'ÖþšnãÆæ@ '
'Port Closed ######## '
' '
'-------------DO NOT DELETE--------------------
'-------------DO NOT DELETE----------------------
' comPortToOpen$="COM4:115200,n,8,1,ds0,cs0,rs" '
' open comPortToOpen$ for random as #cncOutPut '
' print #cncOutPut, "M28" '
' print comPortToOpen$ '
' dataRead$ = input$(#cncOutPut, 10) '
' print dataRead$ '
' CLOSE #cncOutPut '
' print "complete" '
' '
' PRODUCES THIS OUTPUT '
' '
' Opening port ----> COM4:115200,N,8,1,ds0,cs0,rs
' eps per unit: M92 X80.000000 Y80.000000 Z400.000000 E94.000000
' echo:Maximum feedrates (mm/s): M203 X500.000000 Y500.000000 Z4.000000 E45.000000
' echo:Maximum Acceleration (mm/s2): M201 X500 Y500 Z100 E3000
' echo:Acceleration: S=acceleration, T=retrac
' M28
'
'
' t acceleration M204 S500.000000 T500.000000
' echo:Advanced variables: S=Min feedrate (mm/s), T=Min travel feedrate (mm/s), B=minimum segment time (ms), X=maximum XY jerk (mm/s), Z=maximum Z jerk (mm/s), E=maximum E jerk (mm/s) M205 S0.000000 T0.000000
' Port Closed ######## '
' '
'-------------DO NOT DELETE----------------------
|
|
|
Post by mikewilsonfletcherok on May 1, 2024 21:59:33 GMT -5
I actually got CNC movement started tonight by using KISS, that archaic term from Mr. Short's 1988 7th grade BASIC programming class for TRS-80 came back to bite me in the rear. Very basically open correct port, send correct code, close port, and that will make things litterally move. Now to figure out a basic G-Code Jogger and correct commands for my controller and go from there. Brandon and Rod, thank you for pointing me in the right direction.
' This is FULLY FUNCTIONAL AND SIMPLE. Don't go Mike this up and make it complex. Start by defining ' the port properly as baudrates make a world of difference. Open the port. Send the port command. ' Close the port. All of my previous examples failed because I was using the wrong baudrate, wrong ' variable names, and worst of all, wrong G Code command M28 (wrong) instead of G28 (correct). To ' make this more simple and Un-Mike this; ' ' ' OPEN "COM4:115200,n,8,1,ds0,cs0,rs" FOR RANDOM as #cncPort ' PRINT #cncPort, "G28" 'correct GCode for home ' CLOSE #cncPort ' END ' '
comPortToOpen$="COM4:115200,n,8,1,ds0,cs0,rs" ' hardcode port opening for now print comPortToOpen$ ' tell the user what port we will open
open comPortToOpen$ for random as #cncPort ' actually open the port
dataRead$ = input$(#cncPort, 1024) ' read in 1,024 bytes from the open port print dataRead$ ' show the end user the data recieved from the port
print #cncPort, "G28" ' send the GCode to home the machine to mechanical X=0 and Y=0
dataRead$ = input$(#cncPort, 1024) ' read response up to 1,024 bytes from the open port print dataRead$ ' show the end user the data recieved from the port
CLOSE #cncPort ' since this is raw testing with no input close the port print comPortToOpen$; "--> [CLOSED]" ' tell the user we arent doing anything else end
|
|