コード例 #1
0
ファイル: eggbot.py プロジェクト: JesperKrogPoulsen/EggBot
	def plotToEggBot( self ):
		'''Perform the actual plotting, if selected in the interface:'''
		#parse the svg data as a series of line segments and send each segment to be plotted

		if self.serialPort is None:
			return

		if self.options.startCentered and ( not self.getDocProps() ):
			# Cannot handle the document's dimensions!!!
			inkex.errormsg( gettext.gettext(
			'This document does not have valid dimensions.\r\r' +
			'Consider starting with the EggBot template, or ' +
			'setting the document size to 3200 px (wide) x 800 px (tall).\r\r' +
			'Document dimensions may be set in Inkscape with ' +
			'File > Document Properties.\r\rThe document dimensions must be unitless or have ' +
			'units of pixels (px) or percentages (%).   '	) )
			return

		# Viewbox handling
		# Also ignores the preserveAspectRatio attribute
		viewbox = self.svg.get( 'viewBox' )
		if viewbox:
			vinfo = viewbox.strip().replace( ',', ' ' ).split( ' ' )
			if ( float(vinfo[2]) != 0 ) and ( float(vinfo[3]) != 0 ):
				sx = self.svgWidth / float( vinfo[2] )
				sy = self.svgHeight / float( vinfo[3] )
				self.svgTransform = parseTransform( 'scale(%f,%f) translate(%f,%f)' % (sx, sy, -float( vinfo[0] ), -float( vinfo[1] ) ) )

		self.ServoSetup()
		ebb_motion.sendEnableMotors(self.serialPort, 1) # 16X microstepping
		
		# Ensure that the engraver is turned off for the time being
		# It will be turned back on when the first non-virtual pen-down occurs
		if self.options.engraving:
			self.engraverOff()


		try:
			# wrap everything in a try so we can for sure close the serial port
			#self.recursivelyTraverseSvg(self.document.getroot())
			self.penDownActivatesEngraver = True
			self.recursivelyTraverseSvg( self.svg, self.svgTransform )
			self.penUp()   #Always end with pen-up

			# Logically, we want to turn the engraver off here as well,
			# but we put that in our finally clause instead
			# self.engraverOff()

			# return to home, if returnToHome = True
			if ( ( not self.bStopped ) and self.options.returnToHome and ( self.ptFirst ) ):
				self.fX = self.ptFirst[0]
				self.fY = self.ptFirst[1]
				#self.penUp()
				self.nodeCount = self.nodeTarget    # enablesfpx return-to-home only option
				self.plotLineAndTime()
			#inkex.errormsg('Final node count: ' + str(self.svgNodeCount))  #Node Count - Debug option
			if ( not self.bStopped ):
				self.svgLayer = 0
				self.svgNodeCount = 0
				self.svgLastPath = 0
				self.svgLastPathNC = 0
				self.svgTotalDeltaX = 0
				self.svgTotalDeltaY = 0

		finally:
			# We may have had an exception and lost the serial port...
			self.penDownActivatesEngraver = False
			if ( not ( self.serialPort is None ) ) and ( self.options.engraving ):
				self.engraverOff()
コード例 #2
0
	def plotToEggBot( self ):
		'''Perform the actual plotting, if selected in the interface:'''
		#parse the svg data as a series of line segments and send each segment to be plotted

		if self.serialPort is None:
			return

		if self.options.startCentered and ( not self.getDocProps() ):
			# Cannot handle the document's dimensions!!!
			inkex.errormsg( gettext.gettext(
			'This document does not have valid dimensions.\r\r' +
			'Consider starting with the EggBot template, or ' +
			'setting the document size to 3200 px (wide) x 800 px (tall).\r\r' +
			'Document dimensions may be set in Inkscape with ' +
			'File > Document Properties.\r\rThe document dimensions must be unitless or have ' +
			'units of pixels (px) or percentages (%).   '	) )
			return

		# Viewbox handling
		# Also ignores the preserveAspectRatio attribute
		viewbox = self.svg.get( 'viewBox' )
		if viewbox:
			vinfo = viewbox.strip().replace( ',', ' ' ).split( ' ' )
			if ( float(vinfo[2]) != 0 ) and ( float(vinfo[3]) != 0 ):
				sx = self.svgWidth / float( vinfo[2] )
				sy = self.svgHeight / float( vinfo[3] )
				self.svgTransform = parseTransform( 'scale(%f,%f) translate(%f,%f)' % (sx, sy, -float( vinfo[0] ), -float( vinfo[1] ) ) )

		self.ServoSetup()
		ebb_motion.sendEnableMotors(self.serialPort, 1) # 16X microstepping
		
		# Ensure that the engraver is turned off for the time being
		# It will be turned back on when the first non-virtual pen-down occurs
		if self.options.engraving:
			self.engraverOff()


		try:
			# wrap everything in a try so we can for sure close the serial port
			#self.recursivelyTraverseSvg(self.document.getroot())
			self.penDownActivatesEngraver = True
			self.recursivelyTraverseSvg( self.svg, self.svgTransform )
			self.penUp()   #Always end with pen-up

			# Logically, we want to turn the engraver off here as well,
			# but we put that in our finally clause instead
			# self.engraverOff()

			# return to home, if returnToHome = True
			if ( ( not self.bStopped ) and self.options.returnToHome and ( self.ptFirst ) ):
				self.fX = self.ptFirst[0]
				self.fY = self.ptFirst[1]
				#self.penUp()
				self.nodeCount = self.nodeTarget    # enablesfpx return-to-home only option
				self.plotLineAndTime()
			#inkex.errormsg('Final node count: ' + str(self.svgNodeCount))  #Node Count - Debug option
			if ( not self.bStopped ):
				self.svgLayer = 0
				self.svgNodeCount = 0
				self.svgLastPath = 0
				self.svgLastPathNC = 0
				self.svgTotalDeltaX = 0
				self.svgTotalDeltaY = 0

		finally:
			# We may have had an exception and lost the serial port...
			self.penDownActivatesEngraver = False
			if ( not ( self.serialPort is None ) ) and ( self.options.engraving ):
				self.engraverOff()
