fix(touch): recover SpeedL faults and record MoveP pose samples
This commit is contained in:
parent
b293b1d6f2
commit
8df528ed7c
@ -70,6 +70,9 @@ public:
|
|||||||
|
|
||||||
// 抓取编码帧时传入相机驱动的索引。
|
// 抓取编码帧时传入相机驱动的索引。
|
||||||
size_t encoded_index{0};
|
size_t encoded_index{0};
|
||||||
|
|
||||||
|
// Raw RGB acquisition timing, independent of any encoded frame request.
|
||||||
|
bool capture_rgb_timing{false};
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Tag {
|
struct Tag {
|
||||||
@ -115,6 +118,8 @@ public:
|
|||||||
// 本类内部维护的帧序号,每次更新成功后自增。
|
// 本类内部维护的帧序号,每次更新成功后自增。
|
||||||
uint64_t frame_id{0};
|
uint64_t frame_id{0};
|
||||||
|
|
||||||
|
device::RgbFrameTiming rgb_timing;
|
||||||
|
|
||||||
void clearDerived() {
|
void clearDerived() {
|
||||||
gray.release();
|
gray.release();
|
||||||
has_gray = false;
|
has_gray = false;
|
||||||
|
|||||||
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
#include "algorithms/perception/apriltag/include/apriltag_perception.h"
|
#include "algorithms/perception/apriltag/include/apriltag_perception.h"
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
@ -75,6 +76,7 @@ void AprilTagPerception::clearFrameResults() {
|
|||||||
tags_.clear();
|
tags_.clear();
|
||||||
id_to_index_.clear();
|
id_to_index_.clear();
|
||||||
frame_.clearDerived();
|
frame_.clearDerived();
|
||||||
|
frame_.rgb_timing = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AprilTagPerception::processFrame(const Options& opt) {
|
bool AprilTagPerception::processFrame(const Options& opt) {
|
||||||
@ -126,9 +128,18 @@ bool AprilTagPerception::grabFrame(const Options& opt) {
|
|||||||
frame_.stream.bKey = false;
|
frame_.stream.bKey = false;
|
||||||
frame_.stream.depthKey = false;
|
frame_.stream.depthKey = false;
|
||||||
|
|
||||||
|
const auto read_rgb = [&] {
|
||||||
|
if (opt.capture_rgb_timing) {
|
||||||
|
camera_->getRGBImageWithTiming(frame_.stream.rgbImage, frame_.stream.intrinsics,
|
||||||
|
frame_.rgb_timing);
|
||||||
|
frame_.rgb_timing.host_read_complete_at = std::chrono::steady_clock::now();
|
||||||
|
} else {
|
||||||
|
camera_->getRGBImage(frame_.stream.rgbImage, frame_.stream.intrinsics);
|
||||||
|
}
|
||||||
|
};
|
||||||
try {
|
try {
|
||||||
if (opt.depth_policy == DepthPolicy::NONE) {
|
if (opt.depth_policy == DepthPolicy::NONE) {
|
||||||
camera_->getRGBImage(frame_.stream.rgbImage, frame_.stream.intrinsics);
|
read_rgb();
|
||||||
} else {
|
} else {
|
||||||
camera_->getRGBDImages(frame_.stream.rgbImage, frame_.stream.depthImage, frame_.stream.intrinsics);
|
camera_->getRGBDImages(frame_.stream.rgbImage, frame_.stream.depthImage, frame_.stream.intrinsics);
|
||||||
}
|
}
|
||||||
@ -136,7 +147,7 @@ bool AprilTagPerception::grabFrame(const Options& opt) {
|
|||||||
// PREFER: 允许回退 RGB
|
// PREFER: 允许回退 RGB
|
||||||
if (opt.depth_policy == DepthPolicy::PREFER) {
|
if (opt.depth_policy == DepthPolicy::PREFER) {
|
||||||
try {
|
try {
|
||||||
camera_->getRGBImage(frame_.stream.rgbImage, frame_.stream.intrinsics);
|
read_rgb();
|
||||||
frame_.stream.depthImage.release();
|
frame_.stream.depthImage.release();
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
last_status_ = Status::NO_NEW_FRAME;
|
last_status_ = Status::NO_NEW_FRAME;
|
||||||
|
|||||||
@ -26,6 +26,18 @@ namespace cmvr::device {
|
|||||||
float coeffs[5]{};
|
float coeffs[5]{};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct RgbFrameTiming
|
||||||
|
{
|
||||||
|
uint64_t frame_number{0};
|
||||||
|
double source_timestamp_ms{0};
|
||||||
|
const char* timestamp_domain{nullptr};
|
||||||
|
// Host arrival at the capture API. The source clock has its own epoch.
|
||||||
|
std::chrono::steady_clock::time_point host_received_at{};
|
||||||
|
std::chrono::steady_clock::time_point host_read_complete_at{};
|
||||||
|
bool buffered{false};
|
||||||
|
};
|
||||||
|
|
||||||
struct StreamFrameData
|
struct StreamFrameData
|
||||||
{
|
{
|
||||||
//原始图像数据
|
//原始图像数据
|
||||||
@ -66,6 +78,7 @@ namespace cmvr::device {
|
|||||||
bool discontinuity = false;
|
bool discontinuity = false;
|
||||||
uint32_t codec_config_generation = 0;
|
uint32_t codec_config_generation = 0;
|
||||||
std::vector<uint8_t> codec_config;
|
std::vector<uint8_t> codec_config;
|
||||||
|
RgbFrameTiming rgb_timing;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class PtzCommand {
|
enum class PtzCommand {
|
||||||
@ -144,6 +157,11 @@ namespace cmvr::device {
|
|||||||
}
|
}
|
||||||
virtual bool requestKeyFrame() { return false; }
|
virtual bool requestKeyFrame() { return false; }
|
||||||
virtual Eigen::Vector3f get3DPointFromPixel(int u, int v) {return {0,0,0};}
|
virtual Eigen::Vector3f get3DPointFromPixel(int u, int v) {return {0,0,0};}
|
||||||
|
virtual void getRGBImageWithTiming(cv::Mat& color, Rs2Intrinsics& intrinsics,
|
||||||
|
RgbFrameTiming& timing) {
|
||||||
|
timing = {};
|
||||||
|
getRGBImage(color, intrinsics);
|
||||||
|
}
|
||||||
protected:
|
protected:
|
||||||
CameraState state_{};
|
CameraState state_{};
|
||||||
mutable std::mutex stream_overlay_mutex_;
|
mutable std::mutex stream_overlay_mutex_;
|
||||||
|
|||||||
@ -26,6 +26,8 @@ namespace cmvr::device{
|
|||||||
bool stop() override;
|
bool stop() override;
|
||||||
void getState(CameraState& state) override;
|
void getState(CameraState& state) override;
|
||||||
void getRGBImage(cv::Mat& color, Rs2Intrinsics& intrinsics) override;
|
void getRGBImage(cv::Mat& color, Rs2Intrinsics& intrinsics) override;
|
||||||
|
void getRGBImageWithTiming(cv::Mat& color, Rs2Intrinsics& intrinsics,
|
||||||
|
RgbFrameTiming& timing) override;
|
||||||
bool supportsDepthImage() const override { return stream_mode_ != COLOR_MODE; }
|
bool supportsDepthImage() const override { return stream_mode_ != COLOR_MODE; }
|
||||||
bool supportsDepthStream() const override { return stream_mode_ != COLOR_MODE; }
|
bool supportsDepthStream() const override { return stream_mode_ != COLOR_MODE; }
|
||||||
void getDepthImage(cv::Mat& depth, Rs2Intrinsics& intrinsics) override;
|
void getDepthImage(cv::Mat& depth, Rs2Intrinsics& intrinsics) override;
|
||||||
@ -44,6 +46,7 @@ namespace cmvr::device{
|
|||||||
|
|
||||||
Eigen::Vector3f get3DPointFromPixel(int u, int v) override;
|
Eigen::Vector3f get3DPointFromPixel(int u, int v) override;
|
||||||
private:
|
private:
|
||||||
|
void getRGBImage_(cv::Mat& color, Rs2Intrinsics& intrinsics, RgbFrameTiming* timing);
|
||||||
rs2::frameset get_frameset(bool align);
|
rs2::frameset get_frameset(bool align);
|
||||||
void streaming_worker_();
|
void streaming_worker_();
|
||||||
void recording_worker_();
|
void recording_worker_();
|
||||||
|
|||||||
@ -10,6 +10,24 @@
|
|||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace cmvr::device;
|
using namespace cmvr::device;
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
RgbFrameTiming readRgbFrameTiming(const rs2::video_frame& frame,
|
||||||
|
std::chrono::steady_clock::time_point host_received_at)
|
||||||
|
{
|
||||||
|
RgbFrameTiming timing;
|
||||||
|
timing.host_received_at = host_received_at;
|
||||||
|
try {
|
||||||
|
timing.frame_number = frame.get_frame_number();
|
||||||
|
timing.source_timestamp_ms = frame.get_timestamp();
|
||||||
|
timing.timestamp_domain = rs2_timestamp_domain_to_string(frame.get_frame_timestamp_domain());
|
||||||
|
} catch (const rs2::error&) {
|
||||||
|
// RGB acquisition remains valid when source timing is unavailable.
|
||||||
|
}
|
||||||
|
return timing;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
// 检查系统中是否存在指定序列号的 RealSense 设备
|
// 检查系统中是否存在指定序列号的 RealSense 设备
|
||||||
bool checkRealSenseCamera(const std::string& serialNumber = "") {
|
bool checkRealSenseCamera(const std::string& serialNumber = "") {
|
||||||
@ -352,6 +370,16 @@ bool RealsenseCamera::stop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void RealsenseCamera::getRGBImage(cv::Mat& color, Rs2Intrinsics& intrinsics) {
|
void RealsenseCamera::getRGBImage(cv::Mat& color, Rs2Intrinsics& intrinsics) {
|
||||||
|
getRGBImage_(color, intrinsics, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RealsenseCamera::getRGBImageWithTiming(cv::Mat& color, Rs2Intrinsics& intrinsics,
|
||||||
|
RgbFrameTiming& timing) {
|
||||||
|
timing = {};
|
||||||
|
getRGBImage_(color, intrinsics, &timing);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RealsenseCamera::getRGBImage_(cv::Mat& color, Rs2Intrinsics& intrinsics, RgbFrameTiming* timing) {
|
||||||
intrinsics.cx = intrinsics_.ppx;
|
intrinsics.cx = intrinsics_.ppx;
|
||||||
intrinsics.cy = intrinsics_.ppy;
|
intrinsics.cy = intrinsics_.ppy;
|
||||||
intrinsics.fx = intrinsics_.fx;
|
intrinsics.fx = intrinsics_.fx;
|
||||||
@ -377,10 +405,16 @@ void RealsenseCamera::getRGBImage(cv::Mat& color, Rs2Intrinsics& intrinsics) {
|
|||||||
std::lock_guard<std::mutex> lock(frame_mtx_);
|
std::lock_guard<std::mutex> lock(frame_mtx_);
|
||||||
latest_depth_ = frame.value().depthImage.clone();
|
latest_depth_ = frame.value().depthImage.clone();
|
||||||
}
|
}
|
||||||
|
if (timing && !color.empty()) {
|
||||||
|
*timing = frame.value().rgb_timing;
|
||||||
|
timing->buffered = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
rs2::frameset frames = get_frameset(false);
|
rs2::frameset frames = get_frameset(false);
|
||||||
|
const auto host_received_at = timing ? std::chrono::steady_clock::now()
|
||||||
|
: std::chrono::steady_clock::time_point{};
|
||||||
auto color_frame = frames.get_color_frame();
|
auto color_frame = frames.get_color_frame();
|
||||||
auto depth_frame = frames.get_depth_frame();
|
auto depth_frame = frames.get_depth_frame();
|
||||||
|
|
||||||
@ -395,6 +429,9 @@ void RealsenseCamera::getRGBImage(cv::Mat& color, Rs2Intrinsics& intrinsics) {
|
|||||||
std::lock_guard<std::mutex> lock(frame_mtx_);
|
std::lock_guard<std::mutex> lock(frame_mtx_);
|
||||||
latest_depth_ = depth;
|
latest_depth_ = depth;
|
||||||
}
|
}
|
||||||
|
if (timing && !color.empty()) {
|
||||||
|
*timing = readRgbFrameTiming(color_frame, host_received_at);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// CMVR_LOG(INFO) << "realsense get rgb frame successfully";
|
// CMVR_LOG(INFO) << "realsense get rgb frame successfully";
|
||||||
}
|
}
|
||||||
@ -755,6 +792,7 @@ void RealsenseCamera::streaming_worker_() {
|
|||||||
|
|
||||||
rs2::frameset frames;
|
rs2::frameset frames;
|
||||||
frames = get_frameset(true);
|
frames = get_frameset(true);
|
||||||
|
const auto host_received_at = std::chrono::steady_clock::now();
|
||||||
rs2::video_frame color_frame = frames.get_color_frame();
|
rs2::video_frame color_frame = frames.get_color_frame();
|
||||||
rs2::depth_frame depth_frame = frames.get_depth_frame();
|
rs2::depth_frame depth_frame = frames.get_depth_frame();
|
||||||
const bool needs_color = stream_mode_ == COLOR_MODE || stream_mode_ == RGBD_MODE;
|
const bool needs_color = stream_mode_ == COLOR_MODE || stream_mode_ == RGBD_MODE;
|
||||||
@ -787,6 +825,7 @@ void RealsenseCamera::streaming_worker_() {
|
|||||||
cv::Mat temp(cv::Size(color_frame.get_width(), color_frame.get_height()),
|
cv::Mat temp(cv::Size(color_frame.get_width(), color_frame.get_height()),
|
||||||
CV_8UC3, const_cast<void*>(color_frame.get_data()), cv::Mat::AUTO_STEP);
|
CV_8UC3, const_cast<void*>(color_frame.get_data()), cv::Mat::AUTO_STEP);
|
||||||
temp.copyTo(frame_data.rgbImage); // 执行深拷贝
|
temp.copyTo(frame_data.rgbImage); // 执行深拷贝
|
||||||
|
frame_data.rgb_timing = readRgbFrameTiming(color_frame, host_received_at);
|
||||||
}
|
}
|
||||||
if (depth_frame) {
|
if (depth_frame) {
|
||||||
cv::Mat temp(cv::Size(depth_frame.get_width(), depth_frame.get_height()),
|
cv::Mat temp(cv::Size(depth_frame.get_width(), depth_frame.get_height()),
|
||||||
|
|||||||
@ -134,6 +134,11 @@ private:
|
|||||||
bool stepPreparing();
|
bool stepPreparing();
|
||||||
bool stepApproaching();
|
bool stepApproaching();
|
||||||
void cancelApproach();
|
void cancelApproach();
|
||||||
|
void logApproachPoseSample(const char* stage,
|
||||||
|
const Eigen::Matrix4d& T_B_P,
|
||||||
|
const Eigen::Matrix4d& T_B_G,
|
||||||
|
Clock::time_point fk_started_at,
|
||||||
|
Clock::time_point fk_finished_at) const;
|
||||||
bool stepAligning(double nominal_dt);
|
bool stepAligning(double nominal_dt);
|
||||||
// Perception helpers return readiness; waiting keeps stepAligning active.
|
// Perception helpers return readiness; waiting keeps stepAligning active.
|
||||||
bool updateAlignmentAnchor(Eigen::Vector3d& p_target_G);
|
bool updateAlignmentAnchor(Eigen::Vector3d& p_target_G);
|
||||||
|
|||||||
@ -3,6 +3,7 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <exception>
|
#include <exception>
|
||||||
|
#include <iomanip>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
@ -340,6 +341,19 @@ bool TouchScreenTask::startFromPixelUnlocked(int u, int v) {
|
|||||||
if (!arm_->isConnected()) return reject_start("arm is not connected");
|
if (!arm_->isConnected()) return reject_start("arm is not connected");
|
||||||
const auto stopped = arm_->stopMotion();
|
const auto stopped = arm_->stopMotion();
|
||||||
if (!stopped.ok()) return reject_start("stop failed: " + stopped.message);
|
if (!stopped.ok()) return reject_start("stop failed: " + stopped.message);
|
||||||
|
|
||||||
|
const auto speed_l_result = arm_->getSpeedLResult();
|
||||||
|
if (!speed_l_result.ok() && speed_l_result.code != device::ArmErrorCode::UnsupportedCommand &&
|
||||||
|
arm_->isFault()) {
|
||||||
|
if (arm_->isEmergencyStopped() || arm_->isProtectiveStopped()) {
|
||||||
|
return reject_start("safety stop active");
|
||||||
|
}
|
||||||
|
if (!arm_->isConnected()) return reject_start("arm is not connected");
|
||||||
|
const auto cleared = arm_->clearFault();
|
||||||
|
if (!cleared.ok()) return reject_start("speedL clearFault failed: " + cleared.message);
|
||||||
|
CMVR_LOG(INFO) << "[TouchScreenTask] cleared speedL fault on "
|
||||||
|
<< config_.devices().arm_id() << ": " << speed_l_result.message;
|
||||||
|
}
|
||||||
const auto recovered = arm_->recoverSpeedLPlanningFault();
|
const auto recovered = arm_->recoverSpeedLPlanningFault();
|
||||||
if (!recovered.ok()) return reject_start(recovered.message);
|
if (!recovered.ok()) return reject_start(recovered.message);
|
||||||
} catch (const std::exception& error) {
|
} catch (const std::exception& error) {
|
||||||
@ -963,7 +977,9 @@ bool TouchScreenTask::stepPreparing() {
|
|||||||
if (!updatePbvsTarget(anchor_G, T_G_P)) return false;
|
if (!updatePbvsTarget(anchor_G, T_G_P)) return false;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
const auto fk_started_at = Clock::now();
|
||||||
const Eigen::Matrix4d T_B_P = common::math::poseToMatrix(arm_->fk(true));
|
const Eigen::Matrix4d T_B_P = common::math::poseToMatrix(arm_->fk(true));
|
||||||
|
const auto fk_finished_at = Clock::now();
|
||||||
const Eigen::Matrix4d T_B_G = T_B_P * T_G_P.inverse();
|
const Eigen::Matrix4d T_B_G = T_B_P * T_G_P.inverse();
|
||||||
const Eigen::Matrix4d target_B = T_B_G * pbvs_.targetPose();
|
const Eigen::Matrix4d target_B = T_B_G * pbvs_.targetPose();
|
||||||
if (!isHomogeneousTransform(T_B_G) || !isHomogeneousTransform(target_B)) {
|
if (!isHomogeneousTransform(T_B_G) || !isHomogeneousTransform(target_B)) {
|
||||||
@ -995,6 +1011,7 @@ bool TouchScreenTask::stepPreparing() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logApproachPoseSample("BEFORE_MOVE_P", T_B_P, T_B_G, fk_started_at, fk_finished_at);
|
||||||
phase_start_time_ = Clock::now();
|
phase_start_time_ = Clock::now();
|
||||||
const auto started = phase_start_time_;
|
const auto started = phase_start_time_;
|
||||||
const double timeout_s = cfg.timeout_s();
|
const double timeout_s = cfg.timeout_s();
|
||||||
@ -1063,6 +1080,49 @@ bool TouchScreenTask::stepApproaching() {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TouchScreenTask::logApproachPoseSample(const char* stage,
|
||||||
|
const Eigen::Matrix4d& T_B_P,
|
||||||
|
const Eigen::Matrix4d& T_B_G,
|
||||||
|
const Clock::time_point fk_started_at,
|
||||||
|
const Clock::time_point fk_finished_at) const {
|
||||||
|
const auto monotonic_ns = [](Clock::time_point time) {
|
||||||
|
return std::chrono::duration_cast<std::chrono::nanoseconds>(time.time_since_epoch()).count();
|
||||||
|
};
|
||||||
|
const auto& frame = external_perception_->frame();
|
||||||
|
const auto& timing = frame.rgb_timing;
|
||||||
|
const auto& tags = config_.perception().tags();
|
||||||
|
const auto* screen_tag = external_perception_->findTag(tags.screen().id());
|
||||||
|
const auto* hand_tag = external_perception_->findTag(tags.hand().id());
|
||||||
|
const Eigen::Matrix4d target_B = T_B_G * pbvs_.targetPose();
|
||||||
|
const Eigen::IOFormat matrix_format(9, Eigen::DontAlignCols, ",", ",", "[", "]", "[", "]");
|
||||||
|
const Eigen::IOFormat vector_format(9, Eigen::DontAlignCols, ",", ",", "", "", "[", "]");
|
||||||
|
CMVR_LOG(INFO) << "[TouchScreenTask][APPROACH_POSE][" << stage << "] id=" << id_
|
||||||
|
<< ", u=" << target_u_ << ", v=" << target_v_
|
||||||
|
<< ", camera=" << config_.devices().external_camera_id()
|
||||||
|
<< ", perception_frame_id=" << frame.frame_id
|
||||||
|
<< ", rgb_frame_number=" << timing.frame_number
|
||||||
|
<< ", rgb_source_timestamp_ms=" << std::fixed << std::setprecision(3)
|
||||||
|
<< timing.source_timestamp_ms << std::defaultfloat
|
||||||
|
<< ", rgb_timestamp_domain=" << (timing.timestamp_domain ? timing.timestamp_domain : "unavailable")
|
||||||
|
<< ", rgb_buffered=" << timing.buffered
|
||||||
|
<< ", rgb_host_received_mono_ns=" << monotonic_ns(timing.host_received_at)
|
||||||
|
<< ", rgb_read_complete_mono_ns=" << monotonic_ns(timing.host_read_complete_at)
|
||||||
|
<< ", fk_start_mono_ns=" << monotonic_ns(fk_started_at)
|
||||||
|
<< ", fk_end_mono_ns=" << monotonic_ns(fk_finished_at)
|
||||||
|
<< ", screen_tag_id=" << tags.screen().id()
|
||||||
|
<< ", screen_tag_margin=" << (screen_tag ? screen_tag->margin : 0.0)
|
||||||
|
<< ", hand_tag_id=" << tags.hand().id()
|
||||||
|
<< ", hand_tag_margin=" << (hand_tag ? hand_tag->margin : 0.0)
|
||||||
|
<< ", T_C_G=" << tcp_pose_tracker_.T_C_G().topRows<3>().format(matrix_format)
|
||||||
|
<< ", T_C_H=" << tcp_pose_tracker_.T_C_H().topRows<3>().format(matrix_format)
|
||||||
|
<< ", T_H_P=" << T_H_P_.topRows<3>().format(matrix_format)
|
||||||
|
<< ", T_G_P=" << tcp_pose_tracker_.T_G_P().topRows<3>().format(matrix_format)
|
||||||
|
<< ", T_B_P=" << T_B_P.topRows<3>().format(matrix_format)
|
||||||
|
<< ", T_B_G=" << T_B_G.topRows<3>().format(matrix_format)
|
||||||
|
<< ", target_G_m=" << pbvs_.targetPose().block<3, 1>(0, 3).transpose().format(vector_format)
|
||||||
|
<< ", target_B_m=" << target_B.block<3, 1>(0, 3).transpose().format(vector_format);
|
||||||
|
}
|
||||||
|
|
||||||
bool TouchScreenTask::stepAligning(const double nominal_dt) {
|
bool TouchScreenTask::stepAligning(const double nominal_dt) {
|
||||||
const double elapsed =
|
const double elapsed =
|
||||||
std::chrono::duration<double>(Clock::now() - phase_start_time_).count();
|
std::chrono::duration<double>(Clock::now() - phase_start_time_).count();
|
||||||
@ -1187,6 +1247,7 @@ bool TouchScreenTask::updateAlignmentTcpPose() {
|
|||||||
external_options.depth_policy = perception::AprilTagPerception::DepthPolicy::NONE;
|
external_options.depth_policy = perception::AprilTagPerception::DepthPolicy::NONE;
|
||||||
external_options.detect_tags = true;
|
external_options.detect_tags = true;
|
||||||
external_options.fetch_encoded = false;
|
external_options.fetch_encoded = false;
|
||||||
|
external_options.capture_rgb_timing = config_.approach().enable() && !have_last_T_B_G_;
|
||||||
const bool perception_ok = external_perception_->update(external_options);
|
const bool perception_ok = external_perception_->update(external_options);
|
||||||
if (!perception_ok) {
|
if (!perception_ok) {
|
||||||
stopPbvsMotion();
|
stopPbvsMotion();
|
||||||
@ -1300,12 +1361,14 @@ bool TouchScreenTask::mapAlignmentCommandToBase(const Eigen::Matrix4d& T_G_P,
|
|||||||
const double pbvs_dt,
|
const double pbvs_dt,
|
||||||
device::CartesianVelocity& twist_B) {
|
device::CartesianVelocity& twist_B) {
|
||||||
Eigen::Matrix4d T_B_P = Eigen::Matrix4d::Identity();
|
Eigen::Matrix4d T_B_P = Eigen::Matrix4d::Identity();
|
||||||
|
const auto fk_started_at = Clock::now();
|
||||||
try {
|
try {
|
||||||
T_B_P = cmvr::common::math::poseToMatrix(arm_->fk(true));
|
T_B_P = cmvr::common::math::poseToMatrix(arm_->fk(true));
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
enterFailed(Status::ROBOT_STATE_FAILED);
|
enterFailed(Status::ROBOT_STATE_FAILED);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
const auto fk_finished_at = Clock::now();
|
||||||
if (!isHomogeneousTransform(T_B_P)) {
|
if (!isHomogeneousTransform(T_B_P)) {
|
||||||
enterFailed(Status::ROBOT_STATE_FAILED);
|
enterFailed(Status::ROBOT_STATE_FAILED);
|
||||||
return false;
|
return false;
|
||||||
@ -1330,6 +1393,8 @@ bool TouchScreenTask::mapAlignmentCommandToBase(const Eigen::Matrix4d& T_G_P,
|
|||||||
std::max(max_T_B_G_translation_delta_m_, T_B_G_delta_translation_m);
|
std::max(max_T_B_G_translation_delta_m_, T_B_G_delta_translation_m);
|
||||||
max_T_B_G_rotation_delta_rad_ =
|
max_T_B_G_rotation_delta_rad_ =
|
||||||
std::max(max_T_B_G_rotation_delta_rad_, T_B_G_delta_rotation_rad);
|
std::max(max_T_B_G_rotation_delta_rad_, T_B_G_delta_rotation_rad);
|
||||||
|
} else if (config_.approach().enable()) {
|
||||||
|
logApproachPoseSample("AFTER_MOVE_P", T_B_P, T_B_G, fk_started_at, fk_finished_at);
|
||||||
}
|
}
|
||||||
last_T_B_G_ = T_B_G;
|
last_T_B_G_ = T_B_G;
|
||||||
have_last_T_B_G_ = true;
|
have_last_T_B_G_ = true;
|
||||||
|
|||||||
@ -310,6 +310,9 @@ public:
|
|||||||
calls.push_back("stopMotion");
|
calls.push_back("stopMotion");
|
||||||
return stop_result;
|
return stop_result;
|
||||||
}
|
}
|
||||||
|
Result getSpeedLResult() const override {
|
||||||
|
return speed_l_result.value_or(RobotArm::getSpeedLResult());
|
||||||
|
}
|
||||||
Result recoverSpeedLPlanningFault() override {
|
Result recoverSpeedLPlanningFault() override {
|
||||||
calls.push_back("recoverSpeedLPlanningFault");
|
calls.push_back("recoverSpeedLPlanningFault");
|
||||||
if (recovery_result.ok()) planning_fault = false;
|
if (recovery_result.ok()) planning_fault = false;
|
||||||
@ -339,7 +342,10 @@ public:
|
|||||||
return *torque_on_result;
|
return *torque_on_result;
|
||||||
}
|
}
|
||||||
Result moveP(const cmvr::device::CartesianPose&, const cmvr::device::MotionOptions&,
|
Result moveP(const cmvr::device::CartesianPose&, const cmvr::device::MotionOptions&,
|
||||||
cmvr::device::FrameType) override { return unsupported(); }
|
cmvr::device::FrameType) override {
|
||||||
|
if (allow_cartesian_move_p) return Result::success();
|
||||||
|
return unsupported();
|
||||||
|
}
|
||||||
Result torqueOff() override { return unsupported(); }
|
Result torqueOff() override { return unsupported(); }
|
||||||
Result calibrateZeroQ(const std::string&) override { return unsupported(); }
|
Result calibrateZeroQ(const std::string&) override { return unsupported(); }
|
||||||
Result emergencyStop() override { return unsupported(); }
|
Result emergencyStop() override { return unsupported(); }
|
||||||
@ -372,7 +378,15 @@ public:
|
|||||||
Result powerOff() override { return unsupported(); }
|
Result powerOff() override { return unsupported(); }
|
||||||
Result brakeRelease() override { return unsupported(); }
|
Result brakeRelease() override { return unsupported(); }
|
||||||
Result shutdown() override { return unsupported(); }
|
Result shutdown() override { return unsupported(); }
|
||||||
Result clearFault() override { return unsupported(); }
|
Result clearFault() override {
|
||||||
|
calls.push_back("clearFault");
|
||||||
|
if (!clear_fault_result) return unsupported();
|
||||||
|
if (clear_fault_result->ok()) {
|
||||||
|
planning_fault = false;
|
||||||
|
speed_l_result = Result::success();
|
||||||
|
}
|
||||||
|
return *clear_fault_result;
|
||||||
|
}
|
||||||
Result unlockProtectiveStop() override { return unsupported(); }
|
Result unlockProtectiveStop() override { return unsupported(); }
|
||||||
Result loadProgram(const std::string&) override { return unsupported(); }
|
Result loadProgram(const std::string&) override { return unsupported(); }
|
||||||
Result playProgram() override { return unsupported(); }
|
Result playProgram() override { return unsupported(); }
|
||||||
@ -390,6 +404,8 @@ public:
|
|||||||
Result stop_result{Result::success()};
|
Result stop_result{Result::success()};
|
||||||
Result move_result{Result::success()};
|
Result move_result{Result::success()};
|
||||||
Result recovery_result{Result::success()};
|
Result recovery_result{Result::success()};
|
||||||
|
std::optional<Result> speed_l_result;
|
||||||
|
std::optional<Result> clear_fault_result;
|
||||||
std::optional<Result> torque_on_result;
|
std::optional<Result> torque_on_result;
|
||||||
bool planning_fault{false};
|
bool planning_fault{false};
|
||||||
bool connected{true};
|
bool connected{true};
|
||||||
@ -398,6 +414,7 @@ public:
|
|||||||
bool emergency{false};
|
bool emergency{false};
|
||||||
bool protective{false};
|
bool protective{false};
|
||||||
bool motion_busy{false};
|
bool motion_busy{false};
|
||||||
|
bool allow_cartesian_move_p{false};
|
||||||
bool move_j_throws{false};
|
bool move_j_throws{false};
|
||||||
bool torque_on_throws{false};
|
bool torque_on_throws{false};
|
||||||
int stop_l_calls{0};
|
int stop_l_calls{0};
|
||||||
@ -838,6 +855,76 @@ TEST_F(TouchScreenFailureReturnTest, PbvsUsesElapsedUpdateTimeAndResetsAfterTrac
|
|||||||
EXPECT_NEAR(linear_speed(commands[2]), 0.0001, 1e-8);
|
EXPECT_NEAR(linear_speed(commands[2]), 0.0001, 1e-8);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(TouchScreenFailureReturnTest, LogsApproachPoseOnceBeforeAndAfterMoveP) {
|
||||||
|
const auto camera = std::make_shared<FailureReturnCamera>();
|
||||||
|
camera->frame = makeAlignmentTagFrame();
|
||||||
|
ASSERT_FALSE(camera->frame.empty());
|
||||||
|
|
||||||
|
config.set_debug_draw_coordinate_frames(false);
|
||||||
|
config.mutable_approach()->set_enable(true);
|
||||||
|
auto* alignment = config.mutable_alignment();
|
||||||
|
alignment->set_timeout_s(10.0);
|
||||||
|
alignment->mutable_target()->set_mode(cmvr::config::TOUCH_SCREEN_ALIGN_MODE_POSITION_ONLY);
|
||||||
|
// Both synthetic tags lie at the same depth. Place the fake TCP in front
|
||||||
|
// of the screen plane so the approach start passes the clearance check.
|
||||||
|
alignment->mutable_calibration()->mutable_hand_tag_to_tcp()->set_m23(0.08);
|
||||||
|
arm->allow_cartesian_move_p = true;
|
||||||
|
auto& commands = arm->speed_l_commands.emplace();
|
||||||
|
|
||||||
|
cmvr::task::TouchScreenTask task(config);
|
||||||
|
ASSERT_TRUE(task.init(arm, nullptr, camera, camera));
|
||||||
|
using Phase = cmvr::task::TouchScreenTask::Phase;
|
||||||
|
constexpr double nominal_dt = 0.001;
|
||||||
|
|
||||||
|
::testing::internal::CaptureStdout();
|
||||||
|
[&] {
|
||||||
|
ASSERT_TRUE(task.touch(180, 240));
|
||||||
|
ASSERT_TRUE(task.step(nominal_dt));
|
||||||
|
ASSERT_EQ(task.phase(), Phase::APPROACHING);
|
||||||
|
const auto deadline = std::chrono::steady_clock::now() + std::chrono::seconds(1);
|
||||||
|
while (task.phase() == Phase::APPROACHING &&
|
||||||
|
std::chrono::steady_clock::now() < deadline) {
|
||||||
|
ASSERT_TRUE(task.step(nominal_dt));
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
||||||
|
}
|
||||||
|
ASSERT_EQ(task.phase(), Phase::ALIGNING);
|
||||||
|
ASSERT_TRUE(task.step(nominal_dt));
|
||||||
|
ASSERT_TRUE(task.step(nominal_dt));
|
||||||
|
ASSERT_EQ(commands.size(), 2u);
|
||||||
|
}();
|
||||||
|
const auto logs = ::testing::internal::GetCapturedStdout();
|
||||||
|
if (HasFatalFailure()) return;
|
||||||
|
|
||||||
|
constexpr char before_marker[] = "[APPROACH_POSE][BEFORE_MOVE_P]";
|
||||||
|
constexpr char after_marker[] = "[APPROACH_POSE][AFTER_MOVE_P]";
|
||||||
|
const auto before = logs.find(before_marker);
|
||||||
|
const auto after = logs.find(after_marker);
|
||||||
|
ASSERT_NE(before, std::string::npos) << logs;
|
||||||
|
ASSERT_NE(after, std::string::npos) << logs;
|
||||||
|
EXPECT_LT(before, after);
|
||||||
|
EXPECT_EQ(logs.find(before_marker, before + 1), std::string::npos);
|
||||||
|
EXPECT_EQ(logs.find(after_marker, after + 1), std::string::npos);
|
||||||
|
const auto before_line = logs.substr(before, logs.find('\n', before) - before);
|
||||||
|
const auto after_line = logs.substr(after, logs.find('\n', after) - after);
|
||||||
|
|
||||||
|
const auto field = [](const std::string& line, const std::string& name) {
|
||||||
|
const auto start = line.find(name + "=");
|
||||||
|
if (start == std::string::npos) return std::string{};
|
||||||
|
const auto value = start + name.size() + 1;
|
||||||
|
return line.substr(value, line.find(", ", value) - value);
|
||||||
|
};
|
||||||
|
for (const auto* line : {&before_line, &after_line}) {
|
||||||
|
EXPECT_EQ(field(*line, "rgb_timestamp_domain"), "unavailable");
|
||||||
|
EXPECT_EQ(field(*line, "rgb_frame_number"), "0");
|
||||||
|
const auto read_time = field(*line, "rgb_read_complete_mono_ns");
|
||||||
|
ASSERT_FALSE(read_time.empty());
|
||||||
|
EXPECT_GT(std::stoll(read_time), 0);
|
||||||
|
}
|
||||||
|
const auto target = field(before_line, "target_G_m");
|
||||||
|
ASSERT_FALSE(target.empty());
|
||||||
|
EXPECT_EQ(field(after_line, "target_G_m"), target);
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(TouchScreenFailureReturnTest, RejectsUnknownInitializationMotionMethod) {
|
TEST_F(TouchScreenFailureReturnTest, RejectsUnknownInitializationMotionMethod) {
|
||||||
using Init = cmvr::config::TouchScreenTaskInitializationConfig;
|
using Init = cmvr::config::TouchScreenTaskInitializationConfig;
|
||||||
config.mutable_initialization()->set_motion_method(static_cast<Init::MotionMethod>(99));
|
config.mutable_initialization()->set_motion_method(static_cast<Init::MotionMethod>(99));
|
||||||
@ -943,10 +1030,29 @@ TEST_F(TouchScreenFailureReturnTest, DisabledInitializationStillRecoversBeforeSt
|
|||||||
EXPECT_TRUE(task.isBusy());
|
EXPECT_TRUE(task.isBusy());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(TouchScreenFailureReturnTest, NextRunClearsSpeedLFaultBeforeInitialization) {
|
||||||
|
config.mutable_initialization()->set_before_start(true);
|
||||||
|
cmvr::task::TouchScreenTask task(config);
|
||||||
|
const auto camera = std::make_shared<FailureReturnCamera>();
|
||||||
|
ASSERT_TRUE(task.init(arm, nullptr, camera, camera));
|
||||||
|
arm->planning_fault = true;
|
||||||
|
arm->speed_l_result = cmvr::device::Result::failure(
|
||||||
|
cmvr::device::ArmErrorCode::InvalidArgument,
|
||||||
|
"S-curve limits exclude the remaining direction transition");
|
||||||
|
arm->clear_fault_result = cmvr::device::Result::success();
|
||||||
|
|
||||||
|
ASSERT_TRUE(task.touch(320, 240));
|
||||||
|
EXPECT_EQ(arm->calls, (std::vector<std::string>{
|
||||||
|
"stopMotion", "clearFault", "recoverSpeedLPlanningFault", "moveJ"}));
|
||||||
|
EXPECT_FALSE(arm->isFault());
|
||||||
|
EXPECT_TRUE(task.isBusy());
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(TouchScreenFailureReturnTest, RejectedRestartPreservesPreviousFailureAndDoesNotMove) {
|
TEST_F(TouchScreenFailureReturnTest, RejectedRestartPreservesPreviousFailureAndDoesNotMove) {
|
||||||
config.mutable_initialization()->set_before_start(true);
|
config.mutable_initialization()->set_before_start(true);
|
||||||
config.mutable_initialization()->set_after_failure(false);
|
config.mutable_initialization()->set_after_failure(false);
|
||||||
for (const auto* reason : {"failed_stop", "fatal_fault", "emergency", "protective", "disconnected"}) {
|
for (const auto* reason : {"failed_stop", "failed_clear", "fatal_fault", "emergency",
|
||||||
|
"protective", "disconnected"}) {
|
||||||
SCOPED_TRACE(reason);
|
SCOPED_TRACE(reason);
|
||||||
arm = std::make_shared<FailureReturnArm>(config);
|
arm = std::make_shared<FailureReturnArm>(config);
|
||||||
cmvr::task::TouchScreenTask task(config);
|
cmvr::task::TouchScreenTask task(config);
|
||||||
@ -969,6 +1075,14 @@ TEST_F(TouchScreenFailureReturnTest, RejectedRestartPreservesPreviousFailureAndD
|
|||||||
if (failure == "fatal_fault") {
|
if (failure == "fatal_fault") {
|
||||||
arm->recovery_result = cmvr::device::Result::failure(
|
arm->recovery_result = cmvr::device::Result::failure(
|
||||||
cmvr::device::ArmErrorCode::CommandFailed, "injected nonrecoverable fault");
|
cmvr::device::ArmErrorCode::CommandFailed, "injected nonrecoverable fault");
|
||||||
|
} else {
|
||||||
|
arm->speed_l_result = cmvr::device::Result::failure(
|
||||||
|
cmvr::device::ArmErrorCode::InvalidArgument,
|
||||||
|
"S-curve limits exclude the remaining direction transition");
|
||||||
|
}
|
||||||
|
if (failure == "failed_clear") {
|
||||||
|
arm->clear_fault_result = cmvr::device::Result::failure(
|
||||||
|
cmvr::device::ArmErrorCode::Timeout, "speedL measured stop was not confirmed");
|
||||||
}
|
}
|
||||||
|
|
||||||
EXPECT_FALSE(task.touch(350, 260));
|
EXPECT_FALSE(task.touch(350, 260));
|
||||||
@ -979,6 +1093,8 @@ TEST_F(TouchScreenFailureReturnTest, RejectedRestartPreservesPreviousFailureAndD
|
|||||||
if (failure == "fatal_fault") {
|
if (failure == "fatal_fault") {
|
||||||
EXPECT_EQ(arm->calls, (std::vector<std::string>{
|
EXPECT_EQ(arm->calls, (std::vector<std::string>{
|
||||||
"stopMotion", "recoverSpeedLPlanningFault"}));
|
"stopMotion", "recoverSpeedLPlanningFault"}));
|
||||||
|
} else if (failure == "failed_clear") {
|
||||||
|
EXPECT_EQ(arm->calls, (std::vector<std::string>{"stopMotion", "clearFault"}));
|
||||||
} else if (failure == "failed_stop") {
|
} else if (failure == "failed_stop") {
|
||||||
EXPECT_EQ(arm->calls, std::vector<std::string>{"stopMotion"});
|
EXPECT_EQ(arm->calls, std::vector<std::string>{"stopMotion"});
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user