Robotics System Toolbox - set value of joint positions

Hello,
here is a code snippet made from Matlab's documentation:
dhparams = [0 pi/2 0 0;
0.4318 0 0 0
0.0203 -pi/2 0.15005 0;
0 pi/2 0.4318 0;
0 -pi/2 0 0;
0 0 0 0];
robot = rigidBodyTree;
body1 = rigidBody('body1');
jnt1 = rigidBodyJoint('jnt1','revolute');
setFixedTransform(jnt1,dhparams(1,:),'dh');
body1.Joint = jnt1;
addBody(robot,body1,'base')
body2 = rigidBody('body2');
jnt2 = rigidBodyJoint('jnt2','revolute');
body3 = rigidBody('body3');
jnt3 = rigidBodyJoint('jnt3','revolute');
body4 = rigidBody('body4');
jnt4 = rigidBodyJoint('jnt4','revolute');
body5 = rigidBody('body5');
jnt5 = rigidBodyJoint('jnt5','revolute');
body6 = rigidBody('body6');
jnt6 = rigidBodyJoint('jnt6','revolute');
setFixedTransform(jnt2,dhparams(2,:),'dh');
setFixedTransform(jnt3,dhparams(3,:),'dh');
setFixedTransform(jnt4,dhparams(4,:),'dh');
setFixedTransform(jnt5,dhparams(5,:),'dh');
setFixedTransform(jnt6,dhparams(6,:),'dh');
body2.Joint = jnt2;
body3.Joint = jnt3;
body4.Joint = jnt4;
body5.Joint = jnt5;
body6.Joint = jnt6;
addBody(robot,body2,'body1')
addBody(robot,body3,'body2')
addBody(robot,body4,'body3')
addBody(robot,body5,'body4')
addBody(robot,body6,'body5')
showdetails(robot)
show(robot);
% this line will create random configuration
robotConfig = robot.randomConfiguration; % how to set values i.e. define values
% this line returns actual values of the joints in rad
[a1, a2, a3, a4, a5, a6] = robotConfig.JointPosition;
% this line calculate transformation matrix T60
tform = getTransform(robot,robotConfig ,'body6','base');
tform basically calculates forward kinematics i.e. obtain transformation matrix between body 6 and the base of the robot. For calculation, it uses random values generated using randomConfiguration.
Now, I would like to set these values (joint positions) to specific values and not to use random values. I have tried this:
A = num2cell([0.1, 0.2, 1.2, 1.1, 0.6, 0.8]);
robotConfig.JointPosition = A{:};
But still got error message "Scalar structure required for this assignment."
How to achieve that? Does rigidBodyTree has specific way to do this?
Thank you.

답변 (1개)

Askic V
Askic V 2023년 2월 7일
편집: Askic V 2023년 2월 7일
I have managed to find the answer on my own question.
% this line will create random configuration
robotConfig = robot.randomConfiguration; % how to set values i.e. define values
% this line returns actual values of the joints in rad
[a1, a2, a3, a4, a5, a6] = robotConfig.JointPosition;
A = num2cell([0.1, 0.2, 1.2, 1.1, 0.6, 0.8]);
[robotConfig.JointPosition] = A{:};
And it works as supposed to. But this requires that robotConfig is created first with random values and then use this struct to set new values. There must be a better way.
The documentation mention this:
"You can generate a configuration using homeConfiguration(robot), randomConfiguration(robot), or by specifying your own joint names and positions in a structure array." but there is no example how to specify my own position values.
If there are any other suggest, I'd greatly appreciate it.

카테고리

질문:

2023년 2월 7일

편집:

2023년 2월 7일

Community Treasure Hunt

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

Start Hunting!

Translated by