Main Content

ロボットの段階的な構築

この例では、ロボットの構築プロセスを段階的に説明し、さまざまなロボット コンポーネントと、ロボット構築で関数を呼び出す方法を示します。コード セクションを示していますが、寸法や変換の実際の値は、使用するロボットによって異なります。

  1. 剛体オブジェクトを作成します。

    body1 = rigidBody('body1');
    

    Rigid body object represented as an ellipse

  2. ジョイントを作成して剛体に割り当てます。ジョイントのホーム位置プロパティ HomePosition を定義します。同次変換 tform を使用して、ジョイントから親への変換を設定します。関数 trvec2tform を使用して、並進ベクトルを同次変換に変換します。ChildToJointTransform は単位行列に設定されます。

    jnt1 = rigidBodyJoint('jnt1','revolute');
    jnt1.HomePosition = pi/4;
    tform = trvec2tform([0.25, 0.25, 0]); % User defined
    setFixedTransform(jnt1,tform);
    body1.Joint = jnt1;
    

    Rigid body object represented as an ellipse with a body frame and an arrow indicating transformation between body frame and previous frame

  3. 剛体ツリーを作成します。このツリーはボディを接続するベース座標系で初期化されます。

    robot = rigidBodyTree;

    Workspace of robot and position of base frame with rigid body object represented as an ellipse with a body frame and an arrow indicating transformation between body frame and previous frame outside the workspace

  4. 最初のボディをツリーに追加します。ツリーのベースに接続することを指定します。ベース (親) から最初のボディへの固定変換が、以前に定義されています。

    addBody(robot,body1,'base')

    Workspace of robot and position of base frame with rigid body object represented as an ellipse with frame attached to the base of the new rigid body tree.

  5. 2 番目のボディを作成します。このボディのプロパティを定義し、最初の剛体に接続します。変換を、前のボディ座標系に対して相対的に定義します。

    body2 = rigidBody('body2');
    jnt2 = rigidBodyJoint('jnt2','revolute');
    jnt2.HomePosition = pi/6; % User defined
    tform2 = trvec2tform([1, 0, 0]); % User defined
    setFixedTransform(jnt2,tform2);
    body2.Joint = jnt2;
    addBody(robot,body2,'body1'); % Add body2 to body1

    Rigid tree body with an additional body, represented as an ellipse, added to the end of the first body.

  6. その他のボディを追加します。ボディ 3 とボディ 4 をボディ 2 に接続します。

    body3 = rigidBody('body3');
    body4 = rigidBody('body4');
    jnt3 = rigidBodyJoint('jnt3','revolute');
    jnt4 = rigidBodyJoint('jnt4','revolute');
    tform3 = trvec2tform([0.6, -0.1, 0])*eul2tform([-pi/2, 0, 0]); % User defined
    tform4 = trvec2tform([1, 0, 0]); % User defined
    setFixedTransform(jnt3,tform3);
    setFixedTransform(jnt4,tform4);
    jnt3.HomePosition = pi/4; % User defined
    body3.Joint = jnt3
    body4.Joint = jnt4
    addBody(robot,body3,'body2'); % Add body3 to body2
    addBody(robot,body4,'body2'); % Add body4 to body2

    Previous rigid tree body with additional two bodies, both attached to the second body

  7. 制御する必要のある特定のエンドエフェクタがある場合、固定ジョイントをもつ剛体として定義します。このロボットでは、エンドエフェクタの変換を取得できるように、body4 にエンドエフェクタを追加します。

    bodyEndEffector = rigidBody('endeffector');
    tform5 = trvec2tform([0.5, 0, 0]); % User defined
    setFixedTransform(bodyEndEffector.Joint,tform5);
    addBody(robot,bodyEndEffector,'body4');
  8. ロボットを作成したので、ロボット コンフィギュレーションを生成できます。指定したコンフィギュレーションでは、getTransform を使用して 2 つのボディ座標系の間の変換を取得することもできます。エンドエフェクタからベースへの変換を取得します。

    config = randomConfiguration(robot)
    tform = getTransform(robot,config,'endeffector','base')
    config = 
    
      1×2 struct array with fields:
    
        JointName
        JointPosition
    
    
    tform =
    
       -0.5484    0.8362         0         0
       -0.8362   -0.5484         0         0
             0         0    1.0000         0
             0         0         0    1.0000

    Completed rigid body tree with transformation from the end effector to the base

    メモ

    この変換は、この例で指定した寸法に固有です。ロボットの値は、定義する変換によって異なる場合があります。

  9. subtree を使用して、既存のロボットまたはその他のロボット モデルからサブツリーを作成できます。新しいサブツリーのベースとして使用するボディ名を指定します。ボディを追加、変更、または削除して、サブツリーを変更できます。

    newArm = subtree(robot,'body2');
    removeBody(newArm,'body3');
    removeBody(newArm,'endeffector')
    

    Additional two-body robot created as a sub-tree but is independent of the other robot

  10. また、これらのサブツリーをロボットに追加することもできます。サブツリーの追加は、ボディの追加と同様です。指定したボディ名は接続のベースとして機能し、サブツリー上のすべての変換はそのボディの座標系に対して相対的に行われます。サブツリーを追加する前に、ボディとジョイントのすべての名前が一意であることを確認しなければなりません。ボディとジョイントのコピーを作成し、名前を変更して、サブツリー上で置換します。addSubtree を呼び出して、指定したボディにサブツリーを接続します。

    newBody1 = copy(getBody(newArm,'body2'));
    newBody2 = copy(getBody(newArm,'body4'));
    newBody1.Name = 'newBody1';
    newBody2.Name = 'newBody2';
    newBody1.Joint = rigidBodyJoint('newJnt1','revolute');
    newBody2.Joint = rigidBodyJoint('newJnt2','revolute');
    tformTree = trvec2tform([0.2, 0, 0]); % User defined
    setFixedTransform(newBody1.Joint,tformTree);
    replaceBody(newArm,'body2',newBody1);
    replaceBody(newArm,'body4',newBody2);
    
    addSubtree(robot,'body1',newArm);

    Sub rigid body tree connected to the first body of the first rigid body tree

  11. 最後に、showdetails を使用して、構築したロボットを見ることができます。ジョイント タイプが正しいことを確認してください。

    showdetails(robot)
     Idx          Body Name             Joint Name             Joint Type          Parent Name(Idx)   Children Name(s)
     ---          ---------             ----------             ----------          ----------------   ----------------
       1              body1                   jnt1               revolute                   base(0)   body2(2)  newBody1(6)  
       2              body2                   jnt2               revolute                  body1(1)   body3(3)  body4(4)  
       3              body3                   jnt3               revolute                  body2(2)   
       4              body4                   jnt4               revolute                  body2(2)   endeffector(5)  
       5        endeffector        endeffector_jnt                  fixed                  body4(4)   
       6           newBody1                newJnt1               revolute                  body1(1)   newBody2(7)  
       7           newBody2                newJnt2               revolute               newBody1(6)   
    --------------------

参考

|

関連するトピック