Skip to content

UFACTORY Gcode


Description:

UFACTORY Gcode is compatible with LinuxCNC gcode: http://linuxcnc.org/, and refers to the RS-274 standard.

  • Firmware version: v2.5.0 or later
  • UFACTORY Studio version: V2.5.0 or later
  • TCP port: 504

1. G command

G CommandDefinitionCommandDescription
G0Rapid MoveG0 X Y Z A B CThe speed is 240mm/s by default
G1Linear MoveG1 X Y Z A B C FXYZ(mm), ABC(RPY,degree), F(speed,mm/min)
G2Arc Move, clockwise arcG2 X Y Z R P F
G2 X Y Z I J K P F
R-radius
I- X offset
J- Y offset
K- Z offset
P-number of turns, default is 1
G3Arc Move, counterclockwise arcG3 X Y Z R P F
G3 X Y Z I J K P F
R-radius
I- X offset
J- Y offset
K- Z offset
P-number of turns, default is 1
G4DwellG4 P2Unit:s
G17Z-axis, XY-plane.G17
G18Y-axis, XZ-plane.G18
G19X-axis, YZ-plane.G19
G20to use inches for length unitsG20
G21to use millimeters for length unitsG21Apply to G0/G1
G90absolute distance modeG90Apply to G0/G1/G2/G3
G91incremental distance modeG91Apply to G0/G1/G2/G3
G90.1absolute distance mode for I, J & K offsetsG90.1Apply to G2/G3
G91.1incremental distance mode for I, J & K offsetsG91.1Apply to G2/G3

1.1 Code Example

G0 X300 Y100 Z200 A180 B0 C0        ;move to [300,100,200,180,0,0]
G4 P5                               ;sleep 5s
G1 X300 Y100 Z350 A180 B0 C0 F30000 ;move to [300,100,200,180,0,0], speed=500mm/s
G21                                 ;set the unit as mm
G0 X300                             ;move to X=300mm
G20                                 ;set the unit as inches
G0 X10                              ;move to X=10inches(254mm)
G21                                 ;set the unit as mm
G90                                 ;use absolute coordinate
G0 X300                             ;move to X=300mm
G91                                 ;use relative coordinate
G0 X10                              ;move forward 10mm
G90                                 ;use absolute coordinate

You can debug and check more examples via 'UFACTORY Studio-Gcode' page.

2. M command

M CommandDefinitionCommandDescription
M2/M30End programM2/M30
M62Turn on digital output synchronized with motionM62 PP:IONum(0-15, 0-7:CO0-CO7, 8-15:DO0-D7)
M63Turn off digital output synchronized with motionM63 PP:IONum(0-15, 0-7:CO0-CO7, 8-15:DO0-D7)
M64Turn on digital output immediatelyM64 PP:IONum(0-15, 0-7:CO0-CO7, 8-15:DO0-D7)
M65Turn off digital output immediatelyM65 PP:IONum(0-15, 0-7:CO0-CO7, 8-15:DO0-D7)
M67Set an analog output synchronized with motionM67 E1 Q2E:IONum(AO0:0, AO1:1 )
Q:0-10V
M68Set an analog output immediatelyM68 E0 Q5E:IONum(AO0:0, AO1:1 )
Q:0-10V
M100Enable the armM100 P Q
M101Clear errorM101
M102Clear warnM102
M103Set modeM103 PP: mode
M104Set statesM104 PP: states
M115Set Tool GPIOM115 P QP:IONum(0/1/2/3/4)
Q:0/1/10/11
M116Control the end effectorM116 P Q

2.1 M116 Definition

M116End effector
CommandDescription
M116 P1xArm GripperM116 P1 Q0Q: position(-10~850)
M116 P2xArm Vacuum GripperM116 P2 Q0Q0: Open(synchronized with motion)
Q1: Close(synchronized with motion)
Q10: Open(immediately)
Q11: Close(immediately)
M116 P3BIO GripperM116 P3 Q1Q0: Close
Q1: Open
M116 P4Robotiq GripperM116 P4 Q100Q: position(0~255)
M116 P5Robotiq GripperM116 P5 Q100Q: position(0~255)
M116 P11Gripper LiteM116 P11 Q1Q0: Close(synchronized with motion)
Q1: Open(synchronized with motion)
Q10: Close(immediately)
Q11: Open(immediately)
M116 P12Vacuum Gripper LiteM116 P12 Q0Q0: Open(synchronized with motion)
Q1: Close(synchronized with motion)
Q10: Open(immediately)
Q11: Close(immediately)

2.2 Code Example

M62 P1            ;set CO1 to high level, wait=True
M64 P15           ;set DO7 to high level, wait=False
M67 E0 Q10        ;set AO0 to 10V, wait=True
M68 E1 Q2         ;set AO1 to 2V, wait=False


M116 P2 Q10       ;open xArm Vacuum Gripper, wait=False
M116 P2 Q11       ;close xArm Vacuum Gripper, wait=False

3. Python Example

python
import socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.setblocking(True)
sock.connect(('192.168.1.67', 504))

def send_and_recv(data):
    for line in data.split('\n'):
        line = line.strip()
        if not line:
            continue
        sock.send(line.encode('utf-8', 'replace') + b'\n')
        ret = sock.recv(5)
        code, mode_state, err = ret[0:3]
        state, mode = mode_state & 0x0F, mode_state >> 4
        cmdnum = ret[3] << 8 | ret[4]
        if code != 0 or state >= 4 or err > 0:
            print('code: {}, mode: {}, state: {}, err: {}, cmdnum: {}, cmd: {}'.format(code, mode, state, err, cmdnum, line))

# move x to x=500mm, speed= 10000 mm/min
send_and_recv('G1 X500 F10000')

Note:

1. Response:

  • byte0: return value. 0 is success
  • byte1: mode and state
  • byte2: error code
  • byte3 & byte4: buffer

2. Recommend to send 1 non-empty data at a time(with line breaks)

sock.send(b'G0 X300\n')

3. Need to receive the response, otherwise the buffer will be full.

 sock.recv(5)