We drew a simple pixelated image on pixilart, downloaded it as a png and cropped it to less than 30 by 30 pixels.
def pixel(): # -------------------- 29/12/20 ---------------------- ser = serial.Serial('COM6',38400,timeout=4) img = cv2.imread("https://undefinedblog.s3-ap-northeast-1.amazonaws.com/static/post_images/f49c5afa23931655.png", 0) img_reverted= cv2.bitwise_not(img) new_img = img_reverted / 255.0 * 4 #reverses every 2nd array in the matrix (every second row in the image). This is necessary because the #arm moves like a printer down the image, starting from the top left corner going right, down, left, down, right down left down.... etc. for i in range(1, len(new_img), 2): new_img[i].reverse() #if y_amount = x_amount, the original aspect ratio of the image is preserved. y_amount = 3000 #we increased the y_amount because the original image (24x16 pixels) was too small. x_amount = 200 y_direction = True #true = right, false = left for row in new_img: for torque_value in row: if y_direction: SingleActionCommand(ser,y_amount,2, torque_value) #function to move and draw with the arm #move right by amount else: SingleActionCommand(ser,-1*y_amount,2, torque_value) #move left by amount y_direction = not y_direction #after each row, reverse the y-direction SingleActionCommand(ser,x_amount,1,torque_value) #move down the image by x_amount - change x value
The above image has 5 different levels of darkness, but as you can see in the photo below, the separate regions were quite indistinguishable so we drew another picture consisting of 3 different levels.
The tiny drawing next to the pencil is the original image with y_amount = x_amount = 200.
We need to perfect this method and be able to draw any picture the "printer way" as we called it - going pixel by pixel, row by row from the top to the bottom of an image. After that, we can start making use of the pressure sensor which we attached to the hand.
:D