objects in a common figure

1 Ansicht (letzte 30 Tage)
slowlearner
slowlearner am 25 Okt. 2020
Kommentiert: Ameer Hamza am 26 Okt. 2020
This is to long of a code to post here but it's downloadable above. What i have is a function with data struct {rd} describing the links, each links jogging limits, tools structur/tcp, and more. From this i use a function to beable to call on a function to draw the links, call another function to draw the frames and another function to do the rotation and translation. Basicly this is alot of functions within a function. the struct variables are:
function rd = robotdatawtool(id)
% switching depending on the id
rd.name = 'somename'
rd.jang = % starting angles of the joints
rd.joff = % translation in z
rd.range = % translation in x
rd.twist = % rotation in x for next link
rd.jvar = % whether it's 'r'(rotation) 'p'(prismatic)
rd.jvarlimit = % angular limits or each joint or vector for prisms
rd.xyz = % tool basicly just vectors with line([...])
rd.A = %rotational and translational data for the tcp
this then goes to the construction function that has the functions within a function setup
function showrobotu(rd)
%% Defining the variables in struct
if rd.name == 'IRB1600mig' % the name in the struct
phase = 'migweldpos';
pos1 = [1;0]; % where it's supposed to start at [x;y]
elseif rd.name == 'IRB1600tig' % the name in the struct
phase = 'tigweldpos';
pos2 = [-1;0]; % where it's supposed to start at [x;y]
elseif rd.name == 'scarajobber' % the name in the struct
phase = 'orderpos';
pos3 = [0;1]; % where it's supposed to start at [x;y]
end
% then switch depending on the phase
I've managed to make 2 robots show up on the same figure but the third just won't show now it just says :
Matrix dimensions must agree.
Error in thisisarobotjob>showrobotu (line 80)
if rd.name == 'IRB1600mig'
Error in thisisarobotjob (line 14)
showrobotu(rd2)
So the problem seems to be the if statement but I've checked countless times and the name of rd2 is the same as stated in the struct. I don't know what to do at this point maby i've been working to long on this and don't see something obvious but maby anyone spots the error I'm not seeing.
What i want is simply to be able to make all three robots included in the robotdatawtool to showup so i can start coding the trajectorys. I have an Idea in my head on how to be able to make them do seperate tasks at one however that's still just very losely formulated but i figured I'd need to be able to make three of them apear first.
this is the one missing and it's the only one that doesn't look like the other's but i don't see how that would be a problem.

Akzeptierte Antwort

Ameer Hamza
Ameer Hamza am 25 Okt. 2020
This
rd.name == 'IRB1600mig'
is not the correct way to compare strings. Use strcmp()
strcmp(rd.name, 'IRB1600mig')
  3 Kommentare
slowlearner
slowlearner am 26 Okt. 2020
thank you for this info dude it worked was unaware that if statements couldn't handle strings directly. however,
str2 = 'IRDB1600mig'
contains(str2, rd.name)
worked aswell but i noticed that
strcmp(rd.name,'IRB1600mig')
was better!
Ameer Hamza
Ameer Hamza am 26 Okt. 2020
Yes, contains is preferable for more complicated cases. For your case, strcmp is suitable.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Labels and Annotations finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by