Frusta

Check-in [04002210f3]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:First working version of gcode exercise code generator
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:04002210f31898541bc9d27acb750c6bb007f933
User & Date: rmelton 2013-10-23 04:23:14
Context
2013-10-23
16:29
added exercise resonance tests check-in: 7c129b9525 user: rmelton tags: trunk
04:23
First working version of gcode exercise code generator check-in: 04002210f3 user: rmelton tags: trunk
03:07
started gcode writer check-in: a243c85b43 user: rmelton tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to lib/gcode/gcode_0.1.tcl.

251
252
253
254
255
256
257


258
259
260
261
262
263
264
...
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
    proc M108 {args} {;## Set Extruder Speed
    }
    proc M109 {args} {;## Set Extruder Temperature and Wait
    }
    proc M110 {args} {;## Set Current Line Number
    }
    proc M111 {args} {;## Set Debug Level


    }
    proc M112 {args} {;## Emergency Stop
    }

    proc M130 {args} {;## ????
    }
    proc M140 {args} {;## ????
................................................................................
    }
    interp delete gcodeParseInterp
  }

  namespace eval write {
    #http://reprap.org/wiki/G-code
    variable fp
    proc open {} {}



    proc close {} {}




    proc Puts {} {
      variable fp

    }
    proc Display {args} {
      Puts "M117 $args"

    }
























    proc Path {args} {







      set path [concat {*}$args]
      set pathPt [lassign $path P0]


      lassign $P0 x0 y0
      Puts G1 X90.6 Y13.8 E22.4











      foreach pt $pathPt {


        lassign $pt x1 y1
        Puts G1 X90.6 Y13.8 E22.4











      }
    }
  }

}

package provide frusta::gcode 0.1







>
>







 







|
>
>
>
|
>
>
>
>
|

>


<
>

>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

>
>
>
>
>
>
>


>
>
|
|
>
>
>
>
>
>
>
>
>
>
>

>
>
|
|
>
>
>
>
>
>
>
>
>
>
>







251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
...
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
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
    proc M108 {args} {;## Set Extruder Speed
    }
    proc M109 {args} {;## Set Extruder Temperature and Wait
    }
    proc M110 {args} {;## Set Current Line Number
    }
    proc M111 {args} {;## Set Debug Level
    }
    proc M117 {args} {;## Display
    }
    proc M112 {args} {;## Emergency Stop
    }

    proc M130 {args} {;## ????
    }
    proc M140 {args} {;## ????
................................................................................
    }
    interp delete gcodeParseInterp
  }

  namespace eval write {
    #http://reprap.org/wiki/G-code
    variable fp
    proc Open {} {
      variable fp
      set fp [open "output.gcode" w]
    }
    proc Close {} {
      variable fp
      close $fp
      unset fp
    }
    proc Puts {args} {
      variable fp
      puts $fp [join $args " "]
    }
    proc Display {args} {

      Puts M117 [join $args " "]
    }
    proc Init {args} {
      set cArgs {}
      while {[llength $args] > 0 && [string match "-*" [lindex $arg 0]]} {
        set args [lassign $args cmd]
        switch -- $cmd {
          default {error "gcode::write::Init bad cmd=$cmd"}
        }
      }
      Puts G21 ;# set units to mm
      Puts G90 ;# set to absolute positioning
    }
    proc Home {args} {
      set cArgs {}
      while {[llength $args] > 0 && [string match "-*" [lindex $args 0]]} {
        set args [lassign $args cmd]
        switch -- $cmd {
          -x {lappend cArgs X0}
          -y {lappend cArgs Y0}
          -z {lappend cArgs Z0}
          default {error "gcode::write::Home bad cmd=$cmd"}
        }
      }
      Puts G28 [join $cArgs " "]
    }
    proc Path {args} {
      while {[llength $args] > 0 && [string match "-*" [lindex $args 0]]} {
        set args [lassign $args cmd]
        switch -- $cmd {
          -move {}
          default {error "gcode::write::Path bad cmd=$cmd"}
        }
      }
      set path [concat {*}$args]
      set pathPt [lassign $path P0]
      switch -- [llength $P0] {
        1 {
          lassign $P0 x
          Puts G1 X$x
        }
        2 {
          lassign $P0 x y
          Puts G1 X$x Y$y
        }
        3 {
          lassign $P0 x y z
          Puts G1 X$x Y$y Z$z
        }
        default {error "gcode::write::Path bad length P0=$P0"}
      }
      foreach pt $pathPt {
        switch -- [llength $pt] {
          1 {
            lassign $pt x
            Puts G1 X$x
          }
          2 {
            lassign $pt x y
            Puts G1 X$x Y$y
          }
          3 {
            lassign $pt x y z
            Puts G1 X$x Y$y Z$z
          }
          default {error "gcode::write::Path bad length pt=$pt"}
        }
      }
    }
  }

}

