[PYTHON] I tried using Rotrics Dex Arm # 2

This is a continuation of # 1 using Rotrics DexArm. There is no sign that the SDK will come out, so I will manage to send GCode by serial communication. Surprisingly, the response was straightforward, so I was wondering if this was all right.


#!/usr/bin/env python3
import serial, time

#Serial setting
s = serial.Serial("/dev/ttyACM0",115200)

def w(gcode):
    '''
    Send GCode to Dexarm and wait for the response.
    '''
    print(gcode)
    s.write(gcode.encode('utf-8')+b'\r\n')
    r = None
    while r == None or "echo:" in r:
        r = s.readline().decode('utf-8').strip()
        print(r)  # "ok", "echo:busy" or "beyond limit.."

def wait(ms):
    w('G4 P'+str(ms))

def move(x,y,z):
    cood = ""
    if x != None: cood += "X"+str(x)
    if y != None: cood += "Y"+str(y)
    if z != None: cood += "Z"+str(z)
    w('G0 '+cood)

z1 = 0
z2 = 30

def pick():
    move(None,None,z1)
    w('G0 Z0')
    w('M1000')
    wait(500)
    move(None,None,z2)

def drop():
    move(None,None,z1)
    w('M1001')
    move(None,None,z2)
    wait(500)
    w('M1003')

# Main
def main():
    # Initialize
    w("M1111")
    time.sleep(1)
    move(100,0,30)

    # Pick and move objects in different speeds.
    w("G0 F3000")
    move(100,200,z2)
    pick()
    move(0,-200,z2)
    drop()
    w("G0 F6000")
    move(50,200,z2)
    pick()
    move(50,-200,z2)
    drop()
    w("G0 F8000")
    move(0,200,z2)
    pick()
    move(100,-200,z2)
    drop()

    # back to center
    move(200,0,0)
    s.close()
    print("Fin.")

#Main loop
if __name__ == '__main__':
    main()

If you think about it, you don't have to stick to Python, so I'm starting to rewrite it in Ruby. I will write the continuation when I get the actual machine. It may be good to summarize the basic operations in a gem.

#!/usr/bin/env ruby
# sudo apt install ruby-dev -y
# sudo gem install serialport

require 'serialport'

s = SerialPort.new('/dev/ttyACM0', 115200, 8, 1, 0) # device, rate, data, stop, parity

def w(gcode)
    puts gcode
    s.puts gcode + '\r\n'
    r = nil
    while r == nil || r.start_with?("echo:") do
        # "ok", "echo:busy" or "beyond limit.."
        r = s.readline.chomp.strip
        puts r
    end
end

w("M1111")
sleep(1)
s.close

puts "fin"

Recommended Posts

I tried using Rotrics Dex Arm # 2
I tried using Rotrics Dex Arm
I tried using parameterized
I tried using argparse
I tried using mimesis
I tried using anytree
I tried using aiomysql
I tried using Summpy
I tried using coturn
I tried using Pipenv
I tried using matplotlib
I tried using "Anvil".
I tried using Hubot
I tried using ESPCN
I tried using openpyxl
I tried using Ipython
I tried using PyCaret
I tried using cron
I tried using ngrok
I tried using face_recognition
I tried using Jupyter
I tried using PyCaret
I tried using Heapq
I tried using doctest
I tried using folium
I tried using jinja2
I tried using folium
I tried using time-window
[I tried using Pythonista 3] Introduction
I tried using easydict (memo).
I tried face recognition using Face ++
I tried using Random Forest
I tried using BigQuery ML
I tried using Amazon Glacier
I tried using git inspector
[Python] I tried using OpenPose
I tried using magenta / TensorFlow
I tried using AWS Chalice
I tried using Slack emojinator
I tried using GrabCut of OpenCV
I tried using Thonny (Python / IDE)
I tried server-client communication using tmux
I tried reinforcement learning using PyBrain
I tried deep learning using Theano
Somehow I tried using jupyter notebook
[Kaggle] I tried undersampling using imbalanced-learn
I tried shooting Kamehameha using OpenPose
I tried using the checkio API
[Python] I tried using YOLO v3
I tried asynchronous processing using asyncio
I tried using Amazon SQS with django-celery
I tried using Azure Speech to Text.
I tried using Twitter api and Line api
I tried playing a ○ ✕ game using TensorFlow
I tried using YOUTUBE Data API V3
I tried using Selenium with Headless chrome
I tried drawing a line using turtle
[Kaggle] I tried ensemble learning using LightGBM
I tried using PyEZ and JSNAPy. Part 2: I tried using PyEZ
I tried using Bayesian Optimization in Python
I tried to classify text using TensorFlow