blob: 701f7e836574adc415a79cf68bb8ea320b3ebca5 [file] [log] [blame]
Brian Silverman2ccf8c52016-03-15 00:22:26 -04001#include <netdb.h>
2#include <unistd.h>
3
Brian Silvermanbc831182016-04-16 02:06:09 -04004#include <array>
Brian Silvermanbc831182016-04-16 02:06:09 -04005#include <atomic>
Austin Schuhfb5f7de2016-11-26 15:15:19 -08006#include <chrono>
Tyler Chatowbf0609c2021-07-31 16:13:27 -07007#include <cstdlib>
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/time/time.h"
Parker Schuh2cd173d2017-01-28 00:12:01 -080018#include "aos/vision/events/udp.h"
Alex Perrycb7da4b2019-08-28 19:35:56 -070019#include "frc971/control_loops/drivetrain/drivetrain_status_generated.h"
Parker Schuh2cd173d2017-01-28 00:12:01 -080020#include "y2016/constants.h"
21#include "y2016/vision/stereo_geometry.h"
Brian Silverman2ccf8c52016-03-15 00:22:26 -040022#include "y2016/vision/vision_data.pb.h"
Alex Perrycb7da4b2019-08-28 19:35:56 -070023#include "y2016/vision/vision_generated.h"
Brian Silverman2ccf8c52016-03-15 00:22:26 -040024
25namespace y2016 {
26namespace vision {
27
Austin Schuhfb5f7de2016-11-26 15:15:19 -080028namespace chrono = ::std::chrono;
29using ::aos::monotonic_clock;
30
Austin Schuh11945742016-04-13 22:18:36 -070031::aos::vision::Vector<2> CreateCenterFromTarget(double lx, double ly, double rx,
32 double ry) {
ben54dbccb2016-03-20 14:42:28 -070033 return ::aos::vision::Vector<2>((lx + rx) / 2.0, (ly + ry) / 2.0);
34}
35
36double TargetWidth(double lx, double ly, double rx, double ry) {
37 double dx = lx - rx;
38 double dy = ly - ry;
Austin Schuh098e4872016-03-20 16:51:24 -070039 return ::std::hypot(dx, dy);
ben54dbccb2016-03-20 14:42:28 -070040}
41
42void SelectTargets(const VisionData &left_target,
43 const VisionData &right_target,
44 ::aos::vision::Vector<2> *center_left,
Austin Schuh6bf73052016-04-20 20:20:25 -070045 ::aos::vision::Vector<2> *center_right, double *angle_left,
46 double *angle_right) {
ben54dbccb2016-03-20 14:42:28 -070047 // No good targets. Let the caller decide defaults.
48 if (right_target.target_size() == 0 || left_target.target_size() == 0) {
49 return;
50 }
51
52 // Only one option, we have to go with it.
53 if (right_target.target_size() == 1 && left_target.target_size() == 1) {
54 *center_left =
55 CreateCenterFromTarget(left_target.target(0).left_corner_x(),
56 left_target.target(0).left_corner_y(),
57 left_target.target(0).right_corner_x(),
58 left_target.target(0).right_corner_y());
59 *center_right =
60 CreateCenterFromTarget(right_target.target(0).left_corner_x(),
61 right_target.target(0).left_corner_y(),
62 right_target.target(0).right_corner_x(),
63 right_target.target(0).right_corner_y());
64 return;
65 }
66
67 // Now we have to make a decision.
Austin Schuh9f59c8a2016-03-20 21:09:05 -070068 double min_angle = -1.0;
ben54dbccb2016-03-20 14:42:28 -070069 int left_index = 0;
70 // First pick the widest target from the left.
71 for (int i = 0; i < left_target.target_size(); i++) {
Austin Schuh9f59c8a2016-03-20 21:09:05 -070072 const double h = left_target.target(i).left_corner_y() -
73 left_target.target(i).right_corner_y();
74 const double wid1 = TargetWidth(left_target.target(i).left_corner_x(),
75 left_target.target(i).left_corner_y(),
76 left_target.target(i).right_corner_x(),
77 left_target.target(i).right_corner_y());
78 const double angle = h / wid1;
79 if (min_angle == -1.0 || ::std::abs(angle) < ::std::abs(min_angle)) {
80 min_angle = angle;
Austin Schuh6bf73052016-04-20 20:20:25 -070081 *angle_left = angle;
ben54dbccb2016-03-20 14:42:28 -070082 left_index = i;
83 }
84 }
85 // Calculate the angle of the bottom edge for the left.
86 double h = left_target.target(left_index).left_corner_y() -
87 left_target.target(left_index).right_corner_y();
Austin Schuh9f59c8a2016-03-20 21:09:05 -070088
89 double good_ang = min_angle;
ben54dbccb2016-03-20 14:42:28 -070090 double min_ang_err = -1.0;
91 int right_index = -1;
Austin Schuh11945742016-04-13 22:18:36 -070092 // Now pick the bottom edge angle from the right that lines up best with the
93 // left.
ben54dbccb2016-03-20 14:42:28 -070094 for (int j = 0; j < right_target.target_size(); j++) {
95 double wid2 = TargetWidth(right_target.target(j).left_corner_x(),
Austin Schuh11945742016-04-13 22:18:36 -070096 right_target.target(j).left_corner_y(),
97 right_target.target(j).right_corner_x(),
98 right_target.target(j).right_corner_y());
ben54dbccb2016-03-20 14:42:28 -070099 h = right_target.target(j).left_corner_y() -
100 right_target.target(j).right_corner_y();
Austin Schuh11945742016-04-13 22:18:36 -0700101 double ang = h / wid2;
ben54dbccb2016-03-20 14:42:28 -0700102 double ang_err = ::std::abs(good_ang - ang);
103 if (min_ang_err == -1.0 || min_ang_err > ang_err) {
104 min_ang_err = ang_err;
105 right_index = j;
Austin Schuh6bf73052016-04-20 20:20:25 -0700106 *angle_right = ang;
ben54dbccb2016-03-20 14:42:28 -0700107 }
108 }
109
110 *center_left =
111 CreateCenterFromTarget(left_target.target(left_index).left_corner_x(),
112 left_target.target(left_index).left_corner_y(),
113 left_target.target(left_index).right_corner_x(),
114 left_target.target(left_index).right_corner_y());
115 *center_right =
116 CreateCenterFromTarget(right_target.target(right_index).left_corner_x(),
117 right_target.target(right_index).left_corner_y(),
118 right_target.target(right_index).right_corner_x(),
119 right_target.target(right_index).right_corner_y());
120}
121
Austin Schuh11945742016-04-13 22:18:36 -0700122class CameraHandler {
123 public:
Austin Schuhfb5f7de2016-11-26 15:15:19 -0800124 void Received(const VisionData &target, monotonic_clock::time_point now) {
Austin Schuh11945742016-04-13 22:18:36 -0700125 if (current_.received) {
126 last_ = current_;
127 }
128 current_.target = target;
129 current_.rx_time = now;
Austin Schuh6fe1d512016-04-24 19:12:04 -0700130 current_.capture_time = now -
Austin Schuhfb5f7de2016-11-26 15:15:19 -0800131 chrono::nanoseconds(target.send_timestamp() -
132 target.image_timestamp()) +
Austin Schuh6fe1d512016-04-24 19:12:04 -0700133 // It takes a bit to shoot a frame. Push the frame
134 // further back in time.
Austin Schuhfb5f7de2016-11-26 15:15:19 -0800135 chrono::milliseconds(10);
Austin Schuh11945742016-04-13 22:18:36 -0700136 current_.received = true;
137 }
138
Austin Schuhfb5f7de2016-11-26 15:15:19 -0800139 void CheckStale(monotonic_clock::time_point now) {
140 if (now > current_.rx_time + chrono::milliseconds(50)) {
Austin Schuh11945742016-04-13 22:18:36 -0700141 current_.received = false;
142 last_.received = false;
143 }
144 }
145
146 bool received_both() const { return current_.received && last_.received; }
147
148 bool is_valid() const {
149 return current_.target.target_size() > 0 && last_.target.target_size() > 0;
150 }
151
152 const VisionData &target() const { return current_.target; }
153 const VisionData &last_target() const { return last_.target; }
154
Austin Schuhfb5f7de2016-11-26 15:15:19 -0800155 monotonic_clock::time_point capture_time() const {
156 return current_.capture_time;
157 }
158 monotonic_clock::time_point last_capture_time() const {
159 return last_.capture_time;
160 }
Austin Schuh11945742016-04-13 22:18:36 -0700161
162 private:
163 struct TargetWithTimes {
164 VisionData target;
Austin Schuhfb5f7de2016-11-26 15:15:19 -0800165 monotonic_clock::time_point rx_time{monotonic_clock::epoch()};
166 monotonic_clock::time_point capture_time{monotonic_clock::epoch()};
Austin Schuh11945742016-04-13 22:18:36 -0700167 bool received = false;
168 };
169
170 TargetWithTimes current_;
171 TargetWithTimes last_;
172};
173
Austin Schuh6bf73052016-04-20 20:20:25 -0700174void CalculateFiltered(const CameraHandler &older, const CameraHandler &newer,
175 const ::aos::vision::Vector<2> &newer_center,
176 const ::aos::vision::Vector<2> &last_newer_center,
177 double angle, double last_angle,
178 ::aos::vision::Vector<2> *interpolated_result,
179 double *interpolated_angle) {
James Kuszmaul651fc3f2019-05-15 21:14:25 -0700180 const double age_ratio =
181 ::aos::time::DurationInSeconds(older.capture_time() -
182 newer.last_capture_time()) /
183 ::aos::time::DurationInSeconds(newer.capture_time() -
184 newer.last_capture_time());
Austin Schuh6bf73052016-04-20 20:20:25 -0700185 interpolated_result->Set(
Austin Schuh11945742016-04-13 22:18:36 -0700186 newer_center.x() * age_ratio + (1 - age_ratio) * last_newer_center.x(),
187 newer_center.y() * age_ratio + (1 - age_ratio) * last_newer_center.y());
Austin Schuh6bf73052016-04-20 20:20:25 -0700188
189 *interpolated_angle = angle * age_ratio + (1 - age_ratio) * last_angle;
Austin Schuh11945742016-04-13 22:18:36 -0700190}
ben54dbccb2016-03-20 14:42:28 -0700191
Brian Silvermanbc831182016-04-16 02:06:09 -0400192// Handles calculating drivetrain offsets.
193class DrivetrainOffsetCalculator {
194 public:
Austin Schuhbd0a40f2019-06-30 14:56:31 -0700195 DrivetrainOffsetCalculator(::aos::EventLoop *event_loop)
196 : drivetrain_status_fetcher_(
197 event_loop
Alex Perrycb7da4b2019-08-28 19:35:56 -0700198 ->MakeFetcher<::frc971::control_loops::drivetrain::Status>(
199 "/drivetrain")) {}
Brian Silvermanbc831182016-04-16 02:06:09 -0400200
201 // Takes a vision status message with everything except
202 // drivetrain_{left,right}_position set and sets those.
203 // Returns false if it doesn't have enough data to fill them out.
Alex Perrycb7da4b2019-08-28 19:35:56 -0700204 bool CompleteVisionStatus(::y2016::vision::VisionStatusT *status) {
Austin Schuhbd0a40f2019-06-30 14:56:31 -0700205 while (drivetrain_status_fetcher_.FetchNext()) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700206 data_[data_index_].time =
Austin Schuhad154822019-12-27 15:45:13 -0800207 drivetrain_status_fetcher_.context().monotonic_event_time;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700208 data_[data_index_].left =
209 drivetrain_status_fetcher_->estimated_left_position();
210 data_[data_index_].right =
211 drivetrain_status_fetcher_->estimated_right_position();
Austin Schuhbd0a40f2019-06-30 14:56:31 -0700212 ++data_index_;
213 if (data_index_ == data_.size()) data_index_ = 0;
214 if (valid_data_ < data_.size()) ++valid_data_;
215 }
216
Brian Silvermanbc831182016-04-16 02:06:09 -0400217 if (valid_data_ == 0) return false;
218
Austin Schuhfb5f7de2016-11-26 15:15:19 -0800219 const monotonic_clock::time_point capture_time =
220 monotonic_clock::time_point(chrono::nanoseconds(status->target_time));
Brian Silvermanbc831182016-04-16 02:06:09 -0400221 DrivetrainData before, after;
222 FindBeforeAfter(&before, &after, capture_time);
223
224 if (before.time == after.time) {
225 status->drivetrain_left_position = before.left;
226 status->drivetrain_right_position = before.right;
227 } else {
James Kuszmaul651fc3f2019-05-15 21:14:25 -0700228 const double age_ratio =
229 ::aos::time::DurationInSeconds(capture_time - before.time) /
230 ::aos::time::DurationInSeconds(after.time - before.time);
Brian Silvermanbc831182016-04-16 02:06:09 -0400231 status->drivetrain_left_position =
232 before.left * (1 - age_ratio) + after.left * age_ratio;
233 status->drivetrain_right_position =
234 before.right * (1 - age_ratio) + after.right * age_ratio;
235 }
236
237 return true;
238 }
239
Brian Silvermanbc831182016-04-16 02:06:09 -0400240 private:
241 struct DrivetrainData {
Austin Schuhfb5f7de2016-11-26 15:15:19 -0800242 monotonic_clock::time_point time;
Brian Silvermanbc831182016-04-16 02:06:09 -0400243 double left, right;
244 };
245
246 // Fills out before and after with the data surrounding capture_time.
247 // They might be identical if that's the closest approximation.
248 // Do not call this if valid_data_ is 0.
249 void FindBeforeAfter(DrivetrainData *before, DrivetrainData *after,
Austin Schuhfb5f7de2016-11-26 15:15:19 -0800250 monotonic_clock::time_point capture_time) {
Brian Silvermanbc831182016-04-16 02:06:09 -0400251 size_t location = 0;
252 while (true) {
253 // We hit the end of our data. Just fill them both out as the last data
254 // point.
255 if (location >= valid_data_) {
256 *before = *after =
257 data_[previous_index((valid_data_ + data_index_) % data_.size())];
258 return;
259 }
260
261 // The index into data_ corresponding to location positions after
262 // (data_index_ - 1).
263 const size_t index = previous_index(location + data_index_);
264
265 // If we've found the one we want.
266 if (data_[index].time > capture_time) {
267 *after = data_[index];
268 if (location == 0) {
269 // If this is the first one and it's already after, just return the
270 // same thing for both.
271 *before = data_[index];
272 } else {
273 *before = data_[previous_index(index)];
274 }
275 return;
276 }
277
278 ++location;
279 }
280 }
281
282 size_t previous_index(size_t index) const {
283 if (index == 0) {
284 return data_.size() - 1;
285 } else {
286 return index - 1;
287 }
288 }
289
Alex Perrycb7da4b2019-08-28 19:35:56 -0700290 ::aos::Fetcher<::frc971::control_loops::drivetrain::Status>
Austin Schuhbd0a40f2019-06-30 14:56:31 -0700291 drivetrain_status_fetcher_;
292
Brian Silvermanbc831182016-04-16 02:06:09 -0400293 ::std::array<DrivetrainData, 200> data_;
294 // The index into data_ the next data point is going at.
295 size_t data_index_ = 0;
296 // How many elemets of data_ are valid.
297 size_t valid_data_ = 0;
Brian Silvermanbc831182016-04-16 02:06:09 -0400298};
299
Brian Silverman2ccf8c52016-03-15 00:22:26 -0400300void Main() {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700301 aos::FlatbufferDetachedBuffer<aos::Configuration> config =
Austin Schuhc5fa6d92022-02-25 14:36:28 -0800302 aos::configuration::ReadConfig("aos_config.json");
Alex Perrycb7da4b2019-08-28 19:35:56 -0700303
304 ::aos::ShmEventLoop event_loop(&config.message());
Austin Schuh1bf8a212019-05-26 22:13:14 -0700305
306 ::aos::Sender<::y2016::vision::VisionStatus> vision_status_sender =
Tyler Chatow24b5db12020-01-06 21:16:56 -0800307 event_loop.MakeSender<::y2016::vision::VisionStatus>("/vision");
Austin Schuh1bf8a212019-05-26 22:13:14 -0700308
Brian Silverman2ccf8c52016-03-15 00:22:26 -0400309 StereoGeometry stereo(constants::GetValues().vision_name);
Austin Schuhf257f3c2019-10-27 21:00:43 -0700310 AOS_LOG(INFO, "calibration: %s\n",
311 stereo.calibration().ShortDebugString().c_str());
Brian Silverman2ccf8c52016-03-15 00:22:26 -0400312
Austin Schuhbd0a40f2019-06-30 14:56:31 -0700313 DrivetrainOffsetCalculator drivetrain_offset(&event_loop);
Brian Silvermanbc831182016-04-16 02:06:09 -0400314
Austin Schuh11945742016-04-13 22:18:36 -0700315 CameraHandler left;
316 CameraHandler right;
Austin Schuhc65b0ea2016-03-16 22:09:19 -0700317
Parker Schuh2cd173d2017-01-28 00:12:01 -0800318 ::aos::events::RXUdpSocket recv(8080);
Austin Schuhc65b0ea2016-03-16 22:09:19 -0700319 char rawData[65507];
Austin Schuhc65b0ea2016-03-16 22:09:19 -0700320
321 while (true) {
322 // TODO(austin): Don't malloc.
323 VisionData target;
324 int size = recv.Recv(rawData, 65507);
Austin Schuhfb5f7de2016-11-26 15:15:19 -0800325 monotonic_clock::time_point now = monotonic_clock::now();
Austin Schuhc65b0ea2016-03-16 22:09:19 -0700326
327 if (target.ParseFromArray(rawData, size)) {
328 if (target.camera_index() == 0) {
Austin Schuh11945742016-04-13 22:18:36 -0700329 left.Received(target, now);
Austin Schuhc65b0ea2016-03-16 22:09:19 -0700330 } else {
Austin Schuh11945742016-04-13 22:18:36 -0700331 right.Received(target, now);
Brian Silverman2ccf8c52016-03-15 00:22:26 -0400332 }
333 } else {
Austin Schuhf257f3c2019-10-27 21:00:43 -0700334 AOS_LOG(ERROR, "oh noes: parse error\n");
Austin Schuhc65b0ea2016-03-16 22:09:19 -0700335 continue;
336 }
337
Austin Schuh11945742016-04-13 22:18:36 -0700338 left.CheckStale(now);
339 right.CheckStale(now);
Brian Silverman2ccf8c52016-03-15 00:22:26 -0400340
Austin Schuh11945742016-04-13 22:18:36 -0700341 if (left.received_both() && right.received_both()) {
342 const bool left_image_valid = left.is_valid();
343 const bool right_image_valid = right.is_valid();
Austin Schuhc65b0ea2016-03-16 22:09:19 -0700344
Alex Perrycb7da4b2019-08-28 19:35:56 -0700345 auto builder = vision_status_sender.MakeBuilder();
346 VisionStatusT new_vision_status;
347 new_vision_status.left_image_valid = left_image_valid;
348 new_vision_status.right_image_valid = right_image_valid;
Austin Schuhc65b0ea2016-03-16 22:09:19 -0700349 if (left_image_valid && right_image_valid) {
Austin Schuh11945742016-04-13 22:18:36 -0700350 ::aos::vision::Vector<2> center_left(0.0, 0.0);
351 ::aos::vision::Vector<2> center_right(0.0, 0.0);
Austin Schuh6bf73052016-04-20 20:20:25 -0700352 double angle_left;
353 double angle_right;
Austin Schuh11945742016-04-13 22:18:36 -0700354 SelectTargets(left.target(), right.target(), &center_left,
Austin Schuh6bf73052016-04-20 20:20:25 -0700355 &center_right, &angle_left, &angle_right);
Austin Schuh11945742016-04-13 22:18:36 -0700356
357 // TODO(Ben): Remember this from last time instead of recalculating it
358 // each time.
359 ::aos::vision::Vector<2> last_center_left(0.0, 0.0);
360 ::aos::vision::Vector<2> last_center_right(0.0, 0.0);
Austin Schuh6bf73052016-04-20 20:20:25 -0700361 double last_angle_left;
362 double last_angle_right;
Austin Schuh11945742016-04-13 22:18:36 -0700363 SelectTargets(left.last_target(), right.last_target(),
Parker Schuh2cd173d2017-01-28 00:12:01 -0800364 &last_center_left, &last_center_right, &last_angle_left,
365 &last_angle_right);
Austin Schuh11945742016-04-13 22:18:36 -0700366
367 ::aos::vision::Vector<2> filtered_center_left(0.0, 0.0);
368 ::aos::vision::Vector<2> filtered_center_right(0.0, 0.0);
Austin Schuh6bf73052016-04-20 20:20:25 -0700369 double filtered_angle_left;
370 double filtered_angle_right;
Austin Schuh11945742016-04-13 22:18:36 -0700371 if (left.capture_time() < right.capture_time()) {
372 filtered_center_left = center_left;
Austin Schuh6bf73052016-04-20 20:20:25 -0700373 filtered_angle_left = angle_left;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700374 new_vision_status.target_time =
Austin Schuhfb5f7de2016-11-26 15:15:19 -0800375 chrono::duration_cast<chrono::nanoseconds>(
Parker Schuh2cd173d2017-01-28 00:12:01 -0800376 left.capture_time().time_since_epoch())
377 .count();
Austin Schuh6bf73052016-04-20 20:20:25 -0700378 CalculateFiltered(left, right, center_right, last_center_right,
379 angle_right, last_angle_right,
380 &filtered_center_right, &filtered_angle_right);
Austin Schuh11945742016-04-13 22:18:36 -0700381 } else {
382 filtered_center_right = center_right;
Austin Schuh6bf73052016-04-20 20:20:25 -0700383 filtered_angle_right = angle_right;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700384 new_vision_status.target_time =
Austin Schuhfb5f7de2016-11-26 15:15:19 -0800385 chrono::duration_cast<chrono::nanoseconds>(
Parker Schuh2cd173d2017-01-28 00:12:01 -0800386 right.capture_time().time_since_epoch())
387 .count();
Austin Schuh6bf73052016-04-20 20:20:25 -0700388 CalculateFiltered(right, left, center_left, last_center_left,
389 angle_left, last_angle_left, &filtered_center_left,
390 &filtered_angle_left);
Austin Schuh11945742016-04-13 22:18:36 -0700391 }
392
Austin Schuhc65b0ea2016-03-16 22:09:19 -0700393 double distance, horizontal_angle, vertical_angle;
Austin Schuh11945742016-04-13 22:18:36 -0700394 stereo.Process(filtered_center_left, filtered_center_right, &distance,
395 &horizontal_angle, &vertical_angle);
Alex Perrycb7da4b2019-08-28 19:35:56 -0700396 new_vision_status.left_image_timestamp =
Austin Schuh11945742016-04-13 22:18:36 -0700397 left.target().image_timestamp();
Alex Perrycb7da4b2019-08-28 19:35:56 -0700398 new_vision_status.right_image_timestamp =
Austin Schuh11945742016-04-13 22:18:36 -0700399 right.target().image_timestamp();
Alex Perrycb7da4b2019-08-28 19:35:56 -0700400 new_vision_status.left_send_timestamp = left.target().send_timestamp();
401 new_vision_status.right_send_timestamp =
Parker Schuh2cd173d2017-01-28 00:12:01 -0800402 right.target().send_timestamp();
Alex Perrycb7da4b2019-08-28 19:35:56 -0700403 new_vision_status.horizontal_angle = horizontal_angle;
404 new_vision_status.vertical_angle = vertical_angle;
405 new_vision_status.distance = distance;
406 new_vision_status.angle =
Austin Schuh6bf73052016-04-20 20:20:25 -0700407 (filtered_angle_left + filtered_angle_right) / 2.0;
Austin Schuhc65b0ea2016-03-16 22:09:19 -0700408 }
Brian Silverman2ccf8c52016-03-15 00:22:26 -0400409
Alex Perrycb7da4b2019-08-28 19:35:56 -0700410 if (drivetrain_offset.CompleteVisionStatus(&new_vision_status)) {
milind1f1dca32021-07-03 13:50:07 -0700411 if (builder.Send(
412 VisionStatus::Pack(*builder.fbb(), &new_vision_status)) !=
413 aos::RawSender::Error::kOk) {
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
Austin Schuh094d09b2020-11-20 23:26:52 -0800434int main(int argc, char **argv) {
435 ::aos::InitGoogle(&argc, &argv);
Brian Silverman2ccf8c52016-03-15 00:22:26 -0400436 ::y2016::vision::Main();
437}