package provide frusta::gcode 0.1

Changes to lib/machine/machine_0.1.tcl.

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
..
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
..
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
...
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
  set v(z0) [expr {[Settings::Get buildHeight]*0.1}]
  set v(z1) [expr {[Settings::Get buildHeight]*0.9}]
  set v(bedX0) 0
  set v(bedX1) [Settings::Get buildWidth]
  set v(bedY0) 0
  set v(bedY1) [Settings::Get buildHeight]
  set v(loops) 20
  set v(autohome)        1
  set v(doOpositeSides)  1
  set v(doOpositeCircle) 1
  set v(doSideStitch)    1
  set v(doSpiral)        1
  set v(segsOpositeSide)    5
  set v(segsOpositeCircle) 10
  set v(segsStitchSides)   20
................................................................................
      grid $w.test.y $w.test.yMin $w.test.yMax
      grid $w.test.z $w.test.zMin $w.test.zMax
    }
    eval {
      ttk::labelframe $w.loop -text "Test procedure"
      label $w.loop.loopL -text "loop test \#times = "
      spinbox $w.loop.loops -from 0 -to 100 -textvariable [namespace current]::v(loops) -width 6 -justify right
      checkbutton $w.loop.homming        -text "X/Y/Z homming"   -variable [namespace current]::v(autohome)
      checkbutton $w.loop.opositeCorners -text "oposite sides"   -variable [namespace current]::v(doOpositeSides)
      checkbutton $w.loop.opositeCircle  -text "oposite circle"  -variable [namespace current]::v(doOpositeCircle)
      checkbutton $w.loop.stitchSides    -text "stitch sides"    -variable [namespace current]::v(doSideStitch)
      checkbutton $w.loop.doSpiral       -text "spiral"          -variable [namespace current]::v(doSpiral)

      label $w.loop.n -text "\# segments"
      spinbox $w.loop.segsOpositeSide   -from 0 -to 100 -textvariable [namespace current]::v(segsOpositeSide)   -width 6 -justify right
................................................................................
    }

    label $w.stlFileLabel -text "Output STL File:"
    entry $w.stlFileName

    canvas $w.view -width [expr {[Settings::Get buildWidth]}] -height  [expr {[Settings::Get buildDepth]}]
    button $w.preview -text "Preview" -command [namespace code Preview]
    button $w.write -text "Write"

    grid $w.bed           $w.test        $w.view  -sticky n
    grid $w.loop          -              ^        -sticky ew
    grid ^                ^              $w.preview
    grid $w.stlFileLabel  $w.stlFileName $w.write
  }

