MATLAB: Four link, planar robot arm using meshgrid/ndgrid in matlab

four link planar mechanismMATLABreachable areaworkspace

Hello Community,
I am new in this forum, so i hope i didn't make a mess of my first question.
I want to plot the reachable area of a planar, four link mechanism. It is exactly like the linkage in the following link, only with four links instead of only two.
In that case the code is set with meshgrid and the plotted solution in the picture (red dots for the reachable area) in the link is a elegant and quick solution. As i searched the community i found another matlab function ndgrid for multidimensional tasks. Calculating my ndgrid i got a solution with four dimensional matrices as expected. How can I plot this in an x-y-plot? The examples in the community are only two link planar systems most times.
I know usually there should be only one question for every topic, but i have a few general questions for you.
I am working on a project at my university at robotics. I wanted to write a little program in Matlab but i am somehow stuck with that task. It is really a lot of stuff to consider at the beginning.
Since I want to add some additional functions in my prorgram, i. e. force calculations or optimization of some kind…
Would you recommend to use the multibody or robotics system tool boxes to avoid too much coding? I have programed a few things in matlab already, but I am not a very experienced coder.
Is it easy to send variables/code between matlab and simulink/simscape?
Help is much appreciated.
Thank you,
Best regards,
Jan

Best Answer

aren't you able to do the same thing with meshgrid and plot?
I believe plot function takes each of the values of X and Y and combines them together to draw a 2D plot. So it doesn't matter if the grid is four dimension, as long as the two match.
theta1 = 0:0.1:pi/2; % all possible theta1 values
theta2 = 0:0.1:pi; % all possible theta2 values
theta3 = 0:0.1:pi; % all possible theta3 values
theta4 = 0:0.1:pi; % all possible theta4 values
% generate a grid of theta1 and theta2,3,4 values
[THETA1,THETA2,THETA3,THETA4] = meshgrid(theta1,theta2,theta3,theta4);
X = fcn(THETA1,THETA2,THETA3,THETA4); % compute x coordinates
Y = fcn2(THETA1,THETA2,THETA3,THETA4); % compute y coordinates
plot(X(:),Y(:),'r.');
Simulink has pretty good tools regarding robot simulation. Take a look at Simscape Multibody, contact modelling, and so on...
Here are some places you can start learning from