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');