It’s alive!

22 February 2012

Both lateral and frontal controllers are operating in unison to balance the robot and with no extra coding since last post. All I had to do was hit the ‘enable’ key via serial port term to fire up frontal balancer. Not even any additional tuning since designing the two controllers individually.

Video standing still:

..and then perturbing lateral and frontal balancers:

I’m quite chuffed at the performance. A bit is needed to stop occasional, albeit brief, oscillation of the base wheel, but I suspect this is a bandwidth issue on pendulum pitch rate and not so much an issue of fine tuning the respective controller gain.

Time for a beer.

IWP – Matlab/Simulink

19 February 2012

I had a request for an IWP Matlab/Simulink model, so here goes.

What I’m posting is dated October 2008, and was what I wrote to tune my IWP. I don’t remember much about it, but it looks reasonably self-explanatory.

Note that I’ve updated the Simulink model to Matlab R2011b and it appears to work. To run the simulation, first run the Matlab script.

The model should look like this:


To fill in the gaps:

  • “x1dot” through to “x3dot” represents the second derivatives of pendulum angle, pendulum rate, and wheel rate, i.e. the non-linear system model.
  • Feedback gain “-k” is the linear controller.
  • The only transfer function block is the motor delay model. The addition of this is a bit confusing as I should have included it in the system model above. Also, the controller is not designed with this taken into account. It can be replaced with a straight-through connection since the inertia of the wheel and resulting time response completely swamps the inertia of the motor and it’s unloaded time response. I left it in for the fiddle factor (for fiddling with ;-)).
  • The functions at the bottom are the PMDC motor torque to terminal voltage equation. I included this to get an idea of what kind of signal I would need to drive the real system. You’ll notice in the following graph [below] that there is a directional offset added to overcome friction preventing a small terminal voltage from turning the wheel (essentially a dead-space in the zero-velocity region). This dead-space isn’t modeled, but in real life I found implementing the bias helped the controller to keep the pendulum “on its toes”, though the effect would probably not be noticed with a larger inertial load. It also wastes power.

The output of the simulation should look something like this:

DL Links:

iwheel.m
iwheelmodel.mdl

Hope this is of use 🙂

Hmm, it’s been a while. Now that the holiday period is over and I’ve settled into a new home, I’ll hopefully have more time for my hobby projects!

Getting back to the IWP…

So far we have a symbolic model which shows how different system parameters affect the dynamic response of the system. For this particular model, designing and/or measuring system parameters should be relatively painless, but requires close attention to the model and how its parameters are defined.

A given parameter might be quantified by experiment, calculation from first principles, or by a numerical model depending on the complexity of the respective approach. A simpler approach might mean a less accurate result, so it becomes important to identify and meet a reasonable level of accuracy.

Relative accuracies may be obvious: For pendulum dynamics, the mass at the “plum-bob” end needs to be known more accurately than the mass at the point of rotation. For absolute accuracies or less obvious cases, my rule of thumb is to take two approaches, where possible, and aim to cross verify the results to at least 2 significant figures. Odds are that the error stack-up of the model and its parameters will represent the actual system dynamics pretty well.

So what did I do? I used a mechanical CAD package, Solidworks, to do the work for me:

I verified the masses (wheel and pendulum) by weight scale and calculated the rotational inertia of the wheel to good agreement with Solidworks. Subsequently, I would’ve inferred the pendulum chassis inertia to be in the right ball park as well.

IWP reduced-order model

30 October 2010

We start by defining a new state vector, x, as the variables we want to control

x = \left[\begin{matrix} x_1 \\ x_2 \\ x_3 \end{matrix} \right] = \left[\begin{matrix} \theta_1 \\ \dot{\theta_1 } \\ \dot{\theta_2 } \end{matrix} \right].

By substituting x into the EL equation and rearranging in terms of \dot{x}, the reduced order system can be expressed as

\begin{array} {lcl} \dot{x_1} & = & x_2 \\ \dot{x_2} & = & \frac{-I_{WC}\tau + I_{WC} b g \sin{x_1}}{aI_{WC}} = -\frac{\tau }{a} + \frac{bg\sin{x_1 }}{a}  \\ \dot{x_3} & = & \frac{(a+I_{WC})\tau -I_{WC}bg\sin{x_1}}{aI_{WC}} = \frac{(a+I_{WC})\tau }{aI_{WC}} - \frac{bg\sin{x_1}}{a} \end{array}.

We can reformat this into vector field notation

\dot{x} = f(x) + g(x)\tau,

which gives us
f(x) = \left[\begin{matrix} x_2 \\ \frac{bg\sin{x_1}}{a} \\ -\frac{bg\sin{x_1}}{a} \end{matrix} \right],
and
g(x) = \left[\begin{matrix} 0 \\ -\frac{1}{a} \\ \frac{a+I_{WC}}{aI_{WC}} \end{matrix} \right].

That’s it! Next post: do something useful with it 😉

Following on from this post, the Euler-Lagrange (EL) equation is defined

\frac{d}{dt}\left[\frac{\partial L}{\partial \dot{\theta } }\right] - \frac{\partial L}{\partial \theta } = F_{\theta},

