在运行matlab视觉伺服工具箱中的机械臂仿真时遇到以下问题:Error in port widths or dimensions. 'Output Port 1' of 'sl_arm_ibvs/camera' is a [28x1] matrix.
该问题是由于下图中红圈标注处输入向量维度错误导致。
此处的p为相机像素坐标系下的坐标值,应该为2*4向量。
解决方法:新版本的Machine Vision Toolbox for MATLAB工具箱中缺乏了模块“slcamera.m”,打开simulate中的camera模块:
双击matlab fcn模块,提示找不到“slcamera”,选择新建:
键入以下代码:
function p = slcamera(cam, u)
%if all(u == 0)
if (u(1:16,:)==0)
% Simulink is probing for the dimensions
np = (length(u)-16)/3;
p = zeros(2, np);
else
p = zeros(2, 4);
P = reshape(u(17:end), 3, []);
Tcam = reshape(u(1:16), 4, 4);
p = cam.plot(P, 'pose', Tcam, 'drawnow');
end
再次运行simulate,可以看到该报错以及消失,这时应该会遇到如下error:
Error in 'sl_arm_ibvs/camera/MATLAB Fcn'. Evaluation of expression resulted in an invalid output. Only finite
double vector or matrix outputs are supported
关于该报错的解决办法,本人也在研究中,请关注以后的博客。