Inverted Pendulum, which is also a Lamp
Introduction
The inverted pendulum is one of the most popular demonstrations in system control, has been studied since the 19601 and is a prime example at unis and other research institutes. However, the inverted pendulum, which is nothing more than a pendulum that has the centre of mass above the pivot point, yet has no particular use case. To change this once in for all, I build an inverted pendulum lamp, which can be used as a normal stylish desk lamp. (The main incentive, however, wasn’t so heroic. Honestly! It sounded just like a nice project idea!)
Building
Components
Mechanical Setup
To accomplish this symbiosis between this still highly complex balancing problem and the potential usage as a design element, I first had to design a balancing cart 🚗 with a pivoting E27 socket for the lamp 💡. This brings the extra challenge of feeding a, in this case, 230V, cable through various mountings and controlling it using an ordinary relay.
⚙️ DV-Motor (first axel)
- the L298N Motor Driver Module works up to 12V, without removing the jumper wire, therefore a 12V DV-Motor is a good choice for the setup
- should have sufficient torque and RPM. In my case around 300-440 RPM (depending on your wheel size) with a 15:1 gear ratio and 10Ncm was enough
- ❗ be careful with the maximum current! The allowed Amps for the L298N Motor Driver Module is 2A (more information here)
📏 Contious Angle Sensor (second axel)
- used to monitor the position of the cart 🚗 relative to its starting position
- works like a normal potentiometer but allows for more than 360° turning angle.
- not the most reliable solution as it produced high noise in the zero orientation
=> Quick-fix: use a capacitor as a low-pass filter between the ground and output voltage.
📟 Arduino
- the L298 has a 5V regulator and can be used as the power supply for the Arduino (see connection diagram)
- ❗ don’t mount any high current consumer like the lamp 💡 or the motor ⚙ to the 5V output of the board it is not made for such high currents.
📏 Potentiometer 50k (linear)
- used to detect the angle of the pendulum
- additionally used as a mount for the pendulum
🔌 Capsule Slip Ring AC 240V
- the lamp 💡 is powered by an isolated electric circuit with 240V AC
- the slip ring feeds the power thought the rotational pivot point
- also used as a mount for the pendulum
🔌 Relay
- isolates the 12V DC and the 240V AC
- is triggerd by the Arduino
Connecting Motor Driver Board
Connecting Potentiometer
Integration of Relay2
Control Algorithm
In the following section, I will give a brief introduction to the theory of the LQR Controller and provide you with my recommended resources which help you determine the coefficients of the feedback regulator!
Mathematical representation
The simplified system consists of an inverted pendulum which is connected to a motorized card. Without further inspection, we can recognize that we are looking at an unstable system. If the cart is not moved it is nearly impossible to balance the pendulum in the upright position. The objective is it now to design a feedback controller which accelerates the cart enough so that the angle $ \phi $ of the pendulum is close to 180°.
For this we first have to define the nonlinear model:
- M mass of the cart
- m mass of the pendulum
- b coefficient of friction for cart
- l length to pendulum centre of mass
- I mass moment of inertia of the pendulum
- F force applied to the cart
- x cart position coordinate
- $\theta$ pendulum angle from vertical (down)
- u (input) here equivalent to the Force F
LQR Controller
The LQR or Linear quadratic regulator is one of many optimal control techniques, which takes into account the whole state vector and computes the control decision based on a linear model. For non-linear plants like our inverted pendulum, the system equations first have to be linearized about the upright (unstable) equilibrium. This consequently means that our LQR controller is only sufficient within small deviations around the upright position. After linearizing we have to calculate the gains $K$, this is done using the script linked here. With all that done, we now can compute the input voltage of the Motor using the following equation:
$$ u = -Kx $$
A deeper dive into the theory behind the calculation of the linearized model can be found here!
Determine grains
The script which already includes the linearized model to determine the gains for the LQR Controller can be found here!
To furthermore approve your parameters the script [controlled-cart-pendulum.py] from a similar project3 simulates the control behaviour.
DC-Motor system identification
The LQR Controller takes as an input the Force F of the DC-Motor. Therefore the next step is to find the underlying DC-Motor model and estimate the corresponding system parameters. Then the Arduino can change the speed of the engine using the PWM signal.
We can model a standard DC-Motor using the following equation: $$ \frac{d w}{d t}\left(J+m r^{2}\right)+w\left(B+\frac{k^{2}}{R}\right)=\frac{k U}{R} $$
Simplifying this further:
To determine the parameters a,b,c we can record several velocity curves with different input voltages. Using the following plot and theses scripts [dc_motor_lqr_control.py,estimate_params.py] we can now find the exact model parameters!
Credits to zjor for creating the scripts3
Code
The code is based on an existing Arduino project3
|
|