Example #1
0
def sendEnableMotors(portName, Res):
    if (Res < 0):
        Res = 0
    if (Res > 5):
        Res = 5
    if (portName is not None):
        ebb_serial.command(portName, 'EM,' + str(Res) + ',' + str(Res) + '\r')
Example #2
0
def doXYMove( portName, deltaX, deltaY, duration ):
	# Move X/Y axes as: "SM,<move_duration>,<axis1>,<axis2><CR>"
	# Typically, this is wired up such that axis 1 is the Y axis and axis 2 is the X axis of motion.
	# On EggBot, Axis 1 is the "pen" motor, and Axis 2 is the "egg" motor.
	if (portName is not None):
		strOutput = ','.join( ['SM', str( duration ), str( deltaY ), str( deltaX )] ) + '\r'
		ebb_serial.command( portName, strOutput)
Example #3
0
	def ServoSetup( self ):
		# Pen position units range from 0% to 100%, which correspond to
		# a timing range of 6000 - 30000 in units of 1/(12 MHz).
		# 1% corresponds to 20 us, or 240 units of 1/(12 MHz).

		intTemp = 240 * ( self.options.penUpPosition + 25 )
		ebb_serial.command( self.serialPort,  'SC,4,' + str( intTemp ) + '\r' )	
		
		intTemp = 240 * ( self.options.penDownPosition + 25 )
		ebb_serial.command( self.serialPort,  'SC,5,' + str( intTemp ) + '\r'  )	

		#AS
		intTemp = self.options.invertServo & 1 # just 0 or 1 to NEW SC 99
		ebb_serial.command( self.serialPort,  'SC,99,' + str( intTemp ) + '\r'  )	

		# Servo speed units are in units of %/second, referring to the
		# percentages above.  The EBB takes speeds in units of 1/(12 MHz) steps
		# per 21 ms.  Scaling as above, 1% in 1 second corresponds to
		# 240 steps/s, which corresponds to 0.240 steps/ms, which corresponds
		# to 5.04 steps/21 ms.  Rounding this to 5 steps/21 ms is correct
		# to within 1 %.

		intTemp = 5 * self.options.ServoUpSpeed
		ebb_serial.command( self.serialPort,  'SC,11,' + str( intTemp ) + '\r' )	
		intTemp = 5 * self.options.ServoDownSpeed
		ebb_serial.command( self.serialPort,  'SC,12,' + str( intTemp ) + '\r' )	
Example #4
0
def sendEnableMotors( portName, Res ):
	if (Res < 0):
		Res = 0
	if (Res > 5):
		Res = 5	
	if (portName is not None):
		ebb_serial.command( portName, 'EM,' + str(Res) + ',' + str(Res) + '\r' )
Example #5
0
def sendEnableMotors(port_name, res):
    if res < 0:
        res = 0
    if res > 5:
        res = 5
    if port_name is not None:
        ebb_serial.command(port_name, 'EM,{0},{0}\r'.format(res))
Example #6
0
def doXYMove(port_name, delta_x, delta_y, duration):
    # Move X/Y axes as: "SM,<move_duration>,<axis1>,<axis2><CR>"
    # Typically, this is wired up such that axis 1 is the Y axis and axis 2 is the X axis of motion.
    # On EggBot, Axis 1 is the "pen" motor, and Axis 2 is the "egg" motor.
    if port_name is not None:
        str_output = 'SM,{0},{1},{2}\r'.format(duration,delta_y,delta_x)
        ebb_serial.command(port_name, str_output)
Example #7
0
def doABMove(portName, deltaA, deltaB, duration):
    # Issue command to move A/B axes as: "XM,<move_duration>,<axisA>,<axisB><CR>"
    # Then, <Axis1> moves by <AxisA> + <AxisB>, and <Axis2> as <AxisA> - <AxisB>
    if (portName is not None):
        strOutput = ','.join(
            ['XM', str(duration),
             str(deltaA), str(deltaB)]) + '\r'
        ebb_serial.command(portName, strOutput)
Example #8
0
def doXYAccelMove(port_name, delta_x, delta_y, v_initial, v_final):
    # Move X/Y axes as: "AM,<initial_velocity>,<final_velocity>,<axis1>,<axis2><CR>"
    # Typically, this is wired up such that axis 1 is the Y axis and axis 2 is the X axis of motion.
    # On EggBot, Axis 1 is the "pen" motor, and Axis 2 is the "egg" motor.
    # Note that minimum move duration is 5 ms.
    # Important: Requires firmware version 2.4 or higher.
    if port_name is not None:
        str_output = 'AM,{0},{1},{2},{3}\r'.format(v_initial, v_final, delta_x, delta_y)
        ebb_serial.command(port_name, str_output)
