Final Project files for mBed development.

Dependencies:   m3pi mbed

Files at this revision

API Documentation at this revision

Comitter:
lsaristo
Date:
Mon Dec 08 22:43:09 2014 +0000
Parent:
28:9976a94efa83
Child:
30:3211e2962441
Commit message:
Small cleanup and removed unused functions

Changed in this revision

control.c Show diff for this revision Revisions of this file
control.h Show diff for this revision Revisions of this file
main.c Show annotated file Show diff for this revision Revisions of this file
main.c.orig Show diff for this revision Revisions of this file
main.h Show annotated file Show diff for this revision Revisions of this file
user-gui.py Show annotated file Show diff for this revision Revisions of this file
--- a/control.c	Mon Dec 08 10:52:42 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,61 +0,0 @@
-/**
- * @file    control.c
- * @brief   Implemention of robot control algorithms.
- *
- * This file should also contain the logic needed to parse
- * any drawing file and issue motor commands through functions
- * defined in main.h
- *
- * @author  John Wilkey
- */
-#include "control.h"
-#include "main.h"
-extern m3pi pi;
-extern DigitalIn start_button;
-extern DigitalOut oled_2;
-
-void get_ps_file(char* moves)
-{
-    LocalFileSystem local("local");
-    FILE* fp = fopen(_CANVAS_FILE, "r");
-    fseek(fp, 0L, SEEK_END);
-    int size = ftell(fp);
-    fseek(fp, 0L, SEEK_SET);
-    fread(moves, size, 1, fp);
-    fclose(fp);
-}
-
-void robot_loop()
-{    
-    start:
-    pi.cls();
-    pi.locate(0,0);
-    pi.printf("PiCO");
-    pi.locate(0,1);
-    pi.printf("%f mV", pi.battery());
-    wait(.5);
-    while(start_button) {
-        oled_2 = 1;
-        wait(.5);
-        pi.locate(0,0);
-        pi.printf("Ready");
-        oled_2 = 0;
-    }
-    pi.cls();
-    pi.locate(0,0);
-    pi.printf("GO!");
-    wait(.5);
-
-    while(1) {
-        if(!start_button) {
-            pi.stop();
-            goto start;
-        }
-        forward(10);
-        right(90);    
-        
-        //
-        // Right now the robot controller is clearly a very basic
-        // 'hello world' loop that must be changed.      
-    }
-}
\ No newline at end of file
--- a/control.h	Mon Dec 08 10:52:42 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,25 +0,0 @@
-/**
- * @file    control.h
- * @brief   Header file specific to control algorithms.
- * @author  John Wilkey
- */
- 
-#ifndef _CONTROL_H
-#define _CONTROL_H
-
-#include <vector>
-#define _CANVAS_FILE "/local/control.out"     // Should be on local file system. 
-
-/**
- * @brief               Get the formatted file contents from local file.
- * @param[out]  moves   A pointer to the character array of moves
- */
-void get_ps_file(char* moves);
- 
-/** 
- * @brief   A main loop for robot control. Main algorithm for control
- *          should start here
- */
-void robot_loop(); 
-
-#endif
\ No newline at end of file
--- a/main.c	Mon Dec 08 10:52:42 2014 +0000
+++ b/main.c	Mon Dec 08 22:43:09 2014 +0000
@@ -1,72 +1,48 @@
 /**
  * @file    driver.c
- * @brief   Basic driver program for our robot's controller logic. 
+ * @brief   Primary control logic for robot.
  *
- * Maybe add lots of stuff here or maybe split it off into
- * multiple subfiles?
- *
- * @author  John Wilkey - aw hells no! you ain't takin' credit for all this!
+ * @author  John Wilkey
+ * @author  Alec Guertin
+ * @author  Chester Chu
  */
 #include "main.h"
-#include "control.h"
 
-/* These are global data Used externally in all other files */
-m3pi        pi;
-Timer       timer;
-
-/* Digital inputs to the mBed */
-DigitalIn   start_button(p21);
+m3pi        pi;                 /**< m3pi Object for all control operations. */
+Timer       timer;              /**< Timer used to wait in timerWait. */
+DigitalIn   start_button(p21);  /**< Pi start button input on mBed pin 32 */
+int         draw;               /**< Boolean for drawing/moving. */
 