where F_{\theta} is a forcing term introduced to control the IWP. In a passive system this term would be zero, but if we define

\theta = \left[\begin{matrix} \theta_1 \\ \theta_2 \end{matrix} \right],

we can define the forcing term as

F_{\theta } = \left[ \begin{matrix} 0 \\ \tau \end{matrix} \right],

where \tau is torque applied by the motor to spin the wheel.

The computation of the EL equation is simple. We can start with the term in the brackets

\frac{\partial L}{\partial \dot{\theta }} = \left[\begin{matrix} \frac{\partial L}{\dot{\theta_1 }} \\ \frac{\partial L}{\dot{\theta_2 }} \end{matrix} \right] = \left[\begin{matrix} a\dot{\theta_1 } + I_{WC}(\dot{\theta_1 } + \dot{\theta_2 }) \\ I_{WC}(\dot{\theta_1 } + \dot{\theta_2 }) \ \end{matrix} \right]. (1)

Now taking the derivative of (1) with respect to time gives

\frac{\partial }{\partial t} \left[\frac{\partial L}{\partial \dot{\theta }}\right] = \left[\begin{matrix} a\ddot{\theta_1 } + I_{WC}(\ddot{\theta_1 } + \ddot{\theta_2 }) \\ I_{WC}(\ddot{\theta_1 } + \ddot{\theta_2 }) \end{matrix} \right], (2)

and computing the remaining term of the equation gives

\frac{\partial L}{\partial \theta } = \left[\begin{matrix} \frac{\partial L}{\partial \theta_1 } \\ \frac{\partial L}{\partial \theta_2 } \end{matrix} \right] = \left[\begin{matrix} bg\sin{\theta_1 } \\ 0 \end{matrix} \right] . (3)

By substituting (1), (2), and (3) into the EL equation, we arrive at

\left[\begin{matrix} (a+I_{WC}) & I_{WC} \\ I_{WC} & I_{WC} \end{matrix}\right] \left[\begin{matrix} \ddot{\theta_1 } \\ \ddot{\theta_2 } \end{matrix}\right] - \left[\begin{matrix} bg\sin{\theta_1 } \\ 0 \end{matrix}\right] = \left[\begin{matrix} 0 \\ \tau \end{matrix}\right]. (4)

The equations of motion for the IWP model are now fully described by (4). This is an important milestone in taking this approach to designing a controller for the IWP because we now have a virtual representation of the device to simulate our yet-to-be-designed controller with.

You might have noticed that \theta_2 does not appear in (4) because, as mentioned previously, this is a cyclic variable which does not influence the balancing of the IWP. This variable would become redundant information when designing a feedback controller, so by reducing the order of the model beforehand, we can simplify the design of the controller.

Hmm, I think that’s enough \LaTeX blogging for a Saturday afternoon…

Here’s an interesting segue:

Segway boss dies after riding one off a cliff

Poor guy 😦

IWP Lagrangian

26 September 2010

One of many methods of controller design starts off by modeling the dynamics of the physical system. This helps understand the system, check for controllability and observability, choose the control topology, specify and optimize the controller response, check for stability, and simulate the system under different conditions.

A nice and intuitive approach is to find the equations of motion; a mathematical description for the behavior of the system as a function of time. The Euler-Lagrange equation provides a convenient description of the equations of motion because the Lagrangian approach allows the direct use of generalized coordinates. Solving this equation for local minima or maxima means finding the stationary points of the model. For the IWP, this means controlling to \theta{}_1=\dot{\theta{}_1}=\dot{\theta{}_2}=0, while \theta{}_2 is a cyclic coordinate whose steady state value plays no role in the stability of the IWP, so can be left uncontrolled.

The Lagrangian is what must be derived and substituted into the Euler-Lagrange equation to give the equations of motion. The Lagrangian, L, is defined as the total kinetic energy, T, minus the total potential energy, V:

L=T-V.

With the chosen coordinate system, we can calculate the above knowing that:

rotational kinetic energy = \frac{1}{2} \cdot I \cdot \omega{}^2,
potential energy = m \cdot g \cdot h,
and rotational inertia about a point, of a point-mass at radius, r = m \cdot r^2.

Here goes…

Kinetic energy of the wheel caused by I_{WC} and its total angular velocity, \dot{\theta{}_1}+\dot{\theta{}_2}, is

\frac{1}{2}I_{WC}(\dot{\theta{}_1}+\dot{\theta{}_2})^2, (1)

while kinetic energy of the wheel caused by M at point WC and its angular velocity, \dot{\theta{}_1}, about PB is

\frac{1}{2}(ML^2)\dot{\theta{}_1}^2. (2)

Kinetic energy of the pendulum caused by I_{PC} and its angular velocity, \dot{\theta{}_1}, about PC is

\frac{1}{2}I_{PC}\dot{\theta{}_1}^2, (3)

while kinetic energy of the pendulum caused by m at point PC and its angular velocity, \dot{\theta{}_1}, about PB is

\frac{1}{2}(ml^2)\dot{\theta{}_1}^2. (4)

