# Gas station without pumps

## 2016 October 16

### Lagrangian mechanics for linear electronics

Filed under: Uncategorized — gasstationwithoutpumps @ 13:27
Tags: , ,

This post is a continuation of Having trouble learning Lagrangian mechanics, looking at electronic systems rather than mechanical ones.  Again, this is not intended as a tutorial but a dump of my understanding, 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.

For electronics, I’ll use charge $q$ as my coordinate, with current $i = \dot q$ as its derivative with respect to time.  In all but the simplest circuits, there will be multiple charges or currents involved, which I’ll distinguish with subscripts.

Some notation:

• $\mathcal{L}$ is the difference between kinetic and potential energy of the system.  The potential energy will be the energy stored in capacitors, $\frac{q^2}{2C}$, and the kinetic energy the energy in the inductors, $L\dot q^2/2$.  (Note: that is only self-inductance.  If we have mutual inductance $L_{12}$ between two inductors, we need to use $L_{12}\dot q_1\dot q_2 /2$ for the kinetic energy—I’m a bit confused by that, as we could have negative kinetic energy.  I rarely use inductors or transformers in my electronics, so I’ve not had to work out my confusion yet.)
• $\mathcal{P}$ is the power dissipated by the resistors in the system: $R{\dot q}^2/2$.
• $\mathcal{F}$ is the vector input to the system needed to make the energy balance work out.  By using charge for each coordinate, the units here will be volts.

With this notation, the basic formula is

$\frac{d}{dt}\frac{\partial \mathcal{L}}{\partial \dot q} - \frac{\partial \mathcal{L}}{\partial q} + \frac{\partial \mathcal{P}}{\partial \dot q} = F_{q}~.$

Let’s check the units:

• Potential energy: $\frac{\partial}{\partial q} \left(\frac{q^2}{2C}\right)= \frac{q}{C}$, which is indeed volts.
• Kinetic energy: $\frac{d}{dt}\frac{\partial L\dot q^2/2}{\partial \dot q} = L\ddot q$, which is also volts.
• Dissipated power:$\frac{\partial R{\dot q}^2/2}{\partial \dot q} = R \dot q$, which is again volts (Ohm’s Law).

Now all we need to do is to figure out which $q_i$ or $\dot q_i$ has to be associated with each component of the system, and what voltages the $\mathcal{F}_i$ correspond to.  I think that will be easiest if I have some specific circuits to work with.  Let’s start with a very simple one:

Simple RLC series circuit with a voltage source.

We can use a single coordinate, the charge on the capacitor, $q_1$, so that the current flow $\dot q_1$ is clockwise in the schematic. We get the Lagrangian $\mathcal{L} = L_1{\dot q_1}^2/2 - \frac{{q_1}^2}{2C_1}~.$ The power dissipation is $\mathcal{P}=R_1{\dot q_1}^2/2$, and taking the derivatives gives us $\mathcal{F}_1 = L_1 \ddot q_1 + R_1 \dot q_1 + q_1/C$, which is the voltage for the voltage source.

For electronics modeling, we often want to look at the ratio of two different voltages in a system, for example, the output of a filter relative to the input to a filter. How do we set that up? Let’s look at a very simple low-pass RC filter:

The upper schematic shows the normal way to represent the low-pass filter. The lower schematic shows it with a voltage source and a voltmeter, with two loops (one of which has no current).

The potential energy is just $\frac{(q_1+q_2)^2}{2C}$, there is no kinetic energy (no inductors), and the dissipation is $R{\dot q_1}^2/2$. Taking the derivatives of the Lagrangian gives us
$\mathcal{F}_1 = \frac{q_1 + q_2}{C} + R \dot q_1$ and
$\mathcal{F}_2 = \frac{q_1 + q_2}{C}$.
In other words, we get the voltage at the voltage source and the voltage at the voltmeter. If we want to do anything with these equations, we need to recognize that the $q_2$ and $\dot q_2$ terms are 0 (modeling the voltmeter as a perfect infinite impedance), giving us the usual formulas for the input and output voltage, in terms of the charge on the capacitor: $v_{in} = \frac{q_1}{C} + R \dot q_1$ and $v_{out} = \frac{q_1}{C}$.

