2018 revision to classic DataBus AVC code.
Dependencies: LSM303DLM Servo SerialGraphicLCD L3G4200D IncrementalEncoder SimpleShell
main.cpp@42:8d99f64f5898, 2019-01-03 (annotated)
- Committer:
- shimniok
- Date:
- Thu Jan 03 17:50:44 2019 +0000
- Revision:
- 42:8d99f64f5898
- Parent:
- 39:465213249f71
- Child:
- 43:9a285515f33a
Implemented uart2 bridge for testing
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 | 16:eb28d0f64a9b | 9 | #include "pinouts.h" |
shimniok | 0:7e98bbfd102a | 10 | #include "stats_report.h" |
shimniok | 0:7e98bbfd102a | 11 | #include "SDBlockDevice.h" |
shimniok | 0:7e98bbfd102a | 12 | #include "FATFileSystem.h" |
shimniok | 35:c42e7e29c3bd | 13 | #include "Servo.h" |
shimniok | 0:7e98bbfd102a | 14 | #include "SimpleShell.h" |
shimniok | 4:de7feb458652 | 15 | #include "Config.h" |
shimniok | 11:8ec858b7c6d1 | 16 | #include "Updater.h" |
shimniok | 16:eb28d0f64a9b | 17 | #include "Ublox6.h" |
shimniok | 24:a7f92dfc5310 | 18 | #include "Logger.h" |
shimniok | 24:a7f92dfc5310 | 19 | #include "SystemState.h" |
shimniok | 37:b8259500dbd3 | 20 | #include "Display.h" |
shimniok | 0:7e98bbfd102a | 21 | |
shimniok | 24:a7f92dfc5310 | 22 | /////////////////////////////////////////////////////////////////////////////// |
shimniok | 24:a7f92dfc5310 | 23 | // Config |
shimniok | 24:a7f92dfc5310 | 24 | Config config; |
shimniok | 24:a7f92dfc5310 | 25 | |
shimniok | 42:8d99f64f5898 | 26 | |
shimniok | 24:a7f92dfc5310 | 27 | /////////////////////////////////////////////////////////////////////////////// |
shimniok | 24:a7f92dfc5310 | 28 | // Devices |
shimniok | 30:ed791f1f7f7d | 29 | DigitalOut led1(LED1); |
shimniok | 30:ed791f1f7f7d | 30 | DigitalOut led2(LED2); |
shimniok | 30:ed791f1f7f7d | 31 | DigitalOut led3(LED3); |
shimniok | 30:ed791f1f7f7d | 32 | DigitalOut led4(LED4); |
shimniok | 0:7e98bbfd102a | 33 | LocalFileSystem lfs("etc"); |
shimniok | 24:a7f92dfc5310 | 34 | SDBlockDevice bd(p5, p6, p7, p8); // MOSI, MISO, CLK, CS |
shimniok | 24:a7f92dfc5310 | 35 | FATFileSystem ffs("log", &bd); |
shimniok | 24:a7f92dfc5310 | 36 | Serial pc(USBTX, USBRX); |
shimniok | 20:043987d06f8d | 37 | RawSerial s(UART1TX, UART1RX, 38400); |
shimniok | 33:74c514aea0a1 | 38 | InterruptIn lbutton(LBUTTON, PullUp); // button interrupts |
shimniok | 33:74c514aea0a1 | 39 | InterruptIn cbutton(CBUTTON, PullUp); |
shimniok | 33:74c514aea0a1 | 40 | InterruptIn rbutton(RBUTTON, PullUp); |
shimniok | 35:c42e7e29c3bd | 41 | Servo steer(STEERING); |
shimniok | 35:c42e7e29c3bd | 42 | Servo esc(THROTTLE); |
shimniok | 20:043987d06f8d | 43 | |
shimniok | 19:0d1728091519 | 44 | |
shimniok | 24:a7f92dfc5310 | 45 | /////////////////////////////////////////////////////////////////////////////// |
shimniok | 24:a7f92dfc5310 | 46 | // Logging |
shimniok | 29:cb2f55fbfe9c | 47 | EventQueue logQueue(16 * EVENTS_EVENT_SIZE); |
shimniok | 31:20a95043adb0 | 48 | Logger logger; |
shimniok | 25:b8176ebb96c6 | 49 | |
shimniok | 42:8d99f64f5898 | 50 | |
shimniok | 42:8d99f64f5898 | 51 | /////////////////////////////////////////////////////////////////////////////// |
shimniok | 42:8d99f64f5898 | 52 | // Display |
shimniok | 42:8d99f64f5898 | 53 | EventQueue lcdQueue(8 * EVENTS_EVENT_SIZE); |
shimniok | 42:8d99f64f5898 | 54 | Display display(UART3TX, UART3RX); |
shimniok | 42:8d99f64f5898 | 55 | |
shimniok | 42:8d99f64f5898 | 56 | const uint64_t sample_time_ms = 50; |
shimniok | 42:8d99f64f5898 | 57 | |
shimniok | 42:8d99f64f5898 | 58 | void compute_cpu_stats() |
shimniok | 42:8d99f64f5898 | 59 | { |
shimniok | 42:8d99f64f5898 | 60 | static uint64_t prev_idle_time = 0; |
shimniok | 42:8d99f64f5898 | 61 | mbed_stats_cpu_t cpu_stats; |
shimniok | 42:8d99f64f5898 | 62 | |
shimniok | 42:8d99f64f5898 | 63 | // Collect and print cpu stats |
shimniok | 42:8d99f64f5898 | 64 | mbed_stats_cpu_get(&cpu_stats); |
shimniok | 42:8d99f64f5898 | 65 | |
shimniok | 42:8d99f64f5898 | 66 | uint64_t diff = (cpu_stats.idle_time - prev_idle_time); |
shimniok | 42:8d99f64f5898 | 67 | uint8_t idle = (diff * 100) / (sample_time_ms * 1000); // usec; |
shimniok | 42:8d99f64f5898 | 68 | prev_idle_time = cpu_stats.idle_time; |
shimniok | 42:8d99f64f5898 | 69 | display.cpu(idle); |
shimniok | 42:8d99f64f5898 | 70 | } |
shimniok | 42:8d99f64f5898 | 71 | |
shimniok | 25:b8176ebb96c6 | 72 | /////////////////////////////////////////////////////////////////////////////// |
shimniok | 25:b8176ebb96c6 | 73 | // Updater |
shimniok | 25:b8176ebb96c6 | 74 | Updater *u = Updater::instance(); |
shimniok | 26:2dc31a801cc8 | 75 | EventQueue updaterQueue(8 * EVENTS_EVENT_SIZE); |
shimniok | 25:b8176ebb96c6 | 76 | |
shimniok | 25:b8176ebb96c6 | 77 | void updater_callback() { |
shimniok | 30:ed791f1f7f7d | 78 | SensorData d; |
shimniok | 30:ed791f1f7f7d | 79 | float dt; |
shimniok | 42:8d99f64f5898 | 80 | static int count = 0; |
shimniok | 30:ed791f1f7f7d | 81 | |
shimniok | 25:b8176ebb96c6 | 82 | led1 = !led1; |
shimniok | 30:ed791f1f7f7d | 83 | d.timestamp = Kernel::get_ms_count(); |
shimniok | 30:ed791f1f7f7d | 84 | d.encoder = u->encoder(); |
shimniok | 32:eb673f6f5734 | 85 | u->imu(d.gyro, d.accel, d.mag, dt); |
shimniok | 30:ed791f1f7f7d | 86 | logQueue.call(&logger, &Logger::log_sensors, d); |
shimniok | 42:8d99f64f5898 | 87 | if (count++ > 10) { |
shimniok | 42:8d99f64f5898 | 88 | lcdQueue.call(&display, &Display::imu, d); |
shimniok | 42:8d99f64f5898 | 89 | count = 0; |
shimniok | 42:8d99f64f5898 | 90 | } |
shimniok | 25:b8176ebb96c6 | 91 | } |
shimniok | 25:b8176ebb96c6 | 92 | |
shimniok | 42:8d99f64f5898 | 93 | |
shimniok | 24:a7f92dfc5310 | 94 | /////////////////////////////////////////////////////////////////////////////// |
shimniok | 30:ed791f1f7f7d | 95 | // Buttons |
shimniok | 30:ed791f1f7f7d | 96 | EventQueue buttonQueue(16 * EVENTS_EVENT_SIZE); |
shimniok | 33:74c514aea0a1 | 97 | const int BUTTON_DEBOUNCE_SAMPLES = 20; |
shimniok | 33:74c514aea0a1 | 98 | const int BUTTON_DEBOUNCE_THRESH = 8; |
shimniok | 33:74c514aea0a1 | 99 | const int BUTTON_SAMPLE_MS = 0.005; |
shimniok | 30:ed791f1f7f7d | 100 | |
shimniok | 30:ed791f1f7f7d | 101 | void button_event() { |
shimniok | 33:74c514aea0a1 | 102 | int samples = 0; |
shimniok | 33:74c514aea0a1 | 103 | |
shimniok | 33:74c514aea0a1 | 104 | // disable subsequent interrupts |
shimniok | 33:74c514aea0a1 | 105 | lbutton.fall(NULL); |
shimniok | 33:74c514aea0a1 | 106 | |
shimniok | 33:74c514aea0a1 | 107 | // sample repeatedly to debounce |
shimniok | 33:74c514aea0a1 | 108 | for (int i=0; i < BUTTON_DEBOUNCE_SAMPLES; i++) { |
shimniok | 33:74c514aea0a1 | 109 | if (lbutton == 0) samples++; |
shimniok | 33:74c514aea0a1 | 110 | wait(BUTTON_SAMPLE_MS); |
shimniok | 33:74c514aea0a1 | 111 | } |
shimniok | 33:74c514aea0a1 | 112 | |
shimniok | 33:74c514aea0a1 | 113 | if (samples > BUTTON_DEBOUNCE_THRESH) { |
shimniok | 30:ed791f1f7f7d | 114 | if (logger.enabled()) { |
shimniok | 30:ed791f1f7f7d | 115 | logQueue.call(&logger, &Logger::stop); |
shimniok | 30:ed791f1f7f7d | 116 | led3 = 0; |
shimniok | 30:ed791f1f7f7d | 117 | } else { |
shimniok | 30:ed791f1f7f7d | 118 | logQueue.call(&logger, &Logger::start); |
shimniok | 30:ed791f1f7f7d | 119 | led3 = 1; |
shimniok | 30:ed791f1f7f7d | 120 | } |
shimniok | 30:ed791f1f7f7d | 121 | } |
shimniok | 33:74c514aea0a1 | 122 | |
shimniok | 33:74c514aea0a1 | 123 | lbutton.fall(buttonQueue.event(button_event)); |
shimniok | 30:ed791f1f7f7d | 124 | } |
shimniok | 30:ed791f1f7f7d | 125 | |
shimniok | 30:ed791f1f7f7d | 126 | |
shimniok | 30:ed791f1f7f7d | 127 | /////////////////////////////////////////////////////////////////////////////// |
shimniok | 24:a7f92dfc5310 | 128 | // GPS |
shimniok | 24:a7f92dfc5310 | 129 | Ublox6 ublox; |
shimniok | 24:a7f92dfc5310 | 130 | EventQueue gpsQueue(8 * EVENTS_EVENT_SIZE); |
shimniok | 23:5e61cf4a8c34 | 131 | |
shimniok | 23:5e61cf4a8c34 | 132 | // Callback for gps parse data ready |
shimniok | 23:5e61cf4a8c34 | 133 | void gps_callback() { |
shimniok | 24:a7f92dfc5310 | 134 | GpsData d; |
shimniok | 24:a7f92dfc5310 | 135 | |
shimniok | 25:b8176ebb96c6 | 136 | led2 = !led2; |
shimniok | 24:a7f92dfc5310 | 137 | ublox.read(d.latitude, d.longitude, d.course, d.speed, d.hdop, d.svcount); |
shimniok | 30:ed791f1f7f7d | 138 | d.timestamp = Kernel::get_ms_count(); |
shimniok | 29:cb2f55fbfe9c | 139 | logQueue.call(&logger, &Logger::log_gps, d); |
shimniok | 39:465213249f71 | 140 | lcdQueue.call(&display, &Display::gps, d); |
shimniok | 23:5e61cf4a8c34 | 141 | } |
shimniok | 29:cb2f55fbfe9c | 142 | |
shimniok | 22:4d62bd16f037 | 143 | // ISR for GPS serial, passes off to thread |
shimniok | 20:043987d06f8d | 144 | void gps_handler() { |
shimniok | 22:4d62bd16f037 | 145 | while (s.readable()) { |
shimniok | 22:4d62bd16f037 | 146 | int c = s.getc(); |
shimniok | 22:4d62bd16f037 | 147 | gpsQueue.call(&ublox, &Ublox6::parse, c); |
shimniok | 16:eb28d0f64a9b | 148 | } |
shimniok | 19:0d1728091519 | 149 | } |
shimniok | 16:eb28d0f64a9b | 150 | |
shimniok | 42:8d99f64f5898 | 151 | |
shimniok | 24:a7f92dfc5310 | 152 | /////////////////////////////////////////////////////////////////////////////// |
shimniok | 24:a7f92dfc5310 | 153 | // Shell |
shimniok | 30:ed791f1f7f7d | 154 | SimpleShell sh("/log"); |
shimniok | 9:fc3575d2cbbf | 155 | |
shimniok | 24:a7f92dfc5310 | 156 | void test(int argc, char **argv) { |
shimniok | 35:c42e7e29c3bd | 157 | //printf("Hello world!\n"); |
shimniok | 35:c42e7e29c3bd | 158 | char file[32]; |
shimniok | 35:c42e7e29c3bd | 159 | |
shimniok | 35:c42e7e29c3bd | 160 | for (int i=30; i < 40; i++) { |
shimniok | 35:c42e7e29c3bd | 161 | sprintf(file, "/log/%04d.csv", i); |
shimniok | 35:c42e7e29c3bd | 162 | printf("removing <%s>\n", file); |
shimniok | 35:c42e7e29c3bd | 163 | int stat = remove(file); |
shimniok | 35:c42e7e29c3bd | 164 | printf("return: %d\n", stat); |
shimniok | 35:c42e7e29c3bd | 165 | } |
shimniok | 1:7019a60fd585 | 166 | } |
shimniok | 1:7019a60fd585 | 167 | |
shimniok | 24:a7f92dfc5310 | 168 | void stats(int argc, char **argv) { |
shimniok | 24:a7f92dfc5310 | 169 | SystemReport r(200); |
shimniok | 24:a7f92dfc5310 | 170 | r.report_state(); |
shimniok | 24:a7f92dfc5310 | 171 | return; |
shimniok | 24:a7f92dfc5310 | 172 | } |
shimniok | 24:a7f92dfc5310 | 173 | |
shimniok | 24:a7f92dfc5310 | 174 | void read_gps(int argc, char **argv) |
shimniok | 18:3f8a8f6e3cc1 | 175 | { |
shimniok | 18:3f8a8f6e3cc1 | 176 | double lat=0; |
shimniok | 18:3f8a8f6e3cc1 | 177 | double lon=0; |
shimniok | 18:3f8a8f6e3cc1 | 178 | float course=0; |
shimniok | 18:3f8a8f6e3cc1 | 179 | float speed=0; |
shimniok | 18:3f8a8f6e3cc1 | 180 | float hdop=0.0; |
shimniok | 18:3f8a8f6e3cc1 | 181 | int svcount=0; |
shimniok | 18:3f8a8f6e3cc1 | 182 | |
shimniok | 18:3f8a8f6e3cc1 | 183 | ublox.read(lat, lon, course, speed, hdop, svcount); |
shimniok | 18:3f8a8f6e3cc1 | 184 | printf("%3.7f %3.7f\n", lat, lon); |
shimniok | 18:3f8a8f6e3cc1 | 185 | printf("hdg=%03.1f deg spd=%3.1f m/s\n", course, speed); |
shimniok | 18:3f8a8f6e3cc1 | 186 | printf("%d %f\n", svcount, hdop); |
shimniok | 18:3f8a8f6e3cc1 | 187 | } |
shimniok | 18:3f8a8f6e3cc1 | 188 | |
shimniok | 32:eb673f6f5734 | 189 | void read_imu(int argc, char **argv) |
shimniok | 9:fc3575d2cbbf | 190 | { |
shimniok | 12:3cd91e150d9c | 191 | int g[3]; |
shimniok | 32:eb673f6f5734 | 192 | int a[3]; |
shimniok | 32:eb673f6f5734 | 193 | int m[3]; |
shimniok | 13:5566df1250f1 | 194 | float dt; |
shimniok | 12:3cd91e150d9c | 195 | |
shimniok | 11:8ec858b7c6d1 | 196 | Updater *u = Updater::instance(); |
shimniok | 11:8ec858b7c6d1 | 197 | |
shimniok | 32:eb673f6f5734 | 198 | u->imu(g, a, m, dt); |
shimniok | 32:eb673f6f5734 | 199 | |
shimniok | 32:eb673f6f5734 | 200 | printf(" Gyro: %d, %d, %d\n", g[0], g[1], g[2]); |
shimniok | 32:eb673f6f5734 | 201 | printf(" Accel: %d, %d, %d\n", a[0], a[1], a[2]); |
shimniok | 32:eb673f6f5734 | 202 | printf(" Mag: %d, %d, %d\n", m[0], m[1], m[2]); |
shimniok | 32:eb673f6f5734 | 203 | printf(" dt: %f\n", dt); |
shimniok | 12:3cd91e150d9c | 204 | } |
shimniok | 12:3cd91e150d9c | 205 | |
shimniok | 24:a7f92dfc5310 | 206 | void read_enc(int argc, char **argv) |
shimniok | 14:1dd83e626153 | 207 | { |
shimniok | 14:1dd83e626153 | 208 | Updater *u = Updater::instance(); |
shimniok | 14:1dd83e626153 | 209 | |
shimniok | 14:1dd83e626153 | 210 | printf("Encoder: %d\n", u->encoder()); |
shimniok | 14:1dd83e626153 | 211 | } |
shimniok | 14:1dd83e626153 | 212 | |
shimniok | 29:cb2f55fbfe9c | 213 | void log(int argc, char **argv) |
shimniok | 29:cb2f55fbfe9c | 214 | { |
shimniok | 29:cb2f55fbfe9c | 215 | char *usage = "usage: log [start|stop]"; |
shimniok | 29:cb2f55fbfe9c | 216 | |
shimniok | 29:cb2f55fbfe9c | 217 | if (argc == 1) { |
shimniok | 29:cb2f55fbfe9c | 218 | printf("logging "); |
shimniok | 29:cb2f55fbfe9c | 219 | if (logger.enabled()) |
shimniok | 29:cb2f55fbfe9c | 220 | printf("enabled"); |
shimniok | 29:cb2f55fbfe9c | 221 | else |
shimniok | 29:cb2f55fbfe9c | 222 | printf("disabled"); |
shimniok | 29:cb2f55fbfe9c | 223 | printf("\n"); |
shimniok | 29:cb2f55fbfe9c | 224 | } else if (argc == 2) { |
shimniok | 29:cb2f55fbfe9c | 225 | if (!strcmp("start", argv[1])) { |
shimniok | 29:cb2f55fbfe9c | 226 | logger.start(); |
shimniok | 29:cb2f55fbfe9c | 227 | } else if (!strcmp("stop", argv[1])) { |
shimniok | 29:cb2f55fbfe9c | 228 | logger.stop(); |
shimniok | 29:cb2f55fbfe9c | 229 | } else { |
shimniok | 29:cb2f55fbfe9c | 230 | puts(usage); |
shimniok | 29:cb2f55fbfe9c | 231 | } |
shimniok | 29:cb2f55fbfe9c | 232 | } else { |
shimniok | 29:cb2f55fbfe9c | 233 | puts(usage); |
shimniok | 29:cb2f55fbfe9c | 234 | } |
shimniok | 29:cb2f55fbfe9c | 235 | } |
shimniok | 29:cb2f55fbfe9c | 236 | |
shimniok | 29:cb2f55fbfe9c | 237 | |
shimniok | 24:a7f92dfc5310 | 238 | void bridge_uart1(int argc, char **argv) { |
shimniok | 20:043987d06f8d | 239 | RawSerial s(UART1TX, UART1RX, 38400); |
shimniok | 20:043987d06f8d | 240 | while (1) { |
shimniok | 20:043987d06f8d | 241 | if (pc.readable()) s.putc(pc.getc()); |
shimniok | 20:043987d06f8d | 242 | if (s.readable()) pc.putc(s.getc()); |
shimniok | 20:043987d06f8d | 243 | } |
shimniok | 20:043987d06f8d | 244 | } |
shimniok | 20:043987d06f8d | 245 | |
shimniok | 42:8d99f64f5898 | 246 | |
shimniok | 42:8d99f64f5898 | 247 | void bridge_uart2() { |
shimniok | 42:8d99f64f5898 | 248 | RawSerial s(UART2TX, UART2RX, 19200); |
shimniok | 42:8d99f64f5898 | 249 | while (1) { |
shimniok | 42:8d99f64f5898 | 250 | if (pc.readable()) s.putc(pc.getc()); |
shimniok | 42:8d99f64f5898 | 251 | if (s.readable()) pc.putc(s.getc()); |
shimniok | 42:8d99f64f5898 | 252 | } |
shimniok | 42:8d99f64f5898 | 253 | } |
shimniok | 42:8d99f64f5898 | 254 | |
shimniok | 42:8d99f64f5898 | 255 | |
shimniok | 24:a7f92dfc5310 | 256 | void reset(int argc, char **argv) |
shimniok | 12:3cd91e150d9c | 257 | { |
shimniok | 12:3cd91e150d9c | 258 | NVIC_SystemReset(); |
shimniok | 9:fc3575d2cbbf | 259 | } |
shimniok | 9:fc3575d2cbbf | 260 | |
shimniok | 24:a7f92dfc5310 | 261 | /////////////////////////////////////////////////////////////////////////////// |
shimniok | 24:a7f92dfc5310 | 262 | // MAIN |
shimniok | 1:7019a60fd585 | 263 | |
shimniok | 0:7e98bbfd102a | 264 | // main() runs in its own thread in the OS |
shimniok | 0:7e98bbfd102a | 265 | int main() |
shimniok | 11:8ec858b7c6d1 | 266 | { |
shimniok | 20:043987d06f8d | 267 | //bridge_uart1(); |
shimniok | 42:8d99f64f5898 | 268 | bridge_uart2(); |
shimniok | 24:a7f92dfc5310 | 269 | |
shimniok | 25:b8176ebb96c6 | 270 | //Kernel::attach_idle_hook(idler); |
shimniok | 20:043987d06f8d | 271 | |
shimniok | 37:b8259500dbd3 | 272 | display.status("Bootup..."); |
shimniok | 0:7e98bbfd102a | 273 | printf("Bootup...\n"); |
shimniok | 0:7e98bbfd102a | 274 | fflush(stdout); |
shimniok | 1:7019a60fd585 | 275 | |
shimniok | 35:c42e7e29c3bd | 276 | steer = 0.50; |
shimniok | 35:c42e7e29c3bd | 277 | esc = 0.00; |
shimniok | 35:c42e7e29c3bd | 278 | |
shimniok | 4:de7feb458652 | 279 | printf("Loading config...\n"); |
shimniok | 37:b8259500dbd3 | 280 | display.status("Loading config"); |
shimniok | 7:1f2661b840ed | 281 | config.add("intercept_distance", Config::DOUBLE); |
shimniok | 7:1f2661b840ed | 282 | config.add("waypoint_threshold", Config::DOUBLE); |
shimniok | 7:1f2661b840ed | 283 | config.add("minimum_turning_radius", Config::DOUBLE); |
shimniok | 7:1f2661b840ed | 284 | config.add("wheelbase", Config::DOUBLE); |
shimniok | 7:1f2661b840ed | 285 | config.add("track_width", Config::DOUBLE); |
shimniok | 7:1f2661b840ed | 286 | config.add("tire_circumference", Config::DOUBLE); |
shimniok | 7:1f2661b840ed | 287 | config.add("encoder_stripes", Config::INT); |
shimniok | 7:1f2661b840ed | 288 | config.add("esc_brake", Config::INT); |
shimniok | 7:1f2661b840ed | 289 | config.add("esc_off", Config::INT); |
shimniok | 7:1f2661b840ed | 290 | config.add("esc_max", Config::INT); |
shimniok | 7:1f2661b840ed | 291 | config.add("turn_speed", Config::DOUBLE); |
shimniok | 7:1f2661b840ed | 292 | config.add("turn_distance", Config::DOUBLE); |
shimniok | 7:1f2661b840ed | 293 | config.add("start_speed", Config::DOUBLE); |
shimniok | 7:1f2661b840ed | 294 | config.add("cruise_speed", Config::DOUBLE); |
shimniok | 7:1f2661b840ed | 295 | config.add("speed_kp", Config::DOUBLE); |
shimniok | 7:1f2661b840ed | 296 | config.add("speed_ki", Config::DOUBLE); |
shimniok | 7:1f2661b840ed | 297 | config.add("speed_kd", Config::DOUBLE); |
shimniok | 7:1f2661b840ed | 298 | config.add("steer_center", Config::DOUBLE); |
shimniok | 7:1f2661b840ed | 299 | config.add("steer_scale", Config::DOUBLE); |
shimniok | 7:1f2661b840ed | 300 | config.add("gyro_scale", Config::DOUBLE); |
shimniok | 7:1f2661b840ed | 301 | config.add("gps_valid_speed", Config::DOUBLE); |
shimniok | 35:c42e7e29c3bd | 302 | |
shimniok | 4:de7feb458652 | 303 | if (config.load("/etc/2018cfg.txt")) { |
shimniok | 4:de7feb458652 | 304 | printf("error loading config\n"); |
shimniok | 37:b8259500dbd3 | 305 | display.status("config load error"); |
shimniok | 4:de7feb458652 | 306 | } |
shimniok | 10:9fb3feb38746 | 307 | |
shimniok | 38:6fec81f85221 | 308 | printf("Starting display...\n"); |
shimniok | 39:465213249f71 | 309 | Thread lcdThread(osPriorityNormal, 2048, 0, "lcd"); |
shimniok | 38:6fec81f85221 | 310 | lcdThread.start(callback(&lcdQueue, &EventQueue::dispatch_forever)); |
shimniok | 42:8d99f64f5898 | 311 | //lcdQueue.call_every(sample_time_ms, callback(&compute_cpu_stats)); |
shimniok | 38:6fec81f85221 | 312 | |
shimniok | 30:ed791f1f7f7d | 313 | printf("Starting buttons...\n"); |
shimniok | 37:b8259500dbd3 | 314 | display.status("Starting buttons"); |
shimniok | 33:74c514aea0a1 | 315 | lbutton.fall(buttonQueue.event(button_event)); |
shimniok | 30:ed791f1f7f7d | 316 | //cbutton.rise(buttonQueue.event(button_event)); |
shimniok | 30:ed791f1f7f7d | 317 | //rbutton.rise(buttonQueue.event(button_event)); |
shimniok | 30:ed791f1f7f7d | 318 | Thread buttonThread(osPriorityNormal, 256, 0, "buttons"); |
shimniok | 30:ed791f1f7f7d | 319 | buttonThread.start(callback(&buttonQueue, &EventQueue::dispatch_forever)); |
shimniok | 30:ed791f1f7f7d | 320 | |
shimniok | 24:a7f92dfc5310 | 321 | printf("Starting updater...\n"); |
shimniok | 37:b8259500dbd3 | 322 | display.status("Starting updater"); |
shimniok | 25:b8176ebb96c6 | 323 | u->attach(updater_callback); |
shimniok | 24:a7f92dfc5310 | 324 | Thread updaterThread(osPriorityRealtime, 512, 0, "updater"); |
shimniok | 26:2dc31a801cc8 | 325 | updaterQueue.call_every(20, u, &Updater::update); |
shimniok | 26:2dc31a801cc8 | 326 | updaterThread.start(callback(&updaterQueue, &EventQueue::dispatch_forever)); |
shimniok | 24:a7f92dfc5310 | 327 | |
shimniok | 24:a7f92dfc5310 | 328 | printf("Starting gps...\n"); |
shimniok | 37:b8259500dbd3 | 329 | display.status("Starting gps"); |
shimniok | 29:cb2f55fbfe9c | 330 | Thread gpsThread(osPriorityHigh, 2048, 0, "gps"); |
shimniok | 24:a7f92dfc5310 | 331 | gpsThread.start(callback(&gpsQueue, &EventQueue::dispatch_forever)); |
shimniok | 24:a7f92dfc5310 | 332 | ublox.subscribe(gps_callback); |
shimniok | 24:a7f92dfc5310 | 333 | s.attach(gps_handler); |
shimniok | 24:a7f92dfc5310 | 334 | |
shimniok | 37:b8259500dbd3 | 335 | printf("Starting logging...\n"); |
shimniok | 37:b8259500dbd3 | 336 | display.status("Starting logging"); |
shimniok | 29:cb2f55fbfe9c | 337 | Thread logThread(osPriorityNormal, 2048, 0, "log"); |
shimniok | 24:a7f92dfc5310 | 338 | logThread.start(callback(&logQueue, &EventQueue::dispatch_forever)); |
shimniok | 24:a7f92dfc5310 | 339 | |
shimniok | 13:5566df1250f1 | 340 | printf("Starting shell...\n"); |
shimniok | 37:b8259500dbd3 | 341 | display.status("Starting shell"); |
shimniok | 30:ed791f1f7f7d | 342 | sh.command(test, "test"); |
shimniok | 32:eb673f6f5734 | 343 | sh.command(read_imu, "imu"); |
shimniok | 30:ed791f1f7f7d | 344 | sh.command(read_enc, "enc"); |
shimniok | 30:ed791f1f7f7d | 345 | sh.command(read_gps, "gps"); |
shimniok | 30:ed791f1f7f7d | 346 | sh.command(reset, "reset"); |
shimniok | 30:ed791f1f7f7d | 347 | sh.command(stats, "stats"); |
shimniok | 30:ed791f1f7f7d | 348 | sh.command(log, "log"); |
shimniok | 37:b8259500dbd3 | 349 | |
shimniok | 37:b8259500dbd3 | 350 | display.status("DataBus 2018"); |
shimniok | 24:a7f92dfc5310 | 351 | sh.run(); |
shimniok | 22:4d62bd16f037 | 352 | |
shimniok | 0:7e98bbfd102a | 353 | while (true) { |
shimniok | 0:7e98bbfd102a | 354 | // Blink LED and wait 0.5 seconds |
shimniok | 0:7e98bbfd102a | 355 | led1 = !led1; |
shimniok | 0:7e98bbfd102a | 356 | wait(0.5f); |
shimniok | 0:7e98bbfd102a | 357 | } |
shimniok | 0:7e98bbfd102a | 358 | } |