blob: 5aa854e5683f3432f19ee110a979f7a00dd2eda2 [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
Stephan Pleinesf63bde82024-01-13 15:59:33 -080025namespace y2016::vision {
Brian Silverman2ccf8c52016-03-15 00:22:26 -040026
Austin Schuhfb5f7de2016-11-26 15:15:19 -080027namespace chrono = ::std::chrono;
28using ::aos::monotonic_clock;
29
Austin Schuh11945742016-04-13 22:18:36 -070030::aos::vision::Vector<2> CreateCenterFromTarget(double lx, double ly, double rx,
31 double ry) {
ben54dbccb2016-03-20 14:42:28 -070032 return ::aos::vision::Vector<2>((lx + rx) / 2.0, (ly + ry) / 2.0);
33}
34
35double TargetWidth(double lx, double ly, double rx, double ry) {
36 double dx = lx - rx;
37 double dy = ly - ry;
Austin Schuh098e4872016-03-20 16:51:24 -070038 return ::std::hypot(dx, dy);
ben54dbccb2016-03-20 14:42:28 -070039}
40
41void SelectTargets(const VisionData &left_target,
42 const VisionData &right_target,
43 ::aos::vision::Vector<2> *center_left,
Austin Schuh6bf73052016-04-20 20:20:25 -070044 ::aos::vision::Vector<2> *center_right, double *angle_left,
45 double *angle_right) {
ben54dbccb2016-03-20 14:42:28 -070046 // No good targets. Let the caller decide defaults.
47 if (right_target.target_size() == 0 || left_target.target_size() == 0) {
48 return;
49 }
50
51 // Only one option, we have to go with it.
52 if (right_target.target_size() == 1 && left_target.target_size() == 1) {
53 *center_left =
54 CreateCenterFromTarget(left_target.target(0).left_corner_x(),
55 left_target.target(0).left_corner_y(),
56 left_target.target(0).right_corner_x(),
57 left_target.target(0).right_corner_y());
58 *center_right =
59 CreateCenterFromTarget(right_target.target(0).left_corner_x(),
60 right_target.target(0).left_corner_y(),
61 right_target.target(0).right_corner_x(),
62 right_target.target(0).right_corner_y());
63 return;
64 }
65
66 // Now we have to make a decision.
Austin Schuh9f59c8a2016-03-20 21:09:05 -070067 double min_angle = -1.0;
ben54dbccb2016-03-20 14:42:28 -070068 int left_index = 0;
69 // First pick the widest target from the left.
70 for (int i = 0; i < left_target.target_size(); i++) {
Austin Schuh9f59c8a2016-03-20 21:09:05 -070071 const double h = left_target.target(i).left_corner_y() -
72 left_target.target(i).right_corner_y();
73 const double wid1 = TargetWidth(left_target.target(i).left_corner_x(),
74 left_target.target(i).left_corner_y(),
75 left_target.target(i).right_corner_x(),
76 left_target.target(i).right_corner_y());
77 const double angle = h / wid1;
78 if (min_angle == -1.0 || ::std::abs(angle) < ::std::abs(min_angle)) {
79 min_angle = angle;
Austin Schuh6bf73052016-04-20 20:20:25 -070080 *angle_left = angle;
ben54dbccb2016-03-20 14:42:28 -070081 left_index = i;
82 }
83 }
84 // Calculate the angle of the bottom edge for the left.
85 double h = left_target.target(left_index).left_corner_y() -
86 left_target.target(left_index).right_corner_y();
Austin Schuh9f59c8a2016-03-20 21:09:05 -070087
88 double good_ang = min_angle;
ben54dbccb2016-03-20 14:42:28 -070089 double min_ang_err = -1.0;
90 int right_index = -1;
Austin Schuh11945742016-04-13 22:18:36 -070091 // Now pick the bottom edge angle from the right that lines up best with the
92 // left.
ben54dbccb2016-03-20 14:42:28 -070093 for (int j = 0; j < right_target.target_size(); j++) {
94 double wid2 = TargetWidth(right_target.target(j).left_corner_x(),
Austin Schuh11945742016-04-13 22:18:36 -070095 right_target.target(j).left_corner_y(),
96 right_target.target(j).right_corner_x(),
97 right_target.target(j).right_corner_y());
ben54dbccb2016-03-20 14:42:28 -070098 h = right_target.target(j).left_corner_y() -
99 right_target.target(j).right_corner_y();
Austin Schuh11945742016-04-13 22:18:36 -0700100 double ang = h / wid2;
ben54dbccb2016-03-20 14:42:28 -0700101 double ang_err = ::std::abs(good_ang - ang);
102 if (min_ang_err == -1.0 || min_ang_err > ang_err) {
103 min_ang_err = ang_err;
104 right_index = j;
Austin Schuh6bf73052016-04-20 20:20:25 -0700105 *angle_right = ang;
ben54dbccb2016-03-20 14:42:28 -0700106 }
107 }
108
109 *center_left =
110 CreateCenterFromTarget(left_target.target(left_index).left_corner_x(),
111 left_target.target(left_index).left_corner_y(),
112 left_target.target(left_index).right_corner_x(),
113 left_target.target(left_index).right_corner_y());
114 *center_right =
115 CreateCenterFromTarget(right_target.target(right_index).left_corner_x(),
116 right_target.target(right_index).left_corner_y(),
117 right_target.target(right_index).right_corner_x(),
118 right_target.target(right_index).right_corner_y());
119}
120
Austin Schuh11945742016-04-13 22:18:36 -0700121class CameraHandler {
122 public:
Austin Schuhfb5f7de2016-11-26 15:15:19 -0800123 void Received(const VisionData &target, monotonic_clock::time_point now) {
Austin Schuh11945742016-04-13 22:18:36 -0700124 if (current_.received) {
125 last_ = current_;
126 }
127 current_.target = target;
128 current_.rx_time = now;
Austin Schuh6fe1d512016-04-24 19:12:04 -0700129 current_.capture_time = now -
Austin Schuhfb5f7de2016-11-26 15:15:19 -0800130 chrono::nanoseconds(target.send_timestamp() -
131 target.image_timestamp()) +
Austin Schuh6fe1d512016-04-24 19:12:04 -0700132 // It takes a bit to shoot a frame. Push the frame
133 // further back in time.
Austin Schuhfb5f7de2016-11-26 15:15:19 -0800134 chrono::milliseconds(10);
Austin Schuh11945742016-04-13 22:18:36 -0700135 current_.received = true;
136 }
137
Austin Schuhfb5f7de2016-11-26 15:15:19 -0800138 void CheckStale(monotonic_clock::time_point now) {
139 if (now > current_.rx_time + chrono::milliseconds(50)) {
Austin Schuh11945742016-04-13 22:18:36 -0700140 current_.received = false;
141 last_.received = false;
142 }
143 }
144
145 bool received_both() const { return current_.received && last_.received; }
146
147 bool is_valid() const {
148 return current_.target.target_size() > 0 && last_.target.target_size() > 0;
149 }
150
151 const VisionData &target() const { return current_.target; }
152 const VisionData &last_target() const { return last_.target; }
153
Austin Schuhfb5f7de2016-11-26 15:15:19 -0800154 monotonic_clock::time_point capture_time() const {
155 return current_.capture_time;
156 }
157 monotonic_clock::time_point last_capture_time() const {
158 return last_.capture_time;
159 }
Austin Schuh11945742016-04-13 22:18:36 -0700160
161 private:
162 struct TargetWithTimes {
163 VisionData target;
Austin Schuhfb5f7de2016-11-26 15:15:19 -0800164 monotonic_clock::time_point rx_time{monotonic_clock::epoch()};
165 monotonic_clock::time_point capture_time{monotonic_clock::epoch()};
Austin Schuh11945742016-04-13 22:18:36 -0700166 bool received = false;
167 };
168
169 TargetWithTimes current_;
170 TargetWithTimes last_;
171};
172
Austin Schuh6bf73052016-04-20 20:20:25 -0700173void CalculateFiltered(const CameraHandler &older, const CameraHandler &newer,
174 const ::aos::vision::Vector<2> &newer_center,
175 const ::aos::vision::Vector<2> &last_newer_center,
176 double angle, double last_angle,
177 ::aos::vision::Vector<2> *interpolated_result,
178 double *interpolated_angle) {
James Kuszmaul651fc3f2019-05-15 21:14:25 -0700179 const double age_ratio =
180 ::aos::time::DurationInSeconds(older.capture_time() -
181 newer.last_capture_time()) /
182 ::aos::time::DurationInSeconds(newer.capture_time() -
183 newer.last_capture_time());
Austin Schuh6bf73052016-04-20 20:20:25 -0700184 interpolated_result->Set(
Austin Schuh11945742016-04-13 22:18:36 -0700185 newer_center.x() * age_ratio + (1 - age_ratio) * last_newer_center.x(),
186 newer_center.y() * age_ratio + (1 - age_ratio) * last_newer_center.y());
Austin Schuh6bf73052016-04-20 20:20:25 -0700187
188 *interpolated_angle = angle * age_ratio + (1 - age_ratio) * last_angle;
Austin Schuh11945742016-04-13 22:18:36 -0700189}
ben54dbccb2016-03-20 14:42:28 -0700190
Brian Silvermanbc831182016-04-16 02:06:09 -0400191// Handles calculating drivetrain offsets.
192class DrivetrainOffsetCalculator {
193 public:
Austin Schuhbd0a40f2019-06-30 14:56:31 -0700194 DrivetrainOffsetCalculator(::aos::EventLoop *event_loop)
195 : drivetrain_status_fetcher_(
196 event_loop
Alex Perrycb7da4b2019-08-28 19:35:56 -0700197 ->MakeFetcher<::frc971::control_loops::drivetrain::Status>(
198 "/drivetrain")) {}
Brian Silvermanbc831182016-04-16 02:06:09 -0400199
200 // Takes a vision status message with everything except
201 // drivetrain_{left,right}_position set and sets those.
202 // Returns false if it doesn't have enough data to fill them out.
Alex Perrycb7da4b2019-08-28 19:35:56 -0700203 bool CompleteVisionStatus(::y2016::vision::VisionStatusT *status) {
Austin Schuhbd0a40f2019-06-30 14:56:31 -0700204 while (drivetrain_status_fetcher_.FetchNext()) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700205 data_[data_index_].time =
Austin Schuhad154822019-12-27 15:45:13 -0800206 drivetrain_status_fetcher_.context().monotonic_event_time;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700207 data_[data_index_].left =
208 drivetrain_status_fetcher_->estimated_left_position();
209 data_[data_index_].right =
210 drivetrain_status_fetcher_->estimated_right_position();
Austin Schuhbd0a40f2019-06-30 14:56:31 -0700211 ++data_index_;
212 if (data_index_ == data_.size()) data_index_ = 0;
213 if (valid_data_ < data_.size()) ++valid_data_;
214 }
215
Brian Silvermanbc831182016-04-16 02:06:09 -0400216 if (valid_data_ == 0) return false;
217
Austin Schuhfb5f7de2016-11-26 15:15:19 -0800218 const monotonic_clock::time_point capture_time =
219 monotonic_clock::time_point(chrono::nanoseconds(status->target_time));
Brian Silvermanbc831182016-04-16 02:06:09 -0400220 DrivetrainData before, after;
221 FindBeforeAfter(&before, &after, capture_time);
222
223 if (before.time == after.time) {
224 status->drivetrain_left_position = before.left;
225 status->drivetrain_right_position = before.right;
226 } else {
James Kuszmaul651fc3f2019-05-15 21:14:25 -0700227 const double age_ratio =
228 ::aos::time::DurationInSeconds(capture_time - before.time) /
229 ::aos::time::DurationInSeconds(after.time - before.time);
Brian Silvermanbc831182016-04-16 02:06:09 -0400230 status->drivetrain_left_position =
231 before.left * (1 - age_ratio) + after.left * age_ratio;
232 status->drivetrain_right_position =
233 before.right * (1 - age_ratio) + after.right * age_ratio;
234 }
235
236 return true;
237 }
238
Brian Silvermanbc831182016-04-16 02:06:09 -0400239 private:
240 struct DrivetrainData {
Austin Schuhfb5f7de2016-11-26 15:15:19 -0800241 monotonic_clock::time_point time;
Brian Silvermanbc831182016-04-16 02:06:09 -0400242 double left, right;
243 };
244
245 // Fills out before and after with the data surrounding capture_time.
246 // They might be identical if that's the closest approximation.
247 // Do not call this if valid_data_ is 0.
248 void FindBeforeAfter(DrivetrainData *before, DrivetrainData *after,
Austin Schuhfb5f7de2016-11-26 15:15:19 -0800249 monotonic_clock::time_point capture_time) {
Brian Silvermanbc831182016-04-16 02:06:09 -0400250 size_t location = 0;
251 while (true) {
252 // We hit the end of our data. Just fill them both out as the last data
253 // point.
254 if (location >= valid_data_) {
255 *before = *after =
256 data_[previous_index((valid_data_ + data_index_) % data_.size())];
257 return;
258 }
259
260 // The index into data_ corresponding to location positions after
261 // (data_index_ - 1).
262 const size_t index = previous_index(location + data_index_);
263
264 // If we've found the one we want.
265 if (data_[index].time > capture_time) {
266 *after = data_[index];
267 if (location == 0) {
268 // If this is the first one and it's already after, just return the
269 // same thing for both.
270 *before = data_[index];
271 } else {
272 *before = data_[previous_index(index)];
273 }
274 return;
275 }
276
277 ++location;
278 }
279 }
280
281 size_t previous_index(size_t index) const {
282 if (index == 0) {
283 return data_.size() - 1;
284 } else {
285 return index - 1;
286 }
287 }
288
Alex Perrycb7da4b2019-08-28 19:35:56 -0700289 ::aos::Fetcher<::frc971::control_loops::drivetrain::Status>
Austin Schuhbd0a40f2019-06-30 14:56:31 -0700290 drivetrain_status_fetcher_;
291
Brian Silvermanbc831182016-04-16 02:06:09 -0400292 ::std::array<DrivetrainData, 200> data_;
293 // The index into data_ the next data point is going at.
294 size_t data_index_ = 0;
295 // How many elemets of data_ are valid.
296 size_t valid_data_ = 0;
Brian Silvermanbc831182016-04-16 02:06:09 -0400297};
298
Brian Silverman2ccf8c52016-03-15 00:22:26 -0400299void Main() {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700300 aos::FlatbufferDetachedBuffer<aos::Configuration> config =
Austin Schuhc5fa6d92022-02-25 14:36:28 -0800301 aos::configuration::ReadConfig("aos_config.json");
Alex Perrycb7da4b2019-08-28 19:35:56 -0700302
303 ::aos::ShmEventLoop event_loop(&config.message());
Austin Schuh1bf8a212019-05-26 22:13:14 -0700304
305 ::aos::Sender<::y2016::vision::VisionStatus> vision_status_sender =
Tyler Chatow24b5db12020-01-06 21:16:56 -0800306 event_loop.MakeSender<::y2016::vision::VisionStatus>("/vision");
Austin Schuh1bf8a212019-05-26 22:13:14 -0700307
Brian Silverman2ccf8c52016-03-15 00:22:26 -0400308 StereoGeometry stereo(constants::GetValues().vision_name);
Austin Schuhf257f3c2019-10-27 21:00:43 -0700309 AOS_LOG(INFO, "calibration: %s\n",
310 stereo.calibration().ShortDebugString().c_str());
Brian Silverman2ccf8c52016-03-15 00:22:26 -0400311
Austin Schuhbd0a40f2019-06-30 14:56:31 -0700312 DrivetrainOffsetCalculator drivetrain_offset(&event_loop);
Brian Silvermanbc831182016-04-16 02:06:09 -0400313
Austin Schuh11945742016-04-13 22:18:36 -0700314 CameraHandler left;
315 CameraHandler right;
Austin Schuhc65b0ea2016-03-16 22:09:19 -0700316
Parker Schuh2cd173d2017-01-28 00:12:01 -0800317 ::aos::events::RXUdpSocket recv(8080);
Austin Schuhc65b0ea2016-03-16 22:09:19 -0700318 char rawData[65507];
Austin Schuhc65b0ea2016-03-16 22:09:19 -0700319
320 while (true) {
321 // TODO(austin): Don't malloc.
322 VisionData target;
323 int size = recv.Recv(rawData, 65507);
Austin Schuhfb5f7de2016-11-26 15:15:19 -0800324 monotonic_clock::time_point now = monotonic_clock::now();
Austin Schuhc65b0ea2016-03-16 22:09:19 -0700325
326 if (target.ParseFromArray(rawData, size)) {
327 if (target.camera_index() == 0) {
Austin Schuh11945742016-04-13 22:18:36 -0700328 left.Received(target, now);
Austin Schuhc65b0ea2016-03-16 22:09:19 -0700329 } else {
Austin Schuh11945742016-04-13 22:18:36 -0700330 right.Received(target, now);
Brian Silverman2ccf8c52016-03-15 00:22:26 -0400331 }
332 } else {
Austin Schuhf257f3c2019-10-27 21:00:43 -0700333 AOS_LOG(ERROR, "oh noes: parse error\n");
Austin Schuhc65b0ea2016-03-16 22:09:19 -0700334 continue;
335 }
336
Austin Schuh11945742016-04-13 22:18:36 -0700337 left.CheckStale(now);
338 right.CheckStale(now);
Brian Silverman2ccf8c52016-03-15 00:22:26 -0400339
Austin Schuh11945742016-04-13 22:18:36 -0700340 if (left.received_both() && right.received_both()) {
341 const bool left_image_valid = left.is_valid();
342 const bool right_image_valid = right.is_valid();
Austin Schuhc65b0ea2016-03-16 22:09:19 -0700343
Alex Perrycb7da4b2019-08-28 19:35:56 -0700344 auto builder = vision_status_sender.MakeBuilder();
345 VisionStatusT new_vision_status;
346 new_vision_status.left_image_valid = left_image_valid;
347 new_vision_status.right_image_valid = right_image_valid;
Austin Schuhc65b0ea2016-03-16 22:09:19 -0700348 if (left_image_valid && right_image_valid) {
Austin Schuh11945742016-04-13 22:18:36 -0700349 ::aos::vision::Vector<2> center_left(0.0, 0.0);
350 ::aos::vision::Vector<2> center_right(0.0, 0.0);
Austin Schuh6bf73052016-04-20 20:20:25 -0700351 double angle_left;
352 double angle_right;
Austin Schuh11945742016-04-13 22:18:36 -0700353 SelectTargets(left.target(), right.target(), &center_left,
Austin Schuh6bf73052016-04-20 20:20:25 -0700354 &center_right, &angle_left, &angle_right);
Austin Schuh11945742016-04-13 22:18:36 -0700355
356 // TODO(Ben): Remember this from last time instead of recalculating it
357 // each time.
358 ::aos::vision::Vector<2> last_center_left(0.0, 0.0);
359 ::aos::vision::Vector<2> last_center_right(0.0, 0.0);
Austin Schuh6bf73052016-04-20 20:20:25 -0700360 double last_angle_left;
361 double last_angle_right;
Austin Schuh11945742016-04-13 22:18:36 -0700362 SelectTargets(left.last_target(), right.last_target(),
Parker Schuh2cd173d2017-01-28 00:12:01 -0800363 &last_center_left, &last_center_right, &last_angle_left,
364 &last_angle_right);
Austin Schuh11945742016-04-13 22:18:36 -0700365
366 ::aos::vision::Vector<2> filtered_center_left(0.0, 0.0);
367 ::aos::vision::Vector<2> filtered_center_right(0.0, 0.0);
Austin Schuh6bf73052016-04-20 20:20:25 -0700368 double filtered_angle_left;
369 double filtered_angle_right;
Austin Schuh11945742016-04-13 22:18:36 -0700370 if (left.capture_time() < right.capture_time()) {
371 filtered_center_left = center_left;
Austin Schuh6bf73052016-04-20 20:20:25 -0700372 filtered_angle_left = angle_left;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700373 new_vision_status.target_time =
Austin Schuhfb5f7de2016-11-26 15:15:19 -0800374 chrono::duration_cast<chrono::nanoseconds>(
Parker Schuh2cd173d2017-01-28 00:12:01 -0800375 left.capture_time().time_since_epoch())
376 .count();
Austin Schuh6bf73052016-04-20 20:20:25 -0700377 CalculateFiltered(left, right, center_right, last_center_right,
378 angle_right, last_angle_right,
379 &filtered_center_right, &filtered_angle_right);
Austin Schuh11945742016-04-13 22:18:36 -0700380 } else {
381 filtered_center_right = center_right;
Austin Schuh6bf73052016-04-20 20:20:25 -0700382 filtered_angle_right = angle_right;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700383 new_vision_status.target_time =
Austin Schuhfb5f7de2016-11-26 15:15:19 -0800384 chrono::duration_cast<chrono::nanoseconds>(
Parker Schuh2cd173d2017-01-28 00:12:01 -0800385 right.capture_time().time_since_epoch())
386 .count();
Austin Schuh6bf73052016-04-20 20:20:25 -0700387 CalculateFiltered(right, left, center_left, last_center_left,
388 angle_left, last_angle_left, &filtered_center_left,
389 &filtered_angle_left);
Austin Schuh11945742016-04-13 22:18:36 -0700390 }
391
Austin Schuhc65b0ea2016-03-16 22:09:19 -0700392 double distance, horizontal_angle, vertical_angle;
Austin Schuh11945742016-04-13 22:18:36 -0700393 stereo.Process(filtered_center_left, filtered_center_right, &distance,
394 &horizontal_angle, &vertical_angle);
Alex Perrycb7da4b2019-08-28 19:35:56 -0700395 new_vision_status.left_image_timestamp =
Austin Schuh11945742016-04-13 22:18:36 -0700396 left.target().image_timestamp();
Alex Perrycb7da4b2019-08-28 19:35:56 -0700397 new_vision_status.right_image_timestamp =
Austin Schuh11945742016-04-13 22:18:36 -0700398 right.target().image_timestamp();
Alex Perrycb7da4b2019-08-28 19:35:56 -0700399 new_vision_status.left_send_timestamp = left.target().send_timestamp();
400 new_vision_status.right_send_timestamp =
Parker Schuh2cd173d2017-01-28 00:12:01 -0800401 right.target().send_timestamp();
Alex Perrycb7da4b2019-08-28 19:35:56 -0700402 new_vision_status.horizontal_angle = horizontal_angle;
403 new_vision_status.vertical_angle = vertical_angle;
404 new_vision_status.distance = distance;
405 new_vision_status.angle =
Austin Schuh6bf73052016-04-20 20:20:25 -0700406 (filtered_angle_left + filtered_angle_right) / 2.0;
Austin Schuhc65b0ea2016-03-16 22:09:19 -0700407 }
Brian Silverman2ccf8c52016-03-15 00:22:26 -0400408
Alex Perrycb7da4b2019-08-28 19:35:56 -0700409 if (drivetrain_offset.CompleteVisionStatus(&new_vision_status)) {
milind1f1dca32021-07-03 13:50:07 -0700410 if (builder.Send(
411 VisionStatus::Pack(*builder.fbb(), &new_vision_status)) !=
412 aos::RawSender::Error::kOk) {
Austin Schuhf257f3c2019-10-27 21:00:43 -0700413 AOS_LOG(ERROR, "Failed to send vision information\n");
Brian Silvermanbc831182016-04-16 02:06:09 -0400414 }
415 } else {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700416 AOS_LOG(WARNING, "vision without drivetrain");
Brian Silverman2ccf8c52016-03-15 00:22:26 -0400417 }
418 }
Austin Schuhc65b0ea2016-03-16 22:09:19 -0700419
420 if (target.camera_index() == 0) {
Austin Schuhf257f3c2019-10-27 21:00:43 -0700421 AOS_LOG(DEBUG, "left_target: %s\n",
422 left.target().ShortDebugString().c_str());
Austin Schuhc65b0ea2016-03-16 22:09:19 -0700423 } else {
Austin Schuhf257f3c2019-10-27 21:00:43 -0700424 AOS_LOG(DEBUG, "right_target: %s\n",
425 right.target().ShortDebugString().c_str());
Austin Schuhc65b0ea2016-03-16 22:09:19 -0700426 }
Brian Silverman2ccf8c52016-03-15 00:22:26 -0400427 }
Brian Silverman2ccf8c52016-03-15 00:22:26 -0400428}
429
Stephan Pleinesf63bde82024-01-13 15:59:33 -0800430} // namespace y2016::vision
Brian Silverman2ccf8c52016-03-15 00:22:26 -0400431
Austin Schuh094d09b2020-11-20 23:26:52 -0800432int main(int argc, char **argv) {
433 ::aos::InitGoogle(&argc, &argv);
Brian Silverman2ccf8c52016-03-15 00:22:26 -0400434 ::y2016::vision::Main();
435}