obstacle avoidance with sensors and servo installed

Dependencies:   Adafruit_GFX GPS QEI Servo mbed

Files at this revision

API Documentation at this revision

Comitter:
anushachowdary16
Date:
Thu Oct 02 06:41:36 2014 +0000
Commit message:
need to revise

Changed in this revision

Adafruit_GFX.lib Show annotated file Show diff for this revision Revisions of this file
FatFileSystem.lib Show annotated file Show diff for this revision Revisions of this file
GPS.lib Show annotated file Show diff for this revision Revisions of this file
LSM303D.lib Show annotated file Show diff for this revision Revisions of this file
MSCFileSystem.lib Show annotated file Show diff for this revision Revisions of this file
PololuQik2.lib Show annotated file Show diff for this revision Revisions of this file
QEI.lib Show annotated file Show diff for this revision Revisions of this file
SDHCFileSystem.lib Show annotated file Show diff for this revision Revisions of this file
Servo.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 21a2de59d16f Adafruit_GFX.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Adafruit_GFX.lib	Thu Oct 02 06:41:36 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/nkhorman/code/Adafruit_GFX/#969ca9fe5e2b
diff -r 000000000000 -r 21a2de59d16f FatFileSystem.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/FatFileSystem.lib	Thu Oct 02 06:41:36 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/DrCoyle/code/FatFileSystem/#88f22c32a456
diff -r 000000000000 -r 21a2de59d16f GPS.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/GPS.lib	Thu Oct 02 06:41:36 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/8fromPi/code/GPS/#1d60e6a0ffd9
diff -r 000000000000 -r 21a2de59d16f LSM303D.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LSM303D.lib	Thu Oct 02 06:41:36 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/DrCoyle/code/LSM303D/#f186dd92c836
diff -r 000000000000 -r 21a2de59d16f MSCFileSystem.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MSCFileSystem.lib	Thu Oct 02 06:41:36 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/DrCoyle/code/MSCFileSystem/#49f6277bdead
diff -r 000000000000 -r 21a2de59d16f PololuQik2.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PololuQik2.lib	Thu Oct 02 06:41:36 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/DrCoyle/code/PololuQik2/#a87506b24191
diff -r 000000000000 -r 21a2de59d16f QEI.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/QEI.lib	Thu Oct 02 06:41:36 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/aberk/code/QEI/#5c2ad81551aa
diff -r 000000000000 -r 21a2de59d16f SDHCFileSystem.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SDHCFileSystem.lib	Thu Oct 02 06:41:36 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/DrCoyle/code/SDHCFileSystem/#248d03543f5f
diff -r 000000000000 -r 21a2de59d16f Servo.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Servo.lib	Thu Oct 02 06:41:36 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/simon/code/Servo/#36b69a7ced07
diff -r 000000000000 -r 21a2de59d16f main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Oct 02 06:41:36 2014 +0000
@@ -0,0 +1,183 @@
+#include "mbed.h"
+#include "Adafruit_SSD1306.h"
+#include "LSM303D.h"
+#include "QEI.h"
+#include "MSCFileSystem.h"
+#include "SDHCFileSystem.h"
+#include "PololuQik2.h"
+#include "GPS.h"
+#include "Servo.h"
+
+// an SPI sub-class that provides a constructed default format and frequency
+class SPI2 : public SPI
+{
+public:
+    SPI2(PinName mosi, PinName miso, PinName clk) : SPI(mosi,miso,clk)
+    {
+        format(8,3);
+        frequency(2000000);
+    };
+};
+
+//Serial pc(USBTX,USBRX);
+SPI2 gSpi(p5,p6,p7);
+Adafruit_SSD1306 gOled(gSpi,p8,p11,p12);
+LSM303D comp(gSpi,p15);
+QEI Left(p30,p29,NC,48,QEI::X4_ENCODING);  // encoder object for Left wheel
+QEI Right(p17,p16,NC,48,QEI::X4_ENCODING);  // encoder object for Left wheel
+SDFileSystem sd(p5, p6, p7, p26, "sd"); // mosi, miso, sclk, cs
+PololuQik2 motors(p13,NC);
+Serial computer(p28, p27); // tx, rx read from bluetooth module
+GPS gpsAda(NC,p14,9600);
+AnalogIn IR(p18);
+
+Timer t;
+
+int main()
+{
+    int pulses[2], check, mag[3], acc[3], i=0;
+    float hdg;
+    int distance;                 //Variable to store the distance calculated from the sensor
+    int triggerDistance = 30;     //The distance we want the robot to look for a new path
+    int fDistance;                //Variable to store the distance in front of the robot
+    int lDistance;                //Variable to store the distance on the left side of the robot
+    int rDistance;                //Variable to store the distance on the right side of the robot
+    
+    computer.baud(115200);
+    motors.begin();
+    
+    //display CoyleBot Logo
+    gOled.display();
+    wait(1.0);
+    
+    //Initialization returns 1 if talking to right device
+    check=comp.initialize();
+    
+    //Set scales and offset for compass, could spin at start-up to get
+    comp.setOffset(0, 0, 0); // example calibration
+    comp.setScale(1.00, 1.00, 1.00);    // example calibration
+    
+    t.reset();
+    t.start();
+    
+    while(1)
+     {        
+        //Compass, Accelerometer Data
+        mag[0]=comp.magnitometer(1000);
+        mag[1]=comp.magnitometer(1000);
+        mag[2]=comp.magnitometer(1000);
+        acc[0]=comp.accelerometer(1000);
+        acc[1]=comp.accelerometer(1000);
+        acc[2]=comp.accelerometer(1000);
+        hdg=comp.heading();
+        
+        //Get Wheel Encoder Pulses
+        pulses[0]=Left.getPulses();
+        pulses[1]=Right.getPulses();
+        
+        //Clear screen information so it can be written to
+        gOled.clearDisplay();
+        
+        //Go to top of screen
+        gOled.setCursor(20,20);
+       void moveForward();
+           { 
+           //Print RC Commands to SCREEN
+            gOled.printf("Forward  :");
+            gOled.printf("%d %d %d %d %d %d %d %d %d %d %f %f \r\n", i, t.read_ms(),mag[0],mag[1],mag[2],acc[0],acc[1],acc[2],pulses[0],pulses[1],gpsAda.latitude,gpsAda.longitude);
+            gOled.display();
+            //sets the speed of the motor 0, must be a value between -255 and 255
+            motors.setMotor0Speed(100);  
+            //sets the speed of the motor 0, must be a value between -255 and 255
+            motors.setMotor1Speed(100);
+            }
+        void moveBackward();
+            {
+              //Print RC Commands to SCREEN
+            gOled.printf("Backward  :");
+            gOled.printf("%d %d %d %d %d %d %d %d %d %d %f %f \r\n", i, t.read_ms(),mag[0],mag[1],mag[2],acc[0],acc[1],acc[2],pulses[0],pulses[1],gpsAda.latitude,gpsAda.longitude);
+            gOled.display();
+              //sets the speed of the motor 0, must be a value between -255 and 255
+            motors.setMotor0Speed(-100);  
+            //sets the speed of the motor 0, must be a value between -255 and 255
+            motors.setMotor1Speed(-100);
+            }
+        
+       int scan();                                //Get the distance retrieved
+          fDistance = distance;                  //Set that distance to the front distance
+          if(fDistance < triggerDistance){       //If there is something closer than 30cm in front of us
+          moveBackward();                      //Move Backward for a second
+          wait(1000); 
+          void moveRight();                         //Turn Right for half a second
+          wait(500);
+          void moveStop();                          //Stop
+          scan();                              //Take a reading
+          rDistance = distance;                //Store that to the distance on the right side
+          void moveLeft();
+          wait(1000);                         //Turn left for a second
+          moveStop();                          //Stop
+          scan();                              //Take a reading
+          lDistance = distance;                //Store that to the distance on the left side
+          if(lDistance < rDistance){           //If the distance on the left is smaller than that of the right
+          moveRight();                       //Move right for a second
+          wait(1000);
+          moveForward();                     //Then move forward
+    }
+        else
+        {
+      moveForward();                     //If the left side is larger than the right side move forward
+        }
+  }
+         else
+         {
+    moveForward();                       //If there is nothing infront of the robot move forward
+        }
+}
+
+  int scan()
+      {
+      time = sonar.ping();                  //Send out a ping and store the time it took for it to come back in the time variable
+      distance = time / US_ROUNDTRIP_CM;    //Convert that time into a distance
+      if(distance == 0){                    //If no ping was recieved
+        distance = 100;                     //Set the distance to max
+      }
+  delay(10);
+
+
+    void moveBackward()
+        {
+      rightServo.write(180);
+      leftServo.write(0); 
+         }
+
+    void moveForward()
+        {
+          rightServo.write(0);
+          leftServo.write(180);
+        }
+
+    void moveRight()
+        {
+          rightServo.write(0);
+          leftServo.write(0);  
+        }
+
+    void moveLeft()
+        {
+      rightServo.write(180);
+      leftServo.write(180);
+        }
+
+    void moveStop()
+        {
+          rightServo.write(90);
+          leftServo.write(95); 
+        }
+
+       
+
+        i++;
+        
+        
+    }
+}
diff -r 000000000000 -r 21a2de59d16f mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Oct 02 06:41:36 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/552587b429a1
\ No newline at end of file