Is there a way to change the position of the origin of the model when displaying a robot arm using the Robotics System Toolbox in Matlab?

14 Ansichten (letzte 30 Tage)
I want to detect a collision between two robot arms.
The page below mentions the method in part, but in the sample code shown in the answer, the origin is the same, so the result of the collision detection is true regardless of the posture.
Therefore, as a preliminary step to detecting a collision between two robot arms, I would like to know how to arrange two robot arms with different origins and base positions.
The robot model is one that I imported my own urdf for.
importrobot('original_robot.urdf')
  1 Kommentar
Kohei
Kohei am 23 Jan. 2025
After several attempts, I was able to position the two robots with the origin shifted.
It seems that I will need to try separately to see if there is interference between the two arms and if I can use the IK for each one.
% 1. Importing the robots
robot1 = importrobot('original_robot1.urdf');
robot2 = importrobot('original_robot2.urdf');
% ----- 2. Initialization of combinedRobot -----
% Initialize combinedRobot as a copy of robot1
combinedRobot = robot1;
% ----- 3. Define the offset transform for robot2 -----
% Here we set an offset to move 1 meter in the x-axis direction
offsetTranslation = trvec2tform([1, 0, 0]); % [x, y, z] = [1, 0, 0]
% Create a fixed joint and set the offset transform
fixedJoint = rigidBodyJoint('fixedJoint', 'fixed');
setFixedTransform(fixedJoint, offsetTranslation);
% Create the bodyOffset body and assign the fixed joint
bodyOffset = rigidBody('robot2_base');
bodyOffset.Joint = fixedJoint;
% Add bodyOffset to the base of combinedRobot
addBody(combinedRobot, bodyOffset, combinedRobot.BaseName);
% ----- 4. Add robot2 as a subtree to combinedRobot -----
% Add robot2 as a subtree to 'robot2_base'
addSubtree(combinedRobot, 'robot2_base', robot2);
% ----- 5. Setting the joint configuration -----
% Get the home configuration of robot1 and robot2
config1 = homeConfiguration(robot1);
config2 = homeConfiguration(robot2);
% Get the home configuration of combinedRobot
configCombined = combinedRobot.homeConfiguration;
% Set the joint values for robot1
for i = 1:length(config1)
configCombined(i).JointPosition = config1(i).JointPosition;
end
% Set the joint values for robot2
% Assuming the number of joints in robot1 is already included in combinedRobot
startIndex = length(config1) + 1;
for i = 1:length(config2)
% Set the joint values at the position where robot2 is added to combinedRobot
configCombined(startIndex + i - 1).JointPosition = config2(i).JointPosition;
end
figure;
show(combinedRobot)
title('Configuration of Two Robot Arms');

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Karsh Tharyani
Karsh Tharyani am 28 Jan. 2025
Bearbeitet: Karsh Tharyani am 28 Jan. 2025
Hi Kohei,
The suggested workflow in your comment is a good way to model your use-case. Another strategy could be to use a "floating" rigidBodyJoint.
See code snippet below which shows how to do collision checking using a Franka Emika and a Kinova Gen 3.
% Load the Franka Emika and Kinova Gen3 robots
franka=loadrobot('franka',d='r');
kinova=loadrobot('kinovagen3',d='r');
% These will become part a common rigid body tree i.e., a fixed inertial frame
% in the world frame located at (0,0,0)
rbt=rigidBodyTree(d='r');
% Create one floating base for each robot, and add it to the fixed base tree.
frankabase=rigidBody("frankafloat");
frankabase.Joint=rigidBodyJoint("franka_float","floating");
kinovabase=rigidBody("kinovabase");
kinovabase.Joint=rigidBodyJoint("kinova_float","floating");
addBody(rbt,frankabase,rbt.BaseName);
addBody(rbt,kinovabase,rbt.BaseName);
% Add the robots to the fixed base tree
addSubtree(rbt,frankabase.Name,franka,replacebase=false);
addSubtree(rbt,kinovabase.Name,kinova,replacebase=false);
% A random configuration of the two trees.
% Code below shows how to encode the joint positions of the two arms and
% their base locations in a single configuration vector called "randconfig"
randconfig=[rotm2quat(eye(3)),0.5,0,0,homeConfiguration(franka),eul2quat([pi/3,pi/2,0]),-0.6,0,0,randomConfiguration(kinova)];
show(rbt,randconfig)
ans =
Axes (Primary) with properties: XLim: [-6 6] YLim: [-6 6] XScale: 'linear' YScale: 'linear' GridLineStyle: '-' Position: [0.1300 0.1100 0.7750 0.8150] Units: 'normalized' Use GET to show all properties
axis('equal')
% Check collision between the two trees in this configuration
iscolling=checkCollision(rbt,randconfig,"SkippedSelfCollisions","parent");
The only downside to using "floating" joints to combine the two trees is that you can't use inverseKinematics solver on them because it can't solve for "floating" joints. For that, though, you can use the following example - https://www.mathworks.com/help/robotics/ug/inverse-kinematics-for-robots-with-floating-base.html
I hope these suggestions help!
Karsh

Community Treasure Hunt

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

Start Hunting!

Translated by