Example #9
0
def doXYAccelMove( portName, deltaX, deltaY, vInitial, vFinal ):
	# Move X/Y axes as: "AM,<initial_velocity>,<final_velocity>,<axis1>,<axis2><CR>"
	# Typically, this is wired up such that axis 1 is the Y axis and axis 2 is the X axis of motion.
	# On EggBot, Axis 1 is the "pen" motor, and Axis 2 is the "egg" motor.
	# Note that minimum move duration is 5 ms.
	# Important: Requires firmware version 2.4 or higher.
	if (portName is not None):
		strOutput = ','.join( ['AM', str( vInitial ), str( vFinal ), str( deltaX ), str( deltaY )] ) + '\r'
		ebb_serial.command( portName, strOutput)
Example #10
0
 def sendEnableMotors(self, Res=1):
     self.getReady()
     if (Res < 0):
         Res = 0
     if (Res > 5):
         Res = 5
     if (self.port is not None):
         ebb_serial.command(self.port,
                            'EM,' + str(Res) + ',' + str(Res) + '\r')
Example #11
0
def doLowLevelMove(port_name, ri1, steps1, delta_r1, ri2, steps2, delta_r2):
    # A "pre-computed" XY movement of the form
    #  "LM,RateTerm1,AxisSteps1,DeltaR1,RateTerm2,AxisSteps2,DeltaR2<CR>"
    # See http://evil-mad.github.io/EggBot/ebb.html#LM for documentation.
    # Important: Requires firmware version 2.5.1 or higher.
    if port_name is not None:
        if ((ri1 == 0 and delta_r1 == 0) or steps1 == 0) and ((ri2 == 0 and delta_r2 == 0) or steps2 == 0):
            return
        str_output = 'LM,{0},{1},{2},{3},{4},{5}\r'.format(ri1, steps1, delta_r1, ri2, steps2, delta_r2)
        ebb_serial.command(port_name, str_output)
Example #12
0
def doTimedPause(port_name, n_pause):
    if port_name is not None:
        while n_pause > 0:
            if n_pause > 750:
                td = 750
            else:
                td = n_pause
                if td < 1:
                    td = 1  # don't allow zero-time moves
            ebb_serial.command(port_name, 'SM,{0},0,0\r'.format(td))
            n_pause -= td
Example #13
0
def doTimedPause( portName, nPause ):
	if (portName is not None):
		while ( nPause > 0 ):
			if ( nPause > 750 ):
				td = int( 750 )
			else:
				td = nPause
				if ( td < 1 ):
					td = int( 1 ) # don't allow zero-time moves
			ebb_serial.command( portName, 'SM,' + str( td ) + ',0,0\r')		
			nPause -= td
Example #14
0
def doTimedPause(portName, nPause):
    if (portName is not None):
        while (nPause > 0):
            if (nPause > 750):
                td = int(750)
            else:
                td = nPause
                if (td < 1):
                    td = int(1)  # don't allow zero-time moves
            ebb_serial.command(portName, 'SM,' + str(td) + ',0,0\r')
            nPause -= td
Example #15
0
 def doTimedPause(self, nPause):
     self.getReady()
     if (self.port is not None):
         while (nPause > 0):
             if (nPause > 750):
                 td = int(750)
             else:
                 td = nPause
                 if (td < 1):
                     td = int(1)  # don't allow zero-time moves
             ebb_serial.command(self.port, 'SM,' + str(td) + ',0,0\r')
             nPause -= td
Example #16
0
    def configServo(self, value1, value2):
        if ((0 < value1 < 255) == False):
            print("value1 is invalid ")
            return
        if ((0 < value2 < 65535) == False):
            print("value2 is invalid ")
            return

        self.getReady()
        if (self.port is not None):
            strOutput = ','.join(['SC', str(value1), str(value2)]) + '\r'
            ebb_serial.command(self.port, strOutput)