コード例 #3
0
ファイル: eggbot.py プロジェクト: JesperKrogPoulsen/EggBot
	def manualCommand( self ):
		"""Execute commands from the "manual" tab"""

		if self.options.manualType == "none":
			return
			
		if self.serialPort is None:
			return
			
		if self.options.manualType == "raise-pen":
			self.ServoSetupWrapper()
			self.penUp()

		elif self.options.manualType == "lower-pen":
			self.ServoSetupWrapper()
			self.penDown()

		elif self.options.manualType == "enable-motors":
			ebb_motion.sendEnableMotors(self.serialPort, 1) # 16X microstepping

		elif self.options.manualType == "disable-motors":
			self.sendDisableMotors()

		elif self.options.manualType == "version-check":
			strVersion = ebb_serial.query( self.serialPort, 'v\r' )
			inkex.errormsg( 'I asked the EBB for its version info, and it replied:\n ' + strVersion )

		elif self.options.manualType == "enable-engraver":
			if ( not self.options.engraving ):
				inkex.errormsg( gettext.gettext( "The engraver option is disabled. " + \
				" Please enable it first from the \"Options\" tab." ) )
			else:
				self.engraverOn()

		elif self.options.manualType == 'disable-engraver':
			self.engraverOffManual() #Force engraver off, even if it is not enabled.

		else:  # self.options.manualType is "walk-egg-motor" or "walk-pen-motor":
			if self.options.manualType == "walk-egg-motor":
				nDeltaX = self.options.WalkDistance
				nDeltaY = 0
			elif self.options.manualType == "walk-pen-motor":
				nDeltaY = self.options.WalkDistance
				nDeltaX = 0
			else:
				return
				
			ebb_motion.sendEnableMotors(self.serialPort, 1) # 16X microstepping
			
			#Query pen position: 1 up, 0 down (followed by OK)
			strVersion = ebb_serial.query( self.serialPort, 'QP\r' )
			
			if strVersion[0] == '0':
				self.fSpeed = self.options.penDownSpeed
			if strVersion[0] == '1':
				self.fSpeed = self.options.penUpSpeed

			if ( self.options.revPenMotor ):
				nDeltaY = -1 * nDeltaY
			if ( self.options.revEggMotor ):
				nDeltaX = -1 * nDeltaX
			
			nTime = 10000.00 / self.fSpeed * plot_utils.distance( nDeltaX, nDeltaY )
			nTime = int( math.ceil(nTime / 10.0))
			
			strOutput = ','.join( ['SM', str( nTime ), str( nDeltaY ), str( nDeltaX )] ) + '\r'
			#inkex.errormsg( 'strOutput:  ' + strOutput )

			ebb_serial.command( self.serialPort, strOutput )
コード例 #4
0
	def manualCommand( self ):
		"""Execute commands from the "manual" tab"""

		if self.options.manualType == "none":
			return
			
		if self.serialPort is None:
			return
			
		if self.options.manualType == "raise-pen":
			self.ServoSetupWrapper()
			self.penUp()

		elif self.options.manualType == "lower-pen":
			self.ServoSetupWrapper()
			self.penDown()

		elif self.options.manualType == "enable-motors":
			ebb_motion.sendEnableMotors(self.serialPort, 1) # 16X microstepping

		elif self.options.manualType == "disable-motors":
			self.sendDisableMotors()

		elif self.options.manualType == "version-check":
			strVersion = ebb_serial.query( self.serialPort, 'v\r' )
			inkex.errormsg( 'I asked the EBB for its version info, and it replied:\n ' + strVersion )

		elif self.options.manualType == "enable-engraver":
			if ( not self.options.engraving ):
				inkex.errormsg( gettext.gettext( "The engraver option is disabled. " + \
				" Please enable it first from the \"Options\" tab." ) )
			else:
				self.engraverOn()

		elif self.options.manualType == 'disable-engraver':
			self.engraverOffManual() #Force engraver off, even if it is not enabled.

		else:  # self.options.manualType is "walk-egg-motor" or "walk-pen-motor":
			if self.options.manualType == "walk-egg-motor":
				nDeltaX = self.options.WalkDistance
				nDeltaY = 0
			elif self.options.manualType == "walk-pen-motor":
				nDeltaY = self.options.WalkDistance
				nDeltaX = 0
			else:
				return
				
			ebb_motion.sendEnableMotors(self.serialPort, 1) # 16X microstepping
			
			#Query pen position: 1 up, 0 down (followed by OK)
			strVersion = ebb_serial.query( self.serialPort, 'QP\r' )
			
			if strVersion[0] == '0':
				self.fSpeed = self.options.penDownSpeed
			if strVersion[0] == '1':
				self.fSpeed = self.options.penUpSpeed

			if ( self.options.revPenMotor ):
				nDeltaY = -1 * nDeltaY
			if ( self.options.revEggMotor ):
				nDeltaX = -1 * nDeltaX
			
			nTime = 10000.00 / self.fSpeed * plot_utils.distance( nDeltaX, nDeltaY )
			nTime = int( math.ceil(nTime / 10.0))
			
			strOutput = ','.join( ['SM', str( nTime ), str( nDeltaY ), str( nDeltaX )] ) + '\r'
			#inkex.errormsg( 'strOutput:  ' + strOutput )

			ebb_serial.command( self.serialPort, strOutput )