wheelchair code for driver assitance

Dependencies:   mbed

Fork of wheelchairalexa by ryan lin

Files at this revision

API Documentation at this revision

Comitter:
ryanlin97
Date:
Fri Aug 17 03:10:39 2018 +0000
Parent:
11:75f0f13ff6c1
Commit message:
code for driver assistance;

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
wheelchair.cpp Show annotated file Show diff for this revision Revisions of this file
wheelchair.h Show annotated file Show diff for this revision Revisions of this file
diff -r 75f0f13ff6c1 -r 0e5a0571b497 main.cpp
--- a/main.cpp	Thu Aug 16 16:42:45 2018 +0000
+++ b/main.cpp	Fri Aug 17 03:10:39 2018 +0000
@@ -3,14 +3,17 @@
 AnalogIn x(A0);
 AnalogIn y(A1);
 
-DigitalOut off(D0);
-DigitalOut on(D1);
+DigitalOut on(D12);
+DigitalOut off(D11);
 DigitalOut up(D2);
 DigitalOut down(D3);
 
 bool manual = false;
+bool leftBound = false;
+bool rightBound = false;
+bool straightBound = false;
 
-Serial pc(USBTX, USBRX, 57600);
+Serial pc(USBTX, USBRX, 9600);
 Timer t;
 
 Wheelchair smart(xDir,yDir, &pc, &t);
@@ -18,62 +21,39 @@
 
 int main(void)
 {
-    pc.printf("hello\n");
+    smart.stop();
     while(1) {
-        if( pc.readable()) {
-            char c = pc.getc();
-            pc.printf("hello\n");
-            if( c == 'w') {
-                pc.printf("up \n");
-                smart.forward();
-            }
-
-            else if( c == 'a') {
-                pc.printf("left \n");
-                smart.left();
-            }
-
-            else if( c == 'd') {
-                pc.printf("right \n");
-                smart.right();
-            }
-
-            else if( c == 's') {
-                pc.printf("down \n");
-                smart.backward();
-            }
-
-            else if( c == 'r') {
-                smart.turn_right(90);
-            }
-
-            else if( c == 'l') {
-                smart.turn_left(90);
-            }
-
-            else if( c == 't') {
-                char buffer[256];
-                pc.printf ("Enter a long number: ");
-                fgets (buffer, 256, stdin);
-                int angle = atoi (buffer);
-                
-                if(angle == 0) {
-                    pc.printf("invalid input try again\n");
-                    }
-                else {
-                smart.turn(angle);
-                    }
-                    
-            } 
-            
-            else if( c == 'm') {
                 pc.printf("turning on joystick\n");
                 manual = true;
                 t.reset();
                 while(manual) {
-                    smart.move(x,y);
+                    smart.move(x,y,leftBound,rightBound,straightBound);
                     if( pc.readable()) {
                         char d = pc.getc();
+                        if( d == 'l') {
+                            leftBound = true;
+                        }
+
+                        if (d == 'e') {
+                            leftBound = false;
+                        }
+
+                        if( d == 'f') {
+                            straightBound = true;
+                        }
+
+                        if (d == 'o') {
+                            straightBound = false;
+                        }
+
+                        if( d == 'r') {
+                            rightBound = true;
+                        }
+
+                        if( d == 'i') {
+                            rightBound = false;
+                        }
+
                         if( d == 'm') {
                             pc.printf("turning off joystick\n");
                             manual = false;
@@ -82,17 +62,8 @@
                 }
             }
 
-            else {
-                pc.printf("none \n");
-                smart.stop();
-            }
-        }
-
-        else {
-            smart.stop();
-        }
-        wait(process);
-    }
-
+    wait(process);
 }
 
+
+
diff -r 75f0f13ff6c1 -r 0e5a0571b497 wheelchair.cpp
--- a/wheelchair.cpp	Thu Aug 16 16:42:45 2018 +0000
+++ b/wheelchair.cpp	Fri Aug 17 03:10:39 2018 +0000
@@ -21,25 +21,6 @@
     ti = time;
 }
 
-/*
-* joystick has analog out of 200-700, scale values between 1.3 and 3.3
-*/
-void Wheelchair::move(float x_coor, float y_coor)
-{
-
-    float scaled_x = ((x_coor * 1.6f) + 1.7f)/3.3f;
-    float scaled_y = (3.3f - (y_coor * 1.6f))/3.3f;
-    
-   // lowPass(scaled_x);
-    //lowPass(scaled_y);
-    
-    x->write(scaled_x);
-    y->write(scaled_y);
-    
-    //out->printf("yaw %f\n", imu->yaw());
-
-}
-
 void Wheelchair::forward()
 {
     x->write(high);
@@ -86,3 +67,31 @@
  return;   
 }
 
+/*
+* joystick has analog out of 200-700, scale values between 1.3 and 3.3
+*/
+void Wheelchair::move(float x_coor, float y_coor, bool leftbound, bool rightbound, bool straightbound)
+{
+
+
+    float scaled_x = ((x_coor * 1.6f) + 1.7f)/3.3f;
+    float scaled_y = (3.3f - (y_coor * 1.6f))/3.3f;
+    
+    if(leftbound && (scaled_x > 2.5) ) {
+            Wheelchair::stop();
+        }
+    
+    else if(rightbound && (scaled_x < 2.5) ) { 
+            Wheelchair::stop();
+        }
+    
+    else if(straightbound && (scaled_y > 2.5) ) { 
+            Wheelchair::stop();
+        }
+        
+    else {
+    x->write(scaled_x);
+    y->write(scaled_y);
+    }
+}
+
diff -r 75f0f13ff6c1 -r 0e5a0571b497 wheelchair.h
--- a/wheelchair.h	Thu Aug 16 16:42:45 2018 +0000
+++ b/wheelchair.h	Fri Aug 17 03:10:39 2018 +0000
@@ -15,7 +15,7 @@
 {
 public:
     Wheelchair(PinName xPin, PinName yPin, Serial* pc, Timer* time);
-    void move(float x_coor, float y_coor);
+    void move(float x_coor, float y_coor, bool, bool, bool);
     double turn_right(int deg);
     double turn_left(int deg);
     void turn(int deg);