If we take Laplace transforms, we get $V_{in} = Q_1/C + RsQ_1$ and $V_{out}= Q_1/C$, which gives us the transfer function $\frac{V_{out}}{V_{in}} = \frac{1}{RCs + 1}$, as expected.  (Plug in $s=j\omega$ to get the usual format in terms of angular frequency.)

I could do another, more complicated example, but I think that the idea is clear (to me):

• Make a charge (and current) coordinate for each current loop in the circuit—including a dummy loop with current 0 wherever you want to measure the voltage.
• Set up the Lagrangian by adding terms for each inductor (kinetic energy) and subtracting terms for each capacitor (potential energy), and set up the power-dissipation functions by adding terms for each resistor.
• Take the appropriate derivatives to get the voltages.
• If needed, eliminate charge terms by using more easily measured voltage terms.

I don’t find this process any simpler than using complex impedances and the usual Kirchhoff laws, but it isn’t much more complicated.  It may be easier to use the Lagrangian formulation than setting up the equations directly when there are mutual inductances to deal with—I’ll have to think about that some more.

Of course, the big advantage I’ve been told about for Lagrangian mechanics is in electromechanical systems, where you model the mechanical part as in Having trouble learning Lagrangian mechanics and the electronic part as in this post, with only a conservative coupling network added to combine the two. It is in setting up the coupling network that I get confused when trying to model electromechanical systems, and I’ll leave that confusion for a later post.

## 2016 October 15

### Having trouble learning Lagrangian mechanics

Filed under: Uncategorized — gasstationwithoutpumps @ 22:51
Tags: , ,

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.

Some notation:

• $\mathcal{L}$ 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.
• $\mathcal{P}$ is the power dissipated by the system.
• $\mathcal{F}$ 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

$\frac{d}{dt}\frac{\partial \mathcal{L}}{\partial \dot x} - \frac{\partial \mathcal{L}}{\partial x} + \frac{\partial \mathcal{P}}{\partial \dot x} = F_{x}~.$

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 $x$, and the angle of the inverted pendulum (clockwise from upright) $\theta$.  The cart has mass $m_{c}$ and the pendulum $m_p$, with a distance from the pivot on the cart to the center of  mass for the pendulum $l$.  Furthermore, the pendulum has moment of inertia $J$, and there is viscous drag on the cart with a force $-b\dot x$.  The pivot is assumed to be frictionless.

Let’s use $p$ to designate the location of the center of mass of the pendulum: $p= \left(x+l\sin(\theta), l\cos(\theta) \right)$.

The potential energy in the system is just due to the height of the pendulum mass: $m_{p}g l \cos(\theta)$.  The kinetic energy is $m_{c} \dot x^2/2 + m_p \dot p^2/2 + J \dot\theta^2/2$. Combining these gives us

$\mathcal{L} = m_{c} \dot x^2/2 + m_p \dot p^2/2 + J \dot\theta^2/2 - m_{p}g l \cos(\theta)~.$

The power dissipated due to friction is $\mathcal{P} = b \dot x^2/2$.

It would be good to get rid of the extra variable $p$, using just $x$ and $\theta$.  The derivative is $\dot p=\left(\dot x +l \cos(\theta)\dot\theta, -l \sin(\theta)\dot\theta\right)$, and its square is $\dot p^2 = \dot x^2 + 2l\cos(\theta) \dot x \dot \theta + l^2\dot \theta^2$.  Substituting that into our previous formula gives us the Lagrangian in terms of just the generalized coordinates and their time derivatives:

$\mathcal{L} = (m_{c} +m_p) \dot x^2/2 + m_p l \cos(\theta)\dot x\dot \theta + (J +m_{p}l^2)\dot\theta^2/2 - m_{p}g l \cos(\theta)~.$

Applying the basic formula gives us

$F_x = \frac{d \left((m_c+m_p)\dot x +m_p l \cos(\theta)\dot \theta\right)}{dt} + b \dot x$

$F_x = (m_c+m_p)\ddot x + m_p l \cos(\theta)\ddot\theta -m_p l \sin(\theta) {\dot\theta}^2+ b \dot x$

