Esempio n. 1
0
	def _setSync( self, syncMode ):
		"""Set sync mode"""
		if syncMode >= 0 and syncMode <= 0xFF:
			p = snap.Packet( self.address, snap.localAddress, 0, 1, [CMD_SYNC, int(syncMode)] )
			p.send()
		else:
			raise RepRapError("Invalid sync mode")
Esempio n. 2
0
	def setMotor(self, direction, speed):
		"""Set motor direction (reprap.MOTOR_BACKWARD or reprap.MOTOR_FORWARD) and speed (0-255)"""
		if int(direction) > 0 and int(direction) < 3 and int(speed) >= 0 and int(speed <= 0xFF):
			p = snap.Packet( self.address, snap.localAddress, 0, 1, [int(direction), int(speed)] ) ##no command being sent, whats going on?
			p.send()
		else:
			raise RepRapError("Invalid direction or speed value")
Esempio n. 3
0
 def getSensors(self):
     """Debug only. Returns raw PIC port bytes)"""
     p = snap.Packet(self.address, snap.localAddress, 0, 1, [CMD_GETSENSOR])
     p.send()
     rep = p.getReply()
     rep.checkReply(3, CMD_GETSENSOR)
     data = rep.dataBytes
     print data[1], data[2]
Esempio n. 4
0
def testComms():
	"""Test that serial communications are working properly with simple loopback (incomplete)"""
	p = snap.Packet( snap.localAddress, snap.localAddress, 0, 1, [255, 0] ) 	#start sync
	p.send()
	notif = _getNotification( serialPort )
	if notif.dataBytes[0] == 255:
		return True
	return False
Esempio n. 5
0
 def getVersion(self):
     """Returns (major, minor) firmware version as a two integer tuple."""
     p = snap.Packet(self.address, snap.localAddress, 0, 1, [CMD_VERSION])
     p.send()
     rep = p.getReply()
     rep.checkReply(3, CMD_VERSION)
     data = rep.dataBytes
     return data[1], data[2]
Esempio n. 6
0
	def setPower( self, power ):
		"""Set stepper motor power (0-100%)"""
		power = int( float(power) * 0.63 )
		if power >=0 and power <=0x3F:
			p = snap.Packet( self.address, snap.localAddress, 0, 1, [CMD_SETPOWER, int( power * 0.63 )] ) # This is a value from 0 to 63 (6 bits)
			p.send()
		else:
			raise RepRapError("Invalid power value")
Esempio n. 7
0
	def setPos(self, pos):
		"""set current position (integer) (set variable, not physical position. units as steps)"""
		if pos >=0 and pos <= 0xFFFF:
			posMSB ,posLSB = _int2bytes( pos )
			p = snap.Packet( self.address, snap.localAddress, 0, 1, [CMD_SETPOS, posMSB, posLSB] )
			p.send()
		else:
			raise RepRapError("Invalid position value")
Esempio n. 8
0
 def getPos(self):
     """Return the axis postition as an integer (steps)."""
     p = snap.Packet(self.address, snap.localAddress, 0, 1, [CMD_GETPOS])
     p.send()
     rep = p.getReply()
     rep.checkReply(3, CMD_GETPOS)
     data = rep.dataBytes
     pos = _bytes2int(data[1], data[2])
     return pos
Esempio n. 9
0
	def _getModuleType(self):
		"""Returns module type as an integer.
		note: do pics not support this yet? I can't see it in code and get no reply from pic"""
		p = snap.Packet( self.address, snap.localAddress, 0, 1, [CMD_GETMODULETYPE] )	# Create SNAP packet requesting module type
		p.send()
		rep = p.getReply()
		rep.checkReply(2, CMD_GETMODULETYPE)
		data = rep.dataBytes
		return data[1]
Esempio n. 10
0
 def _getRawTemp(self):
     """Get raw temperature pic timer value"""
     p = snap.Packet(self.address, snap.localAddress, 0, 1, [CMD_GETTEMP])
     p.send()
     rep = p.getReply()
     rep.checkReply(3, CMD_GETTEMP)
     data = rep.dataBytes
     #rawTemp, calibration
     return data[1], data[2]
Esempio n. 11
0
 def _setHeat(self, lowHeat, highHeat, tempTarget, tempMax):
     print "Setting heater with params, ", "lowHeat", lowHeat, "highHeat", highHeat, "tempTarget", tempTarget, "tempMax", tempMax
     tempTargetMSB, tempTargetLSB = _int2bytes(tempTarget)
     tempMaxMSB, tempMaxLSB = _int2bytes(tempMax)
     p = snap.Packet(self.address, snap.localAddress, 0, 1, [
         CMD_SETHEAT,
         int(lowHeat),
         int(highHeat), tempTargetMSB, tempTargetLSB, tempMaxMSB, tempMaxLSB
     ])  # assumes MSB first (don't know this!)
     p.send()
Esempio n. 12
0
	def forward(self, speed = None):
		"""Spin axis forward at given speed (0-255)
		If no speed is specified then a value must have been previously set with axisClass.setSpeed()"""
		if speed == None:
			speed = self.speed
			if speed == None:
				raise _RepRapError("Axis speed not set")
		if speed >=0 and speed <= 0xFF:
			p = snap.Packet( self.address, snap.localAddress, 0, 1, [CMD_FORWARD, int(speed)] ) 
			p.send()
		else:
			raise RepRapError("Invalid speed value")
