Example #1
0
	def plotPath( self, path, matTransform ):
		'''
		Plot the path while applying the transformation defined
		by the matrix [matTransform].
		'''
		# turn this path into a cubicsuperpath (list of beziers)...

		d = path.get( 'd' )

		if len( simplepath.parsePath( d ) ) == 0:
			return

		p = cubicsuperpath.parsePath( d )

		# ...and apply the transformation to each point
		applyTransformToPath( matTransform, p )

		# p is now a list of lists of cubic beziers [control pt1, control pt2, endpoint]
		# where the start-point is the last point in the previous segment.
		for sp in p:

			plot_utils.subdivideCubicPath( sp, self.options.smoothness )
			nIndex = 0

			for csp in sp:

				if self.bStopped:
					return

				self.fX = 2 * float( csp[1][0] ) / self.step_scaling_factor
				self.fY = 2 * float( csp[1][1] ) / self.step_scaling_factor

				# store home
				if self.ptFirst is None:

					# if we should start at center, then the first line segment should draw from there
					if self.options.startCentered:
						self.fPrevX = self.svgWidth / ( self.step_scaling_factor )
						self.fPrevY = self.svgHeight / ( self.step_scaling_factor )

						self.ptFirst = ( self.fPrevX, self.fPrevY )
					else:
						self.ptFirst = ( self.fX, self.fY )
						
				if self.plotCurrentLayer:
					if nIndex == 0:
						if (plot_utils.distance(self.fX - self.fPrevX,self.fY - self.fPrevY) > eggbot_conf.MIN_GAP):
							# Only raise pen between two points if there is at least a 1 step gap between them.
							self.penUp()
							self.virtualPenIsUp = True
					elif nIndex == 1:
						self.penDown()
						self.virtualPenIsUp = False

				nIndex += 1

				if self.plotCurrentLayer:
					self.plotLineAndTime()
					self.fPrevX = self.fX
					self.fPrevY = self.fY
Example #2
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 )
Example #3
0
	def plotLineAndTime( self ):
		'''
		Send commands out the com port as a line segment (dx, dy) and a time (ms) the segment
		should take to implement
		'''

		if self.bStopped:
			return
		if ( self.fPrevX is None ):
			return

		nDeltaX = int( self.fX ) - int( self.fPrevX )
		nDeltaY = int( self.fY ) - int( self.fPrevY )

		if self.bPenIsUp:
			self.fSpeed = self.options.penUpSpeed
			
			if ( self.options.wraparound ):
				if ( nDeltaX > self.halfWrapSteps ):
					while ( nDeltaX > self.halfWrapSteps ):
						nDeltaX -= self.wrapSteps
				elif ( nDeltaX < -1 * self.halfWrapSteps ):
					while ( nDeltaX < -1 * self.halfWrapSteps  ):
						nDeltaX += self.wrapSteps

		else:
			self.fSpeed = self.options.penDownSpeed

		if ( plot_utils.distance( nDeltaX, nDeltaY ) > 0 ):
			self.nodeCount += 1

			if self.resumeMode:
				if ( self.nodeCount > self.nodeTarget ):
					self.resumeMode = False
					if ( not self.virtualPenIsUp ):
						self.penDown()
						self.fSpeed = self.options.penDownSpeed

			nTime = int( math.ceil( 1000 / self.fSpeed * plot_utils.distance( nDeltaX, nDeltaY ) ) )

			while ( ( abs( nDeltaX ) > 0 ) or ( abs( nDeltaY ) > 0 ) ):
				xd = nDeltaX
				yd = nDeltaY
				td = nTime
				if ( td < 1 ):
					td = 1		# don't allow zero-time moves.
					
				if (abs((float(xd) / float(td))) < 0.002):	
					xd = 0	#don't allow too-slow movements of this axis
				if (abs((float(yd) / float(td))) < 0.002):	
					yd = 0	#don't allow too-slow movements of this axis
						
				if ( not self.resumeMode ):
					if ( self.options.revPenMotor ):
						yd2 = yd
					else:
						yd2 = -yd
					if ( self.options.revEggMotor ):
						xd2 = -xd
					else:
						xd2 = xd

					self.svgTotalDeltaX += xd
					self.svgTotalDeltaY += yd
					ebb_motion.doXYMove( self.serialPort, xd2, yd2, td )			
					if (td > 50):
						time.sleep(float(td - 50)/1000.0)  #pause before issuing next command
					
				nDeltaX -= xd
				nDeltaY -= yd
				nTime -= td

			strButton = ebb_motion.QueryPRGButton(self.serialPort)	#Query if button pressed
			if strButton[0] == '1': #button pressed
				self.svgNodeCount = self.nodeCount;
				inkex.errormsg( 'Plot paused by button press after node number ' + str( self.nodeCount ) + '.' )
				inkex.errormsg( 'Use the "resume" feature to continue.' )
				#self.penUp()  # Should be redundant...
				self.engraverOff()
				self.bStopped = True
				return
