blob: d5ba448d4fd204f61dea9ce49f4251283ac6e51f [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.,
Austin Schuhc5fa6d92022-02-25 14:36:28 -08006// bazel run //y2022/vision:camera_reader -- --config y2022/aos_config.json
Jim Ostrowskiff0f5e42022-01-22 01:35:31 -08007// --override_hostname pi-7971-1 --ignore_timestamps true
Austin Schuhc5fa6d92022-02-25 14:36:28 -08008DEFINE_string(config, "aos_config.json", "Path to the config file to use.");
Jim Ostrowski2a483b32022-02-15 18:19:14 -08009DEFINE_double(duty_cycle, 0.5, "Duty cycle of the LEDs");
Jim Ostrowskifec0c332022-02-06 23:28:26 -080010DEFINE_uint32(exposure, 5,
11 "Exposure time, in 100us increments; 0 implies auto exposure");
Jim Ostrowskiff0f5e42022-01-22 01:35:31 -080012
13namespace y2022 {
14namespace vision {
15namespace {
16
17using namespace frc971::vision;
18
19void CameraReaderMain() {
20 aos::FlatbufferDetachedBuffer<aos::Configuration> config =
21 aos::configuration::ReadConfig(FLAGS_config);
22
Jim Ostrowski007e2ea2022-01-30 13:13:26 -080023 const aos::FlatbufferSpan<calibration::CalibrationData> calibration_data(
24 CalibrationData());
25 CHECK(calibration_data.Verify());
Jim Ostrowskiff0f5e42022-01-22 01:35:31 -080026
Jim Ostrowskiff0f5e42022-01-22 01:35:31 -080027 aos::ShmEventLoop event_loop(&config.message());
28
29 // First, log the data for future reference.
30 {
Jim Ostrowski007e2ea2022-01-30 13:13:26 -080031 aos::Sender<calibration::CalibrationData> calibration_data_sender =
32 event_loop.MakeSender<calibration::CalibrationData>("/camera");
33 CHECK_EQ(calibration_data_sender.Send(calibration_data),
Jim Ostrowskiff0f5e42022-01-22 01:35:31 -080034 aos::RawSender::Error::kOk);
35 }
36
37 V4L2Reader v4l2_reader(&event_loop, "/dev/video0");
Jim Ostrowskifec0c332022-02-06 23:28:26 -080038 if (FLAGS_exposure > 0) {
39 v4l2_reader.SetExposure(FLAGS_exposure);
40 }
Jim Ostrowskiff0f5e42022-01-22 01:35:31 -080041
Jim Ostrowski007e2ea2022-01-30 13:13:26 -080042 CameraReader camera_reader(&event_loop, &calibration_data.message(),
Jim Ostrowskiff7b3de2022-01-22 22:20:26 -080043 &v4l2_reader);
Jim Ostrowski2a483b32022-02-15 18:19:14 -080044 camera_reader.SetDutyCycle(FLAGS_duty_cycle);
Jim Ostrowskiff7b3de2022-01-22 22:20:26 -080045
Jim Ostrowskiff0f5e42022-01-22 01:35:31 -080046 event_loop.Run();
47}
48
49} // namespace
50} // namespace vision
51} // namespace y2022
52
53int main(int argc, char **argv) {
54 aos::InitGoogle(&argc, &argv);
55 y2022::vision::CameraReaderMain();
56}