How to change the color of a rigidbody visual.
29 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Control Systems Guy
am 22 Dez. 2023
Kommentiert: Control Systems Guy
am 28 Dez. 2023
Hello,
I am creating a rigid body (robot link) and would like to change the color of the visual. For example:
body1 = rigidBody('body1');
jnt1 = rigidBodyJoint('jnt1','revolute');
tform = trvec2tform([0 1 0]);
setFixedTransform(jnt1,tform);
body1.Joint = jnt1;
robot = rigidBodyTree('DataFormat', 'column');
addVisual(body1, "sphere", 1.2)
addBody(robot,body1,'base')
show(robot,"Visuals", "on", 'Frames', 'off')
It always generates the figure in gray scale. I would like to assign a different color to different bodies. How can I do that? I know that I can also add collision boxes or spheres, but they are similarly of the same color by default (green).
0 Kommentare
Akzeptierte Antwort
Chunru
am 23 Dez. 2023
body1 = rigidBody('body1');
jnt1 = rigidBodyJoint('jnt1','revolute');
tform = trvec2tform([0 1 0]);
setFixedTransform(jnt1,tform);
body1.Joint = jnt1;
robot = rigidBodyTree('DataFormat', 'column');
addVisual(body1, "sphere", 1.2)
addBody(robot,body1,'base')
g = show(robot,"Visuals", "on", 'Frames', 'off');
% You can change color of individual object
g.Children(1).FaceColor = 'r';
1 Kommentar
Control Systems Guy
am 23 Dez. 2023
Bearbeitet: Control Systems Guy
am 23 Dez. 2023
Weitere Antworten (1)
Chunru
am 24 Dez. 2023
See below for the question (1). I am not sure the part (2) and you may want to show your current code.
body1 = rigidBody('body1');
jnt1 = rigidBodyJoint('jnt1','revolute');
tform = trvec2tform([0 1 0]);
setFixedTransform(jnt1,tform);
body1.Joint = jnt1;
robot = rigidBodyTree('DataFormat', 'column');
addVisual(body1, "sphere", 1.2)
addBody(robot,body1,'base')
body2 = rigidBody('body2');
jnt2 = rigidBodyJoint('jnt2','revolute');
tform2 = trvec2tform([1, 0, 0]);
setFixedTransform(jnt2,tform2);
body2.Joint = jnt2;
addVisual(body2, "capsule", [.5, 3],[0 0 1 0; 0 1 0 0; -1 0 0 0; 0 0 0 1])
addBody(robot,body2,'body1'); % Add body2 to body1
figure(1)
g = show(robot,"Visuals", "on", 'Frames', 'off');
% Change color for all applicable children
for i=1:length(g.Children)
try
g.Children(i).FaceColor = 'r';
end
end
1 Kommentar
Siehe auch
Kategorien
Mehr zu Robotics 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!