Example #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 )
Example #5
0
	def plotLineAndTime( self ):
		'''
		Send commands out the com port as a line segment (dx, dy) and a time (ms) the segment
		should take to implement
		'''

		if self.bStopped:
			return
		if ( self.fPrevX is None ):
			return

		nDeltaX = int( self.fX ) - int( self.fPrevX )
		nDeltaY = int( self.fY ) - int( self.fPrevY )

		if self.bPenIsUp:
			self.fSpeed = self.options.penUpSpeed
			
			if ( self.options.wraparound ):
				if ( nDeltaX > self.halfWrapSteps ):
					while ( nDeltaX > self.halfWrapSteps ):
						nDeltaX -= self.wrapSteps
				elif ( nDeltaX < -1 * self.halfWrapSteps ):
					while ( nDeltaX < -1 * self.halfWrapSteps  ):
						nDeltaX += self.wrapSteps

		else:
			self.fSpeed = self.options.penDownSpeed


		if ( plot_utils.distance( nDeltaX, nDeltaY ) > 0 ):
			self.nodeCount += 1

			if self.resumeMode:
				if ( self.nodeCount > self.nodeTarget ):
					self.resumeMode = False
					if ( not self.virtualPenIsUp ):
						self.penDown()
						self.fSpeed = self.options.penDownSpeed

			nTime = int( math.ceil( 1000 / self.fSpeed * plot_utils.distance( nDeltaX, nDeltaY ) ) )

			while ( ( abs( nDeltaX ) > 0 ) or ( abs( nDeltaY ) > 0 ) ):
				if ( nTime > 750 ):
					xd = int( round( ( 750.0 * nDeltaX ) / nTime ) )
					yd = int( round( ( 750.0 * nDeltaY ) / nTime ) )
					td = int( 750 )
				else:
					xd = nDeltaX
					yd = nDeltaY
					td = nTime
					if ( td < 1 ):
						td = 1		# don't allow zero-time moves.

				if ( not self.resumeMode ):
					if ( self.options.revPenMotor ):
						yd2 = yd
					else:
						yd2 = -yd
					if ( self.options.revEggMotor ):
						xd2 = -xd
					else:
						xd2 = xd

					strOutput = ','.join( ['SM', str( td ), str( yd2 ), str( xd2 )] ) + '\r'
					self.svgTotalDeltaX += xd
					self.svgTotalDeltaY += yd
					ebb_serial.command( self.serialPort,  strOutput )	

				nDeltaX -= xd
				nDeltaY -= yd
				nTime -= td

			#self.doCommand('NI\r')  #Increment node counter on EBB
			strButton = ebb_motion.QueryPRGButton(self.serialPort)	#Query if button pressed
			
			if strButton[0] == '0':
				pass #button not pressed
			else:
			  self.svgNodeCount = self.nodeCount;
			  inkex.errormsg( 'Plot paused by button press after node number ' + str( self.nodeCount ) + '.' )
			  inkex.errormsg( 'Use the "resume" feature to continue.' )
			  #self.penUp()  # Should be redundant...
			  self.engraverOff()
			  self.bStopped = True
			return
Example #6
0
	def plotLineAndTime( self ):
		'''
		Send commands out the com port as a line segment (dx, dy) and a time (ms) the segment
		should take to implement
		'''

		if self.bStopped:
			return
		if ( self.fPrevX is None ):
			return

		nDeltaX = int( self.fX ) - int( self.fPrevX )
		nDeltaY = int( self.fY ) - int( self.fPrevY )

		if self.bPenIsUp:
			self.fSpeed = self.options.penUpSpeed
			
			if ( self.options.wraparound ):
				if ( nDeltaX > self.halfWrapSteps ):
					while ( nDeltaX > self.halfWrapSteps ):
						nDeltaX -= self.wrapSteps
				elif ( nDeltaX < -1 * self.halfWrapSteps ):
					while ( nDeltaX < -1 * self.halfWrapSteps  ):
						nDeltaX += self.wrapSteps

		else:
			self.fSpeed = self.options.penDownSpeed


		if ( plot_utils.distance( nDeltaX, nDeltaY ) > 0 ):
			self.nodeCount += 1

			if self.resumeMode:
				if ( self.nodeCount > self.nodeTarget ):
					self.resumeMode = False
					if ( not self.virtualPenIsUp ):
						self.penDown()
						self.fSpeed = self.options.penDownSpeed

			nTime = int( math.ceil( 1000 / self.fSpeed * plot_utils.distance( nDeltaX, nDeltaY ) ) )

			while ( ( abs( nDeltaX ) > 0 ) or ( abs( nDeltaY ) > 0 ) ):
				if ( nTime > 750 ):
					xd = int( round( ( 750.0 * nDeltaX ) / nTime ) )
					yd = int( round( ( 750.0 * nDeltaY ) / nTime ) )
					td = int( 750 )
				else:
					xd = nDeltaX
					yd = nDeltaY
					td = nTime
					if ( td < 1 ):
						td = 1		# don't allow zero-time moves.

				if ( not self.resumeMode ):
					if ( self.options.revPenMotor ):
						yd2 = yd
					else:
						yd2 = -yd
					if ( self.options.revEggMotor ):
						xd2 = -xd
					else:
						xd2 = xd

					strOutput = ','.join( ['SM', str( td ), str( yd2 ), str( xd2 )] ) + '\r'
					self.svgTotalDeltaX += xd
					self.svgTotalDeltaY += yd
					ebb_serial.command( self.serialPort,  strOutput )	

				nDeltaX -= xd
				nDeltaY -= yd
				nTime -= td

			#self.doCommand('NI\r')  #Increment node counter on EBB
			strButton = ebb_motion.QueryPRGButton(self.serialPort)	#Query if button pressed
			
			if strButton[0] == '0':
				pass #button not pressed
			else:
				self.svgNodeCount = self.nodeCount;
				inkex.errormsg( 'Plot paused by button press after node number ' + str( self.nodeCount ) + '.' )
				inkex.errormsg( 'Use the "resume" feature to continue.' )
				#self.penUp()  # Should be redundant...
				self.engraverOff()
				self.bStopped = True
				return