Changes thanks to James for being able to run camera_reader from laptop
Added ignore_timestamps option to support webcams that may not have timestamps
Sample usage:
bazel run //y2020/vision:camera_reader -- --config y2020/config.json --override_hostname pi-7971-1 --ignore_timestamps true
Change-Id: Ibc7a251ac019509c43c0f9aec6c118f75afa1953
diff --git a/aos/network/BUILD b/aos/network/BUILD
index 89853f0..8f3f394 100644
--- a/aos/network/BUILD
+++ b/aos/network/BUILD
@@ -70,6 +70,7 @@
],
deps = [
":team_number",
+ "//aos:configuration",
"//aos/testing:googletest",
],
)
diff --git a/aos/network/team_number.cc b/aos/network/team_number.cc
index 14fadab..d2fbc8e 100644
--- a/aos/network/team_number.cc
+++ b/aos/network/team_number.cc
@@ -9,6 +9,8 @@
#include "aos/util/string_to_num.h"
+DECLARE_string(override_hostname);
+
namespace aos {
namespace network {
namespace team_number_internal {
@@ -101,10 +103,14 @@
} // namespace
::std::string GetHostname() {
- char buf[256];
- buf[sizeof(buf) - 1] = '\0';
- PCHECK(gethostname(buf, sizeof(buf) - 1) == 0);
- return buf;
+ if (FLAGS_override_hostname.empty()) {
+ char buf[256];
+ buf[sizeof(buf) - 1] = '\0';
+ PCHECK(gethostname(buf, sizeof(buf) - 1) == 0);
+ return buf;
+ } else {
+ return FLAGS_override_hostname;
+ }
}
uint16_t GetTeamNumber() {
diff --git a/y2020/vision/BUILD b/y2020/vision/BUILD
index 60276c9..b643fcb 100644
--- a/y2020/vision/BUILD
+++ b/y2020/vision/BUILD
@@ -36,6 +36,9 @@
"//tools:armhf-debian",
],
visibility = ["//y2020:__subpackages__"],
+ data = [
+ "//y2020:config.json",
+ ],
deps = [
":v4l2_reader",
":vision_fbs",
diff --git a/y2020/vision/camera_reader.cc b/y2020/vision/camera_reader.cc
index 2615bca..d45ec3f 100644
--- a/y2020/vision/camera_reader.cc
+++ b/y2020/vision/camera_reader.cc
@@ -14,6 +14,11 @@
#include "y2020/vision/v4l2_reader.h"
#include "y2020/vision/vision_generated.h"
+// config used to allow running camera_reader independently. E.g.,
+// bazel run //y2020/vision:camera_reader -- --config y2020/config.json
+// --override_hostname pi-7971-1 --ignore_timestamps true
+DEFINE_string(config, "config.json", "Path to the config file to use.");
+
namespace frc971 {
namespace vision {
namespace {
@@ -523,7 +528,7 @@
void CameraReaderMain() {
aos::FlatbufferDetachedBuffer<aos::Configuration> config =
- aos::configuration::ReadConfig("config.json");
+ aos::configuration::ReadConfig(FLAGS_config);
const auto training_data_bfbs = SiftTrainingData();
const sift::TrainingData *const training_data =
diff --git a/y2020/vision/v4l2_reader.cc b/y2020/vision/v4l2_reader.cc
index f1944c1..91777c7 100644
--- a/y2020/vision/v4l2_reader.cc
+++ b/y2020/vision/v4l2_reader.cc
@@ -6,6 +6,9 @@
#include <sys/stat.h>
#include <sys/types.h>
+DEFINE_bool(ignore_timestamps, false,
+ "Don't require timestamps on images. Used to allow webcams");
+
namespace frc971 {
namespace vision {
@@ -137,8 +140,11 @@
buffer.m.userptr);
CHECK_EQ(ImageSize(), buffer.length);
CHECK(buffer.flags & V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC);
- CHECK_EQ(buffer.flags & V4L2_BUF_FLAG_TSTAMP_SRC_MASK,
- static_cast<uint32_t>(V4L2_BUF_FLAG_TSTAMP_SRC_EOF));
+ if (!FLAGS_ignore_timestamps) {
+ // Require that we have good timestamp on images
+ CHECK_EQ(buffer.flags & V4L2_BUF_FLAG_TSTAMP_SRC_MASK,
+ static_cast<uint32_t>(V4L2_BUF_FLAG_TSTAMP_SRC_EOF));
+ }
return {static_cast<int>(buffer.index),
aos::time::from_timeval(buffer.timestamp)};
}