CNCzone.com-The Largest Machinist Community on the net!



Home Page Mark Forums Read Today's Posts My Replies Classifieds Reviews Photo Gallery Web Links Share Files Advertise With Us Ad List
Go Back   CNCzone.com-The Largest Machinist Community on the net! > Machine Controllers Software and Solutions > G-Code Programing


G-Code Programing Discuss G-code programing and problems here!


This forum is sponsored by:

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Ban this user!
Old 03-10-2008, 12:28 PM
 
Join Date: Oct 2007
Location: USA
Posts: 14
Timbersmith is on a distinguished road
need help with excel vba macro

I'm trying to use VBA to generate a g-code text file that will run a CNC saw that will automaticly move the board to the right position and adjust the saw miter and bevel angles. I've already used other software to model the building and export pieces, then optimize and sequence all those "pieces" for cutting from the "boards" or raw stock. The text file to run the cnc machine needs to have the following format:

G28 M6 '(go to home position and wait for operator input)
G1 X75.0 Y-30.0 Z90 M6 '(inital cut-off. move x=75.0 y=-30 z=90 wait for operator input)
G1 X662.5.0 Y30.0 Z90 M6 '(left cut. similar to abv.)
G28 M6 '(go to home position and wait for operator input)
G1 X75.0 Y-45 Z45 M6 '(piece2 initial cut-off)
G2 X312.5 Y-30 Z90 M6 '(piece2 left cut)
G1 X35.0 Y90 Z90 M6 '(piece3 right cut)
G1 X212.5 Y30 Z90 M6 '(piece3 left cut)
G1 X40.0 Y20 Z90 M6 '(piece4 right cut)
G1 X237.5 Y30 Z90 M6 '(piece4 left Cut)
...



A little graphic might be handy to describe the situation. The graphic shows the saw with the 4 pieces that the two boards need to be cut into. Board 1 gets cut into piece 1 and board 2 gets cut into pieces 2,3 and 4.
http://picasaweb.google.com/kurtafra...85101064800914

G28 is a command to return to the home position, G1=set the saw to the following values, X=how far to move the x motor (red block in graphic), y=what angle to set the miter angle(top view rotation of saw blade), z=what angle to set the bevel motor(front view rotation of sawblade) and M6 says wait for the operator to do something and press the "next" button.

I've got a spreadsheet with 2 tables that define the pieces and boards. The spreadsheet that coresponds to the image would look like this:

Pieces!
Piece# Thickness Width Length Orientation Miter Bevel
1 88.1 180 650 Right -30 90
1 88.1 180 650 Left 30 90
2 88.1 180 300 Right -45 45
2 88.1 180 300 Left -45 90
3 88.1 180 200 Right 90 90
3 88.1 180 200 Left 30 90
4 88.1 180 225 Right 20 90
4 88.1 180 225 Left 30 90

Boards!
Board # Piece# Length
1 1 750
2 2 750
2 3 750
2 4 750

I'm only showing a few pieces and boards and simplifying the data for the example. A normal batch might have 200 boards being cut into 500 pieces.

The pieces need to be processed with a looping structure that loops through the boards sheet,looking up values from the pieces sheet:

Start the text file with a G28 line
For
If this is the first piece in a board
Generate gcode line "G28 M6"
Generate gcode line for initial right end cut-off. "G1 X--- Y--- Z--- M6"
Generate the gcode line for the left cut. "G1 X--- Y--- Z--- M6"
Else
Compare last piece left cut with this piece right cut.
If angle and bevel are not the same
Generate the gcode for this piece right cut "G1 X--- Y--- Z--- M6"
Else
Genreate the gcode for this piece left cut "G1 X--- Y--- Z--- M6"
End If
End If
Next

The Y and Z values (miter and bevel) just come right from the Pieces! sheet. The X value needs to be calculated for the 3 differetn conditions - initial right cut, left cut, or last left to current right. I've got all the math figured out but they are complicated formulas involvoing trig, piece width and thickness, and saw geometry constants like MiterPivotPoint, BladeThickness, and BladeOffset. I think if I can just get the values from the spreadsheet for now, I can substitute back in formulas once the looping structure all works properly. That way I don't unnecesarily complicate my request for help in here.

For now, if we just say that:
Initial Right cut, x=800 - Boards!Length +25.0
Left Cut = Pieces!Length + 12.5
LastLeft to CurrentRight = LastPieceLeftMiter + 10
I can substitute back in the big ugly formulas later.
Reply With Quote

  #2  
Old 03-10-2008, 06:04 PM
ger21's Avatar
Community Moderator
 
Join Date: Mar 2003
Location: Shelby Twp, MI....USA
Posts: 20,455
ger21 is on a distinguished road
Buy me a Beer?

I glanced at this earlier, but didn't have time then. Know that I have time to carefully read it, I don't see any questions in there.

