2018 revision to classic DataBus AVC code.
Dependencies: LSM303DLM Servo SerialGraphicLCD L3G4200D IncrementalEncoder SimpleShell
main.cpp@7:1f2661b840ed, 2018-12-05 (annotated)
- Committer:
- shimniok
- Date:
- Wed Dec 05 17:53:06 2018 +0000
- Revision:
- 7:1f2661b840ed
- Parent:
- 4:de7feb458652
- Child:
- 9:fc3575d2cbbf
Implemented keyword add and value assignment to Config. Testing keywords in main.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
shimniok | 0:7e98bbfd102a | 1 | /* mbed Microcontroller Library |
shimniok | 0:7e98bbfd102a | 2 | * Copyright (c) 2018 ARM Limited |
shimniok | 0:7e98bbfd102a | 3 | * SPDX-License-Identifier: Apache-2.0 |
shimniok | 0:7e98bbfd102a | 4 | */ |
shimniok | 0:7e98bbfd102a | 5 | |
shimniok | 0:7e98bbfd102a | 6 | #include "mbed.h" |
shimniok | 0:7e98bbfd102a | 7 | #include <stdio.h> |
shimniok | 0:7e98bbfd102a | 8 | #include <errno.h> |
shimniok | 0:7e98bbfd102a | 9 | #include "stats_report.h" |
shimniok | 0:7e98bbfd102a | 10 | #include "SDBlockDevice.h" |
shimniok | 0:7e98bbfd102a | 11 | #include "FATFileSystem.h" |
shimniok | 0:7e98bbfd102a | 12 | #include "SimpleShell.h" |
shimniok | 4:de7feb458652 | 13 | #include "Config.h" |
shimniok | 0:7e98bbfd102a | 14 | |
shimniok | 0:7e98bbfd102a | 15 | Serial pc(USBTX, USBRX); |
shimniok | 0:7e98bbfd102a | 16 | //SDBlockDevice bd(p5, p6, p7, p8); // MOSI, MISO, CLK, CS |
shimniok | 0:7e98bbfd102a | 17 | //FATFileSystem ffs("log", &bd); |
shimniok | 0:7e98bbfd102a | 18 | LocalFileSystem lfs("etc"); |
shimniok | 4:de7feb458652 | 19 | Config config; |
shimniok | 0:7e98bbfd102a | 20 | SimpleShell sh; |
shimniok | 0:7e98bbfd102a | 21 | |
shimniok | 0:7e98bbfd102a | 22 | DigitalOut led1(LED1); |
shimniok | 0:7e98bbfd102a | 23 | |
shimniok | 0:7e98bbfd102a | 24 | Thread thread; |
shimniok | 0:7e98bbfd102a | 25 | |
shimniok | 1:7019a60fd585 | 26 | void test() { |
shimniok | 1:7019a60fd585 | 27 | printf("Hello world!\n"); |
shimniok | 1:7019a60fd585 | 28 | } |
shimniok | 1:7019a60fd585 | 29 | |
shimniok | 1:7019a60fd585 | 30 | |
shimniok | 0:7e98bbfd102a | 31 | // main() runs in its own thread in the OS |
shimniok | 0:7e98bbfd102a | 32 | int main() |
shimniok | 0:7e98bbfd102a | 33 | { |
shimniok | 0:7e98bbfd102a | 34 | printf("Bootup...\n"); |
shimniok | 0:7e98bbfd102a | 35 | fflush(stdout); |
shimniok | 1:7019a60fd585 | 36 | |
shimniok | 4:de7feb458652 | 37 | printf("Loading config...\n"); |
shimniok | 7:1f2661b840ed | 38 | |
shimniok | 7:1f2661b840ed | 39 | // Add valid keywords |
shimniok | 7:1f2661b840ed | 40 | config.add("intercept_distance", Config::DOUBLE); |
shimniok | 7:1f2661b840ed | 41 | config.add("waypoint_threshold", Config::DOUBLE); |
shimniok | 7:1f2661b840ed | 42 | config.add("minimum_turning_radius", Config::DOUBLE); |
shimniok | 7:1f2661b840ed | 43 | config.add("wheelbase", Config::DOUBLE); |
shimniok | 7:1f2661b840ed | 44 | config.add("track_width", Config::DOUBLE); |
shimniok | 7:1f2661b840ed | 45 | config.add("tire_circumference", Config::DOUBLE); |
shimniok | 7:1f2661b840ed | 46 | config.add("encoder_stripes", Config::INT); |
shimniok | 7:1f2661b840ed | 47 | config.add("esc_brake", Config::INT); |
shimniok | 7:1f2661b840ed | 48 | config.add("esc_off", Config::INT); |
shimniok | 7:1f2661b840ed | 49 | config.add("esc_max", Config::INT); |
shimniok | 7:1f2661b840ed | 50 | config.add("turn_speed", Config::DOUBLE); |
shimniok | 7:1f2661b840ed | 51 | config.add("turn_distance", Config::DOUBLE); |
shimniok | 7:1f2661b840ed | 52 | config.add("start_speed", Config::DOUBLE); |
shimniok | 7:1f2661b840ed | 53 | config.add("cruise_speed", Config::DOUBLE); |
shimniok | 7:1f2661b840ed | 54 | config.add("speed_kp", Config::DOUBLE); |
shimniok | 7:1f2661b840ed | 55 | config.add("speed_ki", Config::DOUBLE); |
shimniok | 7:1f2661b840ed | 56 | config.add("speed_kd", Config::DOUBLE); |
shimniok | 7:1f2661b840ed | 57 | config.add("steer_center", Config::DOUBLE); |
shimniok | 7:1f2661b840ed | 58 | config.add("steer_scale", Config::DOUBLE); |
shimniok | 7:1f2661b840ed | 59 | config.add("gyro_scale", Config::DOUBLE); |
shimniok | 7:1f2661b840ed | 60 | config.add("gps_valid_speed", Config::DOUBLE); |
shimniok | 7:1f2661b840ed | 61 | |
shimniok | 4:de7feb458652 | 62 | if (config.load("/etc/2018cfg.txt")) { |
shimniok | 4:de7feb458652 | 63 | printf("error loading config\n"); |
shimniok | 4:de7feb458652 | 64 | } |
shimniok | 4:de7feb458652 | 65 | |
shimniok | 1:7019a60fd585 | 66 | sh.attach(test, "test"); |
shimniok | 1:7019a60fd585 | 67 | |
shimniok | 0:7e98bbfd102a | 68 | thread.start(callback(&sh, &SimpleShell::run)); |
shimniok | 0:7e98bbfd102a | 69 | |
shimniok | 0:7e98bbfd102a | 70 | /* |
shimniok | 0:7e98bbfd102a | 71 | FILE *fp; |
shimniok | 0:7e98bbfd102a | 72 | char buf[128]; |
shimniok | 0:7e98bbfd102a | 73 | printf("Initializing the block device... "); |
shimniok | 0:7e98bbfd102a | 74 | fflush(stdout); |
shimniok | 0:7e98bbfd102a | 75 | int err = bd.init(); |
shimniok | 0:7e98bbfd102a | 76 | printf("%s\n", (err ? "Fail :(" : "OK")); |
shimniok | 0:7e98bbfd102a | 77 | |
shimniok | 0:7e98bbfd102a | 78 | printf("Opening sdtest.txt..."); |
shimniok | 0:7e98bbfd102a | 79 | fp = fopen("/log/sdtest.txt", "r"); |
shimniok | 0:7e98bbfd102a | 80 | if(fp) { |
shimniok | 0:7e98bbfd102a | 81 | while (!feof(fp)) { |
shimniok | 0:7e98bbfd102a | 82 | fgets(buf, 127, fp); |
shimniok | 0:7e98bbfd102a | 83 | printf(buf); |
shimniok | 0:7e98bbfd102a | 84 | } |
shimniok | 0:7e98bbfd102a | 85 | fclose(fp); |
shimniok | 0:7e98bbfd102a | 86 | } |
shimniok | 0:7e98bbfd102a | 87 | |
shimniok | 0:7e98bbfd102a | 88 | printf("Opening config.txt..."); |
shimniok | 0:7e98bbfd102a | 89 | fp = fopen("/etc/config.txt", "r"); |
shimniok | 0:7e98bbfd102a | 90 | if(fp) { |
shimniok | 0:7e98bbfd102a | 91 | while (!feof(fp)) { |
shimniok | 0:7e98bbfd102a | 92 | fgets(buf, 127, fp); |
shimniok | 0:7e98bbfd102a | 93 | printf(buf); |
shimniok | 0:7e98bbfd102a | 94 | } |
shimniok | 0:7e98bbfd102a | 95 | fclose(fp); |
shimniok | 0:7e98bbfd102a | 96 | } |
shimniok | 0:7e98bbfd102a | 97 | */ |
shimniok | 0:7e98bbfd102a | 98 | |
shimniok | 0:7e98bbfd102a | 99 | //SystemReport sys_state(500); |
shimniok | 0:7e98bbfd102a | 100 | |
shimniok | 0:7e98bbfd102a | 101 | while (true) { |
shimniok | 0:7e98bbfd102a | 102 | // Blink LED and wait 0.5 seconds |
shimniok | 0:7e98bbfd102a | 103 | led1 = !led1; |
shimniok | 0:7e98bbfd102a | 104 | wait(0.5f); |
shimniok | 0:7e98bbfd102a | 105 | |
shimniok | 0:7e98bbfd102a | 106 | // Following the main thread wait, report on the current system status |
shimniok | 0:7e98bbfd102a | 107 | //sys_state.report_state(); |
shimniok | 0:7e98bbfd102a | 108 | } |
shimniok | 0:7e98bbfd102a | 109 | } |