addConstraint
Add inverse kinematics constraint
Description
addConstraint(
adds an inverse kinematics constraint, viztree
,gikConstraint
)gikConstaint
, to the
Constraints
property of the interactiveRigidBodyTree
object, viztree
.
Examples
Use the interactiveRigidBodyTree
object to manually move around a robot in a figure. The object uses interactive markers in the figure to track the desired poses of different rigid bodies in the rigidBodyTree
object.
Load Robot Model
Use the loadrobot
function to access provided robot models as rigidBodyTree
objects.
robot = loadrobot("atlas");
Visualize Robot and Save Configurations
Create an interactive tree object and associated figure, specifying the loaded robot model and its left hand as the end effector.
viztree = interactiveRigidBodyTree(robot,"MarkerBodyName","l_hand");
Click and drag the interactive marker to change the robot configuration. You can click and drag any of the axes for linear motion, rotate the body about an axis using the red, green, and blue circles, and drag the center of the interactive marker to position it in 3-D space.
The interactiveRigidBodyTree
object uses inverse kinematics to determine a configuration that achieves the desired end-effector pose. If the associated rigid body cannot reach the marker, the figure renders the best configuration from the inverse kinematics solver.
Programmatically set the current configuration. Assign a vector of length equal to the number of nonfixed joints in the RigidBodyTree
to the Configuration
property.
currConfig = homeConfiguration(viztree.RigidBodyTree);
currConfig(1:10) = [ 0.2201 -0.1319 0.2278 -0.3415 0.4996 ...
0.0747 0.0377 0.0718 -0.8117 -0.0427]';
viztree.Configuration = currConfig;
Save the current robot configuration in the StoredConfigurations
property.
addConfiguration(viztree)
To switch the end effector to a different rigid body, right-click the desired body in the figure and select Set body as marker body. Use this process to select the right hand frame.
You can also set the MarkerBodyName
property to the specific body name.
viztree.MarkerBodyName = "r_hand";
Move the right hand to a new position. Set the configuration programmatically. The marker moves to the new position of the end effector.
currConfig(1:18) = [-0.1350 -0.1498 -0.0167 -0.3415 0.4996 0.0747 0.0377 0.0718 -0.8117 -0.0427 0 0.4349 -0.5738 0.0563 -0.0095 0.0518 0.8762 -0.0895]'; viztree.Configuration = currConfig;
Save the current configuration.
addConfiguration(viztree)
Add Constraints
By default, the robot model respects only the joint limits of the rigidBodyJoint
objects associated with the RigidBodyTree
property. To add constraints, generate Robot Constraint objects and specify them as a cell array in the Constraints
property. To see a list of robotic constraints, see Inverse Kinematics. Specify a pose target for the pelvis to keep it fixed to the home position. Specify a position target for the right foot to be raised in front and above its current position.
fixedWaist = constraintPoseTarget("pelvis"); raiseRightLeg = constraintPositionTarget("r_foot","TargetPosition",[1 0 0.5]);
Apply these constraints to the interactive rigid body tree object as a cell array. The right leg in the resulting figure changes position.
viztree.Constraints = {fixedWaist raiseRightLeg};
Notice the change in position of the right leg. Save this configuration as well.
addConfiguration(viztree)
Play Back Configurations
To play back configurations, iterate through the stored configurations index and set the current configuration equal to the stored configuration column vector at each iteration. Because configurations are stored as column vectors, use the second dimension of the matrix.
for i = 1:size(viztree.StoredConfigurations,2) viztree.Configuration = viztree.StoredConfigurations(:,i); pause(0.5) end
Input Arguments
Interactive rigid body tree robot model visualization, specified as an interactiveRigidBodyTree
object.
Generalized inverse kinematics constraint, specified as one of these constraint objects.
Version History
Introduced in R2020a
See Also
Functions
Objects
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)