Austin Schuh | 3634fa1 | 2013-03-03 15:09:06 -0800 | [diff] [blame] | 1 | #include "stdio.h" |
| 2 | |
Austin Schuh | 3634fa1 | 2013-03-03 15:09:06 -0800 | [diff] [blame] | 3 | #include "aos/common/control_loop/Timing.h" |
| 4 | #include "aos/common/time.h" |
| 5 | #include "frc971/control_loops/shooter/shooter_motor.q.h" |
| 6 | |
| 7 | using ::frc971::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; |
Austin Schuh | 3634fa1 | 2013-03-03 15:09:06 -0800 | [diff] [blame] | 13 | |
Austin Schuh | f3d96b8 | 2013-03-06 18:46:11 -0800 | [diff] [blame] | 14 | if (argc == 2) { |
Austin Schuh | 3634fa1 | 2013-03-03 15:09:06 -0800 | [diff] [blame] | 15 | data_file = fopen(argv[1], "w"); |
Austin Schuh | 3634fa1 | 2013-03-03 15:09:06 -0800 | [diff] [blame] | 16 | output_file = data_file; |
| 17 | } else { |
Austin Schuh | f3d96b8 | 2013-03-06 18:46:11 -0800 | [diff] [blame] | 18 | printf("Logging to stdout instead\n"); |
Austin Schuh | 3634fa1 | 2013-03-03 15:09:06 -0800 | [diff] [blame] | 19 | output_file = stdout; |
| 20 | } |
| 21 | |
Austin Schuh | f3d96b8 | 2013-03-06 18:46:11 -0800 | [diff] [blame] | 22 | fprintf(data_file, "time, power, position"); |
| 23 | |
Austin Schuh | 3634fa1 | 2013-03-03 15:09:06 -0800 | [diff] [blame] | 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", |
Austin Schuh | f3d96b8 | 2013-03-06 18:46:11 -0800 | [diff] [blame] | 37 | (shooter.position->sent_time - start_time).ToSeconds(), |
Austin Schuh | 3634fa1 | 2013-03-03 15:09:06 -0800 | [diff] [blame] | 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 | |