Modelling a driven double pendulum device such as a Trebuchet or sling-shot

I am trying to model a driven double pendulum acting as a slingshot- a mechanism similar to a Trebuchet. It’s the same as shown here Double Pendulum -- from Eric Weisstein's World of Physics but with the mass m1 = 0. I want to apply a torque to the inner arm (l1) of the double pendulum, allowing the outer mass m2 to react to inertial and gravity forces only. I want to be able to vary the torque throughout its cycle and track the motion of the outer mass.

Double Pendulum -- from Eric Weisstein's World of Physics and Erik Mahieu’s demonstartion of a driven spherical pendulum use practically the same Lagrangian. In the case of the double pendulum, for the generalised coordinate Theta1 I have just set the Euler equation = Torque, rather than 0.

eqns = {(m1 + m2) l1 \[Theta]1''[t] + 
     m2 l2 \[Theta]2''[t] Cos[\[Theta]1[t] - \[Theta]2[t]] + 
     m2 l2 \[Theta]2'[t]^2 Sin[\[Theta]1[t] - \[Theta]2[t]] + 
     g (m1 + m2) Sin[\[Theta]1[t]] == Torque, 
   m2 l2 \[Theta]2''[t] + 
     m2 l1 \[Theta]1''[t] Cos[\[Theta]1[t] - \[Theta]2[t]] - 
     m2 l1 \[Theta]1'[t]^2 Sin[\[Theta]1[t] - \[Theta]2[t]] + 
     m2 g Sin[\[Theta]2[t]] == 0, \[Theta]1[0] == 0, \[Theta]2[0] == 
    5, \[Theta]1'[0] == 0, \[Theta]2'[0] == 0};
sol = NDSolve[eqns, {\[Theta]1, \[Theta]2}, {t, 0, 1}, 
   MaxSteps -> Infinity, PrecisionGoal -> 4];
pos1[t_] := {l1 Sin[\[Theta]1[t]], -l1 Cos[\[Theta]1[t]]}; 
pos2[t_] := {(l1 Sin[\[Theta]1[t]] + 
    l2 Sin[\[Theta]2[t]]), (-l1 Cos[\[Theta]1[t]] - 
    l2 Cos[\[Theta]2[t]])}

In Mathematica, can I set up a list or matrix of time values of torque, and press run and see what happens? Or there an optimize command to do this?

Otherwise, what I’m looking at is setting up four first order differential equations for the problem, and solving them in Excel, and then playing around with the results. All advice or instructions would be most welcome.

Have you seen this recent discussion: Modelling a Trebuchet

torque could be defined as a function of t as torque[t] using, for example, Interpolation or PieceWise.

Thanks Vitaliy, I saw that discussion. David’s advice in it on how to structure the notebook is very good for a newbie like myself!

Piecewise seems like a good option. I should be able to break the action down into say 100 time steps, and solve each step, and then attach them all together into a single function. I’ll try that.

Calculating the input value for each step is still an issue for me. I need to calculate a value for Torque[t i] - which is an input - for each step i for my piecewise function. I’d like the value to be the one that maximises the value of the term Torque [t i] * Theta1(dot] [t i], subject to the equations of motion being complied with. I think I need to use a ParametricNDSolve function, but I’m not sure how to structure such a statement that solves the equations of motion such that the value of Torque * Theta(dot) is maximized, and then outputs that value of Torque.

If I can do that, I should be able to wrap it up in a Piecewise or Interpolation function, as David has suggested.