You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

57 lines
1.0 KiB

  1. #include "control.h"
  2. #include "path.h"
  3. #include <stdio.h>
  4. #define LATENCY 20
  5. void trial_loop(trial *t) {
  6. do {
  7. if (-1 == trial_wait_for_start(t)) return;
  8. if (t->finished) break;
  9. if (t->runcnt == 0) {
  10. goradar(t);
  11. vehicle_accel(t);
  12. switch (t->v.turn) {
  13. case TURN_LEFT:
  14. case TURN_STRAIGHT:
  15. vehicle_hard_left(t); break;
  16. case TURN_RIGHT:
  17. vehicle_hard_right(t); break;
  18. default: break;
  19. }
  20. while (t->telemetry->length < 4) {
  21. if (-1 == trial_wait_for_input(t)) return;
  22. }
  23. /* TODO: call constant calculatoin */
  24. }
  25. while (t->alive) {
  26. simulate(t, getcurts(t) + LATENCY);
  27. goradar(t);
  28. if (-1 == trial_check_input(t)) return;
  29. // if (-1 == trial_wait_for_input(t)) return;
  30. }
  31. trial_reset_run(t);
  32. } while (!t->finished);
  33. }
  34. int main(int argc, char **argv) {
  35. trial *t;
  36. if (argc <= 2) {
  37. fprintf(stderr, "Syntax: %s hostname port\n", argv[0]);
  38. return 1;
  39. }
  40. if (NULL == (t = trial_new(argv[1], argv[2]))) {
  41. return 2;
  42. }
  43. trial_loop(t);
  44. trial_free(t);
  45. return 0;
  46. }