メインコンテンツ

replaceBody

ロボットのボディを置き換え

説明

replaceBody(robot,bodyname,newbody) は、ロボット モデルのボディを新しいボディに置き換えます。ロボットの Parent プロパティと Children プロパティを除くすべてのプロパティが適宜更新されます。ロボット モデルのそれ以外の部分には影響しません。

すべて折りたたむ

ダイナミクス関数を使用してジョイント トルクとジョイント加速度を計算するには、rigidBodyTreeオブジェクトとrigidBodyにダイナミクス プロパティを指定します。

剛体ツリー モデルを作成します。接続する 2 つの剛体を作成します。

robot = rigidBodyTree('DataFormat','row');
body1 = rigidBody('body1');
body2 = rigidBody('body2');

ボディに接続するジョイントを指定します。body2 から body1 への固定変換を設定します。変換は x 方向に 1 m です。

joint1 = rigidBodyJoint('joint1','revolute');
joint2 = rigidBodyJoint('joint2');
setFixedTransform(joint2,trvec2tform([1 0 0]))
body1.Joint = joint1;
body2.Joint = joint2;

2 つのボディのダイナミクス プロパティを指定します。ボディをロボット モデルに追加します。この例では、ロッド (body1) と、接続された球体 (body2) の基本値が与えられています。

body1.Mass = 2;
body1.CenterOfMass = [0.5 0 0];
body1.Inertia = [0.001 0.67 0.67 0 0 0];

body2.Mass = 1;
body2.CenterOfMass = [0 0 0];
body2.Inertia = 0.0001*[4 4 4 0 0 0];

addBody(robot,body1,'base');
addBody(robot,body2,'body1');

ロボット全体の重心位置を計算します。位置をロボットにプロットします。ビューを xy 平面に移動します。

comPos = centerOfMass(robot);

show(robot);
hold on
plot(comPos(1),comPos(2),'or')
view(2)

Figure contains an axes object. The axes object with xlabel X, ylabel Y contains 6 objects of type patch, line. One or more of the lines displays its values using only markers

2 番目のボディの質量を変更します。重心の変化に注目してください。

body2.Mass = 20;
replaceBody(robot,'body2',body2)

comPos2 = centerOfMass(robot);
plot(comPos2(1),comPos2(2),'*g')
hold off

Figure contains an axes object. The axes object with xlabel X, ylabel Y contains 7 objects of type patch, line. One or more of the lines displays its values using only markers

入力引数

すべて折りたたむ

ロボット モデル。rigidBodyTree オブジェクトとして指定します。このオブジェクトに剛体が追加され、bodyname で指定された剛体で接続されます。

ボディ名。string スカラーまたは文字ベクトルとして指定します。このボディは、robot で指定したロボット モデル上になければなりません。

データ型: char | string

剛体。rigidBody オブジェクトとして指定します。

拡張機能

すべて展開する

バージョン履歴

R2016b で導入