Small cleanup of a few items
Added mount_rootfs.sh helper script for easy mount & check of SD card
Added thresholding of images and suppress drawing axes in charuco_lib
Modified some of the settings in y2022 roborio config
Change-Id: I65633089692e92cf823bf0d97da54a86714f556e
Signed-off-by: Jim Ostrowski <yimmy13@gmail.com>
diff --git a/frc971/raspi/rootfs/mount_rootfs.sh b/frc971/raspi/rootfs/mount_rootfs.sh
new file mode 100755
index 0000000..6673808
--- /dev/null
+++ b/frc971/raspi/rootfs/mount_rootfs.sh
@@ -0,0 +1,39 @@
+#!/bin/bash
+
+### Helper script to mount a Raspberry Pi SD card
+### Optionally run change_hostname if given pi name as argument
+
+set -e
+
+MOUNT_PT="tmp_mount"
+DEVICE="/dev/sda"
+
+if mount | grep "${DEVICE}" >/dev/null ;
+then
+ echo "Overwriting a mounted partition, is ${DEVICE} the sd card?"
+ exit 1
+fi
+
+PARTITION="${MOUNT_PT}.partition"
+
+mkdir -p "${PARTITION}"
+sudo mount "${DEVICE}2" "${PARTITION}"
+
+function target() {
+ HOME=/root/ USER=root sudo proot -0 -q qemu-aarch64-static -w / -r "${PARTITION}" "$@"
+}
+
+if [ "${1}" == "" ]; then
+ echo "No hostname specified, so skipping setting it."
+ echo "You do this manually on the pi by running /root/bin/change_hostname.sh PI_NAME"
+else
+ target /root/bin/change_hostname.sh "${1}"
+fi
+
+
+echo "Starting a shell for any manual configuration"
+target /bin/bash --rcfile /root/.bashrc
+
+# Found I had to do a lazy force unmount ("-l" flag) to make it work reliably
+sudo umount -l "${PARTITION}"
+rmdir "${PARTITION}"
diff --git a/frc971/vision/charuco_lib.cc b/frc971/vision/charuco_lib.cc
index 116aba0..a9bf6cf 100644
--- a/frc971/vision/charuco_lib.cc
+++ b/frc971/vision/charuco_lib.cc
@@ -18,11 +18,16 @@
"If specified, write an image to the specified path for the "
"charuco board pattern.");
DEFINE_bool(coarse_pattern, true, "If true, use coarse arucos; else, use fine");
+DEFINE_uint32(gray_threshold, 0,
+ "If > 0, threshold image based on this grayscale value");
DEFINE_bool(large_board, true, "If true, use the large calibration board.");
DEFINE_uint32(
min_charucos, 10,
"The mininum number of aruco targets in charuco board required to match.");
DEFINE_bool(visualize, false, "Whether to visualize the resulting data.");
+DEFINE_bool(
+ draw_axes, false,
+ "Whether to draw axes on the resulting data-- warning, may cause crashes.");
DEFINE_uint32(disable_delay, 100, "Time after an issue to disable tracing at.");
@@ -156,9 +161,8 @@
}
void CharucoExtractor::SetupTargetData() {
- // TODO(Jim): Put correct values here
- marker_length_ = 0.15;
- square_length_ = 0.1651;
+ marker_length_ = 0.146;
+ square_length_ = 0.2;
// Only charuco board has a board associated with it
board_ = static_cast<cv::Ptr<cv::aruco::CharucoBoard>>(NULL);
@@ -169,7 +173,7 @@
FLAGS_large_board ? cv::aruco::DICT_5X5_250 : cv::aruco::DICT_6X6_250);
if (target_type_ == TargetType::kCharuco) {
- LOG(INFO) << "Using " << (FLAGS_large_board ? " large " : " small ")
+ LOG(INFO) << "Using " << (FLAGS_large_board ? "large" : "small")
<< " charuco board with "
<< (FLAGS_coarse_pattern ? "coarse" : "fine") << " pattern";
board_ =
@@ -191,9 +195,8 @@
}
}
} else if (target_type_ == TargetType::kCharucoDiamond) {
- // TODO<Jim>: Measure this
marker_length_ = 0.15;
- square_length_ = 0.1651;
+ square_length_ = 0.2;
dictionary_ = cv::aruco::getPredefinedDictionary(cv::aruco::DICT_4X4_250);
} else {
// Bail out if it's not a supported target
@@ -228,16 +231,15 @@
// Found that drawAxis hangs if you try to draw with z values too
// small (trying to draw axes at inifinity)
- // TODO<Jim>: Explore what real thresholds for this should be;
- // likely Don't need to get rid of negative values
+ // TODO<Jim>: Either track this down or reimplement drawAxes
if (result.z() < 0.01) {
LOG(INFO) << "Skipping, due to z value too small: " << result.z();
- } else {
+ } else if (FLAGS_draw_axes == true) {
result /= result.z();
if (target_type_ == TargetType::kCharuco) {
cv::aruco::drawAxis(rgb_image, calibration_.CameraIntrinsics(),
- calibration_.CameraDistCoeffs(), rvecs[i],
- tvecs[i], 0.1);
+ calibration_.CameraDistCoeffs(), rvecs[i], tvecs[i],
+ 0.1);
} else {
cv::drawFrameAxes(rgb_image, calibration_.CameraIntrinsics(),
calibration_.CameraDistCoeffs(), rvecs[i], tvecs[i],
@@ -303,6 +305,16 @@
event_loop_->monotonic_now() - eof)
.count();
+ // Have found this useful if there is blurry / noisy images
+ if (FLAGS_gray_threshold > 0) {
+ cv::Mat gray;
+ cv::cvtColor(rgb_image, gray, cv::COLOR_BGR2GRAY);
+
+ cv::Mat thresh;
+ cv::threshold(gray, thresh, FLAGS_gray_threshold, 255, cv::THRESH_BINARY);
+ cv::cvtColor(thresh, rgb_image, cv::COLOR_GRAY2RGB);
+ }
+
// Set up the variables we'll use in the callback function
bool valid = false;
// Return a list of poses; for Charuco Board there will be just one
diff --git a/frc971/vision/charuco_lib.h b/frc971/vision/charuco_lib.h
index b2ca7ee..2d3a907 100644
--- a/frc971/vision/charuco_lib.h
+++ b/frc971/vision/charuco_lib.h
@@ -11,8 +11,8 @@
#include "absl/types/span.h"
#include "aos/events/event_loop.h"
#include "aos/network/message_bridge_server_generated.h"
-#include "frc971/vision/calibration_generated.h"
#include "external/com_github_foxglove_schemas/ImageAnnotations_generated.h"
+#include "frc971/vision/calibration_generated.h"
DECLARE_bool(visualize);
diff --git a/y2022/y2022_roborio.json b/y2022/y2022_roborio.json
index ff8d0c6..068c543 100644
--- a/y2022/y2022_roborio.json
+++ b/y2022/y2022_roborio.json
@@ -334,7 +334,7 @@
"source_node": "roborio",
"frequency": 200,
"num_senders": 2,
- "max_size": 72
+ "max_size": 200
},
{
"name": "/superstructure",
@@ -420,7 +420,7 @@
"priority": 5,
"timestamp_logger": "LOCAL_AND_REMOTE_LOGGER",
"timestamp_logger_nodes": [
- "imu"
+ "roborio"
],
"time_to_live": 5000000
}