................................................................................
    }
    if {$v(doSpiral)} {
      drawPathInCanvas $w.view [spiralOutXY         $v(x0) $v(y0) $v(x1) $v(y1) $v(segsSpiral)]        1 {-fill purple -arrow none}
      drawPathInCanvas $w.view [spiralInXY          $v(x0) $v(y0) $v(x1) $v(y1) $v(segsSpiral)]        1 {-fill pink -arrow none}
    }
  }

  proc buildExercise {} {
    variable v
    gcode::write::open

    gcode::write::display "Motor Exercise"
    $w.view delete all






    if {$v(doOpositeSides)} {
      gcode::write::path -move [squareCrissCrossXY $v(x0) $v(y0) $v(x1) $v(y1) $v(segsOpositeSide)] 25 {-fill blue}
    }
    if {$v(doOpositeCircle)} {
      gcode::write::path -move [roundCrissCrossXY  $v(x0) $v(y0) $v(x1) $v(y1) $v(segsOpositeCircle)] 25 {-fill green}
    }
    if {$v(doSideStitch)} {
      gcode::write::path -move [stitchSidesXY      $v(x0) $v(y0) $v(x1) $v(y1) $v(segsStitchSides)]  25 {-fill white}
    }
    if {$v(doSpiral)} {
      gcode::write::path -move [spiralOutXY         $v(x0) $v(y0) $v(x1) $v(y1) $v(segsSpiral)]        1 {-fill purple -arrow none}
      gcode::write::path -move [spiralInXY          $v(x0) $v(y0) $v(x1) $v(y1) $v(segsSpiral)]        1 {-fill pink -arrow none}
    }


  }

  proc drawPathInCanvas {c path {delay 0} {pathArgs {}}} {
    set pathPt [lassign $path P0]
    lassign $P0 x0 y0
    foreach pt $pathPt {
      lassign $pt x1 y1







|







 







|







 







|







 







|

|
>
|
<
>
>
>
>
>
>
|
|
|
|
|
|
|
|
|
|
|
|
|
>
>







10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
..
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
..
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
...
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
  set v(z0) [expr {[Settings::Get buildHeight]*0.1}]
  set v(z1) [expr {[Settings::Get buildHeight]*0.9}]
  set v(bedX0) 0
  set v(bedX1) [Settings::Get buildWidth]
  set v(bedY0) 0
  set v(bedY1) [Settings::Get buildHeight]
  set v(loops) 20
  set v(autoHome)        1
  set v(doOpositeSides)  1
  set v(doOpositeCircle) 1
  set v(doSideStitch)    1
  set v(doSpiral)        1
  set v(segsOpositeSide)    5
  set v(segsOpositeCircle) 10
  set v(segsStitchSides)   20
................................................................................
      grid $w.test.y $w.test.yMin $w.test.yMax
      grid $w.test.z $w.test.zMin $w.test.zMax
    }
    eval {
      ttk::labelframe $w.loop -text "Test procedure"
      label $w.loop.loopL -text "loop test \#times = "
      spinbox $w.loop.loops -from 0 -to 100 -textvariable [namespace current]::v(loops) -width 6 -justify right
      checkbutton $w.loop.homming        -text "X/Y/Z homming"   -variable [namespace current]::v(autoHome)
      checkbutton $w.loop.opositeCorners -text "oposite sides"   -variable [namespace current]::v(doOpositeSides)
      checkbutton $w.loop.opositeCircle  -text "oposite circle"  -variable [namespace current]::v(doOpositeCircle)
      checkbutton $w.loop.stitchSides    -text "stitch sides"    -variable [namespace current]::v(doSideStitch)
      checkbutton $w.loop.doSpiral       -text "spiral"          -variable [namespace current]::v(doSpiral)

      label $w.loop.n -text "\# segments"
      spinbox $w.loop.segsOpositeSide   -from 0 -to 100 -textvariable [namespace current]::v(segsOpositeSide)   -width 6 -justify right
................................................................................
    }

    label $w.stlFileLabel -text "Output STL File:"
    entry $w.stlFileName

    canvas $w.view -width [expr {[Settings::Get buildWidth]}] -height  [expr {[Settings::Get buildDepth]}]
    button $w.preview -text "Preview" -command [namespace code Preview]
    button $w.write -text "Write" -command [namespace code BuildExercise]

    grid $w.bed           $w.test        $w.view  -sticky n
    grid $w.loop          -              ^        -sticky ew
    grid ^                ^              $w.preview
    grid $w.stlFileLabel  $w.stlFileName $w.write
  }

................................................................................
    }
    if {$v(doSpiral)} {
      drawPathInCanvas $w.view [spiralOutXY         $v(x0) $v(y0) $v(x1) $v(y1) $v(segsSpiral)]        1 {-fill purple -arrow none}
      drawPathInCanvas $w.view [spiralInXY          $v(x0) $v(y0) $v(x1) $v(y1) $v(segsSpiral)]        1 {-fill pink -arrow none}
    }
  }

  proc BuildExercise {} {
    variable v
    gcode::write::Open
    gcode::write::Init
    gcode::write::Display "Motor Exercise"

    for {set i 0} {$i < $v(loops)} {incr i} {
      gcode::write::Display "Motor Exercise $i/$v(loops)"
      if {$v(autoHome)} {
        gcode::write::Home
      }
      gcode::write::Path -move [list $v(x0) $v(y0) $v(z0)]
      if {$v(doOpositeSides)} {
        gcode::write::Path -move [squareCrissCrossXY $v(x0) $v(y0) $v(x1) $v(y1) $v(segsOpositeSide)]
      }
      if {$v(doOpositeCircle)} {
        gcode::write::Path -move [roundCrissCrossXY  $v(x0) $v(y0) $v(x1) $v(y1) $v(segsOpositeCircle)]
      }
      if {$v(doSideStitch)} {
        gcode::write::Path -move [stitchSidesXY      $v(x0) $v(y0) $v(x1) $v(y1) $v(segsStitchSides)]
      }
      if {$v(doSpiral)} {
        gcode::write::Path -move [spiralOutXY         $v(x0) $v(y0) $v(x1) $v(y1) $v(segsSpiral)]
        gcode::write::Path -move [spiralInXY          $v(x0) $v(y0) $v(x1) $v(y1) $v(segsSpiral)]
      }
    }
    gcode::write::Close
  }

  proc drawPathInCanvas {c path {delay 0} {pathArgs {}}} {
    set pathPt [lassign $path P0]
    lassign $P0 x0 y0
    foreach pt $pathPt {
      lassign $pt x1 y1