$F_\theta =\frac{d \left(\left(m_p l \cos(\theta) \dot x + (J+m_pl^2)\dot\theta\right)\right)}{dt} +m_p l \sin(\theta)\dot x{\dot\theta}^2+ g m_p l \sin(\theta)$

$F_\theta = m_p l \cos(\theta) \ddot x - m_p l \sin(\theta)\dot x\dot\theta + (J+m_pl^2)\ddot\theta+m_p l \sin(\theta)\dot x{\dot\theta}^2+ g m_p l \sin(\theta)$

We can linearize this around $\theta=0$ (the inverted pendulum straight up), by setting $\cos(\theta)\approx 1$ and $\sin(\theta)\approx 0$, except for the gravitational term, where we use $\sin(\theta)\approx\theta$:

$F_x = (m_c+m_p)\ddot x + m_p l \ddot\theta+ b \dot x$

$F_\theta = m_p l \ddot x + (J+m_pl^2)\ddot\theta+ g m_p l \theta$

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.

## 2016 October 13

Filed under: Uncategorized — gasstationwithoutpumps @ 13:23
Tags: , , , ,

I’ve started figuring out how to fix my bike seat (see Broken bike seat).  The idea is to insert at 15mm diameter aluminum rod (6061 alloy, tempered to T6) that spans the break and the high-stress point on the other side of the clamp, which is also scored and likely to fracture, and glue it in place. Originally I was planning to get someone to weld it, but that is looking like a bad idea—the heat-affected zone around the weld would lose 80% of its strength, unless the whole seat is retempered, which is a bit problematic with a powdercoat finish.  Also, grinding the weld down to the point where it is smooth enough to fit into the clamp would be difficult, and the result would again lose a lot of the strength.

I found the rod I need at McMaster-Carr, and it should arrive tomorrow, but I now need to choose an adhesive that is strong, flexible, and can cure in a thin film between the rod and the inside of the aluminum tube.

In the comments on Broken bike seat, gflint suggested a silicone adhesive, but most of the consumer ones are one-part adhesives that rely on exposure to moisture from the air to cure, which won’t work for a thin layer 10–15cm long between two pieces of aluminum.  There are two-part silicone adhesives that don’t rely on exposure to humidity for curing, but they are most marketed to industry, not easily available for one-shot end-user projects.  I don’t want to have to buy a $60 tool to apply the adhesive! I started looking for flexible epoxies available to consumers. Here is what I’ve found so far: adhesive cost flexural modulus (stiffness) tensile strength flexural strength TotalBoat FlexEpox$17.99 193,000psi 5,610psi 9,050psi
West System G/flex 650 $27.55 150,000psi ~2,000psi? or is that overlap shear strength? Marine-Tex FlexSet$29.67 ? ? ?

Bob Smith Industries BSI-203H Mid-Cure

$8 3800psi 3M Scotch Weld DP-125$41.52+applicator ? 3300psi (2200psi overlap shear) ?

There are undoubtedly many others (Bondo 280, for example), but I’m having a hard time finding any technical information about them. The costs are what I could find on Amazon.

Currently, I’m leaning towards the TotalBoat FlexEpox, which is cheap, has decent specs, and a slow set time, so I have time to reposition things.  I might have preferred a slightly more flexible glue, but I think this will work.

## 2016 October 11

### Lego as LED holder revisited

Filed under: Circuits course — gasstationwithoutpumps @ 18:01
Tags: , , ,

In Lego as LED holder, I wrote

I think that the Lego bricks work about as well as the old trans-illumination wooden blocks that I’ve been using for a few years, and they are certainly much easier to make, requiring only drilling two ⅛” holes.

I’ll want to play around with different illumination, also.  Lots of cis-illumination pulse monitor kits seem to use green LEDs, for example.  Do those work better?

Since then, I’ve played around with a couple of different approaches for using Lego.  The first, and most obvious, move was to use separate bricks for the LED and the phototransistor. If the phototransistor brick is clicked onto the top of the LED brick, then there is the ABS of the brick top between them, and very little light leakage.  I tried both 1×1 and 1×2 bricks, which cost about the same at about 3¢ each on the used market.

Because I was too lazy to wire leads onto all my different LEDs, I also tried just sticking the LED in the breadboard and resting my finger on the bricks—it isn’t very sturdy, but for quick testing it is not bad:

The LED can support the bricks, if you don’t press too hard.

I tried using several different LEDs. I got good results with 700nm and 607nm peak LEDs, but nothing but DC drift with green (565nm) LEDs. I would have tried a yellow LED, but I only had ones in 5mm packages, which is too big even for the axle holes, so the poor results there may have been due to mechanical, rather than optical difficulties (some signal was visible).

Here are the results with a 700nm red LED:

There is a lot of DC drift, but the underlying 3–4mV signal is clear.

So, I have (at least) three choices for how to do cis illumination with Lego bricks, all of which I like better than using wooden blocks:

I can drill off-center holes in Lego Technic bricks, or centered holes in 1×1 or 1×2 bricks.

Drilling the bricks is very easy, and it would be even easier, if I made a jig that aligned the brick, rather than having to fiddle with the drill-press vice. I might even have the students drill their own bricks. I did not put Lego bricks on the parts list, but if I have to buy $5 worth of Lego bricks for this Winter’s class, it is no big deal. ## 2016 October 9 ### Lego as LED holder Filed under: Circuits course,Uncategorized — gasstationwithoutpumps @ 15:00 Tags: , , , In Pulse monitor using log amplifier, I talked about the problems I was having with using wooden blocks for holding an LED and phototransistor side-by-side, because the wood was too transparent, and the rather clumsy test I made using electrical tape: By cutting between the two 3mm holes I could put black electrical tape to block the short-circuiting light path. I suggested in that post that I would buy a chunk of black ABS plastic for$10 and try making the finger cradles out of that. I realized later that I already have some black ABS plastic, in the form of Lego bricks. If I could use them, that would save me a lot of trouble, and provide a more easily duplicated block for others to use.

I ended up trying a black 1×2 Technic brick (which would cost about 1¢–3¢ each on Bricklink), drilling two ⅛” (~3mm) holes in the faces on either side of the axle hole. The axle hole in the Technic brick provides a light barrier between the two optoelectronic components:

View of the Lego Technic brick from the bottom, showing the light barrier between the two optoelectronic parts.
The bottom needs to be covered (with another brick or electrical tape), and the optoelectronic components need to be taped in place.

View of the drilled Lego Technic brick, showing the optoelectronic components.

I had hoped to be able to insert the 3mm LED and phototransistor from the bottom of the brick, but there was not enough clearance to do so easily, so I inserted them from the opposite face of the brick.

I tried recording the light levels with the front face taped over with black electrical tape, and with a finger covering it. The difference in voltage was large, indicating that the light through the finger was much more than the light leakage around the axle-hole light barrier. I was using an LTR-4206 phototransistor and a 1N914 diode followed by a unity-gain buffer.

I got around 394mV with the finger and 275–284mV with the holes taped. The variation on any given recording run with the holes taped was only about 0.3mV, but different runs, with different amounts of sunlight falling on the brick gave different levels. The minimum difference between the finger and the taped block is about 110mV, which translates to a 19.8dB difference in light (or a factor of 9.8).

But I was not able to get a pulse measurement with cis IR illumination.  I could get a signal of about 1mV peak-to-peak with ambient (shaded sunlight) illumination, which corresponds to about 0.18dB, or 2% fluctuation in finger opacity, but that depended critically on the pressure on my fingertip—if it wasn’t just right, I got no visible pulse signal, just noise.  I could get a bit more consistent results by putting the Lego block between my index and middle fingers and using a rubber band to clamp the fingers together.  If the squeeze was just tight enough to throb, then I got fairly clean results, and I could get them fairly consistently, but I’m not sure whether others will be able to get similarly consistent results.

I also tried taping up the block with no IR illumination, to measure the dark current.  I got 67mV, which should correspond to about 10nA, which is pretty good, since the spec for the LTR-4206 phototransistor give the max dark current as 100nA.

Bottom line: I think that the Lego bricks work about as well as the old trans-illumination wooden blocks that I’ve been using for a few years, and they are certainly much easier to make, requiring only drilling two ⅛” holes.

I’ll want to play around with different illumination, also.  Lots of cis-illumination pulse monitor kits seem to use green LEDs, for example.  Do those work better?

Next Page »

Create a free website or blog at WordPress.com.