I wrote an AutoCAD VBA macro that exports g-code. It's basically just a series of if..then...else statements

What I do is open a file to write to.

Set fs = CreateObject("Scripting.FileSystemObject")
Set gcode = fs.CreateTextFile(Fpath, True)

Then get all the values you need, and concatenate them into a string (along with your G1 X Y Z...). I don't have Excel here, so I'm guessing a little (along with googling).

Set up a string variable to use for each line of code.

Gcodeline = "G28 M6"

Write the line to the file

gcode.writeline (Gcodeline)

Set up the next line:

Gcodeline = "G1 X" + Cstr(Range(A1).value) + " Y" + Cstr(Range(A2).value) + " Z" + Cstr(Range(A3).value) + " M6"

gcode.writeline (Gcodeline)


Keep going until your done, and close the file. Is that what your looking for?
__________________
Gerry

Mach3 2010 Screenset
http://home.comcast.net/~cncwoodworker/2010.html

(Note: The opinions expressed in this post are my own and are not necessarily those of CNCzone and its management)
Reply With Quote

  #3   Ban this user!
Old 03-12-2008, 07:23 PM
 
Join Date: Jul 2003
Location: New Zealand
Posts: 1,039
Kiwi is on a distinguished road

Timbersmith
I'm not familiar with generating gcode from excel, I use VB6 for generating code.
A program could be written to read the data from your excel spread sheet and manipulate as required. eg: The lengths could also be sorted to save waste.
See #15 of this post which shows data which was read from excel and converted to gcode.
http://www.cnczone.com/forums/showth...163#post249163

Send me PM if this is of interest.
Reply With Quote

  #4   Ban this user!
Old 03-13-2008, 11:39 PM
 
Join Date: Jul 2003
Location: New Zealand
Posts: 1,039
Kiwi is on a distinguished road

Timbersmith
Took up the challenge and wrote a VB program..see attached.
I tried writing in Excel but I'm not up to speed with writing the code to notepad from excel.
Attached Files
File Type: zip Book1.zip‎ (1.6 KB, 134 views)
File Type: zip Miter Saw Cutting Code.zip‎ (5.4 KB, 88 views)
Reply With Quote

  #5   Ban this user!
Old 03-14-2008, 04:04 PM
 
Join Date: Jul 2003
Location: New Zealand
Posts: 1,039
Kiwi is on a distinguished road

Timbersmith
Two points that I'm unable to follow.
This line has G2........
G2 X312.5 Y-30 Z90 M6 '(piece2 left cut)
What is the difference?
And this line shows -45
2 88.1 180 300 Left -45 90
Should this be -30 ?

Last edited by Kiwi; 03-14-2008 at 04:11 PM. Reason: correct figures
Reply With Quote

Sponsored Links
  #6   Ban this user!
Old 03-14-2008, 05:48 PM
 
Join Date: Oct 2007
Location: USA
Posts: 14
Timbersmith is on a distinguished road

The reason you are unable to follow is that they are my mistakes! You are right on both counts. Typos from doing it by hand.

I'd love to Skype or IM with you about this live and get some insight and try to conveyit better. It's hard to type out a good description. The piece-to-piece transition is particularly cumbersome.

On Skype I'm kurt.westerlund in Truckee CA USA.

Thanks a miilion for your help Kiwi!
Reply With Quote

  #7   Ban this user!
Old 03-14-2008, 08:35 PM
 
Join Date: Jul 2003
Location: New Zealand
Posts: 1,039
Kiwi is on a distinguished road

Hi Kurt
I'm sorry, I'm not up with Skype as yet.
Did the VB program do what you need (with refinements)?
I've sent you a PM.
Reply With Quote

  #8   Ban this user!
Old 05-07-2008, 07:46 PM
 
Join Date: Jul 2003
Location: New Zealand
Posts: 1,039
Kiwi is on a distinguished road

Kurt
Not sure if you still require this as I haven't heard anything for over 6 weeks.
I hope all is well.
Attached Files
File Type: zip MitreSawCuttingCode.zip‎ (14.0 KB, 121 views)
Reply With Quote

Reply




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Fanuc OM tool change macro for a Kiwa/Excel TR MFG Fanuc 5 01-27-2008 04:00 AM
Convert Fanuc Macro to Fadal Macro bfoster59 Fadal 1 11-08-2007 11:41 PM
Need help to set home on an Excel-810 dpuch Machine Problems, Solutions , Wireless DNC, serial port 0 08-01-2006 02:41 PM
Excel 810 Dale283 Fanuc 0 01-15-2006 05:47 PM
new post processor or excel macro or... trubble2rubble G-Code Programing 3 07-16-2005 08:20 AM




All times are GMT -5. The time now is 10:09 PM.





Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Content Relevant URLs by vBSEO
Template-Modifications by TMS

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361