config.txt to set servo positions for testing

Dependencies:   Servo mbed

Committer:
tylerjw
Date:
Thu Nov 08 21:43:41 2012 +0000
Revision:
0:478ae94859c2
config.txt (r:%f,l:%f)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tylerjw 0:478ae94859c2 1 #include "mbed.h"
tylerjw 0:478ae94859c2 2 #include "Servo.h"
tylerjw 0:478ae94859c2 3
tylerjw 0:478ae94859c2 4 LocalFileSystem local("local"); // Create the local filesystem under the name "local"
tylerjw 0:478ae94859c2 5 BusOut leds(LED1, LED2, LED3, LED4);
tylerjw 0:478ae94859c2 6
tylerjw 0:478ae94859c2 7 int main() {
tylerjw 0:478ae94859c2 8 leds = 0x0;
tylerjw 0:478ae94859c2 9 float right_pos, left_pos;
tylerjw 0:478ae94859c2 10 FILE *fp = fopen("/local/config.txt", "r"); // Open "config.txt" for reading
tylerjw 0:478ae94859c2 11 leds = 0x1;
tylerjw 0:478ae94859c2 12 fscanf(fp, "r:%f,l:%f", &right_pos, &left_pos);
tylerjw 0:478ae94859c2 13 leds = 0x2;
tylerjw 0:478ae94859c2 14 fclose(fp);
tylerjw 0:478ae94859c2 15 leds = 0x3;
tylerjw 0:478ae94859c2 16
tylerjw 0:478ae94859c2 17 // servos
tylerjw 0:478ae94859c2 18 Servo left_s(p21);
tylerjw 0:478ae94859c2 19 Servo right_s(p22);
tylerjw 0:478ae94859c2 20
tylerjw 0:478ae94859c2 21 left_s.calibrate_max(0.0007);
tylerjw 0:478ae94859c2 22 left_s.calibrate_min(-0.0014);
tylerjw 0:478ae94859c2 23 right_s.calibrate(0.0009);
tylerjw 0:478ae94859c2 24
tylerjw 0:478ae94859c2 25 leds = 0x4;
tylerjw 0:478ae94859c2 26
tylerjw 0:478ae94859c2 27 left_s = right_s = 1.0;
tylerjw 0:478ae94859c2 28
tylerjw 0:478ae94859c2 29 wait(1);
tylerjw 0:478ae94859c2 30
tylerjw 0:478ae94859c2 31 leds = 0x5;
tylerjw 0:478ae94859c2 32
tylerjw 0:478ae94859c2 33 right_s = right_pos;
tylerjw 0:478ae94859c2 34 left_s = left_pos;
tylerjw 0:478ae94859c2 35
tylerjw 0:478ae94859c2 36 leds = 0xF;
tylerjw 0:478ae94859c2 37
tylerjw 0:478ae94859c2 38 AnalogIn battery(p19);
tylerjw 0:478ae94859c2 39 DigitalOut battery_warning(p24);
tylerjw 0:478ae94859c2 40 battery_warning = 1;
tylerjw 0:478ae94859c2 41
tylerjw 0:478ae94859c2 42 const float BAT_MUL = 10.26;
tylerjw 0:478ae94859c2 43 float battery_voltage;
tylerjw 0:478ae94859c2 44
tylerjw 0:478ae94859c2 45 while(1) {
tylerjw 0:478ae94859c2 46 battery_voltage = battery.read() * BAT_MUL;
tylerjw 0:478ae94859c2 47 if(battery_voltage < 6.4)
tylerjw 0:478ae94859c2 48 battery_warning = 0;
tylerjw 0:478ae94859c2 49 if(battery_warning == 0 && battery_voltage > 6.4)
tylerjw 0:478ae94859c2 50 battery_warning = 1;
tylerjw 0:478ae94859c2 51
tylerjw 0:478ae94859c2 52 wait(1.0);
tylerjw 0:478ae94859c2 53 }
tylerjw 0:478ae94859c2 54 }