Main Content

interactiveRigidBodyTree

Interact with rigid body tree robot models

Description

TheinteractiveRigidBodyTreeobject creates a figure that displays a robot model using arigidBodyTreeobject and enables you to directly modify the robot configuration using an interactive marker. TherigidBodyTreeobject defines the geometry of the different connected rigid bodies in the robot model and the joint limits for these bodies.

To compute new configurations using inverse kinematics, click and drag the interactive marker in the figure. The marker supports dragging of the center marker, linear motion along specific axes, and rotation about each axes. You can change the end effector by right-clicking a different body and choosingSet body as marker body

To save the current configuration of the robot model, use theaddConfigurationobject function. TheStoredConfigurationsproperty contains the saved configurations.

By default, the joint limits of the robot model are the only constraint on the robot. To add additional constraints, use theaddConstraintobject function. For a list of available constraint objects, seeRobot ConstraintsinInverse Kinematics

Creation

Description

example

viztree= interactiveRigidBodyTree(robot)creates an interactive rigid body tree object and associated figure for the specified robot model. Therobotargument sets theRigidBodyTreeproperty. To interact with the model, click and drag the interactive marker in the figure.

viztree= interactiveRigidBodyTree(robot,'Frames','off')turns off the frame axes plotted for each joint in the robot model.

viztree= interactiveRigidBodyTree(___,Name,Value)sets properties using one or more name-value pair arguments in addition to any of the input argument combinations in previous syntaxes. Enclose each property name in quotes. For example,'RigidBodyTree',robotcreates an interactive rigid body tree object with the specified robot model.

Properties

expand all

Rigid body tree robot model, specified as arigidBodyTreeobject. The robot model defines the geometry of the rigid bodies and the joints connecting them. To access provided robot models, use theloadrobotfunction. To import models from URDF files orSimscape™ Multibody™models, use theimportrobotfunction.

You can set this property when you create the object. After you create the object, this property is read-only.

Inverse kinematics solver, specified as ageneralizedInverseKinematicsSystem object. By default, the solver uses the Levenberg-Marquardt algorithm with a maximum number of iterations of 2. Increasing the maximum number of iterations can decrease the frame rate in the figure.

You can set this property when you create the object. After you create the object, this property is read-only.

Name of rigid body associated with interactive marker, specified as a string scalar or character vector. By default, this property is set to the body with the highest index in theRigidBodyTreeproperty. To change this property using the figure, right-click a rigid body and selectSet body as marker body

Example:"r_foot"

Data Types:char|string

This property is read-only.

Current pose of interactive marker, specified as a 4-by-4 homogeneous transformation matrix.

Data Types:double

This property is read-only.

Current pose of the rigid body associated with the interactive marker, specified as a 4-by-4 homogeneous transformation matrix.

Data Types:double

Constraints on inverse kinematics solver, specified as a cell array of one or more constraint objects:

默认情况下,逆运动学解算器方面only the joint limits of theRigidBodyTreeproperty. To add or remove the constraints on the robot model, use theaddConstraintandremoveConstraintsobject functions respectively. Alternatively, you can assign a new cell array of constraint objects to the property.

Example:{constraintAiming("head","ReferenceBody","right_hand")}

Data Types:cell

Weights on orientation and position of target pose, respectively, specified as a two-element vector,[orientationposition]

To increase priority for matching a desired orientation or position, increase the corresponding weight value.

Example:[1 4]

Data Types:double

Visibility of interactive marker in figure, specified as logical1(true) or0or (false). SetShowMarkertofalseto hide the interactive marker in the figure.

Data Types:logical

Type of control for interactive marker, specified as"InverseKinematics"or"JointControl".默认情况下,这个数字计算所有联合有限公司nfigurations of the robot by using inverse kinematics with the end effector set toMarkerBodyNameproperty value. To control the position of a specific joint on the selected rigid body, set this property to"JointControl"

Data Types:char|string

Relative scale of interactive marker, specified as a positive positive real number. To increase or decrease the size of the marker in the figure, adjust this property.

Data Types:double

Current configuration of rigid body tree robot model, specified as ann-element vector.nis the number of nonfixed joints in theRigidBodyTreeproperty.

Example:[1 pi 0 0.5 3.156]'

Data Types:double

Stored robot configurations, specified as ann-by-pmatrix. Each column of the matrix is a stored robot configuration.nis the number of nonfixed joints in theRigidBodyTreeproperty.pis the number of stored robot configurations. To add or remove stored configurations, use theaddConfigurationorremoveConfigurationsobject functions, respectively.

Data Types:double

Object Functions

addConfiguration Store current configuration
addConstraint Add inverse kinematics constraint
removeConfigurations Remove configurations fromStoredConfigurationsproperty
removeConstraints Remove inverse kinematics constraints
showFigure Show interactive rigid body tree figure

