目次
紙とペンを動かし,文字を書くというプリンターに似た構造になっている
X軸制御機構(mx)を上げ下げするための機構である
ペンをX軸方向に動かすための機構
紙を動かすための機構
紙が入っているかを確認するための機構
PrinthonはLEGO Mindstorms EV3プリンターのために開発したドロー用プログラムである.
Printhonは変数及び関数の定義用プログラム
別途用意する字を書くプログラムにPrinthonをimportさせPrinthonを使用することができる.
#!/usr/bin/env python3 from ev3dev.ev3 import * from time import sleep
print("Printhon ver 0.4\n" "Please connect\n" "\tmy\tto\toutA\n" "\tarm\tto\toutC\n" "\tmx\tto\toutD\n" "\tcs\tto\tin1") input("Please press the enter key after connecting.")
my = LargeMotor('outA') arm = LargeMotor('outC') mx = MediumMotor('outD') cs = ColorSensor('in1')
# constants mxcm = 38.095238 mycm = 20.050125313 n = 56.25 vxy_ratio = 5/3 # x:y=5:3 # *position_sp mxcm_print = mxcm mycm_print = mycm*-1 mycm_paper = mycm # *distance(cm)/speed sleep_x = n sleep_y = vxy_ratio*n
# speed # common my_speed = 100 arm_speed = 30 # x only mx_speed = 500
# paper paper_set_d = 4 paper_out_d = 4
def pu(): arm.run_to_abs_pos(position_sp=-40) sleep(1)
def pd(): if cs.color != 6: # nonwhite input("The paper could not be detected. Press Enter to continue.") arm.run_to_abs_pos(position_sp=0) sleep(2)
def x(x): mx.run_to_rel_pos(position_sp=x*mxcm_print, speed_sp=mx_speed) sleep(abs(x)*sleep_x/mx_speed)
def y(y): my.run_to_rel_pos(position_sp=y*mycm_print) sleep(abs(y)*sleep_y/my_speed)
def xy(x, y): if y == 0: x(x) else: a = (vxy_ratio)*(x/y) mx.run_to_rel_pos(position_sp=x*mxcm_print, speed_sp=abs(my_speed*a)) my.run_to_rel_pos(position_sp=y*mycm_print) sleep(abs(y)*sleep_y/my_speed)
def paper_set(): pu() input("I move the paper, is it OK?\n" "\tPress Enter to continue.") if cs.color == 4: # yellow my.run_forever(speed_sp=my_speed) color = 6 # white else: my.run_forever(speed_sp=-my_speed) color = 4 # yellow while 1: if cs.color == color: my.stop() my.run_to_rel_pos(position_sp=paper_set_d*mycm_paper, speed_sp=my_speed, stop_action='hold') sleep(paper_set_d*sleep_y/my_speed) print("Paper loaded.") break
def paper_out(): pu() if cs.color == 6: # white my.run_forever(speed_sp=-my_speed) while 1: if cs.color == 4: # yellow my.stop() my.run_to_rel_pos(position_sp=-paper_out_d*mycm_paper) sleep(paper_out_d*sleep_y/my_speed) break
def mx_init(): mx.reset() mx.run_to_rel_pos(speed_sp=mx_speed, position_sp=-8.8*mxcm_print, stop_action='brake') sleep(8.8*sleep_x/mx_speed) mx.reset() mx.run_to_abs_pos(speed_sp=mx_speed, stop_action='hold', position_sp=0) mx.run_to_rel_pos(speed_sp=mx_speed, stop_action='hold', position_sp=0)
def my_init(): my.reset() my.run_to_abs_pos(speed_sp=my_speed, stop_action='hold', position_sp=0) my.run_to_rel_pos(speed_sp=my_speed, stop_action='hold', position_sp=0)
def arm_init(): arm.reset() input("Please press the enter key after setting the arm") arm.reset() arm.run_to_abs_pos(speed_sp=arm_speed, stop_action='hold')
def init_all(): arm_init() paper_set() mx_init() my_init() print("Initialization of all motors has been completed.")
#!/usr/bin/env python3 from printhon_ver0_4 import *
init_all() input("Press enter to print \"komatsu\"")
# ko pu() x(4)
# 1 pd() y(-4) xy(-0.3, 0.3) pu()
y(2) x(-1.5)
# 2 pd() xy(-1, -1) pu()
x(4) y(1)
# 3 pd() xy(1, -1) pu()
# matsu x(-5) y(-3)
# 1 pd() x(1.5) pu()
x(-0.5) y(1)
# 2 pd() y(-4) pu()
y(3.2)
# 3 pd() xy(-1, -1) pu()
xy(1, 1)
# 4 pd() xy(1.5, -1.5) pu()
x(1) y(1)
# 5 pd() xy(-1, -1) pu()
x(2) y(1)
# 6 pd() xy(1, -1) pu()
x(-1.8)
# 7 pd() xy(-1.5, -1.5) x(2.5) pu()
xy(-0.5, 0.5)
# 8 pd() xy(1, -1)
paper_out()