クイックスタート

最小接続

from ur.ur_ctrl import UrCtrl

ROBOT_IP = "10.170.10.56"

with UrCtrl(ROBOT_IP) as robot:
    print(robot.current_position)

URCtrl はコンストラクタで接続を開始する。with 文を使うと、終了時に disconnect() が呼ばれる。

現在位置と現在関節角

with URCtrl(ROBOT_IP) as robot:
    p = robot.current_position
    j = robot.current_angle

    print("P =", p)
    print("J =", j)

current_position は mm / degree rotation-vector の P 座標を返す。

current_angle は degree の J 座標を返す。

現在位置から Z+10 mm

from ur.ur_ctrl import UrCtrl, MotionMode

with UrCtrl(ROBOT_IP) as robot:
    current = robot.current_position

    if current is not False:
        target = list(current)
        target[2] += 10.0

        robot.move(
            target,
            motion_mode=MotionMode.LINE,
            speed=20,
            accel=20,
            is_async=False,
        )

教示点 P1 を作る

with URCtrl(ROBOT_IP) as robot:
    robot.teach("P1")
    print(robot.P1)

UR Controller 内に P1 が保存されるわけではない。RobotVarManager が JSON へ保存する。

P1 へ移動する

with URCtrl(ROBOT_IP) as robot:
    robot.move("P1", motion_mode=MotionMode.PTP, speed=30, accel=30)

P pose を PTP で移動する場合、内部では moveJ_IK() を使う。

LINE で P1 へ移動する

with URCtrl(ROBOT_IP) as robot:
    robot.move("P1", motion_mode=MotionMode.LINE, speed=20, accel=20)

内部では moveL() を使う。

IO を出す

with URCtrl(ROBOT_IP) as robot:
    robot.set_IO(0, True)
    robot.set_IO(0, False)

エラーを見る

with URCtrl(ROBOT_IP) as robot:
    ok = robot.move("P999")

    if not ok:
        print(robot.error_code)
        print(robot.error_description)
        print(robot.get_current_error_info())