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"