blob: 9320152e3b71addf07da2d72d9786de1814c3d06 [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
Milind Upadhyayf67f67d2022-03-27 14:29:47 -07008DECLARE_bool(use_outdoors);
Austin Schuhc5fa6d92022-02-25 14:36:28 -08009DEFINE_string(config, "aos_config.json", "Path to the config file to use.");
Milind Upadhyaycaeb9502022-03-19 17:25:45 -070010DEFINE_double(duty_cycle, 0.6, "Duty cycle of the LEDs");
Jim Ostrowskifec0c332022-02-06 23:28:26 -080011DEFINE_uint32(exposure, 5,
12 "Exposure time, in 100us increments; 0 implies auto exposure");
James Kuszmaulb9ba9a52022-03-31 22:16:01 -070013DEFINE_uint32(outdoors_exposure, 20,
Milind Upadhyayf67f67d2022-03-27 14:29:47 -070014 "Exposure time when using --use_outdoors, in 100us increments; 0 "
15 "implies auto exposure");
Jim Ostrowskiff0f5e42022-01-22 01:35:31 -080016
17namespace y2022 {
18namespace vision {
19namespace {
20
21using namespace frc971::vision;
22
23void CameraReaderMain() {
24 aos::FlatbufferDetachedBuffer<aos::Configuration> config =
25 aos::configuration::ReadConfig(FLAGS_config);
26
Jim Ostrowski007e2ea2022-01-30 13:13:26 -080027 const aos::FlatbufferSpan<calibration::CalibrationData> calibration_data(
28 CalibrationData());
29 CHECK(calibration_data.Verify());
Jim Ostrowskiff0f5e42022-01-22 01:35:31 -080030
Jim Ostrowskiff0f5e42022-01-22 01:35:31 -080031 aos::ShmEventLoop event_loop(&config.message());
32
33 // First, log the data for future reference.
34 {
Jim Ostrowski007e2ea2022-01-30 13:13:26 -080035 aos::Sender<calibration::CalibrationData> calibration_data_sender =
36 event_loop.MakeSender<calibration::CalibrationData>("/camera");
37 CHECK_EQ(calibration_data_sender.Send(calibration_data),
Jim Ostrowskiff0f5e42022-01-22 01:35:31 -080038 aos::RawSender::Error::kOk);
39 }
40
41 V4L2Reader v4l2_reader(&event_loop, "/dev/video0");
Milind Upadhyayf67f67d2022-03-27 14:29:47 -070042 const uint32_t exposure =
43 (FLAGS_use_outdoors ? FLAGS_outdoors_exposure : FLAGS_exposure);
44 if (exposure > 0) {
45 v4l2_reader.SetExposure(exposure);
Jim Ostrowskifec0c332022-02-06 23:28:26 -080046 }
Jim Ostrowskiff0f5e42022-01-22 01:35:31 -080047
Jim Ostrowski007e2ea2022-01-30 13:13:26 -080048 CameraReader camera_reader(&event_loop, &calibration_data.message(),
Jim Ostrowskiff7b3de2022-01-22 22:20:26 -080049 &v4l2_reader);
Jim Ostrowski2a483b32022-02-15 18:19:14 -080050 camera_reader.SetDutyCycle(FLAGS_duty_cycle);
Jim Ostrowskiff7b3de2022-01-22 22:20:26 -080051
Jim Ostrowskiff0f5e42022-01-22 01:35:31 -080052 event_loop.Run();
53}
54
55} // namespace
56} // namespace vision
57} // namespace y2022
58
59int main(int argc, char **argv) {
60 aos::InitGoogle(&argc, &argv);
61 y2022::vision::CameraReaderMain();
62}