Example #17
0
def PBOutConfig(port_name, pin, state):
    # Enable an I/O pin. Pin: {0,1,2, or 3}. State: {0 or 1}.
    # Note that B0 is used as an alternate pause button input.
    # Note that B1 is used as the pen-lift servo motor output.
    # Note that B3 is used as the EggBot engraver output.
    # For use with a laser (or similar implement), pin 3 is recommended

    if port_name is not None:
        # Set initial Bx pin value, high or low:
        str_output = 'PO,B,{0},{1}\r'.format(pin, state)
        ebb_serial.command(port_name, str_output)
        # Configure I/O pin Bx as an output
        str_output = 'PD,B,{0},0\r'.format(pin)
        ebb_serial.command(port_name, str_output)
Example #18
0
    def doABMove(self, deltaA, deltaB, duration=500):
        #print("delta : %s, %s"%(deltaA, deltaB))
        #check the speed limit .
        timeA = abs(int(float(deltaA + deltaB) / float(self.speedlimit)))
        timeB = abs(int(float(deltaA - deltaB) / float(self.speedlimit)))
        timemax = max(timeA, timeB)
        if timemax == 0:
            return

        # Issue command to move A/B axes as: "XM,<move_duration>,<axisA>,<axisB><CR>"
        # Then, <Axis1> moves by <AxisA> + <AxisB>, and <Axis2> as <AxisA> - <AxisB>
        if (self.port is not None):
            strOutput = ','.join(
                ['XM', str(timemax),
                 str(deltaA), str(deltaB)]) + '\r'
            self.getReady()
            ebb_serial.command(self.port, strOutput)
Example #19
0
def doLowLevelMove(portName, Ri1, Steps1, DeltaR1, Ri2, Steps2, DeltaR2):
    # A "pre-computed" XY movement of the form
    #  "LM,RateTerm1,AxisSteps1,DeltaR1,RateTerm2,AxisSteps2,DeltaR2<CR>"
    # See http://evil-mad.github.io/EggBot/ebb.html#LM for documentation.
    # Important: Requires firmware version 2.5.1 or higher.
    if (portName is not None):
        if ((((Ri1 == 0) and (DeltaR1 == 0)) or (Steps1 == 0))
                and (((Ri2 == 0) and (DeltaR2 == 0)) or (Steps2 == 0))):
            return
        strOutput = ','.join([
            'LM',
            str(Ri1),
            str(Steps1),
            str(DeltaR1),
            str(Ri2),
            str(Steps2),
            str(DeltaR2)
        ]) + '\r'
        ebb_serial.command(portName, strOutput)
Example #20
0
	def ServoSetup( self ):
		# Pen position units range from 0% to 100%, which correspond to
		# a timing range of 6000 - 30000 in units of 1/(12 MHz).
		# 1% corresponds to 20 us, or 240 units of 1/(12 MHz).

		intTemp = 240 * ( self.options.penUpPosition + 25 )
		ebb_serial.command( self.serialPort,  'SC,4,' + str( intTemp ) + '\r' )	
		
		intTemp = 240 * ( self.options.penDownPosition + 25 )
		ebb_serial.command( self.serialPort,  'SC,5,' + str( intTemp ) + '\r'  )	

		# Servo speed units are in units of %/second, referring to the
		# percentages above.  The EBB takes speeds in units of 1/(12 MHz) steps
		# per 21 ms.  Scaling as above, 1% in 1 second corresponds to
		# 240 steps/s, which corresponds to 0.240 steps/ms, which corresponds
		# to 5.04 steps/21 ms.  Rounding this to 5 steps/21 ms is correct
		# to within 1 %.

		intTemp = 5 * self.options.ServoUpSpeed
		ebb_serial.command( self.serialPort,  'SC,11,' + str( intTemp ) + '\r' )	
		intTemp = 5 * self.options.ServoDownSpeed
		ebb_serial.command( self.serialPort,  'SC,12,' + str( intTemp ) + '\r' )	
Example #21
0
def setPenDownPos(port_name, servo_max):
    if port_name is not None:
        ebb_serial.command(port_name, 'SC,5,{0}\r'.format(servo_max))
Example #22
0
def TogglePen(port_name):
    if port_name is not None:
        ebb_serial.command(port_name, 'TP\r')
Example #23
0
def PBOutValue(port_name, pin, state):
    # Set state of the I/O pin. Pin: {0,1,2, or 3}. State: {0 or 1}.
    # Set the pin as an output with OutputPinBConfigure before using this.
    if port_name is not None:
        str_output = 'PO,B,{0},{1}\r'.format(pin, state)
        ebb_serial.command(port_name, str_output)
