blob: f1c5fdfc694ff2820de85fd79b42993670df30c8 [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.");
9DEFINE_uint32(exposure, 5, "Exposure time, in 100us increments");
10
11namespace y2022 {
12namespace vision {
13namespace {
14
15using namespace frc971::vision;
16
17void CameraReaderMain() {
18 aos::FlatbufferDetachedBuffer<aos::Configuration> config =
19 aos::configuration::ReadConfig(FLAGS_config);
20
Jim Ostrowski007e2ea2022-01-30 13:13:26 -080021 const aos::FlatbufferSpan<calibration::CalibrationData> calibration_data(
22 CalibrationData());
23 CHECK(calibration_data.Verify());
Jim Ostrowskiff0f5e42022-01-22 01:35:31 -080024
Jim Ostrowskiff0f5e42022-01-22 01:35:31 -080025 aos::ShmEventLoop event_loop(&config.message());
26
27 // First, log the data for future reference.
28 {
Jim Ostrowski007e2ea2022-01-30 13:13:26 -080029 aos::Sender<calibration::CalibrationData> calibration_data_sender =
30 event_loop.MakeSender<calibration::CalibrationData>("/camera");
31 CHECK_EQ(calibration_data_sender.Send(calibration_data),
Jim Ostrowskiff0f5e42022-01-22 01:35:31 -080032 aos::RawSender::Error::kOk);
33 }
34
35 V4L2Reader v4l2_reader(&event_loop, "/dev/video0");
Jim Ostrowskiff0f5e42022-01-22 01:35:31 -080036 v4l2_reader.SetExposure(FLAGS_exposure);
37
Jim Ostrowski007e2ea2022-01-30 13:13:26 -080038 CameraReader camera_reader(&event_loop, &calibration_data.message(),
Jim Ostrowskiff7b3de2022-01-22 22:20:26 -080039 &v4l2_reader);
40
Jim Ostrowskiff0f5e42022-01-22 01:35:31 -080041 event_loop.Run();
42}
43
44} // namespace
45} // namespace vision
46} // namespace y2022
47
48int main(int argc, char **argv) {
49 aos::InitGoogle(&argc, &argv);
50 y2022::vision::CameraReaderMain();
51}