## This function does not fully set the dimensions of output port 2 error in matlab?

Najmeh Eskandari

### Najmeh Eskandari (view profile)

さんによって質問されました 2018 年 10 月 15 日

### Najmeh Eskandari (view profile)

さんによって コメントされました 2018 年 11 月 6 日
Sebastian Castro

### Sebastian Castro (view profile)

さんの 回答が採用されました
hi. I simulated impedance control for ur10.but there is an error:
Error in default port dimensions function of S-function 'impedance2/impedance controller'. This function does not fully set the dimensions of output port 2
I guess it the problem is with x signal. x is 1 if this is wrong. the signal should be 6,1 in ur10forwardkinematic block. I don't know where is output port2 exactly and how can I fix this problem? The Simulink file is attached.

#### 0 件のコメント

サインイン to comment.

## 2 件の回答

### Sebastian Castro (view profile)

on 6 Nov 2018

Hi Najmeh Eskandari,
I would highly recommend running this code in MATLAB and debugging it yourself. I just did the same and your line 153 seems to have incorrect MATLAB code that causes an error.
C(k,j)= C(k,j)+0.5*(diff(D(k,j),q(i,1))+diff(D(i,k),q(j,1))-diff(D(i,j),q(k,1)))*dq(i,1);
Error using diff
Difference order N must be a positive integer scalar.
Try starting by fixing that. The second input to the diff function is actually just the number of differences to compute (so it should be an integer), but you are passing in values like q(j,1) and q(j,2) which are noninteger joint angle values, so this is incorrect.
- Sebastian

Najmeh Eskandari

### Najmeh Eskandari (view profile)

on 6 Nov 2018
-diff(D(k,j),q(I,1)) is D(k,j) derivative to q(I,1) variable while for example diff(D(k,j),2) is second order derivative of D(k,j).
Sebastian Castro

### Sebastian Castro (view profile)

on 6 Nov 2018
Hi Najmeh,
I wanted to clarify, the diff function does not calculate an analytical derivative with response to a variable -- rather, it approximates the numerical derivative of an array of values.
What you're basically trying to do is get the Jacobian of the robot dynamics at a specific configuration (set of angles), which you'd have to do in another way. You can either:
If you said you already derived it symbolically, there is a matlabFunction function that will automatically generate MATLAB code from that "long, ugly expression".
You can definitely use that inside a MATLAB Function block. I've done this recently for a simple 2DOF inverse kinematics calculation.
- Sebastian
Najmeh Eskandari

### Najmeh Eskandari (view profile)

on 6 Nov 2018
Thank you Sebastian.I'll try your suggestion.

サインイン to comment.