LoginSignup
7
2

More than 3 years have passed since last update.

Universal Robots向けのCLIツール作ってみた

Posted at

目的

URを動かすためのツールを作ったので自慢したい

対象とする読者

この記事は仕事でUniversalRobotsのロボットを使う必要が出てきたプログラマ向けに書いています。

環境

  • コントロールボックス CB3.1 SW3.4
  • ロボット UR5
  • 言語 python3.6
  • 使用ライブラリ click

何を作ったか

スクリプトをコマンドラインから送ることのできるCLIツールを作りました。この記事で解説しましたが、Universal Robotsのロボットは外部からスクリプトでコントロールが可能です。

ロボットに送るスクリプトをコマンドラインから簡単にテストできるツールが欲しくて作りました。コマンドラインパーサーのclickを使って作ったので、ソース自体は数行でできました。

ソケット繋いで送るだけなので正直公開するか悩みましたが、とりあえずおいておきます。

もう少し機能を追加したら年内にはgithubで公開する予定です。。

アドベントカレンダー記事公開に間に合わなかった。。。

urscript_sender.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import socket
import time
import sys
import click


def to_bytes(script_str):
    return bytes(script_str.encode())


@click.command(help='UR script sending program')
@click.option('-p', '--port', 'port', type=int, default=30002, help='UR robot TCP port. 3002 is default. value between 30001 to 30004')
@click.argument('host',type=str)
@click.argument('file_path', type=str)
def send_script(file_path, host, port):
    with open(file_path, 'r') as file:
        with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
            s.connect((host, port))
            script = ''.join(file) ## 文字列連結
            print(script)
            s.send(to_bytes(script))


def main():
    send_script()


if __name__ == '__main__':
    main()

今後やること

  • Dashbord Serverにジョブコールに対応させる(Play Load等)
  • サブコマンドをもう少し充実させる
  • pipからインストールできるようにGithubで公開する
7
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
2