tool number

Request and discuss new features
Post Reply
cdedwards
Posts: 8
Joined: Tue Dec 31, 2019 2:05 am

tool number

Post by cdedwards » Sat Feb 20, 2021 3:28 pm

Seems you can't search for "tool number" so I need to ask.

I'm using linuxcnc with plasmac. I can create a materials file from the tool table of sheetcam. It's a good materials file for sheetcam.
Now how do I get sheetcam to output that into a M190 P# in the gcode? I edited the post processer and setup the materialFile = true in there. I also added the following snippet to OnInit() as it doesn't appear to call the OnToolChange() at all. Material is always 0 therefore it never runs this.

post.Text (" (Material: ", material, ")\n")
if(material > 0 and materialFile) then
post.Text(" M190 P", material, "\n")
post.Text(" M66 P3 L3 Q1\n")
end


I added this snippet into the OnPenDown() function just to see if I added to the wrong place. Basically the tool number is not being output or material is not being set at all by looking at the tool number and making material equal to it

Code: Select all

N0010 (Filename: makerCARVER Gantry Plates v1.ngc)
N0020 (Post processor: LinuxCNC PlasmaC.scpost)
N0030 (Date: 20/02/2021)
N0040 G21 (Units: Metric)
N0050 G40 G64 P0.005 G90
N0060 F1 S1
N0070 (Material: 0)
N0080 (Part: makerCARVER Gantry Plates v1)
N0090 (Operation: No Offset, 0, 45 Amp 1/4"  Mild Steel)
N0100 G00 X72.7981 Y83.2771
N0110 M65P2 (THC On)
N0120 M65P2 (THC On)
N0130 (Material: 0)
N0140 (Material: 0)
N0150 M03 $0 S1
N0160 G04 P0.6
N0170 G03 X73.8404 Y84.7316 I-1.4111 J2.1119 F[#<_hal[plasmac.cut-feed-rate]> * 

cdedwards
Posts: 8
Joined: Tue Dec 31, 2019 2:05 am

Re: tool number

Post by cdedwards » Sat Feb 20, 2021 5:01 pm

I've narrowed it down to the
post.DefineCustomToolParam("PlasmaTool", "Material", "material", sc.unit0DECPLACE, 0,0,1e17)

This doesn't appear to work at all. If I initalize material to 27 instead of 0 it will load the material as it should. the aforementioned line does nothing and does not set the material to a value at all.

User avatar
Les Newell
Site Admin
Posts: 2843
Joined: Thu May 11, 2006 8:12 pm

Re: tool number

Post by Les Newell » Mon Feb 22, 2021 1:01 pm

The custom parameter variable won't be set until the tool change so your code needs to be in OnToolChange.

cdedwards
Posts: 8
Joined: Tue Dec 31, 2019 2:05 am

Re: tool number

Post by cdedwards » Tue Feb 23, 2021 12:45 am

I'm using the default linuxcnc PlasmaC post file and
post.DefineCustomToolParam("PlasmaTool", "Material", "material", sc.unit0DECPLACE, 0,0,1e17)

is placed just after the start of the post processor file. linuxcnc plasma post doesn't even have a OnToolChange() function.

from the plasmaC post we have the following, which of course does not work.

function OnToolChange()
curFeed = feedRate
if(material > 0 and materialFile) then
post.Text(" M190 P", material, "\n")
post.Text(" M66 P3 L3 Q1\n")
end
end

User avatar
Les Newell
Site Admin
Posts: 2843
Joined: Thu May 11, 2006 8:12 pm

Re: tool number

Post by Les Newell » Tue Feb 23, 2021 9:50 am

I don't see anything obviously wrong there. Could you send me the whole post so I can take a look.

cdedwards
Posts: 8
Joined: Tue Dec 31, 2019 2:05 am

Re: tool number

Post by cdedwards » Tue Feb 23, 2021 11:44 pm

Here's the unedited post file

Code: Select all

------ Configuration options ------

-- Set this to true if you have the multi-tool option enabled in PlasmaC.
-- If not set it to false
multiTool = false

-- Set this to true if you are using a material file.
-- See http://linuxcnc.org/docs/devel/html/plasma/plasmac-user-guide.html#material-file
-- Set it to false otherwise

materialFile = true

-- Set this to true if you want SheetCam to control the feed rate.
-- Set it to false otherwise
-- NOTE if you use rules to change the feed rate, these changes will affect the
-- feed rate even if useFeed is false

useFeed = true


---- End of configuration options ------


if materialFile then
   post.DefineCustomToolParam("PlasmaTool", "Material", "material", sc.unit0DECPLACE, 0,0,1e17)
end


function OnAbout(event)
   ctrl = event:GetTextCtrl()
   ctrl:AppendText("LinuxCNC plasma post processor\n")
   ctrl:AppendText("\n")
   ctrl:AppendText("Modal G-codes and coordinates\n")
   ctrl:AppendText("Comments enclosed with ( and )\n")
   ctrl:AppendText("Incremental IJ\n")
   ctrl:AppendText("Does not use Z axis")
   ctrl:AppendText("NOTE: These parameters in SheetCam have no effect:")
   ctrl:AppendText("Feed rate (optional - see config options)")
   ctrl:AppendText("Pierce delay")
   ctrl:AppendText("Pierce height")
   ctrl:AppendText("Plunge rate")
   ctrl:AppendText("Cut height")

end


function OnInit()
   post.SetCommentChars ("()", "[]")  --make sure ( and ) characters do not appear in system text
   post.Text (" (Filename: ", fileName, ")\n")
   post.Text (" (Post processor: ", postName, ")\n")
   post.Text (" (Date: ", date, ")\n")
   if(scale == metric) then
      post.Text (" G21 (Units: Metric)\n") --metric mode
   else
      post.Text (" G20 (Units: Inches)\n") --inch mode
   end
   post.Text (" G40 G90\n F1 S1\n")
   bigArcs = 1 --stitch arc segments together
   minArcSize = 0.05 --arcs smaller than this are converted to moves
   material = 0
   curFeed = 1;
   curScale = -1
end

function OnNewLine()
   post.Text ("N")
   post.Number (lineNumber, "0000")
   lineNumber = lineNumber + 10
end


function DoFeed()
   if useFeed then
      post.ModalNumber (" F", feedRate * scale, "0.###")
   else
      local scale = feedRate / curFeed
      if scale ~= curScale then
         curScale = scale
         post.Text(" F[#<_hal[plasmac.cut-feed-rate]> * ")
         post.Number(scale,"0.###")
         post.Text("]")
      end
   end
end

function OnFinish()
   post.Text (" M05 M30\n")
end

function OnRapid()
   if(math.hypot (endX - currentX, endY - currentY) < 0.001) then return end
   post.ModalText (" G00")
   post.ModalNumber (" X", endX * scale, "0.0000")
   post.ModalNumber (" Y", endY * scale, "0.0000")
   post.Eol()
end

function OnMove()
   if(math.hypot (endX - currentX, endY - currentY) < 0.001) then return end
   post.ModalText (" G01")
   post.ModalNumber (" X", endX * scale, "0.0000")
   post.ModalNumber (" Y", endY * scale, "0.0000")
   DoFeed()
   post.Eol()
end

function OnArc()
   if(arcAngle <0) then
      post.ModalText (" G03")
   else
      post.ModalText (" G02")
   end
   post.NonModalNumber (" X", endX * scale, "0.0000")
   post.NonModalNumber (" Y", endY * scale, "0.0000")
   post.Text (" I")
   post.Number ((arcCentreX - currentX) * scale, "0.0000")
   post.Text (" J")
   post.Number ((arcCentreY - currentY) * scale, "0.0000")
   DoFeed()
   post.Eol()
end


function OnPenDown()
--[[   if (preheat > 0.001) then
      post.ModalText (" G00")
      post.ModalNumber (" Z", cutHeight * scale, "0.0000")
      post.Text ("\n G04 P")
      post.Number (preheat,"0.###")
      post.Eol()
   end
   post.ModalText (" G00")
   post.ModalNumber (" Z", pierceHeight * scale, "0.0000")]]
   post.Text (" M03")
   if(multiTool) then
      if(toolClass == "ScriberTool") then
         post.Text(" $1 S1")
      else
         post.Text(" $0 S1")
      end
   end
   post.Eol()
   if (pierceDelay > 0.001) then
      post.Text (" G04 P")
      post.Number (pierceDelay,"0.###")
      post.Eol()
   end
end


function OnPenUp()
   post.Text (" M05\n")
   if (endDelay > 0) then
      post.Text (" G04 P")
      post.Number (endDelay,"0.###")
      post.Eol()
   end
end

function OnNewOperation()
   post.Text (" (Operation: ", operationName, ")\n")
end

function OnComment()
  post.Text(" (",commentText,")\n")
end


function OnNewPart()
   post.Text(" (Part: ",partName,")\n");
end

function OnToolChange()
   curFeed = feedRate
   if(material > 0 and materialFile) then
      post.Text(" M190 P", material, "\n")
      post.Text(" M66 P3 L3 Q1\n")
   end
end

function OnDrill()
   OnRapid()
   if(multiTool and toolClass ~= "ScriberTool") then
      post.Text(" M3 $2 S1\n")
   else
      OnPenDown()
      OnPenUp()
   end
end



User avatar
Les Newell
Site Admin
Posts: 2843
Joined: Thu May 11, 2006 8:12 pm

Re: tool number

Post by Les Newell » Wed Feb 24, 2021 12:13 pm

I just tested the post here and it does what it should. I'm seeing M190 P10 when I set the material to 10.
Try restarting SheetCam after selecting the post.

cdedwards
Posts: 8
Joined: Tue Dec 31, 2019 2:05 am

Re: tool number

Post by cdedwards » Thu Feb 25, 2021 12:42 am

ok updated to .26, restarted and reran the file using the PlasmaC post which I edited to change materialsFile = true. No M190 in the file at all.
Restarted sheetcam made sure PlasmaC post was chosen and redid everything. Attached is the gcode file.
makerCARVER Gantry Plates v1.txt
gcode file from linuxcnc PlasmaC post.
(7.17 KiB) Downloaded 2 times
makerCARVER Gantry Plates v1.dxf
DXF of project
(30.35 KiB) Not downloaded yet

User avatar
Les Newell
Site Admin
Posts: 2843
Joined: Thu May 11, 2006 8:12 pm

Re: tool number

Post by Les Newell » Thu Feb 25, 2021 11:22 am

Huh. That's odd. Could you give me the job file (File->save job) with everything set up ready to post process.
I'll give it a go here and see if I can figure out what is going on.

Post Reply