Интегриране на РепРап в Blender

From RepRapWiki
Jump to: navigation, search

Това е първият ми опит за интегриране на РепРап в Blender.
За целта ще използваме последната версия на Blender [1], PySerial [2].

Необходим софтуер:

1. Blender 3.62
2. pyserial (инсталация за python3)

Хардуер:
1. RepRap Prusa с инсталиран Sprinter [3] firmware.

Актуалната версия на комуникацията с Blender ще бъде качвана в github.com [4] blenderRepRap-addon.

Последователност в Blender:

Примерна връзка на репрап в Блендер:

import sys
# we should consider adding pyserial into blender path and make tests !
PYSERIAL_PATH = '/usr/local/lib/python3.2/dist-packages/'

def checkpaths():
    """checks if PySerial already defined in sys.path()"""
    """if defined do nothing, else add path to blender"""
    if (PYSERIAL_PATH in sys.path):
        print('PySerial path already defined.')
    else:
        sys.path.append(PYSERIAL_PATH)
        print('PySerial added to path.')
        
checkpaths()    # adds PySerial path to blender 

from serial import Serial
import glob

def scanserial():
    """scan for available ports. return a list of device names."""
    baselist=[]
#       if os.name=="nt":
#       try:
#           key=_winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,"HARDWARE\\DEVICEMAP\\SERIALCOMM")
#               i=0
#               while(1):
#                   baselist+=[_winreg.EnumValue(key,i)[1]]
#                   i+=1
#       except:
#           pass

    return baselist+glob.glob('/dev/ttyUSB*') + glob.glob('/dev/ttyACM*') + glob.glob("/dev/tty.*") + glob.glob("/dev/cu.*") +  glob.glob("/dev/rfcomm*")

def testport():        
    """Test found available port from scanserial() function and returns 'port name' or 'none' '"""
    ok = 'none'
    
    port_name = scanserial()
    print(port_name)
    print('Number of ports found: ', len(port_name))
    
    num = len(port_name)
    print('Found port numbers: ', num)
    
    for port_name[num-1] in port_name:
        
        printer = Serial(port_name[num-1], 115200, timeout = 20)
        answer = printer.readline().strip()
        printer.close()
        print(answer.decode('ascii'))
        if ('start' in answer.decode('ascii')):
            ok = port_name[num-1]
            print('OK port is: ', ok)
        else:
            pass
    
    if ok is not 'none':            
        return ok
    else:
        return ok
        print( 'Port not found.' )
        
    
def move(axis, direction, value, speed):
    """Moves given 'axis' in '+' or '-' 'direction' with 'value' and 'speed'"""
    axis = str(axis)    # X, Y, Z, E
    direction = str(direction)  # '+' or '-'
    value = str(value)  # relative move 
    speed = str(speed)  # set speed of movement from 0 to 3000

    word = 'G1 ' + axis + direction + value + ' F' + speed + '\r\n' 
    print( word.strip() )
   
    return word.encode('ascii')    

port = testport()
baud = 115200

print(port)
if ('ACM' in port):
    printer = Serial(port, baud, timeout = 5)
    print(printer.readline().strip().decode('ascii'))
    word = 'G91\r\n'
    printer.write(word.encode('ascii'))
    word = move('X', '-', 15, 600)
    printer.write(word)
else: pass 

if ('none' not in port):
    if printer.isOpen():
        printer.close()
else: pass
print('That\'s all folks.')

Резултатът, който излиза в конзолата на Blender 2.62:

PySerial path already defined.
['/dev/ttyACM0']
Number of ports found:  1
Found port numbers:  1
start
OK port is:  /dev/ttyACM0
/dev/ttyACM0
start
G1 X-15 F600
That's all folks.

PySerial path already defined.
[]
Number of ports found:  0
Found port numbers:  0
none
That's all folks.