Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,6 @@ add_subdirectory(yolo)
add_subdirectory(test)
add_subdirectory(pathing)

add_executable(main_bot_main main_bot_main.cc)
target_link_libraries(main_bot_main PRIVATE camera localization utils)

add_executable(second_bot_main second_bot_main.cc)
target_link_libraries(second_bot_main PRIVATE camera localization utils)

add_executable(unambiguous_second unambiguous_second.cc)
target_link_libraries(unambiguous_second PRIVATE ${OpenCV_LIBS} apriltag ntcore camera nlohmann_json::nlohmann_json Eigen3::Eigen localization utils)

Expand Down
12 changes: 7 additions & 5 deletions src/calibration/focus_calibrate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@ auto main(int argc, char* argv[]) -> int {
std::unique_ptr<camera::ICamera> camera =
camera::SelectCameraConfig(camera::GetCameraConstants());

camera::timestamped_frame_t timestamped_frame;
camera->GetFrame(&timestamped_frame);
camera::CscoreStreamer streamer("focus_calibrate", 5801, 30,
camera->GetFrame().frame);
timestamped_frame.frame);

cv::Mat frame, gray, laplace;
cv::Mat gray, laplace;
while (true) {
frame = camera->GetFrame().frame;
streamer.WriteFrame(frame);
camera->GetFrame(&timestamped_frame);
streamer.WriteFrame(timestamped_frame.frame);

cv::cvtColor(frame, gray, cv::COLOR_BGR2GRAY);
cv::cvtColor(timestamped_frame.frame, gray, cv::COLOR_BGR2GRAY);
cv::Laplacian(gray, laplace, CV_64F);
cv::Scalar mean, stddev;
cv::meanStdDev(laplace, mean, stddev, cv::Mat());
Expand Down
11 changes: 6 additions & 5 deletions src/calibration/frame_shower.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,18 @@ auto main(int argc, char* argv[]) -> int {
std::unique_ptr<camera::ICamera> camera = camera::SelectCameraConfig(
absl::GetFlag(FLAGS_camera_name), camera::GetCameraConstants());

camera::timestamped_frame_t timestamped_frame;
camera->GetFrame(&timestamped_frame);
camera::CscoreStreamer streamer("frame_shower",
absl::GetFlag(FLAGS_port).value_or(5801), 30,
camera->GetFrame().frame);
timestamped_frame.frame);

LOG(INFO) << "Camera opened successfully" << std::endl;

cv::Mat frame = camera->GetFrame().frame;
LOG(INFO) << "Size of frame: " << frame.size;
LOG(INFO) << "Size of frame: " << timestamped_frame.frame.size;
while (true) {
frame = camera->GetFrame().frame;
streamer.WriteFrame(frame);
camera->GetFrame(&timestamped_frame);
streamer.WriteFrame(timestamped_frame.frame);
}
return 0;
}
4 changes: 2 additions & 2 deletions src/camera/camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ using timestamped_frame_t = struct TimestampedFrame {

class ICamera {
public:
virtual auto GetFrame() -> timestamped_frame_t = 0;
virtual auto Restart() -> void = 0;
virtual void GetFrame(timestamped_frame_t* output) = 0;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use a reference instead of a pointer?

virtual void Restart() = 0;
[[nodiscard]] virtual auto GetCameraConstant() const -> camera_constant_t = 0;
virtual auto IsDone() -> bool { return false; }
virtual ~ICamera() = default;
Expand Down
4 changes: 2 additions & 2 deletions src/camera/camera_source.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ CameraSource::CameraSource(std::string name, std::unique_ptr<ICamera> camera,
: name_(std::move(name)),
camera_(std::move(camera)),
simulation_(simulation) {
timestamped_frame_ = camera_->GetFrame();
camera_->GetFrame(&timestamped_frame_);
thread_ = std::thread([this] {
while (true) {
if (camera_->IsDone()) {
exit(0);
return;
}
timestamped_frame_t timestamped_frame;
timestamped_frame = camera_->GetFrame();
camera_->GetFrame(&timestamped_frame);
mutex_.lock();
timestamped_frame_ = timestamped_frame;
mutex_.unlock();
Expand Down
19 changes: 8 additions & 11 deletions src/camera/cv_camera.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,29 +63,26 @@ CVCamera::CVCamera(const CameraConstant& c, std::optional<std::string> log_path)
}
}

auto CVCamera::GetFrame() -> timestamped_frame_t {
timestamped_frame_t timestamped_frame;
void CVCamera::GetFrame(timestamped_frame_t* output) {
cv::Mat raw_image;
if (!cap_.grab()) {
Restart();
LOG(WARNING) << "Restarting camera";
}
timestamped_frame.timestamp = frc::Timer::GetFPGATimestamp().to<double>();
output->timestamp = frc::Timer::GetFPGATimestamp().to<double>();
cap_.retrieve(raw_image);

raw_image.copyTo(timestamped_frame.frame);
raw_image.copyTo(output->frame);

if (timestamped_frame.frame.empty()) {
timestamped_frame.frame = backup_image_;
if (output->frame.empty()) {
output->frame = backup_image_;
}
if (timestamped_frame.frame.channels() == 4) {
cv::cvtColor(timestamped_frame.frame, timestamped_frame.frame,
cv::COLOR_BGRA2BGR);
if (output->frame.channels() == 4) {
cv::cvtColor(output->frame, output->frame, cv::COLOR_BGRA2BGR);
}
if (log_path_.has_value()) {
WriteFrame(log_path_.value(), timestamped_frame);
WriteFrame(log_path_.value(), *output);
}
return timestamped_frame;
}

auto CVCamera::Restart() -> void {
Expand Down
2 changes: 1 addition & 1 deletion src/camera/cv_camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class CVCamera : public ICamera {
public:
CVCamera(const CameraConstant& camera_constant,
std::optional<std::string> log_path = std::nullopt);
auto GetFrame() -> timestamped_frame_t override;
void GetFrame(timestamped_frame_t* output) override;
auto Restart() -> void override;
[[nodiscard]] auto GetCameraConstant() const -> camera_constant_t override;

Expand Down
12 changes: 5 additions & 7 deletions src/camera/disk_camera.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,27 +55,25 @@ DiskCamera::DiskCamera(std::string image_folder_path,
}
image_paths_ = std::move(normalized);
}
auto DiskCamera::GetFrame() -> timestamped_frame_t {
void DiskCamera::GetFrame(timestamped_frame_t* output) {
if (image_paths_.empty()) {
std::cout << "Finished reading all frames from DiskCamera. Folder path: "
<< image_folder_path_ << std::endl;
frc::DataLogManager::Stop();
return {.invalid = true};
output->invalid = true;
return;
}

double recorded_ts = image_paths_.top().timestamp;
std::cout << "Recorded ts: " << recorded_ts + start_.value_or(0) << std::endl;
timestamped_frame_t timestamped_frame{
.frame = cv::imread(image_paths_.top().path),
.timestamp = recorded_ts + start_.value_or(0)};
output->frame = cv::imread(image_paths_.top().path);
output->timestamp = recorded_ts + start_.value_or(0);
image_paths_.pop();

if (!image_paths_.empty()) {
double delta = image_paths_.top().timestamp - recorded_ts;
std::this_thread::sleep_for(std::chrono::duration<double>(delta / speed_));
}

return timestamped_frame;
}

auto DiskCamera::Restart() -> void {}
Expand Down
2 changes: 1 addition & 1 deletion src/camera/disk_camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class DiskCamera : public ICamera {
std::optional<camera_constant_t> camera_constant = std::nullopt,
double speed = 1.0, std::optional<double> start = std::nullopt,
std::optional<double> end = std::nullopt);
auto GetFrame() -> timestamped_frame_t override;
void GetFrame(timestamped_frame_t* output) override;
auto Restart() -> void override;
auto IsDone() -> bool override { return image_paths_.empty(); }
[[nodiscard]] auto GetCameraConstant() const -> camera_constant_t override;
Expand Down
2 changes: 1 addition & 1 deletion src/camera/multi_camera_source.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ MultiCameraSource::MultiCameraSource(
}
}
timestamped_frame_t timestamped_frame;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to construct a new timestamped frame every time?

timestamped_frame = cameras_[i]->GetFrame();
cameras_[i]->GetFrame(&timestamped_frame);
mutex_.lock();
timestamped_frames_[i] = timestamped_frame;
frames_used_ = false;
Expand Down
17 changes: 7 additions & 10 deletions src/camera/uvc_camera.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,25 +104,22 @@ UVCCamera::UVCCamera(const CameraConstant& camera_constant,
}
}

auto UVCCamera::GetFrame() -> timestamped_frame_t {
timestamped_frame_t copied_timestamped_frame;
void UVCCamera::GetFrame(timestamped_frame_t* output) {
while (frame_index_ == previous_frame_index_) {
std::this_thread::yield();
}
mutex_.lock();
if (frame_buffer.frame.empty()) {
backup_image_.copyTo(copied_timestamped_frame.frame);
copied_timestamped_frame.invalid = true;
copied_timestamped_frame.timestamp =
frc::Timer::GetFPGATimestamp().to<double>();
backup_image_.copyTo(output->frame);
output->invalid = true;
output->timestamp = frc::Timer::GetFPGATimestamp().to<double>();
} else {
frame_buffer.frame.copyTo(copied_timestamped_frame.frame);
copied_timestamped_frame.invalid = frame_buffer.invalid;
copied_timestamped_frame.timestamp = frame_buffer.timestamp;
frame_buffer.frame.copyTo(output->frame);
output->invalid = frame_buffer.invalid;
output->timestamp = frame_buffer.timestamp;
}
mutex_.unlock();
previous_frame_index_ = frame_index_;
return copied_timestamped_frame;
}

auto UVCCamera::Restart() -> void {
Expand Down
2 changes: 1 addition & 1 deletion src/camera/uvc_camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class UVCCamera : public ICamera {
public:
UVCCamera(const CameraConstant& camera_constant, absl::Status& status,
std::optional<std::string> log_path = std::nullopt);
auto GetFrame() -> timestamped_frame_t override;
void GetFrame(timestamped_frame_t* output) override;
auto Restart() -> void override;
~UVCCamera() override;
[[nodiscard]] auto GetCameraConstant() const -> camera_constant_t override;
Expand Down
100 changes: 0 additions & 100 deletions src/main_bot_main.cc
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that we have removed the old way of running localization, can we update the unambigous main to support only multi-tag or only square solve? This should probably be a seperate pr though. Also, can you clean up some of the code in multi tag solver?

This file was deleted.

Loading
Loading