ECE 4180 Mini Project Balancing Robot Nico van Duijn Samer Mabrouk 3/6/2015 This project consists of a robot balancing on two wheels. We use the 9-axis IMU LSM9DS0 to give us Accelerometer and Gyroscope data about the current angle and angular velocity of the robot. This data is then filtered using complementary filters and PID control to drive the two motors. The motors are controlled through digital outputs in their direction and their seepd by PWM using an H-bridge

Dependencies:   LSM9DS0 mbed

Files at this revision

API Documentation at this revision

Comitter:
nicovanduijn
Date:
Mon Apr 06 16:25:18 2015 +0000
Parent:
1:bf71a7bd2d3e
Child:
3:dd0c62b586ea
Commit message:
Starting point;

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Fri Mar 06 17:12:47 2015 +0000
+++ b/main.cpp	Mon Apr 06 16:25:18 2015 +0000
@@ -44,7 +44,7 @@
 float kp = 800;                                                 // Proportional gain
 float kd = 90;                                                  // Derivative gain
 float ki = 4;                                                   // Integrative gain
-float OVERALL_SCALAR = 7000;                                   // Overall scalar that speed is divided by
+float OVERALL_SCALAR = 7000;                                    // Overall scalar that speed is divided by
 float accBias = 0;                                              // Accelerometer Bias
 float gyroBias = 0;                                             // Gyro Bias
 float accAngle = 0;                                             // Global to hold angle measured by Accelerometer
@@ -94,7 +94,7 @@
     dAngle = -(imu.gx-gyroBias);                                // This is angular velocity
     iAngle=(0.99*iAngle+0.01*gyroAngle);                        // Sorta- running average-integral thing
     if(abs(pAngle)>=0.6&&abs(pAngle)<=25) {                     // If it is tilted enough, but not too much
-        speed=-(ki*iAngle+kd*dAngle+kp*pAngle)/OVERALL_SCALAR;   // drive to correct
+        speed=-(ki*iAngle+kd*dAngle+kp*pAngle)/OVERALL_SCALAR;  // drive to correct
         if(speed<-1) speed=-1;                                  // Cap if undershoot
         else if(speed>1) speed=1;                               // Cap if overshoot
     } else speed=0;                                             // If we've fallen over or are steady on top