For the past few days, I’ve been trying to teach myself enough Lagrangian mechanics that I can derive systems of ordinary differential equations for the sorts of simple systems that come up in control-theory classes.
I think I’ve kind of got it for mechanical systems, and maybe for electronic ones, but I can’t seem to wrap my head around electromechanical systems. I’m going to dump out a little of my understanding here, to clarify it in my own head, and to get corrections or suggestions from my readers, many of whom are far better at physics than me, having actually taken it in college. My son and I studied simple physics using the textbook Matter and Interactions a few years ago, but the book doesn’t get into Lagrangian mechanics, and I don’t think I really understand magnetic fields intuitively well enough to keep the mathematical abstractions straight.
Part of my problem in reading introductions to Lagrangian mechanics (like the Wikipedia one) is that they use almost impenetrable abstract notation and immediately jump to very general cases, leaving me with no intuition about what they are doing.
As I understand it, Lagrangian mechanics starts with the idea of a conserved scalar quantity (like energy), and provides a way of setting up equations of motion by taking partial derivatives with respect to generalized coordinates, which are in turn functions of time.
For mechanical systems the generalized coordinates are generally positions of point masses or angles of joints (velocity and angular velocity are time derivatives of the coordinates). For electronic systems, the generalized coordinates are either charges or voltages and currents, depending whose formulation you read. The charge-based formulation has made a bit more sense to me, as currents are the time-based derivatives of charge. We look at the charge on capacitors and current through inductors to compute energy in the system.
One problem with a lot of the descriptions of Lagrangian mechanics is that they do everything with purely conservative systems, then tack in dissipation as an afterthought, but all real systems that need control have dissipation of energy as a fundamental part of the modeling process. I’ll try to include the dissipation terms in the basic formulation, rather than adding them at the end.
- is the difference between kinetic and potential energy of the system.
In a conservative system, it would always be 0, with energy sloshing back and forth between kinetic and potential forms, but never increasing or decreasing.Correction based on comments: I screwed up here—it is the sum of kinetic and potential energy (the Hamiltonian) not the difference (the Lagrangian) that is constant in a conservative system.
- is the power dissipated by the system.
- is the vector input to the system needed to make the energy balance work out. The units for this vector depend on what the generalized coordinates are. For mechanical systems, Cartesian coordinates will need forces, and angles will need torques. For electronic systems using charges as coordinates, the units are volts.
With this notation, the basic formula is
I may be missing some critical conditions on when this can be applied, but I did manage to work out the equations of motion for an inverted pendulum on a cart from it.
So here is the inverted-pendulum example:
We have two coordinates: the horizontal position of the cart , and the angle of the inverted pendulum (clockwise from upright) . The cart has mass and the pendulum , with a distance from the pivot on the cart to the center of mass for the pendulum . Furthermore, the pendulum has moment of inertia , and there is viscous drag on the cart with a force . The pivot is assumed to be frictionless.
Let’s use to designate the location of the center of mass of the pendulum: .
The potential energy in the system is just due to the height of the pendulum mass: . The kinetic energy is . Combining these gives us
The power dissipated due to friction is .
It would be good to get rid of the extra variable , using just and . The derivative is , and its square is . Substituting that into our previous formula gives us the Lagrangian in terms of just the generalized coordinates and their time derivatives:
Applying the basic formula gives us
We can linearize this around (the inverted pendulum straight up), by setting and , except for the gravitational term, where we use :
These equations of motion can be used to design a controller for the cart and inverted-pendulum system, as long as you don’t let the pendulum get too far from the vertical. I think that the linearized equations are ok, but I may have made some calculus errors in the nonlinear equations I simplified them from.
I’ll stop here, but try to do another (electronic) example in a later blog post.