Inverted Pendulum Project
This presentation outlines our team's work on an inverted pendulum. We
explored control methods and mechanical equations. We encountered
challenges but achieved a working model. This project demonstrates
principles of control systems and robotics.
Control Method Selection
Initial Approach: Hamiltonian Physics The Pivot: Newtonian Physics
Initially, we planned to use Hamiltonian physics. This was for mechanical equations with LQR control. We pivoted to Newtonian physics and PID control. PID control adjusts voltage to control the system.
Motor Control and Optimization
Manual Control
We controlled the motor speed and angle manually. This optimization was done with the motor controller.
Voltage Adjustment
We adjusted the voltage to identify optimal levels. This helped to find the correct voltage.
We tuned the motor controller. We found the ideal operating voltage.
IMU Integration Challenges
1 Data Collection with IMU
We began data collection with the IMU. wiring problem then emerged.
2 Wiring Issue Resolved
Loose wiring was fixed with soldering. We used copper wires with pin headers.
3 getting angles from acc data
using appropriate formulas as described in our code, we got the angle from the acceleration dataqwer
Code Development
PID Control Code Synchronization
We developed basic code for PID control. We also made a code for motor control The PID and motor control and IMU codes
and data collection from IMU
were synchronized
Optimization
Values of Kp, Ki, and Kd need optimization. The Kp, Ki and Kd are to be optimized next.
Our code development was split into stages. We worked to combine it into a single system.
Header and Library Inclusion
#include <Wire.h>
#include <MPU9250.h>
<Wire.h>
I2C library for MPU9250 communication.
<MPU9250.h>
MPU9250 sensor library for easy use.
Pin Definitions
PWM_PIN and DIR_PIN define the motor control pins.
• Pin 9 for Pulse Width Modulation (PWM) to control motor speed.
• Pin 8 for the motor's direction.
PID Tuning Variables
Kp, Ki, Kd
PID constants adjust motor response.
40.0 0.4 8.0
Kp Ki Kd
Proportional gain Integral gain Derivative gain
Tuning variables enable precise control. The gains help optimize the system to desired response of voltage.
• errorSum: Accumulates error for the integral term.
• previousError: Stores the last error to calculate the derivative term.
Main Loop: Sensor Data Collection
Variable Purpose
avgAngleY Average angle data
avgGyroZ Average gyro data
sampleCount Stable average of readings
Sensor data averages stabilize readings. This averaging helps to create accurate control signals.
CODE
#include <Wire.h>
#include <MPU9250.h>
MPU9250 mpu;
#define PWM_PIN 9
#define DIR_PIN 8
// PID tuning variables
float Kp = 40.0;
float Ki = 0.4;
float Kd = 8.0;
float errorSum = 0;
float previousError = 0;
void setup() {
[Link](115200);
[Link]();