How to pause a Kawasaki robot on command using a background PC program

Based on contributions by icorn.

This shows how to implement a software ā€œholdā€ button for a Kawasaki robot: a command sent from your PC that pauses the robot’s motion and lets you resume it later, without killing the controller’s motors or aborting the program.

What you need

Steps

1. Understand PC programs vs. AS programs

A .pc (Process Control) program runs in the background, simultaneously with the main .as program you run on the robot. Unlike regular AS programs, PC programs are allowed to control the flow of execution of other programs — including issuing ā€œmonitor commandsā€ that a normal program can’t.

The two monitor commands you need are HOLD and CONTINUE. Unlike ABORT or HALT, HOLD pauses the program the same way turning the physical ā€œHoldā€ dial would: the robot’s motors stay energized, and you keep control over the robot via software. To call a monitor command from a PC program, prefix it with MC, e.g. MC EXECUTE program_name.

2. Write the background PC program

This program starts your main robot program, then waits for "hold" or "continue" messages over UDP and issues the matching monitor command.

.PROGRAM bg_control.pc () ;

  .retrecv = -1
  WAIT SWITCH (POWER)
  MC EXECUTE main_robot1

  receive:
    .$receive = ""
    ; Receive control commands via UDP, executes the UDP support program
    CALL udp_emergency(.retrecv, .$receive)

    ; Check for errors in UDP reception
    IF .retrecv < 0 THEN
      GOTO receive
    END

    ; Handle received commands
    IF .$receive == "hold" THEN
      MC HOLD  ; THIS IS THE COMMAND THAT PAUSES THE ROBOT!!
      PRINT " -> PROGRAM HELD"
      ; Add a short delay to ensure state update
      TWAIT 0.5
      GOTO receive
    END

    IF .$receive == "continue" THEN
      MC CONTINUE  ; THIS IS THE COMMAND TO RESUME ROBOT MOVEMENT
      PRINT " -> PROGRAM RESUMED"
      ; Add a short delay to ensure state update
      TWAIT 0.5
      GOTO receive
    END

    ; If neither hold nor continue, loop again
    GOTO receive
.END

Replace main_robot1 with the name of your own main program.

3. Write the UDP receive helper program

bg_control.pc calls this program to receive a message over UDP and decode it into a string.

.PROGRAM udp_emergency (.ret,.$receive) ;
    ip[1] = 192
    ip[2] = 168
    ip[3] = 0
    ip[4] = 10
    .$recv_buf[1] = .$receive
    .ret = 0
    timeout = 60
    max_length = 255
    .port = 10020
    .$receive = ""
    .num = 0

    ; Receive a message from the server. Check the Kawasaki AS Manual
    ; for details on UDP_RECVFROM.
    UDP_RECVFROM .eret, .port, .$recv_buf[1], .num, timeout, ip[1], max_length
    IF .eret < 0 THEN
      PRINT "UDP_RECV error in Control Program ", .eret
      PRINT ".num = ", .num
      .ret = -1
    ELSE
      IF .num > 0 THEN
        IF .num * max_length <= 255 THEN
          FOR .j = 1 TO .num
            .$receive = .$receive + .$recv_buf[.j]
          END
        ELSE
          .ret = -1
          PRINT "String too long"
          PRINT .$recv_buf[1]
        END
      ELSE
        PRINT "Invalid response"
        .ret = -1
      END
    END
.END

4. Send hold/continue commands from Python

import socket

ROBOT_IP = '192.168.0.1'       # replace with your robot's IP address
ROBOT_PORT_EMERGENCY = 10020   # any non-privileged port the robot isn't already using

def send_message(message, robot_port=10010):
    with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as server_socket:
        try:
            server_socket.sendto(message.encode(), (ROBOT_IP, robot_port))
            print(f"Message '{message}' sent to robot at {ROBOT_IP}")
        except Exception as e:
            print(f"Error sending message to robot: {e}")

send_message('hold', ROBOT_PORT_EMERGENCY)
send_message('continue', ROBOT_PORT_EMERGENCY)

Troubleshooting

  • Robot never pauses: check that bg_control.pc is actually running as a background program (it needs to be started as a .pc program, not a regular .as program) and that the port in udp_emergency matches ROBOT_PORT_EMERGENCY in Python.
  • .retrecv < 0 loops forever without pausing: this means the UDP receive itself failed (timeout or malformed packet); the program just loops back to wait for the next message. Check the network connection and that the PC is actually sending to the robot’s IP and port.

Further reading

Check the Kawasaki manuals for more detail on PC programs and monitor commands.

Related


Rewritten and consolidated (Sept 2026) from the original student how-to’s: How to ā€˜pause’ a Kawasaki robot on command using a Kawasaki background program.