Jim Ostrowski | ff0f5e4 | 2022-01-22 01:35:31 -0800 | [diff] [blame] | 1 | #include "aos/events/shm_event_loop.h" |
| 2 | #include "aos/init.h" |
Jim Ostrowski | ff7b3de | 2022-01-22 22:20:26 -0800 | [diff] [blame^] | 3 | #include "y2022/vision/camera_reader.h" |
Jim Ostrowski | ff0f5e4 | 2022-01-22 01:35:31 -0800 | [diff] [blame] | 4 | |
| 5 | // config used to allow running camera_reader independently. E.g., |
| 6 | // bazel run //y2022/vision:camera_reader -- --config y2022/config.json |
| 7 | // --override_hostname pi-7971-1 --ignore_timestamps true |
| 8 | DEFINE_string(config, "config.json", "Path to the config file to use."); |
| 9 | DEFINE_uint32(exposure, 5, "Exposure time, in 100us increments"); |
| 10 | |
| 11 | namespace y2022 { |
| 12 | namespace vision { |
| 13 | namespace { |
| 14 | |
| 15 | using namespace frc971::vision; |
| 16 | |
| 17 | void CameraReaderMain() { |
| 18 | aos::FlatbufferDetachedBuffer<aos::Configuration> config = |
| 19 | aos::configuration::ReadConfig(FLAGS_config); |
| 20 | |
| 21 | const aos::FlatbufferSpan<sift::TrainingData> training_data( |
| 22 | SiftTrainingData()); |
| 23 | CHECK(training_data.Verify()); |
| 24 | |
Jim Ostrowski | ff0f5e4 | 2022-01-22 01:35:31 -0800 | [diff] [blame] | 25 | aos::ShmEventLoop event_loop(&config.message()); |
| 26 | |
| 27 | // First, log the data for future reference. |
| 28 | { |
| 29 | aos::Sender<sift::TrainingData> training_data_sender = |
| 30 | event_loop.MakeSender<sift::TrainingData>("/camera"); |
| 31 | CHECK_EQ(training_data_sender.Send(training_data), |
| 32 | aos::RawSender::Error::kOk); |
| 33 | } |
| 34 | |
| 35 | V4L2Reader v4l2_reader(&event_loop, "/dev/video0"); |
Jim Ostrowski | ff0f5e4 | 2022-01-22 01:35:31 -0800 | [diff] [blame] | 36 | v4l2_reader.SetExposure(FLAGS_exposure); |
| 37 | |
Jim Ostrowski | ff7b3de | 2022-01-22 22:20:26 -0800 | [diff] [blame^] | 38 | CameraReader camera_reader(&event_loop, &training_data.message(), |
| 39 | &v4l2_reader); |
| 40 | |
Jim Ostrowski | ff0f5e4 | 2022-01-22 01:35:31 -0800 | [diff] [blame] | 41 | event_loop.Run(); |
| 42 | } |
| 43 | |
| 44 | } // namespace |
| 45 | } // namespace vision |
| 46 | } // namespace y2022 |
| 47 | |
| 48 | int main(int argc, char **argv) { |
| 49 | aos::InitGoogle(&argc, &argv); |
| 50 | y2022::vision::CameraReaderMain(); |
| 51 | } |