Is it possible to call a rigidBodyTree robot model in a Matlab function in Simulink?

조회 수: 4 (최근 30일)
Hi everybody,
I am trying to use the Robotic System Toolbox functions inside a Matlab function in Simulink.
I am having troubles in importing the rigidBodyTree model in the Matlab function.
How can I manage this issue?
Thank you very much in advance!
  댓글 수: 4
Valeria Leto
Valeria Leto 2021년 4월 7일
Hi Lorenzo! could you post your code? I have the same problem but I didn't understand how to fix it.
Lorenzo Scalera
Lorenzo Scalera 2021년 4월 9일
Ciao Valeria, I have created the robot RigidBodyTree in a way similar to what Yiping did.
I have defined a persistent variable, which is initialized only once when the code is run at the first time. Then, "robot" is automatically kept in memory during code execution.
"createRigidBodyTree" is a custom function in which I have built the manipulator RigidBodyTree starting from the DH parameters, as explained in this link:
I hope it can help!
persistent robot
if isempty(robot)
robot=createRigidBodyTree;
end
function robot = createRigidBodyTree
dhparams = [...
robot = rigidBodyTree("MaxNumBodies",8,"DataFormat","row");
body1 = rigidBody('body1');
jnt1 = rigidBodyJoint('jnt1','revolute');
... (please see the link)
end

댓글을 달려면 로그인하십시오.

채택된 답변

Yiping Liu
Yiping Liu 2020년 11월 4일
편집: Yiping Liu 2021년 4월 7일
Lorenzo, the persistent variable is the correct way.
You should also check out the rigid body tree algorithm Simulink blocks in RST:
An example of using the persistent variable (NOTE to get a robot inside a function, starting in 21a, you can also use loadrobot command or the new API on rigidBodyTree class called writeAsFunction, both supporting codegen)
function [q, solInfo] = computeIK(T, qini, solTol, gradTol)
%COMPUTEIK
% input:
% Q - 4x4 homogenerous matrix representing end-effector pose
% qini - initial guess for joint configurations (a vector)
% solTol - Solution Toleraance
% gradTol - Gradient Tolerance
persistent ik
if isempty(ik)
robot = robotics.manip.internal.robotplant.puma560DH(); % Since 21a, there are better/cleaner ways to create a robot inside a function.
robot.DataFormat = 'column';
ik = inverseKinematics('RigidBodyTree', robot);
ik.SolverParameters.MaxIterations = 100;
ik.SolverParameters.AllowRandomRestart = false;
end
ik.SolverParameters.SolutionTolerance = solTol;
ik.SolverParameters.GradientTolerance = gradTol;
[q, solInfo] = ik('L6', T, ones(1,6), qini);
end
% codegen command:
% codegen computeIK.m -args {eye(4), ones(1,13), 0, 0}
  댓글 수: 3
Yiping Liu
Yiping Liu 2021년 4월 7일
I have updated the answer to give you an example.
Karsh Tharyani
Karsh Tharyani 2021년 4월 7일
편집: Karsh Tharyani 2021년 4월 7일
Valeria, you can also refer to this documented example in R2021a

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Manipulator Modeling에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by