Segway..00_00_03_04.Still001.png

PID controlled segway

BRIEF

‘write a python program that uses PID control to create a self balancing two wheeled Segway. Design the program so that when music is played, the Segway ‘dances’ to the beat and uses different dance moves for different phases of music’

March 2019

 

SKILLS

 

coding

electronics

 
 

This project was completed as a group, I mainly took charge of the beat detection algorithm and the design and tuning of the PID algorithm.

 

 
 
 
 

beat detection

We made the robot dance in time to the music by creating a beat detection algorithm. This would calculate the instantaneous energy received from a microphone and repeatedly sample to determine if a beat had occurred. Our algorithm then performed a real time BPM calculation of the song and moved the motors accordingly. We detected changes in the songs phase by monitoring changes in the BPM and sudden changes in the overall song energy.

 
IMG_1102%5B4008%5D.jpg
 

self balancing

 
simplified system diagram for the segway

simplified system diagram for the segway

 

A two wheeled segway is naturally unstable. It wants to fall over. In order to prevent this our team used a feedback control loop with PID control. We used a gyroscope and an accelerometer in combination with each other in order to calculate the actual angle of tilt of the segway. Each sensor provided a slightly different corrupted version of the angle, so we combined them using a complementary filter.

 
 
complementary filter system diagram - showing how the two different angle values are combined in order to produce an accurate angle reading

complementary filter system diagram - showing how the two different angle values are combined in order to produce an accurate angle reading

 
 

As the segway is unstable, the angle of the top panel is constantly changing. In order to deal with this volatile system, we used feedback control to allow the system to adjust its performance. In particular we used PID (proportional, integral derivative) control. This is an advanced form of a feedback loop, which forced the motors to quickly act to correct the angle - without overshooting the mark or moving too slowly.

 
 
PID control system - this is a feedback loop, the difference between the actual speed and the set speed is constantly used to adjust the real speed

PID control system - this is a feedback loop, the difference between the actual speed and the set speed is constantly used to adjust the real speed

 
 

This project was one of my first that incorporated complex electrical system control. Being able code a functioning PID controller that worked in real time was incredibly satisfying, and has hugely improved my confidence to tackle more complex electronics based problems. The live analysis of music was a skill I used extensively when programming the matched filter to recognise certain sounds in the MICO project.