Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
LibLaserCut
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Elektronikföreningen Admittansen
LibLaserCut
Commits
e667aa55
Commit
e667aa55
authored
9 years ago
by
Sven Jung
Browse files
Options
Downloads
Patches
Plain Diff
added laser support for XYPlotter
parent
bd46e325
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/com/t_oster/liblasercut/drivers/MakeBlockXYPlotter.java
+116
-62
116 additions, 62 deletions
src/com/t_oster/liblasercut/drivers/MakeBlockXYPlotter.java
src/com/t_oster/liblasercut/drivers/MakeBlockXYPlotterProperty.java
+1
-1
1 addition, 1 deletion
...oster/liblasercut/drivers/MakeBlockXYPlotterProperty.java
with
117 additions
and
63 deletions
src/com/t_oster/liblasercut/drivers/MakeBlockXYPlotter.java
+
116
−
62
View file @
e667aa55
...
...
@@ -45,18 +45,18 @@ public class MakeBlockXYPlotter extends LaserCutter
private
final
boolean
debug
=
false
;
// print to command line
private
static
final
String
MODELNAME
=
"MakeBlockXYPlotter"
;
private
double
addSpacePerRasterLine
=
0.5
;
private
String
hostname
=
"
file:///Users/Sven/Desktop/out.gcode
"
;
private
String
hostname
=
""
;
private
double
bedWidth
=
300
;
private
double
bedHeight
=
210
;
private
int
speed
Rate
=
255
;
private
int
delay
Rate
=
5000
;
private
int
powerRate
=
255
;
private
String
usedTool
=
"PEN"
;
// PEN, Laser
private
List
<
Double
>
resolutions
=
Arrays
.
asList
(
new
Double
[]{
64
d
// fine liner
});
private
int
c
urrentSpeed
;
private
int
c
urr
en
t
Power
;
private
int
c
hosenDelay
;
private
int
c
hos
enPower
;
private
ToolState
toolState
;
private
PrintWriter
w
=
null
;
...
...
@@ -71,15 +71,15 @@ public class MakeBlockXYPlotter extends LaserCutter
private
static
final
String
SETTING_RASTER_WHITESPACE
=
"Additional space per Raster line (mm)"
;
private
static
final
String
SETTING_BEDWIDTH
=
"Laserbed width (mm)"
;
private
static
final
String
SETTING_BEDHEIGHT
=
"Laserbed height (mm)"
;
private
static
final
String
SETTING_
SPEED
_RATE
=
"Max.
Speed
Rate (abs.
value
)"
;
private
static
final
String
SETTING_POWER_RATE
=
"Max. Power Rate (abs.
value
)"
;
private
static
final
String
SETTING_
DELAY
_RATE
=
"Max.
Delay
Rate (abs.
us
)"
;
private
static
final
String
SETTING_POWER_RATE
=
"Max. Power Rate (abs.
pwm
)"
;
private
static
final
String
SETTING_TOOL
=
"Tool (PEN, LASER)"
;
private
static
String
[]
settingAttributes
=
new
String
[]{
SETTING_HOSTNAME
,
SETTING_RASTER_WHITESPACE
,
SETTING_BEDWIDTH
,
SETTING_BEDHEIGHT
,
SETTING_
SPEED
_RATE
,
SETTING_
DELAY
_RATE
,
SETTING_POWER_RATE
,
SETTING_TOOL
};
...
...
@@ -135,38 +135,39 @@ public class MakeBlockXYPlotter extends LaserCutter
private
void
generateInitializationGCode
()
throws
Exception
{
this
.
send
(
"G54"
);
//use table offset
this
.
send
(
"G21"
);
//units to mm
this
.
send
(
"G90"
);
//following coordinates are absolute
toolOff
();
this
.
send
(
"G28 X Y"
);
//move to 0 0
this
.
send
Command
(
"G28 X Y"
);
//move to 0 0
}
private
void
generateShutdownGCode
()
throws
Exception
{
//back to origin and shutdown
toolOff
();
this
.
send
(
"G28 X Y"
);
//move to 0 0
this
.
send
Command
(
"G28 X Y"
);
//move to 0 0
}
private
void
toolOff
()
throws
Exception
{
if
(
toolState
!=
ToolState
.
OFF
)
{
if
(
usedTool
.
equals
(
"PEN"
))
{
this
.
send
(
"M1 90"
);
this
.
sendCommand
(
"M1 90"
);
this
.
sendCommand
(
String
.
format
(
"M3 %d"
,
0
));
// to ensure fastest speed
}
else
if
(
usedTool
.
equals
(
"LASER"
))
{
this
.
send
(
"M1 ???"
);
this
.
sendCommand
(
String
.
format
(
"M4 %d"
,
0
));
this
.
sendCommand
(
String
.
format
(
"M3 %d"
,
0
));
// to move faster with tool off
}
else
{
throw
new
Exception
(
"Tool "
+
this
.
usedTool
+
" not supported!"
);
}
toolState
=
ToolState
.
OFF
;
toolState
=
ToolState
.
OFF
;
}
}
private
void
toolOn
()
throws
Exception
{
if
(
toolState
!=
ToolState
.
ON
)
{
if
(
usedTool
.
equals
(
"PEN"
))
{
this
.
send
(
"M1 130"
);
this
.
sendCommand
(
String
.
format
(
"M3 %d"
,
0
));
// to ensure fastest speed
this
.
sendCommand
(
"M1 130"
);
}
else
if
(
usedTool
.
equals
(
"LASER"
))
{
this
.
send
(
"M1 ???"
);
this
.
sendCommand
(
String
.
format
(
"M3 %d"
,
(
int
)
((
double
)
delayRate
*
this
.
chosenDelay
/
100
)));
this
.
sendCommand
(
String
.
format
(
"M4 %d"
,
(
int
)
((
double
)
powerRate
*
this
.
chosenPower
/
100
)));
}
else
{
throw
new
Exception
(
"Tool "
+
this
.
usedTool
+
" not supported!"
);
}
...
...
@@ -174,32 +175,34 @@ public class MakeBlockXYPlotter extends LaserCutter
}
}
private
void
setSpeed
(
int
value
)
throws
Exception
{
if
(
usedTool
.
equals
(
"LASER"
))
{
if
(
value
!=
currentSpeed
)
{
this
.
send
(
String
.
format
(
Locale
.
US
,
"G1 F%d"
,
(
int
)
((
double
)
speedRate
*
value
/
100
)));
currentSpeed
=
value
;
private
void
setDelay
(
int
value
)
throws
Exception
{
// saves just the chosen delay value
// delay of the plotter really set on toolOn(), to move faster with tool off
if
(
usedTool
.
equals
(
"LASER"
))
{
// property option only supported if laser
if
(
value
!=
chosenDelay
)
{
chosenDelay
=
value
;
}
}
}
private
void
setPower
(
int
value
)
throws
Exception
{
if
(
usedTool
.
equals
(
"LASER"
))
{
if
(
value
!=
currentPower
)
{
this
.
send
(
String
.
format
(
Locale
.
US
,
"S%d"
,
(
int
)
((
double
)
powerRate
*
value
/
100
)));
currentPower
=
value
;
// saves just the chosen power value
// power of the laser really set on toolOn()
if
(
usedTool
.
equals
(
"LASER"
))
{
// property option only supported if laser
if
(
value
!=
chosenPower
)
{
chosenPower
=
value
;
}
}
}
private
void
move
(
int
x
,
int
y
,
double
resolution
)
throws
Exception
{
toolOff
();
this
.
send
(
String
.
format
(
Locale
.
US
,
"G0 X%f Y%f"
,
Util
.
px2mm
(
x
,
resolution
),
Util
.
px2mm
(
y
,
resolution
)));
this
.
send
Command
(
String
.
format
(
Locale
.
US
,
"G0 X%f Y%f"
,
Util
.
px2mm
(
x
,
resolution
),
Util
.
px2mm
(
y
,
resolution
)));
}
private
void
line
(
int
x
,
int
y
,
double
resolution
)
throws
Exception
{
toolOn
();
this
.
send
(
String
.
format
(
Locale
.
US
,
"G1 X%f Y%f"
,
Util
.
px2mm
(
x
,
resolution
),
Util
.
px2mm
(
y
,
resolution
)));
this
.
send
Command
(
String
.
format
(
Locale
.
US
,
"G1 X%f Y%f"
,
Util
.
px2mm
(
x
,
resolution
),
Util
.
px2mm
(
y
,
resolution
)));
}
private
void
generateVectorGCode
(
VectorPart
vp
,
double
resolution
,
ProgressListener
pl
,
int
startProgress
,
int
maxProgress
)
throws
UnsupportedEncodingException
,
Exception
{
...
...
@@ -218,10 +221,19 @@ public class MakeBlockXYPlotter extends LaserCutter
y
=
cmd
.
getY
();
this
.
line
(
x
,
y
,
resolution
);
break
;
case
SETPROPERTY:
PowerSpeedFocusFrequencyProperty
p
=
(
PowerSpeedFocusFrequencyProperty
)
cmd
.
getProperty
();
this
.
setPower
(
p
.
getPower
());
this
.
setSpeed
(
p
.
getSpeed
());
case
SETPROPERTY:
// called once per part to set chosen properties
MakeBlockXYPlotterProperty
p
=
(
MakeBlockXYPlotterProperty
)
cmd
.
getProperty
();
// only set with LASER tool
// ensure percent power
int
pPercent
=
p
.
getPower
();
pPercent
=
pPercent
<
0
?
0
:
pPercent
;
pPercent
=
pPercent
>
100
?
100
:
pPercent
;
this
.
setPower
(
pPercent
);
// ensure percent speed
int
sPercent
=
p
.
getSpeed
();
sPercent
=
sPercent
<
0
?
0
:
sPercent
;
sPercent
=
sPercent
>
100
?
100
:
sPercent
;
int
dPercent
=
100
-
sPercent
;
// convert speed to delay
this
.
setDelay
(
dPercent
);
break
;
}
i
++;
...
...
@@ -237,9 +249,12 @@ public class MakeBlockXYPlotter extends LaserCutter
boolean
dirRight
=
true
;
Point
rasterStart
=
rp
.
getRasterStart
();
// called once per part to set chosen properties
PowerSpeedFocusProperty
prop
=
(
PowerSpeedFocusProperty
)
rp
.
getLaserProperty
();
this
.
set
Speed
(
prop
.
getSpeed
());
this
.
set
Delay
(
prop
.
getSpeed
());
this
.
setPower
(
prop
.
getPower
());
for
(
int
line
=
0
;
line
<
rp
.
getRasterHeight
();
line
++)
{
Point
lineStart
=
rasterStart
.
clone
();
lineStart
.
y
+=
line
;
...
...
@@ -322,8 +337,15 @@ public class MakeBlockXYPlotter extends LaserCutter
if
(!
this
.
debug
){
if
(
this
.
hostname
.
startsWith
(
"port://"
))
{
String
portString
=
this
.
hostname
.
replace
(
"port://"
,
""
);
CommPortIdentifier
cpi
=
CommPortIdentifier
.
getPortIdentifier
(
portString
);
port
=
(
SerialPort
)
cpi
.
open
(
"VisiCut"
,
2000
);
try
{
CommPortIdentifier
cpi
=
CommPortIdentifier
.
getPortIdentifier
(
portString
);
port
=
(
SerialPort
)
cpi
.
open
(
"VisiCut"
,
2000
);
}
catch
(
Exception
e
)
{
throw
new
Exception
(
"Port '"
+
portString
+
"' is not available."
);
}
if
(
port
==
null
)
{
throw
new
Exception
(
"Error: Could not Open COM-Port '"
+
portString
+
"'"
);
...
...
@@ -336,10 +358,16 @@ public class MakeBlockXYPlotter extends LaserCutter
out
=
new
BufferedOutputStream
(
port
.
getOutputStream
());
portReader
=
new
BufferedReader
(
new
InputStreamReader
(
port
.
getInputStream
()));
// wake up firmware
String
command
=
"\r\n\r\n"
;
out
.
write
(
command
.
getBytes
(
"US-ASCII"
));
out
.
flush
();
Thread
.
sleep
(
2000
);
String
str
;
portReader
.
readLine
();
// "ok"
portReader
.
readLine
();
// "ok"
this
.
checkVersion
();
}
else
if
(
hostname
.
startsWith
(
"file://"
))
{
String
filename
=
this
.
hostname
.
replace
(
"file://"
,
""
);
...
...
@@ -373,13 +401,43 @@ public class MakeBlockXYPlotter extends LaserCutter
}
}
private
void
checkResponse
(
String
command
,
String
response
,
String
expectedAnswer
)
throws
Exception
{
if
(!
response
.
toLowerCase
().
contains
(
expectedAnswer
.
toLowerCase
()))
{
throw
new
Exception
(
String
.
format
(
"Got wrong response to command \"%s\":\n\"%s\" instead of \"%s\""
,
command
,
response
,
expectedAnswer
));
}
}
private
void
sendCommand
(
String
command
)
throws
Exception
{
this
.
send
(
command
);
if
(!
debug
)
{
if
(
this
.
hostname
.
startsWith
(
"port://"
))
{
String
resp
=
this
.
receive
();
this
.
checkResponse
(
command
,
resp
,
"ok"
);
}
}
}
private
void
checkVersion
()
throws
Exception
{
// check if firmware matches implemented protocol
this
.
send
(
"M115"
);
if
(!
debug
)
{
if
(
this
.
hostname
.
startsWith
(
"port://"
))
{
String
resp
=
this
.
receive
();
this
.
checkResponse
(
"Version"
,
resp
,
"SvenJung"
);
String
resp2
=
this
.
receive
();
this
.
checkResponse
(
"Version"
,
resp2
,
"ok"
);
}
}
}
private
void
send
(
String
command
)
throws
Exception
{
if
(!
debug
)
{
if
(
this
.
hostname
.
startsWith
(
"port://"
))
{
// send
String
sendString
=
command
+
"\n"
;
out
.
write
(
sendString
.
getBytes
(
"US-ASCII"
));
out
.
flush
();
this
.
waitForResponse
(
command
);
}
else
if
(
hostname
.
startsWith
(
"file://"
))
{
w
.
println
(
command
);
...
...
@@ -393,33 +451,29 @@ public class MakeBlockXYPlotter extends LaserCutter
}
}
private
void
waitForResponse
(
String
command
)
throws
IOException
,
Exception
{
String
line
;
String
expected
=
"ok"
;
try
{
line
=
portReader
.
readLine
();
line
=
line
.
replace
(
"\n"
,
""
).
replace
(
"\r"
,
""
);
if
(!
line
.
toLowerCase
().
equals
(
expected
.
toLowerCase
()))
{
throw
new
Exception
(
String
.
format
(
"Got wrong response to command: %s:%s"
,
command
,
line
));
}
else
{
return
;
// everything ok
private
String
receive
()
throws
Exception
{
if
(!
debug
)
{
if
(
this
.
hostname
.
startsWith
(
"port://"
))
{
String
line
;
try
{
line
=
portReader
.
readLine
();
line
=
line
.
replace
(
"\n"
,
""
).
replace
(
"\r"
,
""
);
return
line
;
}
catch
(
IOException
e
)
{
throw
new
IOException
(
"IO Exception, e.g. timeout"
);
}
}
}
catch
(
IOException
e
)
{
throw
new
Exception
(
"IO Exception, e.g. timeout"
);
}
return
""
;
}
@Override
public
void
sendJob
(
LaserJob
job
,
ProgressListener
pl
,
List
<
String
>
warnings
)
throws
IllegalJobException
,
Exception
{
this
.
c
urr
en
t
Power
=
-
1
;
this
.
c
urrentSpeed
=
-
1
;
this
.
toolState
=
ToolState
.
O
FF
;
pl
.
progressChanged
(
this
,
0
);
this
.
c
hos
enPower
=
0
;
this
.
c
hosenDelay
=
0
;
this
.
toolState
=
ToolState
.
O
N
;
// assume worst case, set to OFF in initialization code
pl
.
progressChanged
(
this
,
0
);
pl
.
taskChanged
(
this
,
"checking job"
);
checkJob
(
job
);
job
.
applyStartPoint
();
...
...
@@ -465,7 +519,7 @@ public class MakeBlockXYPlotter extends LaserCutter
clone
.
hostname
=
hostname
;
clone
.
bedWidth
=
bedWidth
;
clone
.
bedHeight
=
bedHeight
;
clone
.
speed
Rate
=
speed
Rate
;
clone
.
delay
Rate
=
delay
Rate
;
clone
.
powerRate
=
powerRate
;
clone
.
usedTool
=
usedTool
;
return
clone
;
...
...
@@ -486,8 +540,8 @@ public class MakeBlockXYPlotter extends LaserCutter
return
this
.
bedWidth
;
}
else
if
(
SETTING_BEDHEIGHT
.
equals
(
attribute
))
{
return
this
.
bedHeight
;
}
else
if
(
SETTING_
SPEED
_RATE
.
equals
(
attribute
))
{
return
this
.
speed
Rate
;
}
else
if
(
SETTING_
DELAY
_RATE
.
equals
(
attribute
))
{
return
this
.
delay
Rate
;
}
else
if
(
SETTING_POWER_RATE
.
equals
(
attribute
))
{
return
this
.
powerRate
;
}
else
if
(
SETTING_TOOL
.
equals
(
attribute
))
{
...
...
@@ -506,8 +560,8 @@ public class MakeBlockXYPlotter extends LaserCutter
this
.
bedWidth
=
(
Double
)
value
;
}
else
if
(
SETTING_BEDHEIGHT
.
equals
(
attribute
))
{
this
.
bedHeight
=
(
Double
)
value
;
}
else
if
(
SETTING_
SPEED
_RATE
.
equals
(
attribute
))
{
this
.
speed
Rate
=
(
Integer
)
value
;
}
else
if
(
SETTING_
DELAY
_RATE
.
equals
(
attribute
))
{
this
.
delay
Rate
=
(
Integer
)
value
;
}
else
if
(
SETTING_POWER_RATE
.
equals
(
attribute
))
{
this
.
powerRate
=
(
Integer
)
value
;
}
else
if
(
SETTING_TOOL
.
equals
(
attribute
))
{
...
...
This diff is collapsed.
Click to expand it.
src/com/t_oster/liblasercut/drivers/MakeBlockXYPlotterProperty.java
+
1
−
1
View file @
e667aa55
...
...
@@ -15,7 +15,7 @@ import java.util.LinkedList;
*/
public
class
MakeBlockXYPlotterProperty
extends
PowerSpeedFocusFrequencyProperty
{
private
boolean
showPowerAndSpeed
=
false
;
private
boolean
showPowerAndSpeed
;
public
MakeBlockXYPlotterProperty
(
boolean
showPowerAndSpeed
)
{
this
.
showPowerAndSpeed
=
showPowerAndSpeed
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment