Exemplo n.º 1
0
from cartman import bot, choose_serial_connection

serial_port = choose_serial_connection()

g = bot(name=serial_port)
g.home()

g.set_offset(100,300)

for i in range(1):
    print(g.where())
    g.set_speed(50000)

    g.goto(x=100, y=0)
    g.goto(x=170, y=30)

    g.goto(x=200, y=100)
    g.goto(x=170, y=170)

    g.set_speed(10000)

    g.goto(x=100, y=200)
    g.goto(x=30, y=170)

    g.goto(x=0, y=100)
    g.goto(x=30, y=30)

import math
for i in range(3):
    # go around in circles
Exemplo n.º 2
0
# jogging is fun

# from getkey import getKey as getkey
from onkey import listen

from cartman import bot
b = bot(verbose=True)
b.home()

def jog(x=None,y=None,z=None,f=None):
    def n2z(x): return 0 if x is None else x
    jog_command = '$J=G91G21X{:.2f}Y{:.2f}Z{:.2f}F{:.1f}'.format(
        *[n2z(k) for k in [x,y,z,f]]
    )
    try:
        b.command_ok(jog_command)
    except Exception as e:
        if ':15' in repr(e): # jog exceed limits
            print(e)
        else:
            raise e

def unjog():
    # b.command(b'\x85')
    b.command_ok(b'\x85G4P0\n')
    b.status_report()
    # b.sync(interval=0.1)
    # b.command_ok('G4P100')
    print('X{:.1f} Y{:.1f} Z{:.1f}'.format(*b.working_position))
    time.sleep(0.05)
import time
Exemplo n.º 3
0
import numpy as np
from cartman_defaults import *

a = lambda *k:np.array(k)

def shifted_goto(bot, shift):
    def goto(**kw):
        for idx, axis in enumerate(['x','y','z']):
            if axis in kw:
                kw[axis] = kw[axis] + shift[idx]
        return bot.goto(**kw)
    return goto

from cartman import bot

b = bot()

# bottom left corner of the paper
paper_origin = a(90, 240, 0)
paper_goto = shifted_goto(b, paper_origin)

def pendown():paper_goto(z=1)
def penup():paper_goto(z=10)

def draw_segments(s): # numpy array of shape (N, 2)
    penup()
    paper_goto(x=s[0][0],y=s[0][1])
    pendown()

    for i in range(1,len(s)):
        paper_goto(x=s[i][0],y=s[i][1])
Exemplo n.º 4
0
    return tour


if d.tsp != 0:
    nf = []
    for segs in foursegments:
        indices = travel_salesman_sa([s[0] for s in segs])
        segs = [segs[i] for i in indices]
        nf.append(segs)
else:
    nf = foursegments

# connect to bot
from cartman import bot
bot = bot(verbose=False)

import time
tick = time.time()
bot.home()
bot.set_speed(50000)


def pendown():
    bot.goto(z=-44)


def penup():
    bot.goto(z=-44 + 4)

Exemplo n.º 5
0
def gocart():

    b = bot()

    ps,ws = DefaultPaintStation(b), DefaultWaterStation(b)
    ss = DefaultSpongeStation(b)
    tc = DefaultToolChange(b)

    paper = a(132, 291, -29)
    def brushdown(): b.goto(z=paper[2])
    def brushup(): b.goto(z=paper[2] + 10)

    def paper_goto(arr):
        b.set_offset(paper[0], paper[1])
        b.goto(x=arr[0], y=arr[1])
        b.set_offset(0,0)

    def seg(arr): # in paper coordinate.
        paper_goto(arr[0])
        brushdown()
        for i in range(len(arr)-1):
            paper_goto(arr[i+1])
        brushup()

    def goodwash():
        for i in range(3):
            ws.wash()
            ss.wipe()

    def fa():
        b.set_speed(90000)

    b.home()

    fa()
    tc.pickup(1) # thick first
    fa()
    goodwash()

    color_to_dip = 0
    fa()
    ps.dip(color_to_dip) # yellow

    db = 200
    budget = db # 200mm worth of paint on brush

    for s in bls[0].segments:
        d = measure(s)
        if budget>d:
            fa()
            seg(s)
            budget-=d
        else:
            # no enough budget
            ps.dip(color_to_dip) # get more paint
            budget=db
            fa()
            seg(s)
            budget-=d

    fa()
    goodwash()

    fa()
    tc.putdown(1)
    tc.pickup(0) # thin brush

    color_to_dip=1

    fa()
    goodwash()
    fa()
    ps.dip(color_to_dip) # yellow

    budget = db # 100mm worth of paint on brush

    for s in bls[1].segments:
        d = measure(s)
        if budget>d:
            fa()
            seg(s)
            budget-=d
        else:
            # no enough budget
            ps.dip(color_to_dip) # get more paint
            budget=db
            fa()
            seg(s)
            budget-=d
    fa()
    goodwash()

    fa()
    tc.putdown(0)

    b.sync()
    b.home()
Exemplo n.º 6
0
                         for d in [0, 1]])) for k in [j, j - 1, i, i - 1]
        ])) / temperature) > random.random():
            tour = copy.copy(newTour)
    # plt.plot([cities[tour[i % ncities]][0] for i in range(ncities+1)], [cities[tour[i % ncities]][1] for i in range(ncities+1)], 'xb-');
    # plt.show()

    return tour


# uncomment to travel_salesman
# indices = travel_salesman_sa([s[0] for s in segments])
# segments = [segments[i] for i in indices]

# connect to bot
from cartman import bot
bot = bot()

import time
tick = time.time()
bot.home()
bot.set_speed(50000)


def pendown():
    bot.goto(z=0.5)


def penup():
    bot.goto(z=3)