Code Monkey home page Code Monkey logo

selfbalancingrobot's Introduction

Controller for self-balancing robot ๐Ÿšก

This is an arduino sketch for an inverted pendulum with two wheels (a self balancing robot). Due to the unstable nature of this platform, it must be actively stabilized to maintain balance.

Operation

The program provides stabilization through an MPU6050 IMU and two brushed DC motors driven by an H-bridge. It uses three PID loops acting simultaneously:

  • Pitch stabilization: This is the dominant PID controller of the system. It uses the pitch angle of the vehicle as a proportional term to keep the vehicle upright by accelerating into gravity.

  • Position stabilization: It estimates the velocity by integrating pitch angle, which is proportional to the lateral acceleration (at small angles), and this is integrated again to approximate position (the double integral of the pitch angle). Both are used as the derivative and proportional term respectively. Their combined effect prevent the vehicle from drifting laterally and counters any change in center of gravity.

$$ a_x \propto \theta_x $$

$$ v_x = \int{a_x}dt \propto \int{ \theta_x dt } $$

$$ x = \int{v_x}dt \propto \int{ \int{ \theta_x dt^2 } } $$

  • Yaw stabilization: A controller that maintains heading by using as a proportional term the angular velocity of the yaw axis. It counters the open-loop nature of the motor control, wherein one motor can spin faster and cause the vehicle to turn.

Ultimately, the unstable axis is only stabilized by the measured pitch angle.

Note: Both motors are driven with pulse frequency modulation to counter magnetic cogging and stiction. The duty is cycle is long enough so that each pulse causes the motors to rotate one magnetic pole. Such a waveform provides precise control over low-speed rotation at the cost of jerky movement. This precision is necessary to reduce under and over correction when the vehicle is nearly vertical.

Driving the motors like this causes them to behave similar to a stepper motor, albeit with much less precision, larger steps, and less torque.

Dependencies

These are the libraries needed to compile this sketch:

Schematic

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.