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., |
Austin Schuh | c5fa6d9 | 2022-02-25 14:36:28 -0800 | [diff] [blame] | 6 | // bazel run //y2022/vision:camera_reader -- --config y2022/aos_config.json |
Jim Ostrowski | ff0f5e4 | 2022-01-22 01:35:31 -0800 | [diff] [blame] | 7 | // --override_hostname pi-7971-1 --ignore_timestamps true |
Austin Schuh | c5fa6d9 | 2022-02-25 14:36:28 -0800 | [diff] [blame] | 8 | DEFINE_string(config, "aos_config.json", "Path to the config file to use."); |
Milind Upadhyay | caeb950 | 2022-03-19 17:25:45 -0700 | [diff] [blame^] | 9 | DEFINE_double(duty_cycle, 0.6, "Duty cycle of the LEDs"); |
Jim Ostrowski | fec0c33 | 2022-02-06 23:28:26 -0800 | [diff] [blame] | 10 | DEFINE_uint32(exposure, 5, |
| 11 | "Exposure time, in 100us increments; 0 implies auto exposure"); |
Jim Ostrowski | ff0f5e4 | 2022-01-22 01:35:31 -0800 | [diff] [blame] | 12 | |
| 13 | namespace y2022 { |
| 14 | namespace vision { |
| 15 | namespace { |
| 16 | |
| 17 | using namespace frc971::vision; |
| 18 | |
| 19 | void CameraReaderMain() { |
| 20 | aos::FlatbufferDetachedBuffer<aos::Configuration> config = |
| 21 | aos::configuration::ReadConfig(FLAGS_config); |
| 22 | |
Jim Ostrowski | 007e2ea | 2022-01-30 13:13:26 -0800 | [diff] [blame] | 23 | const aos::FlatbufferSpan<calibration::CalibrationData> calibration_data( |
| 24 | CalibrationData()); |
| 25 | CHECK(calibration_data.Verify()); |
Jim Ostrowski | ff0f5e4 | 2022-01-22 01:35:31 -0800 | [diff] [blame] | 26 | |
Jim Ostrowski | ff0f5e4 | 2022-01-22 01:35:31 -0800 | [diff] [blame] | 27 | aos::ShmEventLoop event_loop(&config.message()); |
| 28 | |
| 29 | // First, log the data for future reference. |
| 30 | { |
Jim Ostrowski | 007e2ea | 2022-01-30 13:13:26 -0800 | [diff] [blame] | 31 | aos::Sender<calibration::CalibrationData> calibration_data_sender = |
| 32 | event_loop.MakeSender<calibration::CalibrationData>("/camera"); |
| 33 | CHECK_EQ(calibration_data_sender.Send(calibration_data), |
Jim Ostrowski | ff0f5e4 | 2022-01-22 01:35:31 -0800 | [diff] [blame] | 34 | aos::RawSender::Error::kOk); |
| 35 | } |
| 36 | |
| 37 | V4L2Reader v4l2_reader(&event_loop, "/dev/video0"); |
Jim Ostrowski | fec0c33 | 2022-02-06 23:28:26 -0800 | [diff] [blame] | 38 | if (FLAGS_exposure > 0) { |
| 39 | v4l2_reader.SetExposure(FLAGS_exposure); |
| 40 | } |
Jim Ostrowski | ff0f5e4 | 2022-01-22 01:35:31 -0800 | [diff] [blame] | 41 | |
Jim Ostrowski | 007e2ea | 2022-01-30 13:13:26 -0800 | [diff] [blame] | 42 | CameraReader camera_reader(&event_loop, &calibration_data.message(), |
Jim Ostrowski | ff7b3de | 2022-01-22 22:20:26 -0800 | [diff] [blame] | 43 | &v4l2_reader); |
Jim Ostrowski | 2a483b3 | 2022-02-15 18:19:14 -0800 | [diff] [blame] | 44 | camera_reader.SetDutyCycle(FLAGS_duty_cycle); |
Jim Ostrowski | ff7b3de | 2022-01-22 22:20:26 -0800 | [diff] [blame] | 45 | |
Jim Ostrowski | ff0f5e4 | 2022-01-22 01:35:31 -0800 | [diff] [blame] | 46 | event_loop.Run(); |
| 47 | } |
| 48 | |
| 49 | } // namespace |
| 50 | } // namespace vision |
| 51 | } // namespace y2022 |
| 52 | |
| 53 | int main(int argc, char **argv) { |
| 54 | aos::InitGoogle(&argc, &argv); |
| 55 | y2022::vision::CameraReaderMain(); |
| 56 | } |