I am trying to simulate the arduino braccio robot in the matlab for a simple pick and place task, here is the complete code for that:
clear; clc; close all;
%% Step 1: Define the Braccio Robot Model
% Create a rigid body tree model
robot = robotics.RigidBodyTree('DataFormat', 'column', 'MaxNumBodies', 6);
% Define base
body1 = robotics.RigidBody('link1');
jnt1 = robotics.Joint('jnt1', 'revolute');
setFixedTransform(jnt1, trvec2tform([0, 0, 0.1])); % Adjust height as needed
jnt1.HomePosition = 0;
body1.Joint = jnt1;
addBody(robot, body1, 'base'); % Adding link1 to the base
% Define link2, link3, link4, link5, and gripper (similar to link1)
% Define link2
body2 = robotics.RigidBody('link2');
jnt2 = robotics.Joint('jnt2', 'revolute');
setFixedTransform(jnt2, trvec2tform([0.1, 0, 0])); % Adjust length as needed
jnt2.HomePosition = 0;
body2.Joint = jnt2;
addBody(robot, body2, 'link1');
% Define link3
body3 = robotics.RigidBody('link3');
jnt3 = robotics.Joint('jnt3', 'revolute');
setFixedTransform(jnt3, trvec2tform([0.1, 0, 0])); % Adjust length as needed
jnt3.HomePosition = 0;
body3.Joint = jnt3;
addBody(robot, body3, 'link2');
% Define link4
body4 = robotics.RigidBody('link4');
jnt4 = robotics.Joint('jnt4', 'revolute');
setFixedTransform(jnt4, trvec2tform([0.1, 0, 0])); % Adjust length as needed
jnt4.HomePosition = 0;
body4.Joint = jnt4;
addBody(robot, body4, 'link3');
% Define link5
body5 = robotics.RigidBody('link5');
jnt5 = robotics.Joint('jnt5', 'revolute');
setFixedTransform(jnt5, trvec2tform([0.1, 0, 0])); % Adjust length as needed
jnt5.HomePosition = 0;
body5.Joint = jnt5;
addBody(robot, body5, 'link4');
% Define gripper
body6 = robotics.RigidBody('gripper');
jnt6 = robotics.Joint('jnt6', 'revolute');
setFixedTransform(jnt6, trvec2tform([0.05, 0, 0])); % Adjust length as needed
jnt6.HomePosition = 0;
body6.Joint = jnt6;
addBody(robot, body6, 'link5');
% Show the robot model
showdetails(robot);
show(robot);
title('Braccio Robot Model');
pause(2);
%% Step 2: Simulate Pick-and-Place Task
% Define the initial and target poses
initialPose = trvec2tform([0.1, 0.0, 0.1]); % Initial position
targetPose = trvec2tform([0.2, 0.1, 0.2]); % Target position
% Inverse kinematics solver
ik = robotics.InverseKinematics('RigidBodyTree', robot);
weights = [0.25, 0.25, 0.25, 1, 1, 1];
initialGuess = robot.homeConfiguration;
% Solve for the initial configuration
[configSol, ~] = ik('gripper', initialPose, weights, initialGuess);
% Display the robot in initial pose
show(robot, configSol);
title('Initial Pose');
drawnow;
pause(2);
% Solve for the target configuration
[configSol, ~] = ik('gripper', targetPose, weights, initialGuess);
% Display the robot in target pose
show(robot, configSol);
title('Target Pose');
drawnow;
pause(2);
%% Step 3: Integrate Model Predictions (Optional)
% Main loop with simulated predictions
pickX = 0.1;
pickY = 0.0;
placeX = 0.2;
placeY = 0.1;
% Get simulated model predictions
angles = getModelPredictions(pickX, pickY, placeX, placeY);
% Initialize predictedConfig as an array of JointState objects
predictedConfig = repmat(robot.homeConfiguration, length(angles), 1);
% Apply the predicted angles to the robot configuration
for i = 1:length(angles)
% Set joint position for each body
predictedConfig(i).JointPosition = angles(:, i);
end
% Display the robot with predicted angles
show(robot, predictedConfig);
title('Predicted Angles Pose');
drawnow;
pause(2);
%% Function Definitions
% Example function to simulate getting predictions from a model
function angles = getModelPredictions(~, ~, ~, ~)
% Simulate model predictions
angles = [0.5, 0.25, -0.5, 0.0, 0.5, 0.1]; % Example values
end
and this is the error I am getting
Unable to perform assignment because dot indexing is not supported for variables of this type.
Error in rigidbody (line 110)
predictedConfig(i).JointPosition = angles(:, i);
I kept getting this error, I don’t understand is it because of the the for loop variable or something related to the robot description.