Is it possible to call a rigidBodyTree robot model in a Matlab function in Simulink?
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Lorenzo Scalera
le 19 Mai 2020
Commenté : Lorenzo Scalera
le 9 Avr 2021
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 commentaires
Valeria Leto
le 7 Avr 2021
Hi Lorenzo! could you post your code? I have the same problem but I didn't understand how to fix it.
Réponse acceptée
Yiping Liu
le 4 Nov 2020
Modifié(e) : Yiping Liu
le 7 Avr 2021
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}
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Manipulator Modeling dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!