|
2 | 2 | # Part of the Eggbot driver for Inkscape |
3 | 3 | # http://code.google.com/p/eggbotcode/ |
4 | 4 | # |
5 | | -# Version 2.5.0, dated 2015-01-30 |
| 5 | +# Version 2.6.0, dated 2015-08-31 |
| 6 | +# REQUIRES: Pyserial version 2.7.0 |
6 | 7 | # |
7 | 8 | # This program is free software; you can redistribute it and/or modify |
8 | 9 | # it under the terms of the GNU General Public License as published by |
|
32 | 33 | import sys |
33 | 34 | import time |
34 | 35 | import eggbot_scan |
| 36 | +import eggbot_conf |
35 | 37 |
|
36 | 38 | F_DEFAULT_SPEED = 1 |
37 | 39 | N_PEN_DOWN_DELAY = 400 # delay (ms) for the pen to go down before the next move |
38 | 40 | N_PEN_UP_DELAY = 400 # delay (ms) for the pen to up down before the next move |
39 | | -N_PAGE_HEIGHT = 800 # Default page height (each unit equiv. to one step) |
40 | | -N_PAGE_WIDTH = 3200 # Default page width (each unit equiv. to one step) |
| 41 | +# N_PAGE_HEIGHT = 800 # Default page height (each unit equiv. to one step) - MOVED TO eggbot_conf.py |
| 42 | +# N_PAGE_WIDTH = 3200 # Default page width (each unit equiv. to one step) - MOVED TO eggbot_conf.py |
41 | 43 |
|
42 | 44 | N_PEN_UP_POS = 50 # Default pen-up position |
43 | 45 | N_PEN_DOWN_POS = 40 # Default pen-down position |
|
64 | 66 | DRY_RUN_OUTPUT_FILE = os.path.join( HOME, 'dry_run.txt' ) |
65 | 67 | MISC_OUTPUT_FILE = os.path.join( HOME, 'misc.txt' ) |
66 | 68 |
|
67 | | -## if platform == 'darwin': |
68 | | -## ''' There's no good value for OS X ''' |
69 | | -## STR_DEFAULT_COM_PORT = '/dev/cu.usbmodem1a21' |
70 | | -## elif platform == 'sunos': |
71 | | -## ''' Untested: YMMV ''' |
72 | | -## STR_DEFAULT_COM_PORT = '/dev/term/0' |
73 | | -## else: |
74 | | -## ''' Works fine on Ubuntu; YMMV ''' |
75 | | -## STR_DEFAULT_COM_PORT = '/dev/ttyACM0' |
76 | 69 |
|
77 | 70 | def parseLengthWithUnits( str ): |
78 | 71 | ''' |
@@ -139,10 +132,6 @@ def __init__( self ): |
139 | 132 | action="store", type="float", |
140 | 133 | dest="smoothness", default=.2, |
141 | 134 | help="Smoothness of curves" ) |
142 | | -## self.OptionParser.add_option( "--comPort", |
143 | | -## action="store", type="string", |
144 | | -## dest="comport", default=STR_DEFAULT_COM_PORT, |
145 | | -## help="USB COM port to connect eggbot.") |
146 | 135 | self.OptionParser.add_option( "--startCentered", |
147 | 136 | action="store", type="inkbool", |
148 | 137 | dest="startCentered", default=True, |
@@ -252,22 +241,23 @@ def __init__( self ): |
252 | 241 | nDeltaX = 0 |
253 | 242 | nDeltaY = 0 |
254 | 243 |
|
255 | | - self.svgWidth = float( N_PAGE_WIDTH ) |
256 | | - self.svgHeight = float( N_PAGE_HEIGHT ) |
| 244 | + self.svgWidth = float( eggbot_conf.N_PAGE_WIDTH ) |
| 245 | + self.svgHeight = float( eggbot_conf.N_PAGE_HEIGHT ) |
257 | 246 | self.svgTransform = [[1.0, 0.0, 0.0], [0.0, 1.0, 0.0]] |
258 | 247 |
|
259 | 248 | # So that we only generate a warning once for each |
260 | 249 | # unsupported SVG element, we use a dictionary to track |
261 | 250 | # which elements have received a warning |
262 | 251 | self.warnings = {} |
263 | 252 |
|
264 | | - # Hack for mismatched EBB/motors, |
265 | | - # which have half resolution |
266 | | - try: |
267 | | - import motor1600 |
268 | | - self.step_scaling_factor = 2 |
269 | | - except ImportError: |
270 | | - self.step_scaling_factor = 1 |
| 253 | + # "Normal" value: self.step_scaling_factor = 2, for 3200 steps/revolution. |
| 254 | + |
| 255 | + self.step_scaling_factor = eggbot_conf.STEP_SCALE |
| 256 | + |
| 257 | + self.wrapSteps = 6400 / self.step_scaling_factor |
| 258 | + self.halfWrapSteps = self.wrapSteps / 2 |
| 259 | + |
| 260 | + |
271 | 261 |
|
272 | 262 | def effect( self ): |
273 | 263 | '''Main entry point: check to see which tab is selected, and act accordingly.''' |
@@ -318,15 +308,6 @@ def effect( self ): |
318 | 308 | self.EggbotOpenSerial() |
319 | 309 | self.manualCommand() |
320 | 310 |
|
321 | | -## elif self.options.tab == '"timing"': |
322 | | -## self.EggbotOpenSerial() |
323 | | -## if self.serialPort is not None: |
324 | | -## self.ServoSetupWrapper() |
325 | | -## |
326 | | -## elif self.options.tab == '"options"': |
327 | | -## self.EggbotOpenSerial() |
328 | | -## if self.serialPort is not None: |
329 | | -## |
330 | 311 | self.svgDataRead = False |
331 | 312 | self.UpdateSVGEggbotData( self.svg ) |
332 | 313 | self.EggbotCloseSerial() |
@@ -1047,8 +1028,8 @@ def getDocProps( self ): |
1047 | 1028 | Use a default value in case the property is not present or is |
1048 | 1029 | expressed in units of percentages. |
1049 | 1030 | ''' |
1050 | | - self.svgHeight = self.getLength( 'height', N_PAGE_HEIGHT ) |
1051 | | - self.svgWidth = self.getLength( 'width', N_PAGE_WIDTH ) |
| 1031 | + self.svgHeight = self.getLength( 'height', eggbot_conf.N_PAGE_HEIGHT ) |
| 1032 | + self.svgWidth = self.getLength( 'width', eggbot_conf.N_PAGE_WIDTH ) |
1052 | 1033 | if ( self.svgHeight == None ) or ( self.svgWidth == None ): |
1053 | 1034 | return False |
1054 | 1035 | else: |
@@ -1093,16 +1074,16 @@ def plotPath( self, path, matTransform ): |
1093 | 1074 |
|
1094 | 1075 | nIndex += 1 |
1095 | 1076 |
|
1096 | | - self.fX = float( csp[1][0] ) / self.step_scaling_factor |
1097 | | - self.fY = float( csp[1][1] ) / self.step_scaling_factor |
| 1077 | + self.fX = 2 * float( csp[1][0] ) / self.step_scaling_factor |
| 1078 | + self.fY = 2 * float( csp[1][1] ) / self.step_scaling_factor |
1098 | 1079 |
|
1099 | 1080 | # store home |
1100 | 1081 | if self.ptFirst is None: |
1101 | 1082 |
|
1102 | 1083 | # if we should start at center, then the first line segment should draw from there |
1103 | 1084 | if self.options.startCentered: |
1104 | | - self.fPrevX = self.svgWidth / ( 2 * self.step_scaling_factor ) |
1105 | | - self.fPrevY = self.svgHeight / ( 2 * self.step_scaling_factor ) |
| 1085 | + self.fPrevX = self.svgWidth / ( self.step_scaling_factor ) |
| 1086 | + self.fPrevY = self.svgHeight / ( self.step_scaling_factor ) |
1106 | 1087 |
|
1107 | 1088 | self.ptFirst = ( self.fPrevX, self.fPrevY ) |
1108 | 1089 | else: |
@@ -1223,14 +1204,14 @@ def plotLineAndTime( self ): |
1223 | 1204 |
|
1224 | 1205 | if self.bPenIsUp: |
1225 | 1206 | self.fSpeed = self.options.penUpSpeed |
1226 | | - |
| 1207 | + |
1227 | 1208 | if ( self.options.wraparound ): |
1228 | | - if ( nDeltaX > 1600 / self.step_scaling_factor ): |
1229 | | - while ( nDeltaX > 1600 / self.step_scaling_factor ): |
1230 | | - nDeltaX -= 3200 / self.step_scaling_factor |
1231 | | - elif ( nDeltaX < -1600 / self.step_scaling_factor ): |
1232 | | - while ( nDeltaX < -1600 / self.step_scaling_factor ): |
1233 | | - nDeltaX += 3200 / self.step_scaling_factor |
| 1209 | + if ( nDeltaX > self.halfWrapSteps ): |
| 1210 | + while ( nDeltaX > self.halfWrapSteps ): |
| 1211 | + nDeltaX -= self.wrapSteps |
| 1212 | + elif ( nDeltaX < -1 * self.halfWrapSteps ): |
| 1213 | + while ( nDeltaX < -1 * self.halfWrapSteps ): |
| 1214 | + nDeltaX += self.wrapSteps |
1234 | 1215 |
|
1235 | 1216 | else: |
1236 | 1217 | self.fSpeed = self.options.penDownSpeed |
@@ -1348,9 +1329,9 @@ def getSerialPort( self ): |
1348 | 1329 | # Before searching, first check to see if the last known |
1349 | 1330 | # serial port is still good. |
1350 | 1331 |
|
1351 | | - serialPort = self.testSerialPort( self.svgSerialPort ) |
1352 | | - if serialPort: |
1353 | | - return serialPort |
| 1332 | +# serialPort = self.testSerialPort( self.svgSerialPort ) |
| 1333 | +# if serialPort: |
| 1334 | +# return serialPort |
1354 | 1335 |
|
1355 | 1336 | # Try any devices which seem to have EBB boards attached |
1356 | 1337 | for strComPort in eggbot_scan.findEiBotBoards(): |
|
0 commit comments