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

조회 수: 24 (최근 30일)
Jan Selig
Jan Selig 2018년 7월 5일
댓글: Jan Selig 2018년 7월 6일
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

채택된 답변

Wooshik Kim
Wooshik Kim 2018년 7월 5일
편집: Wooshik Kim 2018년 7월 5일
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
  댓글 수: 1
Jan Selig
Jan Selig 2018년 7월 6일
Hello Wooshik Kim,
thank you for your answer and your time. The problem with meshgrid() is, that the function works only for 2D or 3D application, in other words you can only put in two or three input-arguments and you will get only two or three outputs. At least if I got that right from the documentation.
Therefore I think I have to use ndgrid(). With that function it is possible to compute multiple in- and output variables. Anyone who uses meshgrid and ndgrid should be aware of the different notation of the matrices. Further information is described in the following link:
https://ch.mathworks.com/matlabcentral/answers/99720-what-is-the-difference-between-the-ndgrid-and-meshgrid-functions-in-matlab
Thank you very much for your help, you gave me a hint for the right direction and i could solve the problem.
If anyone else needs the code:
l1 = 2; % length of first arm
l2 = 1.75; % length of second arm
l3 = 1.25; % length of second arm
l4 = 0.75; % length of second arm
theta1 = (0:5:130)*pi/180; % all possible theta1 values
theta2 = (0:5:95)*pi/180; % all possible theta2 values
theta3 = (0:5:80)*pi/180; % all possible theta2 values
theta4 = (0:5:40)*pi/180; % all possible theta2 values
% generate a grid of theta1 and theta2,3,4 values
[THETA1,THETA2,THETA3, THETA4] = ndgrid(theta1,theta2,theta3, theta4);
% functions to calculate the x and y coordinates for four links with variable angles
X = l1 * cos(THETA1) + l2 * cos(THETA1 + THETA2) + l3 * cos(THETA1 + THETA2 + THETA3) + l4 * sin(THETA1 + THETA2 + THETA3 + THETA4); % compute x coordinates
Y = l1 * sin(THETA1) + l2 * sin(THETA1 + THETA2) + l3 * sin(THETA1 + THETA2 + THETA3) + l4 * sin(THETA1 + THETA2 + THETA3 + THETA4); % compute y coordinates
hold on;
plot(Y(:),X(:),'r.')
xlabel('X')
ylabel('Y')
hold off;
I was searching for the failure in the plot, but i got the order of my matrices mixed up. I set the question as answered. Thanks again.
Best regards,
Jan

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Simscape Multibody에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by