How can I change the base position of universalUR10 robot model

2 views (last 30 days)
Code:
ur10 = loadrobot('universalUR10');
ur10Moved = rigidBodyTree;
rb = rigidBody('newBaseForUR10');
rb.Joint.setFixedTransform(trvec2tform([3,0,0]));
ur10Moved.addBody(rb, 'base');
ur10Moved.addSubtree('newBaseForUR10', ur10);
show(ur10);
xlim([-2 4])
zlim([0, 1.5])
hold on
show(ur10Moved);
Error:
The name of the body, base, has already been used in the robot. Use a different name for the body.
when I use a different name, i got this error:
Body with name bbase is not found. Check the BodyNames property of the rigidBodyTree object to get a list of body names.

Accepted Answer

Hannes Daepp
Hannes Daepp on 22 Nov 2021
This issue is because the default base name in a new rigidBodyTree is "base", which is also a rigid body in the loaded UR10.
This is evident when you first create the new rigid body tree:
ur10Moved = rigidBodyTree
ur10Moved =
rigidBodyTree with properties: NumBodies: 0 Bodies: {1×0 cell} Base: [1×1 rigidBody] BodyNames: {1×0 cell} BaseName: 'base' Gravity: [0 0 0] DataFormat: 'struct'
ur10Moved.BaseName
ans = 'base'
As you can see, the BaseName property of UR10 is already set to "base". Then when you load the UR10, it too has a body named "base":
ur10 = loadrobot('universalUR10');
ur10.showdetails
-------------------- Robot: (10 bodies) Idx Body Name Joint Name Joint Type Parent Name(Idx) Children Name(s) --- --------- ---------- ---------- ---------------- ---------------- 1 base_link world_joint fixed world(0) base(2) shoulder_link(3) 2 base base_link-base_fixed_joint fixed base_link(1) 3 shoulder_link shoulder_pan_joint revolute base_link(1) upper_arm_link(4) 4 upper_arm_link shoulder_lift_joint revolute shoulder_link(3) forearm_link(5) 5 forearm_link elbow_joint revolute upper_arm_link(4) wrist_1_link(6) 6 wrist_1_link wrist_1_joint revolute forearm_link(5) wrist_2_link(7) 7 wrist_2_link wrist_2_joint revolute wrist_1_link(6) wrist_3_link(8) 8 wrist_3_link wrist_3_joint revolute wrist_2_link(7) ee_link(9) tool0(10) 9 ee_link ee_fixed_joint fixed wrist_3_link(8) 10 tool0 wrist_3_link-tool0_fixed_joint fixed wrist_3_link(8) --------------------
Since body names must be unique, these two rigid body tree objects cannot be combined as-is.
However, the base name is not fixed after construction, so an easy way to get around this issue would be to change the base name in the new rigid body tree that you are creating so that there are no conflicts once the UR10 is added. That is:
% Load the UR10 from the robot library
ur10 = loadrobot('universalUR10');
% Create the new rigid body tree with a new base name
ur10Moved = rigidBodyTree;
ur10Moved.BaseName = 'newBase';
% Add a new custom base to the renamed base
rb = rigidBody('newBaseForUR10');
rb.Joint.setFixedTransform(trvec2tform([3,0,0]));
ur10Moved.addBody(rb, ur10Moved.BaseName);
Then you should be able to add the UR10 as a subtree without any issue
ur10Moved.addSubtree('newBaseForUR10', ur10);

More Answers (0)

Products


Release

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!