Brian Silverman | 6ae77dd | 2013-03-29 22:28:08 -0700 | [diff] [blame^] | 1 | #include "aos/aos_core.h" |
| 2 | #include "math.h" |
| 3 | |
| 4 | #include "frc971/queues/GyroAngle.q.h" |
| 5 | #include "frc971/queues/CameraTarget.q.h" |
| 6 | #include "aos/common/time.h" |
| 7 | #include "vision/RingBuffer.h" |
| 8 | |
| 9 | using frc971::vision::RingBuffer; |
| 10 | using frc971::sensors::gyro; |
| 11 | using frc971::vision::targets; |
| 12 | using frc971::vision::target_angle; |
| 13 | |
| 14 | int main(){ |
| 15 | RingBuffer< ::aos::time::Time,double> buff; |
| 16 | ::aos::Init(); |
| 17 | while (true) { |
| 18 | gyro.FetchNextBlocking(); |
| 19 | buff.Sample(gyro->sent_time, gyro->angle); |
| 20 | if(targets.FetchNext()){ |
| 21 | const frc971::vision::CameraTarget *goal = targets.get(); |
| 22 | ::aos::time::Time stamp = ::aos::time::Time::InNS(goal->timestamp); |
| 23 | double angle_goal = |
| 24 | buff.ValueAt(stamp) - M_PI * goal->percent_azimuth_off_center / 4; |
| 25 | printf("%g ",angle_goal); |
| 26 | printf("%g\n",gyro->angle); |
| 27 | |
| 28 | target_angle.MakeWithBuilder() |
| 29 | .target_angle(angle_goal).Send(); |
| 30 | } |
| 31 | } |
| 32 | ::aos::Cleanup(); |
| 33 | } |
| 34 | |