Info
This question is closed. Reopen it to edit or answer.
Model compile errors after using rigidBodyTree objects and functions
2 views (last 30 days)
Show older comments
Recently, I am using simulink to simulate a robot, and in order to compute the center of mass(com) of the robot, I use simscape to generate a rigidbodytree model and use 'writeAsFunction' function to make a m-file and the function works well.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1245287/image.jpeg)
Then, I use matlab function block in simulink to call it, but I get errors when I run the simulation, it seems to generate sfun, but I don't need sfun
These errors only happens after I use matlab function block to call these 'rigidbodytree' functions.
Could you please help me to find out why the simulation generate these errors?
Thanks a lot.
error pictures
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1245292/image.jpeg)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1245297/image.jpeg)
The matlab function in simulink
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1245302/image.jpeg)
function [angL,angR] = fcn(angHipL,angKneeL,angHipR,angKneeR)
persistent robot
if isempty(robot)
robot=wheelchairCodegen('row');
end
config=[angHipL angKneeL 0 0 angHipR angKneeR 0 0];
comLocation=centerOfMass(robot,config);
tform_wheel2baseL=getTransform(robot,config,'Body4','Base');
trVec_wheel2baseL=tform2trvec(tform_wheel2baseL);
vec_wheel2comL=trVec_wheel2baseL-comLocation;
tform_wheel2baseR=getTransform(robot,config,'Body8','Base');
trVec_wheel2baseR=tform2trvec(tform_wheel2baseR);
vec_wheel2comR=trVec_wheel2baseR-comLocation;
angL=atan2d(vec_wheel2comL(1),abs(vec_wheel2comL(3)));
angR=atan2d(vec_wheel2comR(1),abs(vec_wheel2comR(3)));
end
0 Comments
Answers (0)
This question is closed.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!