1. Hey guyz. Welcome to the All New Phlatforum!



    Sign Up and take a look around. There are so many awesome new features.

    The Phlatforum is a place we can all hang out and

    have fun sharing our RC adventures!

  2. Dismiss Notice

GCode posted in inch not mm

Discussion in 'SketchUcam Help' started by Biggles1212, Jul 11, 2009.

  1. Biggles1212

    Biggles1212 New Member

    Offline
    Messages:
    6
    Trophy Points:
    0
    :? I've been looking around so forgive me if I missed where to switch this option. Every time I post the code it posts in inches. I couldn't work out what was wrong with my Mach3 until I noticed it was in G20 mode. My PC is not hooked up to the CNC so I don't know how it will affect things.

    Is there a way to force it to post in mm as it would really help me to visualize whats going on.

    Thanks

    Barry :|
     
  2. Biggles1212

    Biggles1212 New Member

    Offline
    Messages:
    6
    Trophy Points:
    0
    :) So far I've had a little success by "tweaking" the scripts to use mm and not mm. There are two scripts one for constants {constants.rb} and the other for milling {Phlatmill.rb} by changing these to a degree I've got the X-Y axis sorted. Next to work out where to fix up for the Z-Axis.

    Please note so far the Parameters in constants are now in mm but Parameters for Safe Length {X-Axis} and Safe Width {Y-Axis} are still shown in inchs.

    My Mods to Constants.Rb

    $default_spindle_speed = 8000
    $default_feed_rate = 1000
    $default_plunge_rate = 200
    $default_material_thickness = 20.mm
    $default_bit_diameter = 6.mm
    $default_tab_width = 6.mm
    $default_tab_depth_factor = 50
    $default_vtabs = false
    $default_fold_depth_factor = 50

    $default_safe_origin_x = 0.0.mm
    $default_safe_origin_y = 0.0.mm
    $default_safe_width = 1500.0.mm
    $default_safe_height = 2700.0.mm
    $default_comment_remark = "Comment or Remark"

    Mods to Phlatmill.rb

    cncPrint("G90 G21 G49n") # G90 - Absolute programming (type B and C systems)
    cncPrint("G21n") # G21 - Programming in mm
    #cncPrint("G49n") # G49 - Tool offset compensation cancel
     
  3. tvcasualty

    tvcasualty New Member

    Offline
    Messages:
    637
    Trophy Points:
    0
    I don't have SU to reference but can you not change the model settings to metric mm? I was under the impression that would adjust the code.
     
  4. Biggles1212

    Biggles1212 New Member

    Offline
    Messages:
    6
    Trophy Points:
    0
    I've been battling with this this whole morning. It's quite painstaking. One possibility is for me to work with the units as if they're inch and leave my little mod where I've changed the G20 to G21. Unfortunately while I'm very used to swapping between the two, I have my machine which is a 3000mmx1500mm bed and its set in mm.

    I've quite a bit of programming experience under my belt so the going isn't too difficulty on the ruby script. For now I've just been looking at recognizable features of the program as its not too different in syntax to C+.

    Although, I have noticed that every time I open the Parameters off the icon, the safe area keeps getting smaller. I type in mm and it works fine, but when I open the tab again, its converted to inch and you have to type the safe limits etc again.

    Fortunately for me I have the determination of a pitbull at the worst of times and I've decided to get the better of this one.
     
  5. Flashsolutions

    Flashsolutions Active Member

    Offline
    Messages:
    1,123
    Trophy Points:
    38
    Location:
    Leesburg, Florida
    I think you have a typo in the constants.rb script for the width and height....

    $default_safe_width = 1500.0.mm
    $default_safe_height = 2700.0.mm

    should be

    $default_safe_width = 1500.0mm
    $default_safe_height = 2700.0mm



     
  6. Biggles1212

    Biggles1212 New Member

    Offline
    Messages:
    6
    Trophy Points:
    0
    Hi Flash .

    I tried to remove the decimal point between the value and the mm but SU7 throws errors. I put them back and it worked better.

    I've had a tough time playing with this conversion to mm. The program seems to convert everything to inches without fail. Unfortunately I don't understand the scripting code well enough.

    Earlier today I made a change that seemed to hold tight till I saw the parameter problem and then I fiddled the script back to errors.

    I love the script though and have been posting to Mach 3 and testing it. I just don't have the heart to take my PC to the garage so I can test something out. Its about time to get that spare PC.

    I'm not sure if running it on my machine is going to make it cut in mm or inch yet. I've never used the G20 mode and my machine is half stripped as I'm converting from lead screws to rack and pinion drive with a belt reduction. :)
     
  7. Biggles1212

    Biggles1212 New Member

    Offline
    Messages:
    6
    Trophy Points:
    0
    I've managed to get the right safe z height travel and cut depth sorted out on the script but still have no idea why the program continues to use inches when posting to G-Code. I'm wondering if the issue is not perhaps with SU7 itself. :cry:
     
  8. swarfer

    swarfer Moderator Staff Member

    Offline
    Messages:
    808
    Trophy Points:
    28
    Location:
    Grahamstown, South Africa
    I have just stumbled on phlatscript today (yay wow awesome etc - now I must build the machine).
    and today I have solved the metric gcode problem (though I haven't bothered with the constant changes you made, yet - seems to me to be code needed in the setup dialog to allow a choice of output mode).

    Anyhow, compare your phlatmill.rb with the one at
    http://iwr.ru.ac.za/~david/phlat/
    and insert the 'tometric' bits. You can ignore the changes I made to make TurboCNC happy with the code (yet to be tested)

    Thing is, Sketchups native internal units are imperial, no matter what is displayed on the screen.
    I have modded it so it converts anything being 'output' to millimeters,leaving all internal math alone.

    If the writers of phlatscript want to make use of my code they certainly may. I'll probably do more mods when my machinery come online...
     
  9. gasmasher

    gasmasher New Member

    Offline
    Messages:
    402
    Trophy Points:
    0
    Location:
    Atlanta, GA
    Thanks for taking a look at this swarfer and providing a solution. I'll look over your changes and get them merged into development at some point soon. I'm looking forward to any other contributions you may have.

    I am planning to provide a unit type option at some point but the code needs to be looked over to fix anything that is not unit agnostic.
     
  10. swarfer

    swarfer Moderator Staff Member

    Offline
    Messages:
    808
    Trophy Points:
    28
    Location:
    Grahamstown, South Africa
    What I did was leave all the internals in the native inches, and only convert for output.
    If there were a 'metric' checkbox in the setup, my 'tometric()' method could query that to determine what to output. Leaving the internals alone removes one level of floating point fuzziness which is 'a good thing'

    I had a quick look yesterday at the code, thinking to add a checkbox to the settings dialog, but I ran out of time. Maybe I'll drag the laptop home and see what I can come up with.
    Ultimately one would need to ask Sketchup what the display units are and act appropriatlely, but also allow the user to work in inches on the screen, but output metric gcode. This will give greater accuracy on a metric leadscrew machine. Here in South Africa, it is impossible to buy anything but metric (my Myford lathe is imperial and I am comfortable with that) so any machine build will be metric.
     
  11. swarfer

    swarfer Moderator Staff Member

    Offline
    Messages:
    808
    Trophy Points:
    28
    Location:
    Grahamstown, South Africa
    Hopefully you havn't gone too far with that. On Saturday I sat with the laptop and made extensive changes to 4 files, which replace what I did on Friday.
    The dialog has 2 checkboxes added as you can see here
    [​IMG]

    Also, the code will detect metric mode and output metric gcode if the drawign is metric.
    The 'Force Metric' checkbox will enable metric gcode no matter what units the drawing uses.
    This should actually be a radio button collection to allow 'Force Imperial OR Force Metric' to be selected, or none (but I coudln't figure out how to do that without manuals).

    The 'TurboCNC' check box enables gcode that is friendly to TurboCNC, which doesn't understand G49 and maybe other stuff, though a test file I ran through it was ok, I may find other stuff when I start cutting complicated shapes etc.

    The dialog still has an issue in setting the default values. Though I put in code to selected the metric default values for bit diameter etc when the drawing is metric, they still come up as 1/4". Strangely, the same sort of selection code works for the safe width/height settings. Pressing the 'restore defaults' button will set the bit diameter etc correctly.

    So, if you want metric gcode RIGHT NOW, install phlatscript 0.918 as per the instructions.
    Once that is working, replace the existing files with my files on the web page listed above (not the .png).
    Restart Sketchup, of course.
     
  12. gizzmo

    gizzmo New Member

    Offline
    Messages:
    15
    Trophy Points:
    1
    Hey Swarfer,

    Do you think you would be able to make this work for version 0.920?
    I tried the files you alter but get an error at startup.

    uninitialized constant PhlatScript::phlatTool::pB_MENU_TOOLBARError Loading File phlatboyztools.rb
    uninitialized constant PhlatScript::phlatTool::pB_MENU_TOOLBAR

    Many thx in advance!
    GreetZ
    David
     
  13. swarfer

    swarfer Moderator Staff Member

    Offline
    Messages:
    808
    Trophy Points:
    28
    Location:
    Grahamstown, South Africa
    Can be done, but 920 has a lot of changes and at least for me has bugs (would not do an outside cut after some edits), so I decided to wait and see if there is an update in the next few days before merging the code. If you really want metric in the short term, for now you need to install v918.

    I'll see what can be done....
     
  14. swarfer

    swarfer Moderator Staff Member

    Offline
    Messages:
    808
    Trophy Points:
    28
    Location:
    Grahamstown, South Africa
    Ok, I did a simple no choices conversion, it will output according to the drawing units.
    Nothing fancy, if your drawing is metric, it will output metric, otherwise imperial.

    Get it down the bottom of (do not get any other files from that page)
    http://iwr.ru.ac.za/~david/phlat/
     
  15. gasmasher

    gasmasher New Member

    Offline
    Messages:
    402
    Trophy Points:
    0
    Location:
    Atlanta, GA
    swarfer, thanks for picking this up again in the new version. Could you detail the problem with not getting an offset cut a little more so I can take a look at it? If you have a sample SU file that would be helpful and you can PM it if you want to keep it private.
     
  16. swarfer

    swarfer Moderator Staff Member

    Offline
    Messages:
    808
    Trophy Points:
    28
    Location:
    Grahamstown, South Africa
    I thought I posted about it but it seems to have got lost. Sadly I don't have the sketchup file anymore as I didn't save it (yup, thought DAMN just after closing SU). What I did was draw several random shapes, in particular polygons with narrow internal angles to see if that corner problem has been solved. One was shaped like 2 fingers raised '/' 4 edges , and I did a cut inside AND outside on that one. When I did a gcode check in NCPlot the central point of the V crossed over, ie the outside cut went to the same point as the inside cut, crossing the actual drawn outline.
    I went back to SKetchup and deleted both inside and outside cuts, drew an extra line from the point of the V and deleted it, and replaced the inside cut without problem. But then when I clicked the outside cut tool any shape I selected showed the cut line on the inside. I tried ordering edges etc, but it just stayed that way, even though I deleted edges and replaced them and a few other edits.

    By the way during my quick metrification yesterday (always more fun than work!) I ran the resulting code through EMC2 in sim mode and I'm impressed with the smooth curves, now if only I can build a machine that cuts nearly as well I'll be happy. Note that I changed the resolution (and justification) of the output numbers, imperial gets 3 decimals and metric gets 2. You had %10.6f and I thought that may be needed for the arc interpolations but EMC was happy with those settings (it will often bitch about start and end points being at different radii if there is not enough resolution). 0.01mm is less than .5 thou, I don't think any of our machines cut to more accuracy than that (and certainly less repeatability?). 0.001 resolution in imperial mode is probably enough for most machines IMHO, but any user who needs an extra digit can easily mod the code where @resolution is set.

    I changed the justification to make the gcode more readable 'to me'. It's just the way I like it :D
    I need to be able to read it because I plan to add a DVD laser to the cutting head for writing part numbers, and I'll probably need to hand code some of that and will need to figure out where to do stuff in the code. The laser will probably be on the W axis parallel to the Z. Driving it down to get in range will hit a switch to turn it on, restract for off.
    Maybe phlatscript can detect something like a 0% centerline cut and output the correct codes? I'll have to see when I get there, I have built the stepper interfaces and am busy testing motors (I have a collection of steppers from printers, up to Nema34 size), next I'll build a small 3 axis gantry router which will cut about 150x150x50mm, just to learn what not to do, then comes the 1200x700x150 cnc router.
     
  17. swarfer

    swarfer Moderator Staff Member

    Offline
    Messages:
    808
    Trophy Points:
    28
    Location:
    Grahamstown, South Africa
    hey, I discovered how to reproduce some of what I saw.

    What I did
    Draw the V shape starting top left, bottom middle, top right, top middle, top left.
    do inside cut
    do outside cut
    the result is that the top portion of the outside cut shares an inside point with the inside cut.
    Sure, you are unlikely to actually cut something like this, but this is a possible intermedaite step, having mistakenly selected inside, then select outside before deleting the inside cut.

    Sketchup file http://iwr.ru.ac.za/~david/phlat/bug1.skp
    screen dump http://iwr.ru.ac.za/~david/phlat/bug1.png
     
  18. gasmasher

    gasmasher New Member

    Offline
    Messages:
    402
    Trophy Points:
    0
    Location:
    Atlanta, GA
    I see what the problem is and fixed it this morning. It is in testing ;)
     
  19. swarfer

    swarfer Moderator Staff Member

    Offline
    Messages:
    808
    Trophy Points:
    28
    Location:
    Grahamstown, South Africa
    Hiya

    Thanks for the info on the shift key, I may well have pressed it at some point who knows.

    On laser marking. I looked at gcodeutil.rb and while I wasn't thinking of adding a new line marking style, I agree that that is the way to go. Detecting 0 cut depth could also work but would require some extra housekeeping to get the W axis to retract in the right places.
    It could also be done in phlatmill.rb but a new line style is a much better solution.

    DVD laser modules can do about 200mw which is enough to mark medium to dark surfaces if you move slowly. That is what CNC does best (-:
    http://www.flickr.com/photos/audin/1244728357/

    That shows the basics, but from what I've read so far a good constant current power supply is the way to go, else the laser diode will die. And don't forget a heat sink on the laser.

    This will also require that a tool offset is set up in the CNC software, because the laser will be offset from the router, and the gcode must select that tool for each 'writing' move, and reselect the normal tool afterward.

    BTW I notice that some of the menu items have disappeared, like 'set as centreline' and so on. Are those coming back? I found them very useful. Is 'phlatten edges' equivalent to 'order selected edges'? Going off to seak and read a readme file...
     

Share This Page