blob: 93ec131adba2191dfe0b3b4d5cf876d7f654ac42 [file] [log] [blame]
Brian Silverman2ccf8c52016-03-15 00:22:26 -04001#include <netdb.h>
Parker Schuh2cd173d2017-01-28 00:12:01 -08002#include <stdlib.h>
Brian Silverman2ccf8c52016-03-15 00:22:26 -04003#include <unistd.h>
4
Brian Silvermanbc831182016-04-16 02:06:09 -04005#include <array>
Brian Silvermanbc831182016-04-16 02:06:09 -04006#include <atomic>
Austin Schuhfb5f7de2016-11-26 15:15:19 -08007#include <chrono>
Brian Silvermanbc831182016-04-16 02:06:09 -04008#include <limits>
Austin Schuhfb5f7de2016-11-26 15:15:19 -08009#include <memory>
10#include <thread>
11#include <vector>
Brian Silverman2ccf8c52016-03-15 00:22:26 -040012
Alex Perrycb7da4b2019-08-28 19:35:56 -070013#include "aos/events/event_loop.h"
14#include "aos/events/shm_event_loop.h"
James Kuszmaul651fc3f2019-05-15 21:14:25 -070015#include "aos/init.h"
John Park33858a32018-09-28 23:05:48 -070016#include "aos/logging/logging.h"
John Park33858a32018-09-28 23:05:48 -070017#include "aos/mutex/mutex.h"
18#include "aos/time/time.h"
Parker Schuh2cd173d2017-01-28 00:12:01 -080019#include "aos/vision/events/udp.h"
Alex Perrycb7da4b2019-08-28 19:35:56 -070020#include "frc971/control_loops/drivetrain/drivetrain_status_generated.h"
Parker Schuh2cd173d2017-01-28 00:12:01 -080021#include "y2016/constants.h"
22#include "y2016/vision/stereo_geometry.h"
Brian Silverman2ccf8c52016-03-15 00:22:26 -040023#include "y2016/vision/vision_data.pb.h"
Alex Perrycb7da4b2019-08-28 19:35:56 -070024#include "y2016/vision/vision_generated.h"
Brian Silverman2ccf8c52016-03-15 00:22:26 -040025
26namespace y2016 {
27namespace vision {
28
Austin Schuhfb5f7de2016-11-26 15:15:19 -080029namespace chrono = ::std::chrono;
30using ::aos::monotonic_clock;
31
Austin Schuh11945742016-04-13 22:18:36 -070032::aos::vision::Vector<2> CreateCenterFromTarget(double lx, double ly, double rx,
33 double ry) {
ben54dbccb2016-03-20 14:42:28 -070034 return ::aos::vision::Vector<2>((lx + rx) / 2.0, (ly + ry) / 2.0);
35}
36
37double TargetWidth(double lx, double ly, double rx, double ry) {
38 double dx = lx - rx;
39 double dy = ly - ry;
Austin Schuh098e4872016-03-20 16:51:24 -070040 return ::std::hypot(dx, dy);
ben54dbccb2016-03-20 14:42:28 -070041}
42
43void SelectTargets(const VisionData &left_target,
44 const VisionData &right_target,
45 ::aos::vision::Vector<2> *center_left,
Austin Schuh6bf73052016-04-20 20:20:25 -070046 ::aos::vision::Vector<2> *center_right, double *angle_left,
47 double *angle_right) {
ben54dbccb2016-03-20 14:42:28 -070048 // No good targets. Let the caller decide defaults.
49 if (right_target.target_size() == 0 || left_target.target_size() == 0) {
50 return;
51 }
52
53 // Only one option, we have to go with it.
54 if (right_target.target_size() == 1 && left_target.target_size() == 1) {
55 *center_left =
56 CreateCenterFromTarget(left_target.target(0).left_corner_x(),
57 left_target.target(0).left_corner_y(),
58 left_target.target(0).right_corner_x(),
59 left_target.target(0).right_corner_y());
60 *center_right =
61 CreateCenterFromTarget(right_target.target(0).left_corner_x(),
62 right_target.target(0).left_corner_y(),
63 right_target.target(0).right_corner_x(),
64 right_target.target(0).right_corner_y());
65 return;
66 }
67
68 // Now we have to make a decision.
Austin Schuh9f59c8a2016-03-20 21:09:05 -070069 double min_angle = -1.0;
ben54dbccb2016-03-20 14:42:28 -070070 int left_index = 0;
71 // First pick the widest target from the left.
72 for (int i = 0; i < left_target.target_size(); i++) {
Austin Schuh9f59c8a2016-03-20 21:09:05 -070073 const double h = left_target.target(i).left_corner_y() -
74 left_target.target(i).right_corner_y();
75 const double wid1 = TargetWidth(left_target.target(i).left_corner_x(),
76 left_target.target(i).left_corner_y(),
77 left_target.target(i).right_corner_x(),
78 left_target.target(i).right_corner_y());
79 const double angle = h / wid1;
80 if (min_angle == -1.0 || ::std::abs(angle) < ::std::abs(min_angle)) {
81 min_angle = angle;
Austin Schuh6bf73052016-04-20 20:20:25 -070082 *angle_left = angle;
ben54dbccb2016-03-20 14:42:28 -070083 left_index = i;
84 }
85 }
86 // Calculate the angle of the bottom edge for the left.
87 double h = left_target.target(left_index).left_corner_y() -
88 left_target.target(left_index).right_corner_y();
Austin Schuh9f59c8a2016-03-20 21:09:05 -070089
90 double good_ang = min_angle;
ben54dbccb2016-03-20 14:42:28 -070091 double min_ang_err = -1.0;
92 int right_index = -1;
Austin Schuh11945742016-04-13 22:18:36 -070093 // Now pick the bottom edge angle from the right that lines up best with the
94 // left.
ben54dbccb2016-03-20 14:42:28 -070095 for (int j = 0; j < right_target.target_size(); j++) {
96 double wid2 = TargetWidth(right_target.target(j).left_corner_x(),
Austin Schuh11945742016-04-13 22:18:36 -070097 right_target.target(j).left_corner_y(),
98 right_target.target(j).right_corner_x(),
99 right_target.target(j).right_corner_y());
ben54dbccb2016-03-20 14:42:28 -0700100 h = right_target.target(j).left_corner_y() -
101 right_target.target(j).right_corner_y();
Austin Schuh11945742016-04-13 22:18:36 -0700102 double ang = h / wid2;
ben54dbccb2016-03-20 14:42:28 -0700103 double ang_err = ::std::abs(good_ang - ang);
104 if (min_ang_err == -1.0 || min_ang_err > ang_err) {
105 min_ang_err = ang_err;
106 right_index = j;
Austin Schuh6bf73052016-04-20 20:20:25 -0700107 *angle_right = ang;
ben54dbccb2016-03-20 14:42:28 -0700108 }
109 }
110
111 *center_left =
112 CreateCenterFromTarget(left_target.target(left_index).left_corner_x(),
113 left_target.target(left_index).left_corner_y(),
114 left_target.target(left_index).right_corner_x(),
115 left_target.target(left_index).right_corner_y());
116 *center_right =
117 CreateCenterFromTarget(right_target.target(right_index).left_corner_x(),
118 right_target.target(right_index).left_corner_y(),
119 right_target.target(right_index).right_corner_x(),
120 right_target.target(right_index).right_corner_y());
121}
122
Austin Schuh11945742016-04-13 22:18:36 -0700123class CameraHandler {
124 public:
Austin Schuhfb5f7de2016-11-26 15:15:19 -0800125 void Received(const VisionData &target, monotonic_clock::time_point now) {
Austin Schuh11945742016-04-13 22:18:36 -0700126 if (current_.received) {
127 last_ = current_;
128 }
129 current_.target = target;
130 current_.rx_time = now;
Austin Schuh6fe1d512016-04-24 19:12:04 -0700131 current_.capture_time = now -
Austin Schuhfb5f7de2016-11-26 15:15:19 -0800132 chrono::nanoseconds(target.send_timestamp() -
133 target.image_timestamp()) +
Austin Schuh6fe1d512016-04-24 19:12:04 -0700134 // It takes a bit to shoot a frame. Push the frame
135 // further back in time.
Austin Schuhfb5f7de2016-11-26 15:15:19 -0800136 chrono::milliseconds(10);
Austin Schuh11945742016-04-13 22:18:36 -0700137 current_.received = true;
138 }
139
Austin Schuhfb5f7de2016-11-26 15:15:19 -0800140 void CheckStale(monotonic_clock::time_point now) {
141 if (now > current_.rx_time + chrono::milliseconds(50)) {
Austin Schuh11945742016-04-13 22:18:36 -0700142 current_.received = false;
143 last_.received = false;
144 }
145 }
146
147 bool received_both() const { return current_.received && last_.received; }
148
149 bool is_valid() const {
150 return current_.target.target_size() > 0 && last_.target.target_size() > 0;
151 }
152
153 const VisionData &target() const { return current_.target; }
154 const VisionData &last_target() const { return last_.target; }
155
Austin Schuhfb5f7de2016-11-26 15:15:19 -0800156 monotonic_clock::time_point capture_time() const {
157 return current_.capture_time;
158 }
159 monotonic_clock::time_point last_capture_time() const {
160 return last_.capture_time;
161 }
Austin Schuh11945742016-04-13 22:18:36 -0700162
163 private:
164 struct TargetWithTimes {
165 VisionData target;
Austin Schuhfb5f7de2016-11-26 15:15:19 -0800166 monotonic_clock::time_point rx_time{monotonic_clock::epoch()};
167 monotonic_clock::time_point capture_time{monotonic_clock::epoch()};
Austin Schuh11945742016-04-13 22:18:36 -0700168 bool received = false;
169 };
170
171 TargetWithTimes current_;
172 TargetWithTimes last_;
173};
174
Austin Schuh6bf73052016-04-20 20:20:25 -0700175void CalculateFiltered(const CameraHandler &older, const CameraHandler &newer,
176 const ::aos::vision::Vector<2> &newer_center,
177 const ::aos::vision::Vector<2> &last_newer_center,
178 double angle, double last_angle,
179 ::aos::vision::Vector<2> *interpolated_result,
180 double *interpolated_angle) {
James Kuszmaul651fc3f2019-05-15 21:14:25 -0700181 const double age_ratio =
182 ::aos::time::DurationInSeconds(older.capture_time() -
183 newer.last_capture_time()) /
184 ::aos::time::DurationInSeconds(newer.capture_time() -
185 newer.last_capture_time());
Austin Schuh6bf73052016-04-20 20:20:25 -0700186 interpolated_result->Set(
Austin Schuh11945742016-04-13 22:18:36 -0700187 newer_center.x() * age_ratio + (1 - age_ratio) * last_newer_center.x(),
188 newer_center.y() * age_ratio + (1 - age_ratio) * last_newer_center.y());
Austin Schuh6bf73052016-04-20 20:20:25 -0700189
190 *interpolated_angle = angle * age_ratio + (1 - age_ratio) * last_angle;
Austin Schuh11945742016-04-13 22:18:36 -0700191}
ben54dbccb2016-03-20 14:42:28 -0700192
Brian Silvermanbc831182016-04-16 02:06:09 -0400193// Handles calculating drivetrain offsets.
194class DrivetrainOffsetCalculator {
195 public:
Austin Schuhbd0a40f2019-06-30 14:56:31 -0700196 DrivetrainOffsetCalculator(::aos::EventLoop *event_loop)
197 : drivetrain_status_fetcher_(
198 event_loop
Alex Perrycb7da4b2019-08-28 19:35:56 -0700199 ->MakeFetcher<::frc971::control_loops::drivetrain::Status>(
200 "/drivetrain")) {}
Brian Silvermanbc831182016-04-16 02:06:09 -0400201
202 // Takes a vision status message with everything except
203 // drivetrain_{left,right}_position set and sets those.
204 // Returns false if it doesn't have enough data to fill them out.
Alex Perrycb7da4b2019-08-28 19:35:56 -0700205 bool CompleteVisionStatus(::y2016::vision::VisionStatusT *status) {
Austin Schuhbd0a40f2019-06-30 14:56:31 -0700206 while (drivetrain_status_fetcher_.FetchNext()) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700207 data_[data_index_].time =
Austin Schuhad154822019-12-27 15:45:13 -0800208 drivetrain_status_fetcher_.context().monotonic_event_time;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700209 data_[data_index_].left =
210 drivetrain_status_fetcher_->estimated_left_position();
211 data_[data_index_].right =
212 drivetrain_status_fetcher_->estimated_right_position();
Austin Schuhbd0a40f2019-06-30 14:56:31 -0700213 ++data_index_;
214 if (data_index_ == data_.size()) data_index_ = 0;
215 if (valid_data_ < data_.size()) ++valid_data_;
216 }
217
Brian Silvermanbc831182016-04-16 02:06:09 -0400218 if (valid_data_ == 0) return false;
219
Austin Schuhfb5f7de2016-11-26 15:15:19 -0800220 const monotonic_clock::time_point capture_time =
221 monotonic_clock::time_point(chrono::nanoseconds(status->target_time));
Brian Silvermanbc831182016-04-16 02:06:09 -0400222 DrivetrainData before, after;
223 FindBeforeAfter(&before, &after, capture_time);
224
225 if (before.time == after.time) {
226 status->drivetrain_left_position = before.left;
227 status->drivetrain_right_position = before.right;
228 } else {
James Kuszmaul651fc3f2019-05-15 21:14:25 -0700229 const double age_ratio =
230 ::aos::time::DurationInSeconds(capture_time - before.time) /
231 ::aos::time::DurationInSeconds(after.time - before.time);
Brian Silvermanbc831182016-04-16 02:06:09 -0400232 status->drivetrain_left_position =
233 before.left * (1 - age_ratio) + after.left * age_ratio;
234 status->drivetrain_right_position =
235 before.right * (1 - age_ratio) + after.right * age_ratio;
236 }
237
238 return true;
239 }
240
Brian Silvermanbc831182016-04-16 02:06:09 -0400241 private:
242 struct DrivetrainData {
Austin Schuhfb5f7de2016-11-26 15:15:19 -0800243 monotonic_clock::time_point time;
Brian Silvermanbc831182016-04-16 02:06:09 -0400244 double left, right;
245 };
246
247 // Fills out before and after with the data surrounding capture_time.
248 // They might be identical if that's the closest approximation.
249 // Do not call this if valid_data_ is 0.
250 void FindBeforeAfter(DrivetrainData *before, DrivetrainData *after,
Austin Schuhfb5f7de2016-11-26 15:15:19 -0800251 monotonic_clock::time_point capture_time) {
Brian Silvermanbc831182016-04-16 02:06:09 -0400252 size_t location = 0;
253 while (true) {
254 // We hit the end of our data. Just fill them both out as the last data
255 // point.
256 if (location >= valid_data_) {
257 *before = *after =
258 data_[previous_index((valid_data_ + data_index_) % data_.size())];
259 return;
260 }
261
262 // The index into data_ corresponding to location positions after
263 // (data_index_ - 1).
264 const size_t index = previous_index(location + data_index_);
265
266 // If we've found the one we want.
267 if (data_[index].time > capture_time) {
268 *after = data_[index];
269 if (location == 0) {
270 // If this is the first one and it's already after, just return the
271 // same thing for both.
272 *before = data_[index];
273 } else {
274 *before = data_[previous_index(index)];
275 }
276 return;
277 }
278
279 ++location;
280 }
281 }
282
283 size_t previous_index(size_t index) const {
284 if (index == 0) {
285 return data_.size() - 1;
286 } else {
287 return index - 1;
288 }
289 }
290
Alex Perrycb7da4b2019-08-28 19:35:56 -0700291 ::aos::Fetcher<::frc971::control_loops::drivetrain::Status>
Austin Schuhbd0a40f2019-06-30 14:56:31 -0700292 drivetrain_status_fetcher_;
293
Brian Silvermanbc831182016-04-16 02:06:09 -0400294 ::std::array<DrivetrainData, 200> data_;
295 // The index into data_ the next data point is going at.
296 size_t data_index_ = 0;
297 // How many elemets of data_ are valid.
298 size_t valid_data_ = 0;
Brian Silvermanbc831182016-04-16 02:06:09 -0400299};
300
Brian Silverman2ccf8c52016-03-15 00:22:26 -0400301void Main() {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700302 aos::FlatbufferDetachedBuffer<aos::Configuration> config =
303 aos::configuration::ReadConfig("config.json");
304
305 ::aos::ShmEventLoop event_loop(&config.message());
Austin Schuh1bf8a212019-05-26 22:13:14 -0700306
307 ::aos::Sender<::y2016::vision::VisionStatus> vision_status_sender =
Tyler Chatow24b5db12020-01-06 21:16:56 -0800308 event_loop.MakeSender<::y2016::vision::VisionStatus>("/vision");
Austin Schuh1bf8a212019-05-26 22:13:14 -0700309
Brian Silverman2ccf8c52016-03-15 00:22:26 -0400310 StereoGeometry stereo(constants::GetValues().vision_name);
Austin Schuhf257f3c2019-10-27 21:00:43 -0700311 AOS_LOG(INFO, "calibration: %s\n",
312 stereo.calibration().ShortDebugString().c_str());
Brian Silverman2ccf8c52016-03-15 00:22:26 -0400313
Austin Schuhbd0a40f2019-06-30 14:56:31 -0700314 DrivetrainOffsetCalculator drivetrain_offset(&event_loop);
Brian Silvermanbc831182016-04-16 02:06:09 -0400315
Austin Schuh11945742016-04-13 22:18:36 -0700316 CameraHandler left;
317 CameraHandler right;
Austin Schuhc65b0ea2016-03-16 22:09:19 -0700318
Parker Schuh2cd173d2017-01-28 00:12:01 -0800319 ::aos::events::RXUdpSocket recv(8080);
Austin Schuhc65b0ea2016-03-16 22:09:19 -0700320 char rawData[65507];
Austin Schuhc65b0ea2016-03-16 22:09:19 -0700321
322 while (true) {
323 // TODO(austin): Don't malloc.
324 VisionData target;
325 int size = recv.Recv(rawData, 65507);
Austin Schuhfb5f7de2016-11-26 15:15:19 -0800326 monotonic_clock::time_point now = monotonic_clock::now();
Austin Schuhc65b0ea2016-03-16 22:09:19 -0700327
328 if (target.ParseFromArray(rawData, size)) {
329 if (target.camera_index() == 0) {
Austin Schuh11945742016-04-13 22:18:36 -0700330 left.Received(target, now);
Austin Schuhc65b0ea2016-03-16 22:09:19 -0700331 } else {
Austin Schuh11945742016-04-13 22:18:36 -0700332 right.Received(target, now);
Brian Silverman2ccf8c52016-03-15 00:22:26 -0400333 }
334 } else {
Austin Schuhf257f3c2019-10-27 21:00:43 -0700335 AOS_LOG(ERROR, "oh noes: parse error\n");
Austin Schuhc65b0ea2016-03-16 22:09:19 -0700336 continue;
337 }
338
Austin Schuh11945742016-04-13 22:18:36 -0700339 left.CheckStale(now);
340 right.CheckStale(now);
Brian Silverman2ccf8c52016-03-15 00:22:26 -0400341
Austin Schuh11945742016-04-13 22:18:36 -0700342 if (left.received_both() && right.received_both()) {
343 const bool left_image_valid = left.is_valid();
344 const bool right_image_valid = right.is_valid();
Austin Schuhc65b0ea2016-03-16 22:09:19 -0700345
Alex Perrycb7da4b2019-08-28 19:35:56 -0700346 auto builder = vision_status_sender.MakeBuilder();
347 VisionStatusT new_vision_status;
348 new_vision_status.left_image_valid = left_image_valid;
349 new_vision_status.right_image_valid = right_image_valid;
Austin Schuhc65b0ea2016-03-16 22:09:19 -0700350 if (left_image_valid && right_image_valid) {
Austin Schuh11945742016-04-13 22:18:36 -0700351 ::aos::vision::Vector<2> center_left(0.0, 0.0);
352 ::aos::vision::Vector<2> center_right(0.0, 0.0);
Austin Schuh6bf73052016-04-20 20:20:25 -0700353 double angle_left;
354 double angle_right;
Austin Schuh11945742016-04-13 22:18:36 -0700355 SelectTargets(left.target(), right.target(), &center_left,
Austin Schuh6bf73052016-04-20 20:20:25 -0700356 &center_right, &angle_left, &angle_right);
Austin Schuh11945742016-04-13 22:18:36 -0700357
358 // TODO(Ben): Remember this from last time instead of recalculating it
359 // each time.
360 ::aos::vision::Vector<2> last_center_left(0.0, 0.0);
361 ::aos::vision::Vector<2> last_center_right(0.0, 0.0);
Austin Schuh6bf73052016-04-20 20:20:25 -0700362 double last_angle_left;
363 double last_angle_right;
Austin Schuh11945742016-04-13 22:18:36 -0700364 SelectTargets(left.last_target(), right.last_target(),
Parker Schuh2cd173d2017-01-28 00:12:01 -0800365 &last_center_left, &last_center_right, &last_angle_left,
366 &last_angle_right);
Austin Schuh11945742016-04-13 22:18:36 -0700367
368 ::aos::vision::Vector<2> filtered_center_left(0.0, 0.0);
369 ::aos::vision::Vector<2> filtered_center_right(0.0, 0.0);
Austin Schuh6bf73052016-04-20 20:20:25 -0700370 double filtered_angle_left;
371 double filtered_angle_right;
Austin Schuh11945742016-04-13 22:18:36 -0700372 if (left.capture_time() < right.capture_time()) {
373 filtered_center_left = center_left;
Austin Schuh6bf73052016-04-20 20:20:25 -0700374 filtered_angle_left = angle_left;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700375 new_vision_status.target_time =
Austin Schuhfb5f7de2016-11-26 15:15:19 -0800376 chrono::duration_cast<chrono::nanoseconds>(
Parker Schuh2cd173d2017-01-28 00:12:01 -0800377 left.capture_time().time_since_epoch())
378 .count();
Austin Schuh6bf73052016-04-20 20:20:25 -0700379 CalculateFiltered(left, right, center_right, last_center_right,
380 angle_right, last_angle_right,
381 &filtered_center_right, &filtered_angle_right);
Austin Schuh11945742016-04-13 22:18:36 -0700382 } else {
383 filtered_center_right = center_right;
Austin Schuh6bf73052016-04-20 20:20:25 -0700384 filtered_angle_right = angle_right;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700385 new_vision_status.target_time =
Austin Schuhfb5f7de2016-11-26 15:15:19 -0800386 chrono::duration_cast<chrono::nanoseconds>(
Parker Schuh2cd173d2017-01-28 00:12:01 -0800387 right.capture_time().time_since_epoch())
388 .count();
Austin Schuh6bf73052016-04-20 20:20:25 -0700389 CalculateFiltered(right, left, center_left, last_center_left,
390 angle_left, last_angle_left, &filtered_center_left,
391 &filtered_angle_left);
Austin Schuh11945742016-04-13 22:18:36 -0700392 }
393
Austin Schuhc65b0ea2016-03-16 22:09:19 -0700394 double distance, horizontal_angle, vertical_angle;
Austin Schuh11945742016-04-13 22:18:36 -0700395 stereo.Process(filtered_center_left, filtered_center_right, &distance,
396 &horizontal_angle, &vertical_angle);
Alex Perrycb7da4b2019-08-28 19:35:56 -0700397 new_vision_status.left_image_timestamp =
Austin Schuh11945742016-04-13 22:18:36 -0700398 left.target().image_timestamp();
Alex Perrycb7da4b2019-08-28 19:35:56 -0700399 new_vision_status.right_image_timestamp =
Austin Schuh11945742016-04-13 22:18:36 -0700400 right.target().image_timestamp();
Alex Perrycb7da4b2019-08-28 19:35:56 -0700401 new_vision_status.left_send_timestamp = left.target().send_timestamp();
402 new_vision_status.right_send_timestamp =
Parker Schuh2cd173d2017-01-28 00:12:01 -0800403 right.target().send_timestamp();
Alex Perrycb7da4b2019-08-28 19:35:56 -0700404 new_vision_status.horizontal_angle = horizontal_angle;
405 new_vision_status.vertical_angle = vertical_angle;
406 new_vision_status.distance = distance;
407 new_vision_status.angle =
Austin Schuh6bf73052016-04-20 20:20:25 -0700408 (filtered_angle_left + filtered_angle_right) / 2.0;
Austin Schuhc65b0ea2016-03-16 22:09:19 -0700409 }
Brian Silverman2ccf8c52016-03-15 00:22:26 -0400410
Alex Perrycb7da4b2019-08-28 19:35:56 -0700411 if (drivetrain_offset.CompleteVisionStatus(&new_vision_status)) {
412 if (!builder.Send(
413 VisionStatus::Pack(*builder.fbb(), &new_vision_status))) {
Austin Schuhf257f3c2019-10-27 21:00:43 -0700414 AOS_LOG(ERROR, "Failed to send vision information\n");
Brian Silvermanbc831182016-04-16 02:06:09 -0400415 }
416 } else {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700417 AOS_LOG(WARNING, "vision without drivetrain");
Brian Silverman2ccf8c52016-03-15 00:22:26 -0400418 }
419 }
Austin Schuhc65b0ea2016-03-16 22:09:19 -0700420
421 if (target.camera_index() == 0) {
Austin Schuhf257f3c2019-10-27 21:00:43 -0700422 AOS_LOG(DEBUG, "left_target: %s\n",
423 left.target().ShortDebugString().c_str());
Austin Schuhc65b0ea2016-03-16 22:09:19 -0700424 } else {
Austin Schuhf257f3c2019-10-27 21:00:43 -0700425 AOS_LOG(DEBUG, "right_target: %s\n",
426 right.target().ShortDebugString().c_str());
Austin Schuhc65b0ea2016-03-16 22:09:19 -0700427 }
Brian Silverman2ccf8c52016-03-15 00:22:26 -0400428 }
Brian Silverman2ccf8c52016-03-15 00:22:26 -0400429}
430
431} // namespace vision
432} // namespace y2016
433
434int main(int /*argc*/, char ** /*argv*/) {
435 ::aos::InitNRT();
436 ::y2016::vision::Main();
437}