Final Project files for mBed development.

Dependencies:   m3pi mbed

Files at this revision

API Documentation at this revision

Comitter:
lsaristo
Date:
Sat Nov 15 05:07:24 2014 +0000
Parent:
8:12d780f7443e
Child:
10:94b068b2ce1d
Commit message:
A few minor changes

Changed in this revision

main.c Show annotated file Show diff for this revision Revisions of this file
main.h Show annotated file Show diff for this revision Revisions of this file
--- a/main.c	Thu Nov 13 07:12:31 2014 +0000
+++ b/main.c	Sat Nov 15 05:07:24 2014 +0000
@@ -7,12 +7,20 @@
  *
  * @author  John Wilkey
  */
-#include "project.h"
+#include "main.h"
 
 /** 
  * These are global data Used externally in all other files 
  */
 m3pi        pi;
+
+//
+// Digital inputs to the mBed
+DigitalIn   btn_b(p21);
+
+//
+// Digital outputs from the mBed. Note that by default these are
+// used to drive the 8 LED's on the top board. 
 DigitalOut  pin15(p15);
 DigitalOut  pin16(p16);
 DigitalOut  pin17(p17);
@@ -20,43 +28,65 @@
 DigitalOut  pin19(p19);
 DigitalOut  pin20(p20);
 
+// 
+// mBed onboard LEDs
+DigitalOut  oled_1(LED1);
+DigitalOut  oled_2(LED2);
+DigitalOut  oled_3(LED3);
+DigitalOut  oled_4(LED4);
+
+
 /**
  * @brief Entry point. Main loop.
  */
 int main()
 {
-    pretty_print("PiCO");
-
-    while(1) {
-        wait(2);
-        forward(10, DRIVE_SPEED);
-        wait(2);
-        backward(10, DRIVE_SPEED);
-    }
+    //
+    // Basic setup information
+    DigitalOut olen_1(LED1);
+    pi.locate(0,0);
+    pi.printf("PiCO");
+    pi.locate(0,1);
+    pi.printf("%f mV", pi.battery());
 
     //
-    // Our code should NEVER reach this point. 
-    return EXIT_FAILURE;
+    // Main program loop.
+    while(1) {
+        forward(10);
+        right(90);
+        forward(10);
+        right(90);
+        forward(10);
+        wait(2);
+        left(180);
+    }
+    
+    //
+    // We should never reach this point!
 }
 
-int forward(float amt, float spd)
+int forward(int amt)
 {
-    if(amt > 1) { spd = 1; }
-    pi.forward(spd);
-    wait(amt);
+    pi.locate(0,0);
+    pi.printf("Fwd %d", amt);
+    pi.forward(DRIVE_SPEED);
+    wait(amt*DRIVE_RATE);
     return EXIT_SUCCESS;
 }
 
-int backward(float amt, float spd)
+int backward(int amt)
 {
-    if(amt > 1) { spd = 1; }
-    pi.backward(spd);
-    wait(amt);
+    pi.locate(0,0);
+    pi.printf("Back %d", amt);
+    pi.backward(DRIVE_SPEED);
+    wait(amt*DRIVE_RATE);
     return EXIT_SUCCESS;
 }
 
 int right(float deg)
 {
+    pi.locate(0,0);
+    pi.printf("Right %f", deg);
     pi.right(TURN_SPEED);
     wait(deg/360);
     return EXIT_SUCCESS;
@@ -64,14 +94,9 @@
 
 int left(float deg)
 {
+    pi.locate(0,0);
+    pi.printf("Left %f", deg);
     pi.left(TURN_SPEED);
     wait(deg/360);
     return EXIT_SUCCESS;
-}
-
-void pretty_print(char* msg)
-{
-    pi.locate(0,1);
-    pi.printf(msg);
-}
-
+}
\ No newline at end of file
--- a/main.h	Thu Nov 13 07:12:31 2014 +0000
+++ b/main.h	Sat Nov 15 05:07:24 2014 +0000
@@ -8,32 +8,32 @@
 #ifndef _PROJECT_H
 #define _PROJECT_H
 
-#include <stdio.h>
 #include "mbed.h"
 #include "m3pi.h"
-#define TURN_SPEED 0.25
+#include <string.h>
+#include <stdarg.h>
+#include <stdio.h>
+#define TURN_SPEED  0.25
 #define DRIVE_SPEED 0.5
 #define ERR_SUCCESS 0
 #define ERR_FAILURE 1
-
+#define DRIVE_RATE  1/50
 
 /**
  * @brief Driver forward.
  *
- * @param[in]   amt     Amount to drive forward.
- * @param[in]   spd     Drive speed.
+ * @param[in]   amt     Amount to drive forward. In centimeters.
  * @return              Success or failure. 
  */
-int forward(float amt, float spd);
+int forward(int amt);
 
 /**
  * @brief Drive backward.
  *
- * @param[in]   amt     Amount to drive backward.
- * @param[in]   spd     Drive speed.
+ * @param[in]   amt     Amount to drive backward. In centimeters.
  * @return              Success or failure. 
  */
-int backward(float amt, float spd);
+int backward(int amt);
 
 /**
  * @brief Turn right.
@@ -57,15 +57,6 @@
  * @brief Controller decision logic.
  *
  * Decide what to do next based on the status of the drawing so far.
- *
  */
 void next_action();
-
-/**
- * @brief Print a formatted message to the LCD
- */
-void pretty_print(char* msg);
-
-
-
 #endif