Code for an autonomous plane I'm building. Includes process scheduling, process communication, and hardware sensor interfacing (via I2C). NOTE: currently in development, source code will be updated frequently.
control.cpp@0:0c627ff4c5ed, 2013-10-30 (annotated)
- Committer:
- teamgoat
- Date:
- Wed Oct 30 02:31:43 2013 +0000
- Revision:
- 0:0c627ff4c5ed
- Child:
- 1:1abb115c2005
First compiled version (reads sensors, I think)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
teamgoat | 0:0c627ff4c5ed | 1 | #include "control.h" |
teamgoat | 0:0c627ff4c5ed | 2 | #include "sensor.h" |
teamgoat | 0:0c627ff4c5ed | 3 | #include "steps.h" |
teamgoat | 0:0c627ff4c5ed | 4 | #include "mbed.h" |
teamgoat | 0:0c627ff4c5ed | 5 | |
teamgoat | 0:0c627ff4c5ed | 6 | #define MAXPROC 15 |
teamgoat | 0:0c627ff4c5ed | 7 | |
teamgoat | 0:0c627ff4c5ed | 8 | process procs[MAXPROC] = {0}; |
teamgoat | 0:0c627ff4c5ed | 9 | |
teamgoat | 0:0c627ff4c5ed | 10 | void schedule(); |
teamgoat | 0:0c627ff4c5ed | 11 | void init_procs(); |
teamgoat | 0:0c627ff4c5ed | 12 | |
teamgoat | 0:0c627ff4c5ed | 13 | |
teamgoat | 0:0c627ff4c5ed | 14 | int main() |
teamgoat | 0:0c627ff4c5ed | 15 | { |
teamgoat | 0:0c627ff4c5ed | 16 | init_procs(); |
teamgoat | 0:0c627ff4c5ed | 17 | while (true) |
teamgoat | 0:0c627ff4c5ed | 18 | { |
teamgoat | 0:0c627ff4c5ed | 19 | get_sensor_data(); |
teamgoat | 0:0c627ff4c5ed | 20 | schedule(); |
teamgoat | 0:0c627ff4c5ed | 21 | } |
teamgoat | 0:0c627ff4c5ed | 22 | } |
teamgoat | 0:0c627ff4c5ed | 23 | |
teamgoat | 0:0c627ff4c5ed | 24 | void init_procs() |
teamgoat | 0:0c627ff4c5ed | 25 | { |
teamgoat | 0:0c627ff4c5ed | 26 | procs[0].status = READY; |
teamgoat | 0:0c627ff4c5ed | 27 | procs[0].start = &get_sensor_data; |
teamgoat | 0:0c627ff4c5ed | 28 | return; |
teamgoat | 0:0c627ff4c5ed | 29 | } |
teamgoat | 0:0c627ff4c5ed | 30 | |
teamgoat | 0:0c627ff4c5ed | 31 | void schedule() |
teamgoat | 0:0c627ff4c5ed | 32 | { |
teamgoat | 0:0c627ff4c5ed | 33 | for (int i=0; i<MAXPROC; i++) |
teamgoat | 0:0c627ff4c5ed | 34 | { |
teamgoat | 0:0c627ff4c5ed | 35 | process proc = procs[i]; |
teamgoat | 0:0c627ff4c5ed | 36 | if(proc.status == READY) |
teamgoat | 0:0c627ff4c5ed | 37 | { |
teamgoat | 0:0c627ff4c5ed | 38 | proc.start(); |
teamgoat | 0:0c627ff4c5ed | 39 | return; |
teamgoat | 0:0c627ff4c5ed | 40 | } |
teamgoat | 0:0c627ff4c5ed | 41 | } |
teamgoat | 0:0c627ff4c5ed | 42 | } |
teamgoat | 0:0c627ff4c5ed | 43 |