-/*
- * Digital outputs from the mBed. Note that by default these are
- * used to drive the 8 LED's on the top board. 
- */
-DigitalOut  pin13(p13);
-DigitalOut  pin14(p14);
-DigitalOut  pin15(p15);
-DigitalOut  pin16(p16);
-DigitalOut  pin17(p17);
-DigitalOut  pin18(p18);
-DigitalOut  pin19(p19);
-DigitalOut  pin20(p20);
+/* 4 mBed onboard LEDs */
+DigitalOut  oled_1(LED1), oled_2(LED2), oled_3(LED3), oled_4(LED4);
 
-/* mBed onboard LEDs */
-DigitalOut  oled_1(LED1);
-DigitalOut  oled_2(LED2);
-DigitalOut  oled_3(LED3);
-DigitalOut  oled_4(LED4);
+/* 8 LEDs driven from mBed digital outs. */
+DigitalOut  pin13(p13), pin14(p14), pin15(p15), pin16(p16),
+            pin17(p17), pin18(p18), pin19(p19), pin20(p20);         
 
 /* Local File System */
 LocalFileSystem local("local");
 
-/* Boolean for drawing/moving. */
-int draw;
-
-/**
- * @brief Entry point. Main loop.
- */
+/** @brief Entry point. Main loop. */
 int main()
 {
-    FILE *ps_file;
-    int instbuflen = 250;
-    char instbuf[instbuflen];
-    
-    // Basic setup information
+    FILE    *ps_file;
+    float   cal_time;
+    float   pos         = 0;
+    float   over_thresh = 0.05;
+    float   correction  = 0.2*DRIVE_SPEED;
+    int     instbuflen  = 250;
+    char    instbuf[instbuflen];
+ 
     start_button.mode(PullUp);
-        
     pi.cls();
     pi.locate(0,0);
-    pi.printf("PiCO");
+    pi.printf("Ready");
     pi.locate(0,1);
     pi.printf("%f mV", pi.battery());
     wait(.5);
-        
-    // Drawing environment calibration.
     pi.sensor_auto_calibrate();
-    float   pos         = 0;
-    float   over_thresh = 0.05;
-    float   correction  = 0.2*DRIVE_SPEED;
-    float   cal_time;
+    
     wait(1);
 
     do {
@@ -256,9 +232,8 @@
     }
     pi.cls();
     pi.locate(0,0);
-    pi.printf("done");
+    pi.printf("Done");
     while (1);
-    return 0;
 }
 
 int retrieve_inst(char *buf, int *x, int *y, int *draw)
@@ -289,7 +264,7 @@
     return 1;
 }
 
-int forward(int amt)
+void forward(int amt)
 {
     Timer t;
     pi.locate(0,0);
@@ -302,10 +277,9 @@
     pi.right_motor(.7*DRIVE_SPEED);
     t.stop();
     pi.stop();
-    return EXIT_SUCCESS;
 }
 
-int backward(int amt)
+void backward(int amt)
 {
     Timer t;
     t.start();
@@ -315,10 +289,9 @@
     while(t.read_ms() < amt);
     t.stop();
     pi.stop();
-    return EXIT_SUCCESS;
 }
 
-int right(float deg)
+void right(float deg)
 {
     if(deg < 0) {
         return left(-1*deg);
@@ -329,7 +302,6 @@
     while(t.read_ms() < ((float)(deg/360)*TIME_FACT));
     t.stop();
     pi.stop();
-    return EXIT_SUCCESS;
 }
 
 void timerWait(float seconds)
@@ -340,7 +312,7 @@
     t.stop();
 }
 