Example #24
0
	def engraverOff( self ):
		# Note: we don't bother checking self.engraverIsOn -- turn it off regardless
		# Reason being that we may not know the true hardware state
		if self.options.engraving:
			ebb_serial.command( self.serialPort, 'PO,B,3,0\r')		
			self.engraverIsOn = False
Example #25
0
def sendPenUp(port_name, pen_delay):
    if port_name is not None:
        str_output = 'SP,1,{0}\r'.format(pen_delay)
        ebb_serial.command(port_name, str_output)
Example #26
0
def doABMove( portName, deltaA, deltaB, duration ):
	# Issue command to move A/B axes as: "XM,<move_duration>,<axisA>,<axisB><CR>"
	# Then, <Axis1> moves by <AxisA> + <AxisB>, and <Axis2> as <AxisA> - <AxisB>
	if (portName is not None):
		strOutput = ','.join( ['XM', str( duration ), str( deltaA ), str( deltaB )] ) + '\r'
		ebb_serial.command( portName, strOutput)				
Example #27
0
def setPenUpRate(port_name, pen_up_rate):
    if port_name is not None:
        ebb_serial.command(port_name, 'SC,11,{0}\r'.format(pen_up_rate))
Example #28
0
def doABMove(port_name, delta_a, delta_b, duration):
    # Issue command to move A/B axes as: "XM,<move_duration>,<axisA>,<axisB><CR>"
    # Then, <Axis1> moves by <AxisA> + <AxisB>, and <Axis2> as <AxisA> - <AxisB>
    if port_name is not None:
        str_output = 'XM,{0},{1},{2}\r'.format(duration, delta_a, delta_b)
        ebb_serial.command(port_name, str_output)
Example #29
0
	def engraverOffManual( self ):
		# Turn off engraver, whether or not the engraver is enabled. 
		# This is only called by manual commands like "engraver off" and "motors off."
		ebb_serial.command( self.serialPort, 'PO,B,3,0\r')		
		self.engraverIsOn = False			
Example #30
0
def setPenDownRate(port_name, pen_down_rate):
    if port_name is not None:
        ebb_serial.command(port_name, 'SC,12,{0}\r'.format(pen_down_rate))
Example #31
0
 def sendPenUp(self):
     if (self.port is not None):
         strOutput = 'SP,0' + '\r'
         ebb_serial.command(self.port, strOutput)
         time.sleep(self.sleeptime_pen)
Example #32
0
def sendPenDown( portName, PenDelay ):
	if (portName is not None):
		ebb_serial.command( portName, 'SP,0\r')	
		if (PenDelay > 0):
			doTimedPause( portName,PenDelay)	
Example #33
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 #34
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 #35
0
	def engraverOn( self ):
		if self.options.engraving and ( not self.engraverIsOn ):
			self.engraverIsOn = True
			ebb_serial.command( self.serialPort,  'PD,B,3,0\r')		#Added 6/6/2011, necessary.
			ebb_serial.command( self.serialPort,  'PO,B,3,1\r' )		
Example #36
0
def setPenUpPos(port_name, servo_min):
    if port_name is not None:
        ebb_serial.command(port_name, 'SC,4,{0}\r'.format(servo_min))
Example #37
0
 def getReset(self):
     return ebb_serial.command(self.port, "R\r")
Example #38
0
def setEBBLV(port_name, ebb_lv):
    # Set the EBB "Layer" Variable, an 8-bit number we can read and write.
    # (Unrelated to our plot layers; name is an historical artifact.)
    if port_name is not None:
        ebb_serial.command(port_name, 'SL,{0}\r'.format(ebb_lv))
Example #39
0
def sendPenDown(port_name, pen_delay, pen_pin=1):
    if port_name is not None:
        str_output = 'SP,0,{0},{1}\r'.format(pen_delay, pen_pin)
        ebb_serial.command(port_name, str_output)
Example #40
0
def sendDisableMotors( portName ):
	if (portName is not None):
		ebb_serial.command( portName, 'EM,0,0\r')	
Example #41
0
def sendDisableMotors(port_name):
    if port_name is not None:
        ebb_serial.command(port_name, 'EM,0,0\r')
Example #42
0
def sendPenDown( portName, PenDelay ):
	if (portName is not None):
		strOutput = ','.join( ['SP,0', str( PenDelay )] ) + '\r'
		ebb_serial.command( portName, strOutput)
Example #43
0
def TogglePen( portName ):
	if (portName is not None):
		ebb_serial.command( portName, 'TP\r')