EE149
/
FinalProject
Final Project files for mBed development.
control.c@10:94b068b2ce1d, 2014-11-15 (annotated)
- Committer:
- lsaristo
- Date:
- Sat Nov 15 23:03:06 2014 +0000
- Revision:
- 10:94b068b2ce1d
- Child:
- 11:a30f30d3066e
Started working on control files for robot movement control.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lsaristo | 10:94b068b2ce1d | 1 | /** |
lsaristo | 10:94b068b2ce1d | 2 | * @file control.c |
lsaristo | 10:94b068b2ce1d | 3 | * @brief Implemention of robot control algorithms. |
lsaristo | 10:94b068b2ce1d | 4 | * |
lsaristo | 10:94b068b2ce1d | 5 | * This file should also contain the logic needed to parse |
lsaristo | 10:94b068b2ce1d | 6 | * any drawing file and issue motor commands through functions |
lsaristo | 10:94b068b2ce1d | 7 | * defined in main.h |
lsaristo | 10:94b068b2ce1d | 8 | * |
lsaristo | 10:94b068b2ce1d | 9 | * @author John Wilkey |
lsaristo | 10:94b068b2ce1d | 10 | */ |
lsaristo | 10:94b068b2ce1d | 11 | #include "control.h" |
lsaristo | 10:94b068b2ce1d | 12 | #include "main.h" |
lsaristo | 10:94b068b2ce1d | 13 | extern m3pi pi; |
lsaristo | 10:94b068b2ce1d | 14 | extern DigitalIn start_button; |
lsaristo | 10:94b068b2ce1d | 15 | |
lsaristo | 10:94b068b2ce1d | 16 | void get_ps_file(char* moves) |
lsaristo | 10:94b068b2ce1d | 17 | { |
lsaristo | 10:94b068b2ce1d | 18 | char* contents; |
lsaristo | 10:94b068b2ce1d | 19 | FILE* fp = fopen(_CANVAS_FILE, "r"); |
lsaristo | 10:94b068b2ce1d | 20 | fseek(fp, 0L, SEEK_END); |
lsaristo | 10:94b068b2ce1d | 21 | int size = ftell(fp); |
lsaristo | 10:94b068b2ce1d | 22 | fseek(fp, 0L, SEEK_SET); |
lsaristo | 10:94b068b2ce1d | 23 | contents = (char*)malloc(size); |
lsaristo | 10:94b068b2ce1d | 24 | fread(contents, size, 1, fp); |
lsaristo | 10:94b068b2ce1d | 25 | fclose(fp); |
lsaristo | 10:94b068b2ce1d | 26 | } |
lsaristo | 10:94b068b2ce1d | 27 | |
lsaristo | 10:94b068b2ce1d | 28 | void robot_loop() |
lsaristo | 10:94b068b2ce1d | 29 | { |
lsaristo | 10:94b068b2ce1d | 30 | start: |
lsaristo | 10:94b068b2ce1d | 31 | while(1) { |
lsaristo | 10:94b068b2ce1d | 32 | if(start_button) { |
lsaristo | 10:94b068b2ce1d | 33 | pi.stop(); |
lsaristo | 10:94b068b2ce1d | 34 | goto start; |
lsaristo | 10:94b068b2ce1d | 35 | } |
lsaristo | 10:94b068b2ce1d | 36 | |
lsaristo | 10:94b068b2ce1d | 37 | // |
lsaristo | 10:94b068b2ce1d | 38 | // Right now the robot controller is clearly a very basic |
lsaristo | 10:94b068b2ce1d | 39 | // 'hello world' loop that must be changed. |
lsaristo | 10:94b068b2ce1d | 40 | forward(10); |
lsaristo | 10:94b068b2ce1d | 41 | right(90); |
lsaristo | 10:94b068b2ce1d | 42 | forward(10); |
lsaristo | 10:94b068b2ce1d | 43 | right(90); |
lsaristo | 10:94b068b2ce1d | 44 | forward(10); |
lsaristo | 10:94b068b2ce1d | 45 | wait(2); |
lsaristo | 10:94b068b2ce1d | 46 | left(180); |
lsaristo | 10:94b068b2ce1d | 47 | } |
lsaristo | 10:94b068b2ce1d | 48 | } |