Kaiwen Zhenran 16299 Final Project Inverted Pendulum

by kgeng in Circuits > Arduino

670 Views, 1 Favorites, 0 Comments

Kaiwen Zhenran 16299 Final Project Inverted Pendulum

图像_2022-05-09_180453902.png

Overview:

The goal of the project is to build an inverted pendulum that can balance itself using a reaction wheel. The MPU6050 module on the pendulum measures the angle and angular velocity, which is sent to the Arduino Nano for processing. After computing, the Arduino commands the motor to spin the reaction wheel with appropriate direction and speed.

Materials

Arduino Nano Every 2s Lipo Battery (7.4v nominal) 370 DC motor MPU6050 (Gyro + Accelerometer) BTS7960 H-bridge module 3d Printed Reaction Wheel Various wires for wiring Various lego parts for structure and pendulum

Simulation Software: Matlab

Step 1: Modeling

图像_2022-05-09_180946786.png
图像_2022-05-09_181032483.png

Mechanical analysis of the first-order inverted pendulum system to obtain the dynamic equation

At the equilibrium position, linearize the nonlinear dynamic equation

According to the linearized dynamic differential equation, write the state space expression, and analyze the stability and controllability of the system

Design the LQR controller and verify the stability in MATLAB (step response of the closed-loop system)

Firstly, the force analysis of the system is carried out as shown in Figure 2, and the mechanical equations are established for the pendulum and the car body respectively:

Step 2: Simulation With PID and LQR

图像_2022-05-09_181154690.png
图像_2022-05-09_181227003.png
MATLAB CAR PENDULUM
图像_2022-05-09_181506513.png

According to the linearized dynamic equation, it is easy to write the state space expression of the system, as follows.

The A, B, C, D matrices are shown in the following formula.

The steps for LQR to calculate the state feedback matrix K are:
①Select Q and R matrices

②Calculate the matrix P

③ Solve the state feedback matrix K

Note: To solve K, you can use the command K=lqr(A,B,Q,R) in MATLAB

Step 3 : Robot Construction 1st Try

CRAZY CAR PENDULUM

Our first try is to construct a car pendulum system

We made the p and d coefficient large to deal with the non-linearity

However, the car was not fast enough to keep the pendulum balanced

Step 4: Physics

图像_2022-05-09_182002837.png

Our plan B is to contruct the system with reaction wheel.

As the motor accelerates the rotating mass, it applies torque on the flywheel and itself. Move the reaction wheel in the opposite direction to the direction the pendulum needs to spin. The pendulum will start spinning in the desired direction. When the pendulum reaches the desired direction, the rotation of the reaction wheel stops.
If the combined external torque is zero (ie M external = 0), then L1=L2, that is, L=constant vector.

That is to say, for a fixed point o, the total external moment on the particle is zero, then the angular momentum vector of the particle remains unchanged. This conclusion is called the law of conservation of particle angular momentum.

Step 5: Robot Construction 2nd Try

FQRZOQDL2YQJPQL.png
FWJ0X77L2YQJJWK.png

The main structure of the robot is built out of lego.

The pendulum is mounted on a shaft, with motor on top secured by a zip-tie.

A counterweight extension is added to the other side of the pendulum, in order to reduce the power needed to balance the pendulum.

The MPU 6050 module is glued to the pendulum

Due to the pendulum being light and the torque generated by the reaction wheel being relatively small, the tension of the wires actually significantly impacts the system.

Soft and thin silicon are therefore selected to minimize the effect on the impact.

Step 6: Circuit Construction:

图像_2022-05-09_182249130.png

The electronics are based around the Arduino Nano Every microcontroller. The MPU6050 module sends accelerometer and gyroscope data to the Arduino via I2C connection, and the Arduino drives the BTS7960 H-bridge Module with two pwm pins, which then drives the motor. The Arduino is powered by the USB connection from the laptop, which also supplies power to the 5v logical unit of the BTS7960 module.

Our first iteration used the on-board driver and the 520 motor that comes from the elegoo kit. That setup was able to balance if starting from the up-right position, but unable to jump-up from the resting position. Later we replaced them with the current configuration for better performance.

Step 7 : Kalman Filter Design

图像_2022-05-09_182341780.png

Since the angular position data from the accelerometer is noisy, we used a kalman filter to smoothen it.

Since it is hard for us to accurately model the system, and that the cycle time of the arduino seems to differ somewhat depending on the code, we decided to hand-tune the kalman constants. Another issue that further necessitates kalman filters with hand tuning is that the motor is mounted very close to the IMU, and the vibration significantly affects the accelerometer reading, as well as making the system even more not-modelable.

We wrote a program to graph the accelerometer reading, the gyro reading, and the filtered bodyangle. It also spins the motor to simulate the effect of vibrations. We then move the pendulum by hand and adjust the kalman constants to get the bodyangle to be as responsive and smooth as possible.

Here is the result, with blue being accelerometer reading(note the extra noise as the result of vibration), red being gyro reading, and green being the filtered bodyangle. As you can see, the body angle is pretty responsive yet not affected by the noise.

Step 8: Code Design

https://github.com/kevinPOI/ArduinoReactionWheel

(basic readings is for kalman tuning, and reactionWheelV2 is for running) Essentially, the program lets user input zeroing, p, and d through the Arduino Terminal before running. When running, the arduino takes data from the IMU, filters it, then computes a command with PID. The reaction wheel can’t generate torque if it is already spinning at maximum speed. Therefore, we wrote a jump-up program that enables it to resume balancing even if forced to a resting position during a run. If the program senses that the pendulum isn’t making meaningful movement despite high motor command, it will reverse-rev the reaction wheel, then quickly switch back to the correct direction for maximum angular impulse.

Step 9 : Results

Reaction wheel 16299
16299 Reaction Wheel v2

V1: This version balance has a smoother and more stable balancing

https://youtube.com/shorts/_235B6bCXiA?feature=share

V2: This version uses a more powerful motor and more aggressive PID, combining with aforementioned program, to perform jump-ups from resting position, even when forced into it during a run. However it takes more time to settle down.

https://youtube.com/shorts/kEqGXVohef4?feature=share

Works Cited

1.

2. https://www.instructables.com/Inverted-Pendulum-Ro...

3. https://physics.stackexchange.com/questions/154580/how-exactly-does-a-reaction-wheel-work