blob: 52ee51a3c8198da49bab8ac05836b4b393d164b1 [file] [log] [blame]
Jim Ostrowskiff0f5e42022-01-22 01:35:31 -08001#include "aos/events/shm_event_loop.h"
2#include "aos/init.h"
Jim Ostrowskiff7b3de2022-01-22 22:20:26 -08003#include "y2022/vision/camera_reader.h"
Jim Ostrowskiff0f5e42022-01-22 01:35:31 -08004
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
8DEFINE_string(config, "config.json", "Path to the config file to use.");
Jim Ostrowskifec0c332022-02-06 23:28:26 -08009DEFINE_uint32(exposure, 5,
10 "Exposure time, in 100us increments; 0 implies auto exposure");
Jim Ostrowskiff0f5e42022-01-22 01:35:31 -080011
12namespace y2022 {
13namespace vision {
14namespace {
15
16using namespace frc971::vision;
17
18void CameraReaderMain() {
19 aos::FlatbufferDetachedBuffer<aos::Configuration> config =
20 aos::configuration::ReadConfig(FLAGS_config);
21
Jim Ostrowski007e2ea2022-01-30 13:13:26 -080022 const aos::FlatbufferSpan<calibration::CalibrationData> calibration_data(
23 CalibrationData());
24 CHECK(calibration_data.Verify());
Jim Ostrowskiff0f5e42022-01-22 01:35:31 -080025
Jim Ostrowskiff0f5e42022-01-22 01:35:31 -080026 aos::ShmEventLoop event_loop(&config.message());
27
28 // First, log the data for future reference.
29 {
Jim Ostrowski007e2ea2022-01-30 13:13:26 -080030 aos::Sender<calibration::CalibrationData> calibration_data_sender =
31 event_loop.MakeSender<calibration::CalibrationData>("/camera");
32 CHECK_EQ(calibration_data_sender.Send(calibration_data),
Jim Ostrowskiff0f5e42022-01-22 01:35:31 -080033 aos::RawSender::Error::kOk);
34 }
35
36 V4L2Reader v4l2_reader(&event_loop, "/dev/video0");
Jim Ostrowskifec0c332022-02-06 23:28:26 -080037 if (FLAGS_exposure > 0) {
38 v4l2_reader.SetExposure(FLAGS_exposure);
39 }
Jim Ostrowskiff0f5e42022-01-22 01:35:31 -080040
Jim Ostrowski007e2ea2022-01-30 13:13:26 -080041 CameraReader camera_reader(&event_loop, &calibration_data.message(),
Jim Ostrowskiff7b3de2022-01-22 22:20:26 -080042 &v4l2_reader);
43
Jim Ostrowskiff0f5e42022-01-22 01:35:31 -080044 event_loop.Run();
45}
46
47} // namespace
48} // namespace vision
49} // namespace y2022
50
51int main(int argc, char **argv) {
52 aos::InitGoogle(&argc, &argv);
53 y2022::vision::CameraReaderMain();
54}