LoginSignup
1
2

More than 1 year has passed since last update.

DOBOT×AI 判別対象をグリッパーで掴む

Posted at

以下のテキストのソースコードは、判別対象を吸引カップで移動させるようになっています。
DOBOT Magician AIx画像認識xロボットアーム制御

対象物が小さい、あるいは細長く、吸引カップでは保持できないことがあります。
そのような場合、DOBOT magicianに付属する空気式グリッパーで掴む必要があります。

変更前

グリッパーで対象物を掴んで動かすプログラムに修正します。
dobot_aiフォルダ内にある「dobotClassifier.py」の以下の部分で対象物を移動させています。

dobotClassifier.py
# Z座標
# オブジェクトの大きさ、環境に合わせて変更する
z = -58
dobotClassifier.py
def dobot_classifier(label, pos_x, pos_y):
    '''
    指定された座標のオブジェクトを取り、ラベルごとに仕分ける
    '''
    # オブジェクトの真上に移動
    dobot.move(pos_x, pos_y, 0, 0)
    dobot.wait(1)
    # オブジェクトを取れる位置まで移動し、オブジェクトを取る
    dobot.move(pos_x, pos_y, z, 0)
    dobot.suctioncup(True, True)
    dobot.wait(1)
    # オブジェクトの真上に移動
    dobot.move(pos_x, pos_y, 0, 0)
    dobot.wait(1)

    # ラベルに合わせた座標を指定
    if label <= 3:
        x = 150 + 50 * label
        y = 100
    elif label <= 6:
        x = 150 + 50 * (label - 4)
        y = 150
    elif label <= 8:
        x = 150 + 50 * (label - 7)
        y = 200
    else:
        x = 300
        y = 0

    # ラベルごとに仕分ける位置の真上に移動
    dobot.move(x, y, 0, 0)
    dobot.wait(2)

    # オブジェクトを置く
    dobot.move(x, y, -30, 0)
    dobot.suctioncup(False, False)
    dobot.wait(2)

    print("move -> (%d, %d)" % (x, y))

    # カメラに映らない場所に移動
    dobot.move(150, 100, 0, 0)

    return True

変更後

以下の様に修正します。

dobotClassifier.py
# Z座標
# オブジェクトの大きさ、環境に合わせて変更する
z = -40

※ 上記の数値は、オブジェクトの大きさや動かす環境に合わせて変更してください。

dobotClassifier.py
def dobot_classifier(label, pos_x, pos_y):
    '''
    指定された座標のオブジェクトを取り、ラベルごとに仕分ける
    '''
    # オブジェクトの真上に移動
    dobot.move(pos_x, pos_y, 0, 0)
    dobot.wait(1)
    # オブジェクトを取れる位置まで移動し、オブジェクトを取る
    dobot.gripper(True, False)
    dobot.move(pos_x, pos_y, z, 0)
    dobot.gripper(True, True)
    dobot.wait(1)
    # オブジェクトの真上に移動
    dobot.move(pos_x, pos_y, 0, 0)
    dobot.wait(1)

    # ラベルに合わせた座標を指定
    if label <= 3:
        x = 150 + 50 * label
        y = 100
    elif label <= 6:
        x = 150 + 50 * (label - 4)
        y = 150
    elif label <= 8:
        x = 150 + 50 * (label - 7)
        y = 200
    else:
        x = 300
        y = 0

    # ラベルごとに仕分ける位置の真上に移動
    dobot.move(x, y, 0, 0)
    dobot.wait(2)

    # オブジェクトを置く
    dobot.move(x, y, -30, 0)
    dobot.gripper(True, False)
    dobot.wait(2)
    dobot.move(x, y, 0, 0)
    dobot.gripper(False, False)

    print("move -> (%d, %d)" % (x, y))

    # カメラに映らない場所に移動
    dobot.move(150, 100, 0, 0)

    return True

修正したプログラムは、グリッパーの角度(R座標)は0度のままなので、対象物や置き方によって変更する必要があります。

1
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
1
2