-int left(float deg)
+void left(float deg)
 {
     if(deg < 0) {
         return right(-1*deg);
@@ -351,7 +323,6 @@
     while(t.read_ms() < ((float)(deg/360)*TIME_FACT));
     t.stop();
     pi.stop();
-    return EXIT_SUCCESS;
 }
 
 void pen_down()
--- a/main.c.orig	Mon Dec 08 10:52:42 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,192 +0,0 @@
-/**
- * @file    driver.c
- * @brief   Basic driver program for our robot's controller logic. 
- *
- * Maybe add lots of stuff here or maybe split it off into
- * multiple subfiles?
- *
- * @author  John Wilkey
- */
-#include "main.h"
-#include "control.h"
-
-/** 
- * These are global data Used externally in all other files 
- */
-m3pi        pi;
-Timer       timer;
-
-//
-// Digital inputs to the mBed
-DigitalIn   start_button(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);
-DigitalOut  pin18(p18);
-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()
-{
-    //
-    // Basic setup information
-    start_button.mode(PullUp);
-        
-    //
-    // Drawing environment calibration.
-    pi.sensor_auto_calibrate();
-    pi.backward(DRIVE_SPEED);
-    float   pos;
-    float   over_thresh = 0.5;
-    float   correction  = 0.1;
-    
-    do {
-        pos = pi.line_position();
-        if(pos > over_thresh) {
-            pi.right_motor(DRIVE_SPEED);
-            pi.left_motor(DRIVE_SPEED - correction);
-        } else if(pos < -over_thresh) {
-            pi.left_motor(DRIVE_SPEED);
-            pi.right_motor(DRIVE_SPEED - correction);
-        } else {
-            pi.forward(DRIVE_SPEED);
-        }
-        pi.cls();
-        pi.locate(0,0);
-        pi.printf("P: %f", pos);
-    } while(pos != -1 && pos != 1);
-    if(pos == 1) {
-        timer.start();
-        pi.forward(DRIVE_SPEED);
-    } else {
-        pi.stop();
-        pi.cls();
-        pi.locate(0,0);
-        pi.printf("LP: %f",pos);
-        while(1);
-    }
-
-    while(pi.line_position() == 1);
-    do {
-        pos = pi.line_position();
-        if(pos > over_thresh) {
-            pi.right_motor(DRIVE_SPEED);
-            pi.left_motor(DRIVE_SPEED - correction);
-        } else if(pos < -over_thresh) {
-            pi.left_motor(DRIVE_SPEED);
-            pi.right_motor(DRIVE_SPEED - correction);
-        } else {
-            pi.forward(DRIVE_SPEED);
-        }
-        pi.cls();
-        pi.locate(0,0);
-        pi.printf("Pos: %f", pos);
-    } while(pos != -1 && pos != 1);
-    if(pos == 1) {
-        oled_1 = 1;
-        timer.stop();
-        pi.stop();           
-    } else {
-        pi.stop();
-        pi.cls();
-        pi.locate(0,0);
-        pi.printf("LP:%f", pos);
-        while(1);
-    }
-    // If we got here, calibration is complete.
-    
-    //
-    // Main program loop.
-    // robot_loop();
-    
-    //
-    // We should never reach this point!
-    while(1);
-}
-
-int forward(int amt)
-{
-    Timer t;
-    t.start();
-    oled_2 = 1;
-    pi.locate(0,0);
-    pi.printf("Fwd %d", amt);
-    pi.forward(DRIVE_SPEED);
-    while(t.read_ms() < amt*DRIVE_RATE*1000);
-    t.stop();
-    oled_2 = 0;
-    pi.stop();
-    return EXIT_SUCCESS;
-}
-
-int backward(int amt)
-{
-    Timer t;
-    oled_3 = 1;
-    pi.locate(0,0);
-    pi.printf("Back %d", amt);
-    pi.backward(DRIVE_SPEED);
-    t.start();
-    while(t.read_ms() < amt*DRIVE_RATE*1000);
-    t.stop();
-    oled_3 = 0;
-    pi.stop();
-    return EXIT_SUCCESS;
-}
-
-int right(float deg)
-{
-    Timer t;
-    oled_4 = 1;
-    pi.locate(0,0);
-    pi.printf("Right %f", deg);
-    pi.right(TURN_SPEED);
-    t.start();
-    while(t.read_ms() < (deg/360)*1000);
-    t.stop();
-    oled_4 = 0;
-    pi.stop();
-    return EXIT_SUCCESS;
-}
-
-int left(float deg)
-{
-    Timer t;
-    oled_4 = 1;
-    oled_2 = 1;
-    pi.locate(0,0);
-    pi.printf("Left %f", deg);
-    pi.left(TURN_SPEED);
-    t.start();
-    while(t.read_ms() < (deg/360)*1000);
-    t.stop();
-    oled_4 = 0;
-    oled_2 = 0;
-    pi.stop();
-    return EXIT_SUCCESS;
-}
-
-void pen_down()
-{
-    oled_1 = 1;
-}
-
-void pen_up()
-{
-    oled_1 = 0;
-}
\ No newline at end of file
--- a/main.h	Mon Dec 08 10:52:42 2014 +0000
+++ b/main.h	Mon Dec 08 22:43:09 2014 +0000
@@ -3,6 +3,8 @@
  * @brief   Main header file for includes and whatnot 
  *          for the other project files.
  * @author  John Wilkey
+ * @author  Alec Guertin
+ * @author  Chester Chu
  */
  
 #ifndef _MAIN_H
@@ -24,10 +26,7 @@
 #define CLOSE_ENOUGH .0008
 
 
-/**
- * @brief   move the robot from its current position to (x,y)
- *
- */
+/** @brief Move the robot from its current position to (x,y) */
 void move(int x, int y, int draw);
 
 /**
@@ -43,52 +42,42 @@
 int retrieve_inst(char *buf, int *x, int *y, int *draw);
 
 /**
- * @brief Driver forward.
+ * @brief Driver forward for a time.
  *
- * @param[in]   amt     Amount to drive forward. In centimeters.
- * @return              Success or failure. 
+ * @param[in]   amt     Amount to drive forward. In milliseconds.
  */
-int forward(int amt);
+void forward(int amt);
 
 /**
- * @brief Drive backward.
+ * @brief Drive backward for a time.
  *
- * @param[in]   amt     Amount to drive backward. In centimeters.
- * @return              Success or failure. 
+ * @param[in]   amt     Amount to drive backward. In milliseconds.
  */
-int backward(int amt);
+void backward(int amt);
 
 /**
- * @brief Turn right.
+ * @brief Turn right by some angle.
  *
- * @param[in]   deg     Desired final turn angle from starting position.
- * @param[in]   spd     Desired turning speed.
- * @return              Success or failure. 
+ * @param[in]   deg     Desired final turn angle in degrees from start.
+ *                      Note that a negative angle will turn in the opposite
+ *                      direction.
  */
-int right(float deg);
+void right(float deg);
 
 /**
- * @brief Turn left.
+ * @brief Turn left by some angle.
  *
- * @param[in]   deg     Desired final turn angle from starting position.
- * @param[in]   spd     Desired turning speed.
- * @return              Success or failure. 
+ * @param[in]   deg     Desired final turn angle in degrees from start.
+ *                      Note that a negative angle will turn in the opposite
+ *                      direction.
  */
-int left (float deg);
+void left (float deg);
 
-/**
- * @brief Enable pen motion. 
- *
- * Note that at the moment, for simplicity, this method just activates an LED
- * on the expansion board to indicate that the pen should be in DOWN mode. 
- */
+/** @brief Lower pen intro drawing position */
 void pen_down();
  
- /**
-  * @brief Raise pen
-  */
-void pen_up();
-  
+/** @brief Raise pen into moveto position */
+void pen_up();  
 
 /**
  * @brief Controller decision logic.
@@ -98,10 +87,12 @@
 void next_action();
 
 /**
- * @brief Wait for a number of seconds, possibly fractional.
+ * @brief   Wait for a number of seconds, possibly fractional.
+ * 
+ * Timer resolution is on the order of microseconds. A negative wait
+ * time does nothing. 
  *
- * This is because mBed wait() function SUCKS
+ * @param[in]   amt     Time to wait, in seconds.
  */
-void timerWait(float);
-
-#endif
+void timerWait(float amt);
+#endif
\ No newline at end of file
--- a/user-gui.py	Mon Dec 08 10:52:42 2014 +0000
+++ b/user-gui.py	Mon Dec 08 22:43:09 2014 +0000
@@ -38,7 +38,7 @@
 """paint.py: not exactly a paint program. just a smooth line drawing demo."""
 
 TEMP_FILE = "canvas-temp.ps"
-OUTPUT_FILE = "control.out"
+OUTPUT_FILE = "test.ps"
 b1 = "up"
 xold, yold = None, None
 height = 600