I could not move the arm using the code from MATLAB and I get the error "Error using untitled "Arduino hardware not detected on port COM4."

5 views (last 30 days)
This is the code "
a = arduino('COM4')
clear a;
% Robot parameters (lengths of links)
L1 = 1;
L2 = 1;
L3 = 1;
L4 = 1;
L5 = 1;
% Desired end-effector position for going up and down
desired_height = 2;
% Calculate inverse kinematics for the desired position
[theta1, theta2, theta3, theta4, theta5] = inverseKinematics(desired_height, L1, L2, L3, L4, L5);
% Display the joint angles
disp('Joint Angles:');
disp(['Theta1: ', num2str(90), ' radians']);
disp(['Theta2: ', num2str(80), ' radians']);
disp(['Theta3: ', num2str(45), ' radians']);
disp(['Theta4: ', num2str(60), ' radians']);
disp(['Theta5: ', num2str(20), ' radians']);
% Move the robotic arm to the desired position (you need to implement this part)
% MoveRobotToPosition(theta1, theta2, theta3, theta4, theta5);
% Display a message indicating that the arm has moved
disp('Robotic arm moved to the desired position.');
% Function to calculate inverse kinematics
function [theta1, theta2, theta3, theta4, theta5] = inverseKinematics(desired_height, L1, L2, L3, L4, L5)
% Assume a simple planar robotic arm for illustration purposes
% You need to replace this with the actual inverse kinematics solution
% Calculate joint angles using trigonometry
theta1 = atan2(desired_height, L1);
theta2 = acos((L2^2 + L3^2 - L4^2 - L5^2) / (2 * L2 * L3));
theta3 = -theta2; % Adjust based on your arm's kinematics
theta4 = pi - atan2(desired_height, L1); % Adjust based on your arm's kinematics
theta5 = 0; % Adjust based on your arm's kinematics
end
"

Answers (1)

Sathvik
Sathvik on 28 Nov 2023
Hi
I understand that you are facing an issue while using Arduino hardware in Simulink.
Please open device manager, expand Ports and verify if the Arduino board is on COM4 like in the picture attached.
If the arduino board is connected to a COM port other than COM4, provide the COM port displayed in device manager as the input argument to the arduino function in line 1.
a = arduino('COM4')
However, the code may still not be able to control a robotic arm, since the arduino object is cleared in the very next line.
clear a;
You may also refer to this Simulink model example on how to control a robotic arm using Arduino.
Hope this helps!

Categories

Find more on Robotics System Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!