Esempio n. 13
0
	def _DDA( self, seekTo, slaveDelta, speed = False, waitArrival = True):
		"""Set DDA mode"""
		if not speed:
			speed = self.speed
		if (seekTo <= self.limit or self.limit == 0) and seekTo >=0 and seekTo <= 0xFFFF and slaveDelta >=0 and slaveDelta <= 0xFFFF and speed >=0 and speed <= 0xFF:
			masterPosMSB, masterPosLSB = _int2bytes( seekTo )
			slaveDeltaMSB, slaveDeltaLSB = _int2bytes( slaveDelta )
			p = snap.Packet( self.address, snap.localAddress, 0, 1, [CMD_DDA, int(speed), masterPosMSB ,masterPosLSB, slaveDeltaMSB, slaveDeltaLSB] ) 	#start sync
			p.send()
			if waitArrival:
				notif = p.getReply()
				if not notif.dataBytes[0] == CMD_DDA:
					raise _RepRapError("Expected DDA notification")
Esempio n. 14
0
	def homeReset(self, speed = None, waitArrival = True):
		"""Go to 0 position. If waitArrival is True, funtion waits until reset is compete to return"""
		if speed == None:
			speed = self.speed
			if speed == None:
				raise _RepRapError("Axis speed not set")
		if speed >= 0 and speed <= 0xFF:
			p = snap.Packet( self.address, snap.localAddress, 0, 1, [CMD_HOMERESET, int(speed)] ) 
			p.send()
			if waitArrival:
				notif = p.getReply()
				if not notif.dataBytes[0] == CMD_HOMERESET:
					raise _RepRapError("Expected home reset notification")
		else:
			raise RepRapError("Invalid speed value")
Esempio n. 15
0
def scanNetwork():
	"""Scan reprap network for devices (incomplete) - this will be used by autoconfig functions when complete"""
	devices = []
	for remoteAddress in range(2, 6):									# For every address in range. full range will be 255
		print "Trying address " + str(remoteAddress)
		p = snap.Packet( remoteAddress, snap.localAddress, 0, 1, [CMD_GETMODULETYPE] )	# Create snap packet requesting module type
		#p = snap.Packet( remoteAddress, snap.localAddress, 0, 1, [CMD_VERSION] )
		p.send()											# Send snap packet, if sent ok then await reply
		rep = p.getReply()
		print "dev", remoteAddress
		#devices.append( { 'address':remoteAddress, 'type':rep.dataBytes[1], 'subType':rep.dataBytes[2] } )	# If device replies then add to device list.
		time.sleep(0.5)
	for d in devices:
		#now get versions
		print "device", d
Esempio n. 16
0
    def seek(self, pos, speed=None, waitArrival=True, units=None):
        """Seek to axis location pos. If waitArrival is True, funtion waits until seek is compete to return"""

        # If no speed is specified use value set for axis, if this doesn't exist raise exception
        if speed == None:
            speed = self.speed
            if speed == None:
                raise _RepRapError("Axis speed not set")

        # If no units area specified use units set for axis, if this doesn't exist use steps
        if units == None:
            units = self.units
            if units == None:
                units = UNITS_STEPS

        # Convert units into steps
        if units == UNITS_STEPS:
            pass
        elif units == UNITS_MM:
            newX = int(float(newX) * self.stepsPerMM)
            newY = int(float(newY) * self.stepsPerMM)
        elif units == UNITS_INCHES:
            newX = int(float(newX) * self.stepsPerMM * 25.4)
            newX = int(float(newY) * self.stepsPerMM * 25.4)
        else:
            raise _RepRapError("Invalid units")

        # Check that position is withing limits and speed is valid
        if (pos <= self.limit or self.limit == 0
            ) and pos >= 0 and pos <= 0xFFFF and speed >= 0 and speed <= 0xFF:
            posMSB, posLSB = _int2bytes(pos)
            p = snap.Packet(self.address, snap.localAddress, 0, 1,
                            [CMD_SEEK, int(speed), posMSB, posLSB])
            p.send()
            if waitArrival:
                notif = p.getReply()
                if not notif.dataBytes[0] == CMD_SEEK:
                    raise _RepRapError("Expected seek notification")
        else:
            raise _RepRapError("Invalid speed or position value")
Esempio n. 17
0
 def free(self):
     """Power off coils on stepper"""
     p = snap.Packet(self.address, snap.localAddress, 0, 1, [CMD_FREE])
     p.send()
Esempio n. 18
0
 def _setTempScaler(self, val):
     p = snap.Packet(self.address, snap.localAddress, 0, 1,
                     [CMD__setTempScaler, int(val)])
     p.send()
Esempio n. 19
0
 def backward1(self):
     """Move axis one step backward"""
     p = snap.Packet(self.address, snap.localAddress, 0, 1, [CMD_BACKWARD1])
     p.send()
Esempio n. 20
0
    def forward1(self):
        """Move axis one step forward
		Return the completed state as a bool."""
        p = snap.Packet(self.address, snap.localAddress, 0, 1, [CMD_FORWARD1])
        p.send()
Esempio n. 21
0
 def freeMotor(self):
     """Power off the extruder motor"""
     p = snap.Packet(self.address, snap.localAddress, 0, 1, [CMD_FREE])
     p.send()
Esempio n. 22
0
 def setCooler(self, speed):
     """Set the speed (0-255) of the cooling fan"""
     p = snap.Packet(self.address, snap.localAddress, 0, 1,
                     [CMD_SETCOOLER, int(speed)])
     p.send()
Esempio n. 23
0
 def setNotify(self):
     """Set axis to notify on arrivals"""
     p = snap.Packet(self.address, snap.localAddress, 0, 1,
                     [CMD_NOTIFY, snap.localAddress
                      ])  # set notifications to be sent to host
     p.send()
Esempio n. 24
0
 def _setVoltageReference(self, val):
     p = snap.Packet(self.address, snap.localAddress, 0, 1,
                     [CMD_SETVREF, int(val)])
     p.send()