Azzera filtri
Azzera filtri

problems with setting constraints for double pendulum

1 visualizzazione (ultimi 30 giorni)
Hello! I have problems with setting up the optimal control fmincon for a double pendulum: In the end, I would like to limit the pendulum angle so that the first pendulum only moves between -pi/4 and pi/2 and the 2. Pendel between -pi/2 und pi/2. I did understand that the nonlinear constraint has to be fulfilled by c(X) < 0 . X includes the coordinates for location q and the actuation momentum tau.
function [c,ceq,gc,gceq] = constraints(x,J,parameter) % mit J = 40
Nq = parameter.Nq; % Dimension q = 2 (aus structure parameter)
Ntau = parameter.Ntau; % Dimension tau = 2
% Ueberpruefe die Dimension von x
if length(x)~=((Nq+Ntau)*(J+1)) %x muss die gleiche Dimension haben wie [q0,q1,...,qN,tau0,tau1,...,tauN]
error('beschr: x hat falsche Dimension');
end
% Extrahiere Lagekoordinaten
Q = x(1:Nq*(J+1)); %alle [q0,q1,...,qN]
% Extrahiere Aktuierungsmomente
Tau = x(Nq*(J+1)+1:end); %alle [tau0,tau1,...,tauN]
q0 = Q(1:Nq);
%ceq = .....
ceq(X) = 0 works just fine, so I did not mention it further. Now I tried to limit q to the lower limit:
%nichtlineare Randbedingung
c = zeros((J+1+2)*Nq,1); % Anzahl Gleichungsbeschraenkungen
gc = zeros((J+1+2)*Nq,(J+1)*(Nq+Ntau)); % Zugehoeriger Gradient
gctau = zeros((J+1+2)*Nq,(J+1)*Ntau); % Zugehoeriger Gradient von tau, spielt aber eigentlich keine Rolle hier(?), da ja nur Lagekoordinaten begrenzt werden
phi1min = -pi/4;
phi2min = -pi/2;
q0 = Q(1:Nq);
c(1:Nq) = q0 + [phi1min;phi2min]; %soll ja <0 sein...
gc(1:Nq,1:Nq) = eye(Nq); %Gradient
q1 = Q(Nq+1:2*Nq);
c(Nq+1:2*Nq) = q1 + [phi1min;phi2min];
gc(Nq+1:2*Nq,Nq+1:2*Nq) = eye(Nq);
j = 1;
while j<J
q = Q;
c((j+1)*Nq+1:(j+2)*Nq) = q(j:j+1) + [phi1min;phi2min];
gc((j+1)*Nq+1:(j+2)*Nq,(j+1)*Nq+1:(j+2)*Nq) = eye(Nq);
j = j+1;
end
gc(:,(J+1)*Nq+1:end) = gctau;
gc = gc.';
end
Now, Matlab performs without an error but the pendulum doesn't move at all when I try to plot it. I don't know what to do and would be grateful for any help :)
  1 Commento
Alan Weiss
Alan Weiss il 18 Dic 2017
I do not understand your problem formulation. To write equations for a double pendulum, I would give the angles of the two line segments as my parameters. Then I'd try to figure out the equations of motions using these two parameters along with the other problem variables such as mass or masses and limitations of angles. The equations of motion are a second order ODE. So I would expect a numerical solution to include a call to an ode function such as ode45.
The constraints in this formulation would be bounds on the two angles, no nonlinear constraint needed, unless I missed something. And I do not understand what needs to be optimized.
So, for more help, I suggest that you give us more details. I cannot understand what your code as given is supposed to do, or why you should expect to see something to move.
Alan Weiss
MATLAB mathematical toolbox documentation

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Programming in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by