James Kuszmaul | f7f5ec1 | 2013-11-01 17:58:58 -0700 | [diff] [blame^] | 1 | #include "stdio.h" |
| 2 | |
| 3 | #include "aos/common/control_loop/Timing.h" |
| 4 | #include "aos/common/time.h" |
| 5 | #include "bot3/control_loops/shooter/shooter_motor.q.h" |
| 6 | |
| 7 | using ::bot3::control_loops::shooter; |
| 8 | using ::aos::time::Time; |
| 9 | |
| 10 | int main(int argc, char * argv[]) { |
| 11 | FILE *data_file = NULL; |
| 12 | FILE *output_file = NULL; |
| 13 | |
| 14 | if (argc == 2) { |
| 15 | data_file = fopen(argv[1], "w"); |
| 16 | output_file = data_file; |
| 17 | } else { |
| 18 | printf("Logging to stdout instead\n"); |
| 19 | output_file = stdout; |
| 20 | } |
| 21 | |
| 22 | fprintf(data_file, "time, power, position"); |
| 23 | |
| 24 | ::aos::Init(); |
| 25 | |
| 26 | Time start_time = Time::Now(); |
| 27 | |
| 28 | while (true) { |
| 29 | ::aos::time::PhasedLoop10MS(2000); |
| 30 | shooter.goal.FetchLatest(); |
| 31 | shooter.status.FetchLatest(); |
| 32 | shooter.position.FetchLatest(); |
| 33 | shooter.output.FetchLatest(); |
| 34 | if (shooter.output.get() && |
| 35 | shooter.position.get()) { |
| 36 | fprintf(output_file, "\n%f, %f, %f", |
| 37 | (shooter.position->sent_time - start_time).ToSeconds(), |
| 38 | shooter.output->voltage, |
| 39 | shooter.position->position); |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | if (data_file) { |
| 44 | fclose(data_file); |
| 45 | } |
| 46 | |
| 47 | ::aos::Cleanup(); |
| 48 | return 0; |
| 49 | } |
| 50 | |