- 參與人
三乙陳季磊、梁世叡、劉承洋、鄭又寧
三丙黃皓群、潘耑彣
- 目標
使用機器人手臂書寫文字
- 遭遇的問題
- 用什麼筆?
我們需要機械手臂能抓住且不需花太大力氣便能寫出字的筆,而毛筆太溼了,最後我們選用麥克筆
- 如何抓握?
我們的筆是用直的抓,方便固定
- 如何固定筆?
我們使用橡皮筋及束帶固定麥克筆,確認他能與紙面接觸
- 寫什麼字?
我們是寫方塊狀的數字,因為變化較少,執行較容易
wakuwaku 版本
程式碼:
#!/usr/bin/python3
# coding=utf8
import sys
sys.path.append('/home/pi/ArmPi/')
import time
import threading
from ArmIK.Transform import *
from ArmIK.ArmMoveIK import *
import HiwonderSDK.Board as Board
if sys.version_info.major == 2:
print('Please run this program with python3!')
sys.exit(0)
AK = ArmIK()
h = 2.5
x = -5
y = 20
#z = 5
pen_up = 0
data = [
[(0,0,1),(1,0.5,0),(1,1,1),(1,1.5,0),(1,2,1)],
[(0,1,1),(1,1,0),(1,0,0),(1,0,1),(1,1,1),(1,1.5,0)],
[(0,0,2),(1,0,0),(0,1,1),(1,0,0.5),(1,1,0)],
[(0,0,1),(1,0,0),(1,1,0),(1,1,1),(1,1.5,0)]
]
def initMove():
Board.setBusServoPulse(1, 500 - 50, 300)
Board.setBusServoPulse(2, 500, 500)
AK.setPitchRangeMoving((0, 10, 10), -30, -30, -90, 1500)
def move(a,b):
global pen_up,x,y
if(pen_up == 0):
AK.setPitchRangeMoving((x, y, h+4), -30, -30, -90, 500)
time.sleep(0.5)
pen_up = 1
x=a
y=b
data=AK.setPitchRangeMoving((x, y, h+4), -30, -30, -90)
print(data[2])
time.sleep(data[2]/1000*1.7)
def draw(a,b):
global pen_up,x,y
if(pen_up==1):
AK.setPitchRangeMoving((x, y, h), -30, -30, -90, 500)
time.sleep(0.5)
pen_up=0
x=a
y=b
data=AK.setPitchRangeMoving((x, y, h), -30, -30, -90)
time.sleep(data[2]/1000*1.7)
initMove()
time.sleep(2)
AK.setPitchRangeMoving((x, y, 5), -30, -30, -90)
a = input("pen")
setBusServoPulse(1,700,100)
b = input("go")
time.sleep(0.1)
a = "0123"
cursor_x = -5
cursor_y = 28
dis = 2 #字母間距為1.5倍的字母寬
font_size = 2 #1為原始大小
for char in a:
num = ord(char) - ord('0')
instruct = data[num]
print(instruct)
for step in instruct:
if(step[0]==0):
print("move")
print(str(step[1]*font_size+cursor_x)+','+str(step[2]*font_size+cursor_y))
move(step[1]*font_size+cursor_x,step[2]*font_size+cursor_y)
else:
print("draw")
print(str(step[1]*font_size+cursor_x)+','+str(step[2]*font_size+cursor_y))
draw(step[1]*font_size+cursor_x,step[2]*font_size+cursor_y)
cursor_x += dis*font_size
move(-5,24)
for char in a:
num = ord(char) - ord('0')
instruct = data[num]
print(instruct)
for step in instruct:
if(step[0]==0):
print("move")
print(str(step[1]*font_size+cursor_x)+','+str(step[2]*font_size+cursor_y))
move(step[1]*font_size+cursor_x,step[2]*font_size+cursor_y)
else:
print("draw")
print(str(step[1]*font_size+cursor_x)+','+str(step[2]*font_size+cursor_y))
draw(step[1]*font_size+cursor_x,step[2]*font_size+cursor_y)
cursor_x += dis*font_size
move(0,10)
範例影片:
結果:
數字版本
程式碼:
#!/usr/bin/python3
# coding=utf8
import sys
sys.path.append('/home/pi/ArmPi/')
import time
import threading
from ArmIK.Transform import *
from ArmIK.ArmMoveIK import *
import HiwonderSDK.Board as Board
if sys.version_info.major == 2:
print('Please run this program with python3!')
sys.exit(0)
AK = ArmIK()
h = 2.5
x = -5
y = 20
#z = 5
pen_up = 0
data = [
[(0,0,2),(1,1,2),(1,1,0),(1,0,0),(1,0,2)],
[(0,1,2),(1,1,0)],
[(0,0,2),(1,1,2),(1,1,1),(1,0,1),(1,0,0),(1,1,0)],
[(0,0,2),(1,1,2),(1,1,0),(1,0,0),(0,0,1),(1,1,1)],
[(0,0,2),(1,0,1),(1,1,1),(1,1,2),(1,1,0)],
[(0,1,2),(1,0,2),(1,0,1),(1,1,1),(1,1,0),(1,0,0)],
[(0,1,2),(1,0,2),(1,0,0),(1,1,0),(1,1,1),(1,0,1)],
[(0,0,1),(1,0,2),(1,1,2),(1,1,0)],
[(0,0,2),(1,1,2),(1,1,0),(1,0,0),(1,0,2),(0,0,1),(1,1,1)],
[(0,1,1),(1,0,1),(1,0,2),(1,1,2),(1,1,0)]
]
def initMove():
Board.setBusServoPulse(1, 500 - 50, 300)
Board.setBusServoPulse(2, 500, 500)
AK.setPitchRangeMoving((0, 10, 10), -30, -30, -90, 1500)
def move(a,b):
global pen_up,x,y
if(pen_up == 0):
AK.setPitchRangeMoving((x, y, h+4), -30, -30, -90, 500)
time.sleep(0.5)
pen_up = 1
x=a
y=b
data=AK.setPitchRangeMoving((x, y, h+4), -30, -30, -90)
print(data[2])
time.sleep(data[2]/1000*1.7)
def draw(a,b):
global pen_up,x,y
if(pen_up==1):
AK.setPitchRangeMoving((x, y, h), -30, -30, -90, 500)
time.sleep(0.5)
pen_up=0
x=a
y=b
data=AK.setPitchRangeMoving((x, y, h), -30, -30, -90)
time.sleep(data[2]/1000*1.7)
initMove()
time.sleep(2)
AK.setPitchRangeMoving((x, y, 5), -30, -30, -90)
a = input("pen")
setBusServoPulse(1,700,100)
#b = input("go")
#time.sleep(0.1)
a = input("please type some number: ")
cursor_x = 0
cursor_y = 28
dis = 1.5 #字母間距為1.5倍的字母寬
font_size = 1 #1為原始大小
for char in a:
num = ord(char) - ord('0')
instruct = data[num]
print(instruct)
for step in instruct:
if(step[0]==0):
print("move")
print(str(step[1]*font_size+cursor_x)+','+str(step[2]*font_size+cursor_y))
move(step[1]*font_size+cursor_x,step[2]*font_size+cursor_y)
else:
print("draw")
print(str(step[1]*font_size+cursor_x)+','+str(step[2]*font_size+cursor_y))
draw(step[1]*font_size+cursor_x,step[2]*font_size+cursor_y)
cursor_x += dis*font_size
move(0,10)
範例影片: