CauldronDevelopmentLLC / CAMotics

Open-Source Simulation & Computer Aided Machining - A 3-axis CNC GCode simulator
Other
619 stars 143 forks source link

How do you use TPL outside of the main CAMotics application? #240

Closed NikiSchlifke closed 1 year ago

NikiSchlifke commented 7 years ago

Of course I can just any editor I want, save a file as .tpl and load it in CAMotics. But since tpl is supposed to be JavaScript I'd rather use a proper IDE with code inspection and other convenience functions. Maybe even use ES6, webpack and such. Any tips on how to accomplish that?

jcoffland commented 7 years ago

You can use any editor you like. Just save the .tpl file and rerun the simulation and all should work well. You do not need to exit CAMotics to do so.

NikiSchlifke commented 7 years ago

Yeah, that's what it says in the first sentence of my post.

It's more in the direction of coming up with annotations for the internal camotic funtions that do not exist in javascript (I might do that) The other thing is using ES6 syntax, maybe even have a "frontend" that I can use, etc...

The question I have is how is the TPL interpreter coupled to the camotic application?

jcoffland commented 7 years ago

You can run TPL with outside of the CAMotics application using the tplang command line tool. In fact, this is how CAMotics runs TPL. The --sim-json option is important for passing simulation data to TPL. This gives TPL programs access to the tool table, tool sizes, and workpiece dimensions. This is very handy for creating TPL programs which automatically adapt to those inputs.

Here is some sample sim JSON input:

{
  "tools": {
    "1": {
      "units": "MM",
      "shape": "BALLNOSE",
      "length": 10,
      "diameter": 2.5,
      "description": ""
    },
    "2": {
      "units": "MM",
      "shape": "CYLINDRICAL",
      "length": 10,
      "diameter": 2,
      "description": ""
    },
    "3": {
      "units": "MM",
      "shape": "CYLINDRICAL",
      "length": 10,
      "diameter": 2,
      "description": ""
    }
  },
  "workpiece": {
    "min": [-3, -3, -3],
    "max": [122, 18, 0]
  }
}

All measurements are in mm.

vespakoen commented 5 years ago

Hi, I wanted to use it standalone as well, and I thought it was a good exercise anyways to write something like this, so I made a clone (with some modifications) over here:

https://github.com/openjscam/openjscam

It is pure javascript so can be used in node.js or the browser, some things are missing but it largely seems to be working, contributions are welcome ;)

jcoffland commented 5 years ago

@vespakoen, that's fantastic. Nice work. It would be awesome to develop a set of unit tests which contained various inputs and their expected outputs. We could use this to test both against your code and the CAMotics TPLang code to make the language more standard.

Would you consider adding a link to https://tplang.org/ from your GitHub?

vespakoen commented 5 years ago

Hey, that's exactly my plan =) & glad you like it! my project is only 3 days old, but already producing gcode! The main difference I made is that the transformations use a callback function, so:

// just translate
translate({ x: 100 }, function () {
   cut({ x: 10, y: 10 })
})
// just rotate
rotate(45, function () {
   cut({ x: 10, y: 10 })
})
// translate and rotate (the order of how things are applied in my code are maybe in the wrong order right now)
translate({ x: 100 }, function () {
  rotate(45, function () {
    cut({ x: 10, y: 10 })
  })
})
// stuff that's here won't be translated

We can possibly also implement popMatrix and translate, rotate etc without the callback parameter in the future.

Here is the PR for the website: https://github.com/CauldronDevelopmentLLC/tplang-web/pull/1

Cheers!