How does the jtraj simulink block work (internally)?

368 views
Skip to first unread message

Joe M

unread,
Aug 7, 2014, 9:28:49 AM8/7/14
to robotics...@googlegroups.com

Basically I have created a trajectory in Matlab using the ctraj function and I have generated the joint angles using inverse kinematics. For example;

t           q1        q2 …

0.1       0          0 

0.2       1.5       1.5 …

Etc.

And I have put this in a Matlab function block in simulink. What the function does is; it takes a clock input and compares it with the time vector shown above…

So for each loop the program looks for a value of t = clocktime, and it outputs the value of q1 and q2 for that time.

This works ok-ish but I would like to know how the simulink block jtraj actually does it.

The reason is, the jtraj block seems to provide the values of q in synchronisation with the simulation. So if for example I save the generated time vector and variables to the workspace, I have a value of q at every time step, while when I do the same thing with the function I created, I get zeros for some of the time values.

Thanks.


Joe M

unread,
Aug 7, 2014, 9:35:57 AM8/7/14
to robotics...@googlegroups.com

Sorry the image didn't show. I forgot how difficult it is to post image on here but anyways hope you get what I was trying to describe. I'll try and post the image again below (fingers crossed):

and the code (the last two lines are the key):

current_time = input(1);
sizeQ = [input(2),input(3)];
tEnd = length(input)-(sizeQ(1)*sizeQ(2));
t = input(4:tEnd);
Q = input(tEnd+1:end);
Q = reshape(Q,sizeQ);
tPosition = max(find(t <= current_time));
q = Q(tPosition,:);


Joe M

unread,
Aug 8, 2014, 11:10:03 AM8/8/14
to robotics...@googlegroups.com
I shall answer my own question for anyone interested;

I found out how to look under the mask of the jtraj simulink block and realised it uses the interp1 function to interpolate between the interpolated joint angles with respect to the clock time.

However, this doesn't work for all cases. For example, if you try to use the jtraj simulink block to interpolate between the following joint angles;
q0 = [0.0000 -1.1473 0.7111 0.0000 0.4362 0.0000] and qf = [0.0000 -0.8844 0.2720 0.0000 0.6125 0.0000]

you get the following error:

Evaluation of expression resulted in an invalid output. Only finite double vector or matrix outputs are supported

If anyone has any ideas on how to work around this please do let me know.

Thanks.
Message has been deleted

Joe M

unread,
Aug 8, 2014, 12:08:25 PM8/8/14
to robotics...@googlegroups.com
Never mind, problem solved, you just match the simulation time with the trajectory time.
Reply all
Reply to author
Forward
0 new messages