How do I solve forward dynamics 2nd order ODE with time-dependent parameters using ODE45?
Ältere Kommentare anzeigen
I'm trying to solve a forward dynamics problem using ODE45, but the problem is tau is a vector in part (c) and so ODE45 is showing error when I'm using tau vector,

I'm not able to solve (c) part (denoted by red dot) of my assignment. here is my code,

This is the function I'm using, here tau = Torque, I've already calculated tau in first practical and I've to use it in this practical but I don't know how to do it,

5 Kommentare
Torsten
am 6 Mär. 2022
Call ODE45 for each value of tau separately, i.e. loop over the tau-vector:
for i=1:numel(tau)
tauh = tau(i);
[time,Y] = ode45(@(t,y)Diffeqn(t,y,tauh,m,L,Lc,Izz,g),t,y);
...
end
Akash Vyas
am 6 Mär. 2022
Bearbeitet: Akash Vyas
am 6 Mär. 2022
Hi @Akash Vyas
The symbol tau (τ) is the control torque.
You've got the error because you put tau into an algebraic loop error that ODE45 cannot effectively solve:
Either it is a feedback control law (a formula) to compute the desired torque value that depends on θ and
, or a fixed torque value (or a series of torque values at certain time intervals where you need to inject them in to the system) that you obtained from Practical 1.
If it is a feedback control law, then tau looks like this:
The closed-loop system then becomes
which can be simplified to
So, the desired response of the 2nd-order system is determined by the selection of
the fundamental proportional gain,
and the fundamental derivative gain,
.
Since the operation time only lasts for 3 seconds, I assume that the robot arm shall achieve the steady-state (
) at 1 second from the initial time. If that is acceptable to you, then you can try for
Don't forget to multiply the fundamental control gains with the inertia
.
kp = 36;
kd = 12;
tau = - Izz*kp*theta - Izz*kd*dtheta + m*g*Lc*cos(theta);
Akash Vyas
am 7 Mär. 2022
Akzeptierte Antwort
Weitere Antworten (1)
Bjorn Gustavsson
am 7 Mär. 2022
Following from the comments above it seems as if you have a smoothly varying time-dependent torque that you know at a set of points in time. For that you could use simple interpolation of the torque at any given point in time. To do that you need to modify your ODE-function to allow for both a torque_of_t and a t_for_torque variables, instead of a single torque-input. Perhaps something like this:
function dy = ODE_fcn(..., tau_of_t,t_for_tau)
tau_now = interp1(t_for_tau,tau_of_t, t,'pchip');
% Then plug in tau_now where you use tau.
% The rest should be fine
end
Or you could wrap the interpolation into a function-handle:
tau_fcn = @(t) interp1(t_for_tau,tau_of_t,t,'pchip');
% then send this into your ODE
% But then you need to change the use of tau to a call to the function:
% Inside ODE:
tau_now = tau(t);
HTH
1 Kommentar
Akash Vyas
am 10 Mär. 2022
Kategorien
Mehr zu State-Space Control Design finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!








