I am facing problems in minimizing the objective function to compute the motion profiles of robotic arm. Any help is greatly appreciated.

2 views (last 30 days)
Muhammad Saeed on 23 Jun 2021
Answered: Himanshu on 4 Jun 2024
objective = @(h) h(1)+h(2)+h(3)+h(4)+h(5)+h(6)+h(7)+h(8)+h(9);
h0= [0.01,0.20,0.29,0.07,0.26,0.06,0.27,0.07,0.05];
disp(['Initial Objective: ' num2str(objective(h0))])
A = [];
b = [];
Aeq = [];
beq = [];
% variable bounds
lb = [];
ub = [];
nonlincon = @nlcon1;
1. abs[(w(i+1)-w(i))/h(i)]=<240
2. h(i)>0
options = optimoptions(@fmincon,'MaxIterations',15000000,'MaxFunctionEvaluations',15000, 'StepTolerance', 1500);
x = fmincon(objective,h0,A,b,Aeq,beq,lb,ub,nonlincon,options);
A following erroe appears
Converged to an infeasible point.
and also h(i) are negative such as
-0.9526 -0.7626 -0.6726 -0.8926 -0.7026 -0.9026 -0.6926 -0.8926 -0.9126

Himanshu on 4 Jun 2024
It looks like you're facing a couple of issues with minimizing your objective function. The error message "Converged to an infeasible point" and the appearance of negative values in your solution suggest that there might be problems with how constraints are defined or applied.
Here are some changes you can make to define your constraints properly and make corrections in your code:
• All elements of h should be greater than 0. This is a simple bound constraint that can be directly applied in fmincon by setting the lower bound (lb) for each element of h. To ensure h(i) > 0, set the lower bounds for each h(i) to a small positive number (e.g., 1e-6 if they cannot be exactly 0).
• The constraint abs[(w(i+1)-w(i))/h(i)] <= 240 seems to be a nonlinear constraint related to the velocities (w) and time intervals (h). This needs to be defined properly in your nonlinear constraints function (nlcon1). This function should return two arrays, c and ceq, where c contains the inequalities c <= 0 and ceq contains the equalities ceq = 0. For your velocity constraint, if w is dependent on h or another variable, you'll need to calculate it inside this function or pass it as a parameter.
Here's myapproach with placeholders for parts you need to fill in:
objective = @(h) sum(h); % Simplified objective function
h0 = [0.01,0.20,0.29,0.07,0.26,0.06,0.27,0.07,0.05];
disp(['Initial Objective: ' num2str(objective(h0))])
% Bounds
lb = 1e-6 * ones(size(h0)); % Lower bounds to ensure h(i) > 0
ub = []; % Upper bounds not defined
% Nonlinear constraints
function [c, ceq] = nlcon1(h)
% Assuming w is calculated from h or is a known vector
% You need to define how w is related to h or provide w values
w = ... % Define or calculate w based on h or other variables
c = []; % Initialize c for inequality constraints
for i = 1:(length(h)-1)
c(end+1) = abs((w(i+1)-w(i))/h(i)) - 240; % Velocity constraint
end
ceq = []; % No equality constraints in this example
end
nonlincon = @nlcon1;
% Optimization options
options = optimoptions(@fmincon,'MaxIterations',15000000,'MaxFunctionEvaluations',15000, 'StepTolerance', 1e-6);
% Optimization
[x, fval, exitflag, output] = fmincon(objective, h0, A, b, Aeq, beq, lb, ub, nonlincon, options);
if exitflag <= 0
disp('The optimization did not converge to a solution. Check constraints and settings.');
else
disp(['Optimized Objective: ' num2str(objective(x))]);
disp('Optimized h:');
disp(x);
end
The above mentioned changes should help you resolve the error mentioned by you.