Since the angular velocities of the pendulum about PC and PB are equal, equations (3) and (4) can be simplified to one term describing the total kinetic energy contribution of the pendulum due to the inertia of the pendulum about {PB}, and its angular velocity, \dot{\theta{}_1}, about PB

\frac{1}{2}I_{PB}\dot{\theta{}_1}^2, (5)

Combining (1), (2), and (5) gives total kinetic energy of the system

\begin{array} {lcl} T & = & \frac{1}{2}(ML^2)\dot{\theta{}_1}^2+\frac{1}{2}I_{WC}(\dot{\theta{}_1}+\dot{\theta{}_2})^2+\frac{1}{2}I_{PB}\dot{\theta{}_1}^2, \\ & = & \frac{1}{2}(ML^2+I_{PB})\dot{\theta{}_1}^2+\frac{1}{2}I_{WC}(\dot{\theta{}_1}+\dot{\theta{}_2})^2. \end{array} (6)

The potential energy of the wheel due to gravity, g, is

M L g \cos \theta{}_1, (7)

and the potential energy of the pendulum due to gravity, g, is

m l g \cos \theta{}_1. (8)

Combining (7) and (8) gives total potential energy of the system

V = m l g \cos \theta{}_1 + M L g \cos \theta{}_1. (9)

We can now summarize the system dynamics by substituting (6) and (9) into the Lagrangian. By absorbing some constants for the sake of brevity, we arrive at

\begin{array} {lcl} L & = & \frac{1}{2}(ML^2+I_{PB})\dot{\theta{}_1}^2+\frac{1}{2}I_{WC}(\dot{\theta{}_1}+\dot{\theta{}_2})^2 \\ & & - m l g \cos \theta{}_1 - M L g \cos \theta{}_1 \\ & = & \frac{1}{2}a\dot{\theta{}_1}^2+\frac{1}{2}I_{WC}(\dot{\theta{}_1}+\dot{\theta{}_2})^2 - b g \cos \theta{}_1, \end{array}

where

\begin{array} {lcl} a & = & ML^2+I_{PB} \\ b & = & m l + M L. \end{array}

More to come in the next post 😉

IWP parameters

23 September 2010

Starting off the second of a series of posts about my IWP project, I discover that wordpress.com have support for \LaTeX. Woot! This means that I’ll be able to present my equations in the format they were intended. It also means I have no excuse not to start off with some maths 😉

To keep things consistent, I will stick to the parameters defined below:

Where:

\begin{array}{lcl} \theta{}_1 & = & \mbox{Pendulum angle with respect to vertical axis,} \\ \theta{}_2 & = & \mbox{Wheel angle with respect to pendulum axis,} \\ m & = & \mbox{Mass of pendulum,} \\ M & = & \mbox{Mass of Wheel,} \\ l & = & \mbox{Length from pendulum base (PB) to pendulum center of mass (PC),} \\ L & = & \mbox{Length from pendulum base (PB) to wheel center of mass (WC),} \\ I_{PC} &=& \mbox{Rotational Inertia of pendulum about pendulum center of mass (PC),} \\ I_{PB} &=& \mbox{Rotational Inertia of pendulum about pendulum base (PB),} \\ I_{WC} &=& \mbox{Rotational Inertia of wheel about wheel centre of mass (WC),} \\ g &=& \mbox{Constant of gravitational acceleration.} \end{array}

Assumptions: The pendulum, reduced to a line representation in the above illustration, will in actuality comprise of the chassis plus all rigidly attached masses, which might include the motor enclosure, printed circuit boards and/or batteries etc. Accordingly, the center of mass and the moments of inertia of the pendulum should be calculated with this in mind. The same thing applies to the wheel, which might include the rotor mass and inertia.

I will dedicate the next post to calculating the system Lagrangian using the parameters above. Until then, goodbye..

Inertia Wheel Pendulum

22 September 2010

The Inertia Wheel Pendulum (IWP) is an underactuated mechanical system, meaning it has fewer actuators than degrees of freedom. The number of degrees of freedom is defined by the number of independent generalized coordinates of the system. For the IWP, it is convenient to use polar coordinates to represent the angle and rate of the pendulum about the pendulum base, and the angle and rate of the inertia wheel about the centre of the wheel.

The wheel is actuated by a motor, while the pendulum coordinates remain underactuated, however, the pendulum can be controlled by the action of the wheel through dynamic coupling. In the case of the IWP, this means the single motor can be used to control the angular position and rate of the pendulum as well as that of the wheel.

A simple model of the IWP has two equilibrium points, assuming the base of the pendulum to be anchored at a point that enables it to rotate, unconstrained, through 360°. The downward pointing position is the passively stable equilibrium point; the “relaxed” state the system would settle at if no power was applied to the motor. The upward pointing position is passively unstable but can be stabilized by closed-loop regulation of the motor torque and generalized coordinates.

While getting an IWP to point down is easy, thanking gravity, getting one to balance upright is a little more challenging. This ex post facto series of blog entries will touch on some of the theory behind the IWP and the steps I took to design and construct a working prototype. Stay tuned for more!