Final Project files for mBed development.

Dependencies:   m3pi mbed

control.c

Committer:
lsaristo
Date:
2014-11-16
Revision:
12:1aa6b8a74136
Parent:
11:a30f30d3066e
Child:
14:41fa8b95a9ab

File content as of revision 12:1aa6b8a74136:

/**
 * @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)
{
    char* contents;
    FILE* fp = fopen(_CANVAS_FILE, "r");
    fseek(fp, 0L, SEEK_END);
    int size = ftell(fp);
    fseek(fp, 0L, SEEK_SET);
    contents = (char*)malloc(size);
    fread(contents, size, 1, fp);
    memcpy(moves, contents, size);
    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.      
    }
}