blob: f12814f9865685b53f01244cf0b2bc2959f5d30e [file] [log] [blame]
Brian Silverman6ae77dd2013-03-29 22:28:08 -07001#include "math.h"
2
Brian Silverman5b3e51e2013-03-29 22:53:44 -07003#include "aos/common/time.h"
4#include "aos/atom_code/init.h"
5
Brian Silverman6ae77dd2013-03-29 22:28:08 -07006#include "frc971/queues/GyroAngle.q.h"
7#include "frc971/queues/CameraTarget.q.h"
Brian Silverman5b3e51e2013-03-29 22:53:44 -07008
Brian Silverman6ae77dd2013-03-29 22:28:08 -07009#include "vision/RingBuffer.h"
10
11using frc971::vision::RingBuffer;
12using frc971::sensors::gyro;
13using frc971::vision::targets;
14using frc971::vision::target_angle;
15
16int main(){
17 RingBuffer< ::aos::time::Time,double> buff;
18 ::aos::Init();
19 while (true) {
20 gyro.FetchNextBlocking();
21 buff.Sample(gyro->sent_time, gyro->angle);
22 if(targets.FetchNext()){
23 const frc971::vision::CameraTarget *goal = targets.get();
24 ::aos::time::Time stamp = ::aos::time::Time::InNS(goal->timestamp);
25 double angle_goal =
26 buff.ValueAt(stamp) - M_PI * goal->percent_azimuth_off_center / 4;
27 printf("%g ",angle_goal);
28 printf("%g\n",gyro->angle);
29
30 target_angle.MakeWithBuilder()
31 .target_angle(angle_goal).Send();
32 }
33 }
34 ::aos::Cleanup();
35}
36