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