There is no offset between my first joint and the base when I want to model a two axis planar robot using Robotics System Toolbox

13 views (last 30 days)
Here is the image of the robot and related D-H parameters:
and this is my code:
% 1. Buliding the manipulator robot tree
% 0. Create a rigid body tree
two_axis_planar_robot = rigidBodyTree;
% 1. Create a rigid body with a unique name
body1 = rigidBody('body1');
% 2. Create a revolute joint
jnt1 = rigidBodyJoint('jnt1','revolute');
body1.Joint = jnt1;
% 3. D-H Parameters
dhparams = [1 , 0 , 0 , 0
1 , 0 , 0 , 0];
% Note the toolbox order:
% 1st column : a
% 2nd column : alpha
% 3rd column : d
% 4th column : theta
% 4. Add the rigid body to the tree. Specify the body name that you are
% attaching the rigid body to. Because this is the first body, use the base
% name of the tree
setFixedTransform(jnt1,dhparams(1,:),'dh');
basename = two_axis_planar_robot.BaseName;
addBody(two_axis_planar_robot,body1,basename)
% 5. Use showdetails on the tree to confirm the rigid body and joint were
% added properly.
showdetails(two_axis_planar_robot)
%Show
show(two_axis_planar_robot);
axis([-2,2,-2,2,-2,2])
grid minor
axis on
Finally, the result:
Due to the D-H parameters table, the first link should appear!!

Accepted Answer

Karsh Tharyani
Karsh Tharyani on 31 Mar 2021
Edited: Karsh Tharyani on 31 Mar 2021
If you replace jnt1 in setFixedTransform(jnt1, dhparams(1,:), 'dh') with body1.Joint you should notice the offset.
Alternatively, you can construct the joint completely before assigning it to the body via body1.Joint (i.e., move body1.Joint = j1 after setFixedTransform(jnt1, dhparams(1,:), 'dh').
When you assign a joint to a body using body.Joint, the body stores a copy of the handle object assigned to it (in this case, the passed handle object is j1). Thus, modifying the handle object after it has been assigned won't have an effect on the stored joint, and that's why you don't notice the offset. Therefore, using setFixedTransform(body1.Joint,... gives you access of the stored handle.
You can learn more about handle objects here: https://www.mathworks.com/help/matlab/matlab_oop/handle-objects.html

More Answers (0)

Community Treasure Hunt

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

Start Hunting!