Examples

collapse all

Use theinteractiveRigidBodyTreeobject 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 therigidBodyTreeobject.

Load Robot Model

Use theloadrobotfunction to access provided robot models asrigidBodyTreeobjects.

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");

Figure Interactive Visualization contains an axes object. The axes object contains 179 objects of type patch, line, surface.

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.

TheinteractiveRigidBodyTreeobject 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 theRigidBodyTreeto theConfigurationproperty.

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;

Figure Interactive Visualization contains an axes object. The axes object contains 179 objects of type patch, line, surface.

Save the current robot configuration in theStoredConfigurationsproperty.

addConfiguration(viztree)

To switch the end effector to a different rigid body, right-click the desired body in the figure and selectSet body as marker body.Use this process to select the right hand frame.

You can also set theMarkerBodyNameproperty to the specific body name.

viztree.MarkerBodyName ="r_hand";

Figure Interactive Visualization contains an axes object. The axes object contains 179 objects of type patch, line, surface.

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;

Figure Interactive Visualization contains an axes object. The axes object contains 179 objects of type patch, line, surface.

Save the current configuration.

addConfiguration(viztree)

Add Constraints

By default, the robot model respects only the joint limits of therigidBodyJointobjects associated with theRigidBodyTreeproperty. To add constraints, generateRobot Constraintobjects and specify them as a cell array in theConstraintsproperty. To see a list of robotic constraints, seeInverse 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 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};

Figure Interactive Visualization contains an axes object. The axes object contains 179 objects of type patch, line, surface.

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.

fori = 1:size(viztree.StoredConfigurations,2) viztree.Configuration = viztree.StoredConfigurations(:,i); pause(0.5)end

Figure Interactive Visualization contains an axes object. The axes object contains 179 objects of type patch, line, surface.

Use theinteractiveRigidBodyTreeobject to visualize a robot model and interactively create waypoints and use them to generate a smooth trajectory usingcubicpolytraj.For more information, see theinteractiveRigidBodyTreeobject andcubicpolytrajfunction.

Load the Robot Model

Use theloadrobotfunction to access provided robot models asrigidBodyTreeobjects.

robot = loadrobot('abbIrb120');

Visualize Robot and Save Configurations

Create an interactive tree object using theinteractiveRigidBodyTreefunction. By default, the interactive marker is set to the body with the highest index in theRigidBodyTreeproperty. To change this property using the figure, right-click a rigid body and selectSet body as marker body.Alternatively,MarkerBodyNameproperty for theinteractiveRigidBodyTreecan be set using name-value pairs.

iRBT = interactiveRigidBodyTree(robot);

Figure Interactive Visualization contains an axes object. The axes object contains 34 objects of type patch, line, surface.

Interactively Add Configurations

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.

TheinteractiveRigidBodyTreeobject 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.

When the robot is in a desired configuration use theaddConfigurationobject function to add the configuration to theStoredConfigurationproperty of the object.

In this example, 6 waypoints are created using the interactive marker andaddConfigurationobject function. They are saved inwayPoints.mat.Stored configurations can be accessed usingiRBT.StoredConfigurations

load("wayPts.mat");

Generate Smooth Trajectory Using the Waypoints

Use thecubicpolytrajfunction to generate smooth trajectory between the waypoints. Define time points that correspond to each waypoint. Define the time vector for generating the trajectory. ThecubicpolyTrajfunction generates a configuration for each timestep in the timevectortvec.

iRBT.StoredConfigurations = wayPts ;% Waypointstpts = [0 2 4 6 8 10];% Time Pointstvec = 0:0.1:10;% Time Vector[q,qd,qdd,pp] = cubicpolytraj(iRBT.StoredConfigurations,tpts,tvec);

Visualize Robot Motion on the Trajectory

Define the simulation frequency using arateControlobject. Use theshowFigurefunction to visualize the robot model and use aforloop to play all the configurations of the robot.

r = rateControl(10); iRBT.ShowMarker = false;% Hide the markershowFigure(iRBT)fori = 1:size(q',1) iRBT.Configuration = q(:,i); waitfor(r);end

Figure Interactive Visualization contains an axes object. The axes object contains 24 objects of type patch, line.

Limitations

  • If theinteractiveRigidBodyTreeobject is deleted while the figure is still open, the interactivity of the figure is disabled and the title of the figure is updated.

Tips

  • To maximize performance when visualizing complex robot models with complex meshes, ensure you enable hardware-accelerated OpenGL. By default, MATLAB®uses hardware-accelerated OpenGL if your graphics hardware supports it. For more information, see theopenglfunction.

Version History

Introduced in R2020a