feat: add the wall reflector detection action
Action handler that detects two flat reflective tape strips on a wall from a raw LaserScan and publishes the stop-station target (and a marker frame) as static TFs for the next move_to stage. Geometry comes from dock_pattern_detector's ReflectorPairMatcher. The handler adds scan freshness checks (stamp after settle, max age, strictly increasing stamps) and a deadline for detections waiting on TF, derives lidar flip and tilt from TF, and never reuses samples across pause/resume or runs.
This commit is contained in:
167
test/config/action_handlers_params.yaml
Normal file
167
test/config/action_handlers_params.yaml
Normal file
@@ -0,0 +1,167 @@
|
||||
# Cấu hình CHỈ cho test tổng hợp; không phải số hiệu chuẩn robot.
|
||||
actions_wall:
|
||||
handlers:
|
||||
- {name: forward, type: WallReflectorDetectionActionHandler}
|
||||
- {name: backward, type: WallReflectorDetectionActionHandler}
|
||||
- {name: wrong_direction, type: WallReflectorDetectionActionHandler}
|
||||
forward:
|
||||
action_types: [DetectWallReflectors]
|
||||
scan_topic: /f_scan
|
||||
entry_direction: forward
|
||||
default_profile: standard
|
||||
output_frame: wall_reflector_target
|
||||
marker_frame: wall_reflector_frame
|
||||
settle_delay: 0.2
|
||||
timeout: 5.0
|
||||
max_scan_age: 0.3
|
||||
max_future_skew: 0.05
|
||||
pending_tf_timeout: 0.2
|
||||
min_samples: 3
|
||||
sample_window: 1.0
|
||||
profiles:
|
||||
standard:
|
||||
tape_width: 0.05
|
||||
width_tolerance: 0.025
|
||||
tape_spacing: 0.40
|
||||
spacing_tolerance: 0.025
|
||||
tape_min_intensity: 8000.0
|
||||
tape_core_intensity: 15000.0
|
||||
tape_min_points: 3
|
||||
tape_bloom_max_angle: 0.0
|
||||
tape_plateau_min_fraction: 0.5
|
||||
edge_bias_bound: 0.0
|
||||
max_edge_uncertainty: 0.04
|
||||
wall_min_span: 0.65
|
||||
wall_max_rms: 0.006
|
||||
wall_max_residual: 0.02
|
||||
wall_max_gap: 0.15
|
||||
wall_merge_distance: 0.02
|
||||
offset_x: 0.6
|
||||
alternate:
|
||||
tape_width: 0.05
|
||||
width_tolerance: 0.025
|
||||
tape_spacing: 0.40
|
||||
spacing_tolerance: 0.025
|
||||
tape_min_intensity: 8000.0
|
||||
tape_core_intensity: 15000.0
|
||||
tape_min_points: 3
|
||||
tape_bloom_max_angle: 0.0
|
||||
tape_plateau_min_fraction: 0.5
|
||||
edge_bias_bound: 0.0
|
||||
max_edge_uncertainty: 0.04
|
||||
wall_min_span: 0.65
|
||||
wall_max_rms: 0.006
|
||||
wall_max_residual: 0.02
|
||||
wall_max_gap: 0.15
|
||||
wall_merge_distance: 0.02
|
||||
offset_x: 0.8
|
||||
offset_y: 0.1
|
||||
offset_yaw: 0.2
|
||||
backward:
|
||||
action_types: [DetectWallReflectorsBackward]
|
||||
scan_topic: /b_scan2
|
||||
entry_direction: backward
|
||||
default_profile: standard
|
||||
output_frame: wall_reflector_target
|
||||
marker_frame: wall_reflector_frame
|
||||
settle_delay: 0.2
|
||||
timeout: 5.0
|
||||
max_scan_age: 0.3
|
||||
max_future_skew: 0.05
|
||||
pending_tf_timeout: 0.2
|
||||
min_samples: 3
|
||||
sample_window: 1.0
|
||||
profiles:
|
||||
standard:
|
||||
tape_width: 0.05
|
||||
width_tolerance: 0.025
|
||||
tape_spacing: 0.40
|
||||
spacing_tolerance: 0.025
|
||||
tape_min_intensity: 8000.0
|
||||
tape_core_intensity: 15000.0
|
||||
tape_min_points: 3
|
||||
tape_bloom_max_angle: 0.0
|
||||
tape_plateau_min_fraction: 0.5
|
||||
edge_bias_bound: 0.0
|
||||
max_edge_uncertainty: 0.04
|
||||
wall_min_span: 0.65
|
||||
wall_max_rms: 0.006
|
||||
wall_max_residual: 0.02
|
||||
wall_max_gap: 0.15
|
||||
wall_merge_distance: 0.02
|
||||
offset_x: 0.6
|
||||
alternate:
|
||||
tape_width: 0.05
|
||||
width_tolerance: 0.025
|
||||
tape_spacing: 0.40
|
||||
spacing_tolerance: 0.025
|
||||
tape_min_intensity: 8000.0
|
||||
tape_core_intensity: 15000.0
|
||||
tape_min_points: 3
|
||||
tape_bloom_max_angle: 0.0
|
||||
tape_plateau_min_fraction: 0.5
|
||||
edge_bias_bound: 0.0
|
||||
max_edge_uncertainty: 0.04
|
||||
wall_min_span: 0.65
|
||||
wall_max_rms: 0.006
|
||||
wall_max_residual: 0.02
|
||||
wall_max_gap: 0.15
|
||||
wall_merge_distance: 0.02
|
||||
offset_x: 0.8
|
||||
offset_y: 0.1
|
||||
offset_yaw: 0.2
|
||||
wrong_direction:
|
||||
action_types: [DetectWallWrong]
|
||||
scan_topic: /b_scan2
|
||||
entry_direction: forward
|
||||
default_profile: standard
|
||||
output_frame: wall_reflector_target
|
||||
marker_frame: wall_reflector_frame
|
||||
settle_delay: 0.2
|
||||
timeout: 5.0
|
||||
max_scan_age: 0.3
|
||||
max_future_skew: 0.05
|
||||
pending_tf_timeout: 0.2
|
||||
min_samples: 3
|
||||
sample_window: 1.0
|
||||
profiles:
|
||||
standard:
|
||||
tape_width: 0.05
|
||||
width_tolerance: 0.025
|
||||
tape_spacing: 0.40
|
||||
spacing_tolerance: 0.025
|
||||
tape_min_intensity: 8000.0
|
||||
tape_core_intensity: 15000.0
|
||||
tape_min_points: 3
|
||||
tape_bloom_max_angle: 0.0
|
||||
tape_plateau_min_fraction: 0.5
|
||||
edge_bias_bound: 0.0
|
||||
max_edge_uncertainty: 0.04
|
||||
wall_min_span: 0.65
|
||||
wall_max_rms: 0.006
|
||||
wall_max_residual: 0.02
|
||||
wall_max_gap: 0.15
|
||||
wall_merge_distance: 0.02
|
||||
offset_x: 0.6
|
||||
alternate:
|
||||
tape_width: 0.05
|
||||
width_tolerance: 0.025
|
||||
tape_spacing: 0.40
|
||||
spacing_tolerance: 0.025
|
||||
tape_min_intensity: 8000.0
|
||||
tape_core_intensity: 15000.0
|
||||
tape_min_points: 3
|
||||
tape_bloom_max_angle: 0.0
|
||||
tape_plateau_min_fraction: 0.5
|
||||
edge_bias_bound: 0.0
|
||||
max_edge_uncertainty: 0.04
|
||||
wall_min_span: 0.65
|
||||
wall_max_rms: 0.006
|
||||
wall_max_residual: 0.02
|
||||
wall_max_gap: 0.15
|
||||
wall_merge_distance: 0.02
|
||||
offset_x: 0.8
|
||||
offset_y: 0.1
|
||||
offset_yaw: 0.2
|
||||
WallReflectorDetectionActionHandler:
|
||||
library_path: libwall_reflector_detection_action_handler
|
||||
498
test/wall_reflector_detection_action_test.cpp
Normal file
498
test/wall_reflector_detection_action_test.cpp
Normal file
@@ -0,0 +1,498 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <cmath>
|
||||
#include <cstdlib>
|
||||
#include <limits>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <robot/node_handle.h>
|
||||
#include <tf3/buffer_core.h>
|
||||
#include <action_core/action_registry.h>
|
||||
#include <robot_sensor_ports/sensor_store.h>
|
||||
#include <robot_sensor_ports/sensor_types.h>
|
||||
#include <robot_sensor_msgs/LaserScan.h>
|
||||
#include <yaml-cpp/yaml.h>
|
||||
|
||||
#include "wall_scan_sim.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
using action_core::ActionHandler;
|
||||
using action_core::ActionRegistry;
|
||||
using action_core::ActionStatus;
|
||||
using action_core::ActionTick;
|
||||
constexpr double kPi = 3.14159265358979323846;
|
||||
constexpr const char* kNamespace = "actions_wall";
|
||||
constexpr const char* kTarget = "wall_reflector_target";
|
||||
constexpr const char* kMarker = "wall_reflector_frame";
|
||||
|
||||
robot_protocol_msgs::Action action(const std::string& type, const std::string& profile = "")
|
||||
{
|
||||
robot_protocol_msgs::Action value;
|
||||
value.actionId = "test";
|
||||
value.actionType = type;
|
||||
if (!profile.empty())
|
||||
{
|
||||
robot_protocol_msgs::ActionParameter parameter;
|
||||
parameter.key = "reflector_profile";
|
||||
parameter.value = profile;
|
||||
value.actionParameters.push_back(parameter);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
robot_sensor_msgs::LaserScan makeScan(const char* frame, double stamp,
|
||||
const wall_scan_sim::World& world = {})
|
||||
{
|
||||
const auto geometry = wall_scan_sim::geometry(0.003926990554);
|
||||
const auto synthetic = wall_scan_sim::rayCast(world, geometry);
|
||||
robot_sensor_msgs::LaserScan scan;
|
||||
scan.header.frame_id = frame;
|
||||
scan.header.stamp = robot::Time(stamp);
|
||||
scan.angle_min = static_cast<float>(geometry.angle_min);
|
||||
scan.angle_increment = static_cast<float>(geometry.angle_increment);
|
||||
scan.angle_max = scan.angle_min + (geometry.size - 1) * scan.angle_increment;
|
||||
scan.range_min = 0.05;
|
||||
scan.range_max = 6.0;
|
||||
scan.ranges.assign(synthetic.ranges.begin(), synthetic.ranges.end());
|
||||
scan.intensities = synthetic.intensities;
|
||||
return scan;
|
||||
}
|
||||
|
||||
double yawOf(const tf3::TransformStampedMsg& transform)
|
||||
{
|
||||
const auto& q = transform.transform.rotation;
|
||||
return std::atan2(2.0 * (q.w * q.z + q.x * q.y), 1.0 - 2.0 * (q.y * q.y + q.z * q.z));
|
||||
}
|
||||
|
||||
double angleError(double first, double second)
|
||||
{
|
||||
return std::abs(std::atan2(std::sin(first - second), std::cos(first - second)));
|
||||
}
|
||||
|
||||
class Rig
|
||||
{
|
||||
public:
|
||||
Rig()
|
||||
{
|
||||
robot_sensor_ports::SensorStoreConfig config;
|
||||
for (const char* topic : {"/f_scan", "/b_scan2"})
|
||||
{
|
||||
robot_sensor_ports::SensorEntryConfig sensor;
|
||||
sensor.topic = topic;
|
||||
sensor.data_type = "robot_sensor_msgs/LaserScan";
|
||||
sensor.capacity = 1;
|
||||
sensor.max_age = 0.5;
|
||||
config.sensors.push_back(sensor);
|
||||
}
|
||||
std::string error;
|
||||
store_ok = store.configure(config, error);
|
||||
mount("front_laser", 0.0, 0.0, 0.0);
|
||||
mount("rear_laser", kPi, 0.0, 0.0);
|
||||
mount("flipped_laser", 0.0, kPi, 0.0);
|
||||
mount("tilted_laser", 0.0, 0.0, 0.2);
|
||||
context.tf = &tf;
|
||||
context.sensors = &store;
|
||||
context.global_frame = "map";
|
||||
context.robot_base_frame = "base_link";
|
||||
registry.setContext(context);
|
||||
loaded = registry.loadFromConfig(nh, kNamespace);
|
||||
}
|
||||
|
||||
void mount(const char* child, double yaw, double roll, double pitch)
|
||||
{
|
||||
const double cr = std::cos(roll / 2), sr = std::sin(roll / 2);
|
||||
const double cp = std::cos(pitch / 2), sp = std::sin(pitch / 2);
|
||||
const double cy = std::cos(yaw / 2), sy = std::sin(yaw / 2);
|
||||
tf3::TransformStampedMsg transform;
|
||||
transform.header.frame_id = "base_link";
|
||||
transform.child_frame_id = child;
|
||||
transform.transform.rotation.w = cr * cp * cy + sr * sp * sy;
|
||||
transform.transform.rotation.x = sr * cp * cy - cr * sp * sy;
|
||||
transform.transform.rotation.y = cr * sp * cy + sr * cp * sy;
|
||||
transform.transform.rotation.z = cr * cp * sy - sr * sp * cy;
|
||||
tf.setTransform(transform, "test", true);
|
||||
}
|
||||
|
||||
void robotPose(double stamp, double x = 0.0)
|
||||
{
|
||||
const robot::Time time(stamp);
|
||||
tf3::TransformStampedMsg transform;
|
||||
transform.header.stamp = tf3::Time(time.sec, time.nsec);
|
||||
transform.header.frame_id = "map";
|
||||
transform.child_frame_id = "base_link";
|
||||
transform.transform.translation.x = x;
|
||||
transform.transform.rotation.w = 1.0;
|
||||
tf.setTransform(transform, "test", false);
|
||||
}
|
||||
|
||||
ActionTick feed(ActionHandler* handler, double now, double stamp, const char* frame = "front_laser",
|
||||
const char* topic = "/f_scan", bool add_tf = true,
|
||||
const wall_scan_sim::World& world = {})
|
||||
{
|
||||
if (add_tf)
|
||||
robotPose(stamp);
|
||||
auto scan = makeScan(frame, stamp, world);
|
||||
robot_sensor_ports::put(store, topic, scan, robot::Time(stamp));
|
||||
return handler->update(robot::Time(now));
|
||||
}
|
||||
|
||||
ActionTick happy(ActionHandler* handler, double start = 10.0, const char* frame = "front_laser",
|
||||
const char* topic = "/f_scan")
|
||||
{
|
||||
ActionTick result;
|
||||
for (int index = 0; index < 5; ++index)
|
||||
{
|
||||
const double now = start + 0.3 + index * 0.1;
|
||||
result = feed(handler, now, now, frame, topic);
|
||||
if (result.status != ActionStatus::kRunning)
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
bool hasOutput(const char* frame)
|
||||
{
|
||||
try
|
||||
{
|
||||
tf.lookupTransform("map", frame, tf3::Time());
|
||||
return true;
|
||||
}
|
||||
catch (const std::exception&)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
tf3::TransformStampedMsg output(const char* frame)
|
||||
{
|
||||
return tf.lookupTransform("map", frame, tf3::Time());
|
||||
}
|
||||
|
||||
robot::NodeHandle nh;
|
||||
tf3::BufferCore tf;
|
||||
robot_sensor_ports::SensorStore store;
|
||||
action_core::ActionContext context;
|
||||
ActionRegistry registry;
|
||||
bool store_ok = false;
|
||||
bool loaded = false;
|
||||
};
|
||||
|
||||
TEST(WallReflectorAction, PluginLoadAndForwardTarget)
|
||||
{
|
||||
Rig rig;
|
||||
ASSERT_TRUE(rig.store_ok);
|
||||
ASSERT_TRUE(rig.loaded);
|
||||
auto* handler = rig.registry.find("DetectWallReflectors");
|
||||
ASSERT_NE(handler, nullptr);
|
||||
ASSERT_TRUE(handler->start(action("DetectWallReflectors"), robot::Time(10.0)));
|
||||
const auto result = rig.happy(handler);
|
||||
ASSERT_EQ(result.status, ActionStatus::kSucceeded) << result.message;
|
||||
EXPECT_NE(result.message.find("published"), std::string::npos);
|
||||
const auto marker = rig.output(kMarker);
|
||||
const auto target = rig.output(kTarget);
|
||||
EXPECT_NEAR(marker.transform.translation.x, 1.0, 0.01);
|
||||
EXPECT_NEAR(target.transform.translation.x, 0.4, 0.01);
|
||||
EXPECT_LT(angleError(yawOf(marker), kPi), 0.01);
|
||||
EXPECT_LT(angleError(yawOf(target), 0.0), 0.01);
|
||||
}
|
||||
|
||||
TEST(WallReflectorAction, BackwardTargetAndProfileSelection)
|
||||
{
|
||||
Rig rig;
|
||||
ASSERT_TRUE(rig.loaded);
|
||||
auto* handler = rig.registry.find("DetectWallReflectorsBackward");
|
||||
ASSERT_NE(handler, nullptr);
|
||||
ASSERT_TRUE(handler->start(action("DetectWallReflectorsBackward", "alternate"), robot::Time(10.0)));
|
||||
const auto result = rig.happy(handler, 10.0, "rear_laser", "/b_scan2");
|
||||
ASSERT_EQ(result.status, ActionStatus::kSucceeded) << result.message;
|
||||
const auto marker = rig.output(kMarker);
|
||||
const auto target = rig.output(kTarget);
|
||||
EXPECT_NEAR(marker.transform.translation.x, -1.0, 0.01);
|
||||
EXPECT_NEAR(target.transform.translation.x, -0.2, 0.01);
|
||||
EXPECT_NEAR(target.transform.translation.y, 0.1, 0.01);
|
||||
EXPECT_LT(angleError(yawOf(marker), 0.0), 0.01);
|
||||
EXPECT_LT(angleError(yawOf(target), 0.2), 0.01);
|
||||
}
|
||||
|
||||
TEST(WallReflectorAction, EmptyMarkerFramePublishesTargetOnly)
|
||||
{
|
||||
Rig rig;
|
||||
ASSERT_TRUE(rig.loaded);
|
||||
rig.nh.setParam("actions_wall/forward/marker_frame", "");
|
||||
ActionRegistry target_only;
|
||||
target_only.setContext(rig.context);
|
||||
ASSERT_TRUE(target_only.loadFromConfig(rig.nh, kNamespace));
|
||||
rig.nh.setParam("actions_wall/forward/marker_frame", kMarker);
|
||||
auto* handler = target_only.find("DetectWallReflectors");
|
||||
ASSERT_NE(handler, nullptr);
|
||||
ASSERT_TRUE(handler->start(action("DetectWallReflectors"), robot::Time(10.0)));
|
||||
const auto result = rig.happy(handler);
|
||||
ASSERT_EQ(result.status, ActionStatus::kSucceeded) << result.message;
|
||||
EXPECT_TRUE(rig.hasOutput(kTarget));
|
||||
EXPECT_FALSE(rig.hasOutput(kMarker));
|
||||
}
|
||||
|
||||
TEST(WallReflectorAction, UnknownProfileFailsStartWithReason)
|
||||
{
|
||||
Rig rig;
|
||||
ASSERT_TRUE(rig.loaded);
|
||||
auto* handler = rig.registry.find("DetectWallReflectors");
|
||||
ASSERT_NE(handler, nullptr);
|
||||
testing::internal::CaptureStdout();
|
||||
EXPECT_FALSE(handler->start(action("DetectWallReflectors", "missing"), robot::Time(10.0)));
|
||||
EXPECT_NE(testing::internal::GetCapturedStdout().find("unknown profile"), std::string::npos);
|
||||
EXPECT_FALSE(rig.hasOutput(kTarget));
|
||||
}
|
||||
|
||||
TEST(WallReflectorAction, InvalidConfigurationReportsReason)
|
||||
{
|
||||
Rig rig;
|
||||
ASSERT_TRUE(rig.loaded);
|
||||
const std::string root = "actions_wall/forward/";
|
||||
YAML::Node original;
|
||||
ASSERT_TRUE(rig.nh.getParam(root + "profiles/standard", original));
|
||||
YAML::Node missing = YAML::Clone(original);
|
||||
missing.remove("tape_width");
|
||||
rig.nh.setParam(root + "profiles/standard", missing);
|
||||
ActionRegistry invalid_profile;
|
||||
invalid_profile.setContext(rig.context);
|
||||
testing::internal::CaptureStdout();
|
||||
EXPECT_FALSE(invalid_profile.loadFromConfig(rig.nh, kNamespace));
|
||||
EXPECT_NE(testing::internal::GetCapturedStdout().find("tape_width"), std::string::npos);
|
||||
rig.nh.setParam(root + "profiles/standard", original);
|
||||
|
||||
rig.nh.setParam(root + "marker_frame", kTarget);
|
||||
ActionRegistry invalid_frames;
|
||||
invalid_frames.setContext(rig.context);
|
||||
testing::internal::CaptureStdout();
|
||||
EXPECT_FALSE(invalid_frames.loadFromConfig(rig.nh, kNamespace));
|
||||
EXPECT_NE(testing::internal::GetCapturedStdout().find("frame"), std::string::npos);
|
||||
rig.nh.setParam(root + "marker_frame", kMarker);
|
||||
|
||||
rig.nh.setParam(root + "default_profile", "missing");
|
||||
ActionRegistry invalid_default;
|
||||
invalid_default.setContext(rig.context);
|
||||
testing::internal::CaptureStdout();
|
||||
EXPECT_FALSE(invalid_default.loadFromConfig(rig.nh, kNamespace));
|
||||
EXPECT_NE(testing::internal::GetCapturedStdout().find("default_profile"), std::string::npos);
|
||||
rig.nh.setParam(root + "default_profile", "standard");
|
||||
}
|
||||
|
||||
TEST(WallReflectorAction, TfLateUsesScanStampAndRetries)
|
||||
{
|
||||
Rig rig;
|
||||
ASSERT_TRUE(rig.loaded);
|
||||
auto* handler = rig.registry.find("DetectWallReflectors");
|
||||
ASSERT_NE(handler, nullptr);
|
||||
ASSERT_TRUE(handler->start(action("DetectWallReflectors"), robot::Time(10.0)));
|
||||
auto tick = rig.feed(handler, 10.3, 10.3, "front_laser", "/f_scan", false);
|
||||
EXPECT_EQ(tick.status, ActionStatus::kRunning);
|
||||
EXPECT_NE(tick.message.find("TF at scan stamp"), std::string::npos);
|
||||
rig.robotPose(10.3, 0.5);
|
||||
rig.robotPose(10.35, 3.0);
|
||||
tick = handler->update(robot::Time(10.35));
|
||||
EXPECT_EQ(tick.status, ActionStatus::kRunning);
|
||||
rig.robotPose(10.4, 0.5);
|
||||
tick = rig.feed(handler, 10.4, 10.4, "front_laser", "/f_scan", false);
|
||||
EXPECT_EQ(tick.status, ActionStatus::kRunning);
|
||||
rig.robotPose(10.5, 0.5);
|
||||
tick = rig.feed(handler, 10.5, 10.5, "front_laser", "/f_scan", false);
|
||||
ASSERT_EQ(tick.status, ActionStatus::kSucceeded) << tick.message;
|
||||
EXPECT_NEAR(rig.output(kMarker).transform.translation.x, 1.5, 0.01);
|
||||
}
|
||||
|
||||
TEST(WallReflectorAction, NewerPendingReplacesOlderDetection)
|
||||
{
|
||||
Rig rig;
|
||||
ASSERT_TRUE(rig.loaded);
|
||||
auto* handler = rig.registry.find("DetectWallReflectors");
|
||||
ASSERT_NE(handler, nullptr);
|
||||
ASSERT_TRUE(handler->start(action("DetectWallReflectors"), robot::Time(10.0)));
|
||||
EXPECT_EQ(rig.feed(handler, 10.3, 10.3, "front_laser", "/f_scan", false).status,
|
||||
ActionStatus::kRunning);
|
||||
EXPECT_EQ(rig.feed(handler, 10.4, 10.4, "front_laser", "/f_scan", false).status,
|
||||
ActionStatus::kRunning);
|
||||
rig.robotPose(10.3, 2.0);
|
||||
auto tick = handler->update(robot::Time(10.41));
|
||||
EXPECT_EQ(tick.status, ActionStatus::kRunning);
|
||||
EXPECT_FALSE(rig.hasOutput(kTarget));
|
||||
rig.robotPose(10.4, 0.5);
|
||||
tick = handler->update(robot::Time(10.42));
|
||||
EXPECT_EQ(tick.status, ActionStatus::kRunning);
|
||||
rig.robotPose(10.5, 0.5);
|
||||
EXPECT_EQ(rig.feed(handler, 10.5, 10.5, "front_laser", "/f_scan", false).status,
|
||||
ActionStatus::kRunning);
|
||||
rig.robotPose(10.6, 0.5);
|
||||
tick = rig.feed(handler, 10.6, 10.6, "front_laser", "/f_scan", false);
|
||||
ASSERT_EQ(tick.status, ActionStatus::kSucceeded) << tick.message;
|
||||
EXPECT_NEAR(rig.output(kMarker).transform.translation.x, 1.5, 0.01);
|
||||
}
|
||||
|
||||
TEST(WallReflectorAction, BackwardClockJumpClearsFilterAndWaits)
|
||||
{
|
||||
Rig rig;
|
||||
ASSERT_TRUE(rig.loaded);
|
||||
auto* handler = rig.registry.find("DetectWallReflectors");
|
||||
ASSERT_NE(handler, nullptr);
|
||||
ASSERT_TRUE(handler->start(action("DetectWallReflectors"), robot::Time(10.0)));
|
||||
EXPECT_EQ(rig.feed(handler, 10.3, 10.3).status, ActionStatus::kRunning);
|
||||
EXPECT_EQ(rig.feed(handler, 10.4, 10.4).status, ActionStatus::kRunning);
|
||||
const auto tick = handler->update(robot::Time(9.0));
|
||||
EXPECT_EQ(tick.status, ActionStatus::kRunning);
|
||||
EXPECT_NE(tick.message.find("clock moved backwards"), std::string::npos);
|
||||
EXPECT_FALSE(rig.hasOutput(kTarget));
|
||||
}
|
||||
|
||||
TEST(WallReflectorAction, TfNeverArrivesPendingExpiresAndTimeoutExplains)
|
||||
{
|
||||
Rig rig;
|
||||
ASSERT_TRUE(rig.loaded);
|
||||
auto* handler = rig.registry.find("DetectWallReflectors");
|
||||
ASSERT_NE(handler, nullptr);
|
||||
ASSERT_TRUE(handler->start(action("DetectWallReflectors"), robot::Time(10.0)));
|
||||
EXPECT_EQ(rig.feed(handler, 10.3, 10.3, "front_laser", "/f_scan", false).status,
|
||||
ActionStatus::kRunning);
|
||||
const auto expired = handler->update(robot::Time(10.6));
|
||||
EXPECT_NE(expired.message.find("pending TF expired"), std::string::npos);
|
||||
const auto result = handler->update(robot::Time(15.1));
|
||||
EXPECT_EQ(result.status, ActionStatus::kFailed);
|
||||
EXPECT_NE(result.message.find("pending TF expired"), std::string::npos);
|
||||
EXPECT_FALSE(rig.hasOutput(kTarget));
|
||||
}
|
||||
|
||||
TEST(WallReflectorAction, RejectsOldFutureRepeatedAndStaleScans)
|
||||
{
|
||||
Rig rig;
|
||||
ASSERT_TRUE(rig.loaded);
|
||||
auto* handler = rig.registry.find("DetectWallReflectors");
|
||||
ASSERT_NE(handler, nullptr);
|
||||
ASSERT_TRUE(handler->start(action("DetectWallReflectors"), robot::Time(10.0)));
|
||||
auto tick = rig.feed(handler, 10.3, 9.9);
|
||||
EXPECT_NE(tick.message.find("before settle"), std::string::npos);
|
||||
tick = rig.feed(handler, 10.31, 10.5);
|
||||
EXPECT_NE(tick.message.find("future"), std::string::npos);
|
||||
tick = rig.feed(handler, 10.7, 10.3);
|
||||
EXPECT_NE(tick.message.find("stale"), std::string::npos);
|
||||
tick = rig.feed(handler, 10.8, 10.8);
|
||||
EXPECT_EQ(tick.status, ActionStatus::kRunning);
|
||||
tick = rig.feed(handler, 10.81, 10.8);
|
||||
EXPECT_NE(tick.message.find("repeated"), std::string::npos);
|
||||
for (double now : {10.82, 10.83, 10.84})
|
||||
EXPECT_EQ(handler->update(robot::Time(now)).status, ActionStatus::kRunning);
|
||||
tick = handler->update(robot::Time(11.2));
|
||||
EXPECT_NE(tick.message.find("stale"), std::string::npos);
|
||||
EXPECT_FALSE(rig.hasOutput(kTarget));
|
||||
}
|
||||
|
||||
TEST(WallReflectorAction, UpsideDownLidarDerivedFromTf)
|
||||
{
|
||||
Rig rig;
|
||||
ASSERT_TRUE(rig.loaded);
|
||||
auto* handler = rig.registry.find("DetectWallReflectors");
|
||||
ASSERT_NE(handler, nullptr);
|
||||
ASSERT_TRUE(handler->start(action("DetectWallReflectors"), robot::Time(10.0)));
|
||||
const auto result = rig.happy(handler, 10.0, "flipped_laser");
|
||||
ASSERT_EQ(result.status, ActionStatus::kSucceeded) << result.message;
|
||||
EXPECT_NEAR(rig.output(kTarget).transform.translation.x, 0.4, 0.01);
|
||||
EXPECT_LT(angleError(yawOf(rig.output(kTarget)), 0.0), 0.01);
|
||||
}
|
||||
|
||||
TEST(WallReflectorAction, TiltAndDirectionFailWithReason)
|
||||
{
|
||||
Rig rig;
|
||||
ASSERT_TRUE(rig.loaded);
|
||||
auto* front = rig.registry.find("DetectWallReflectors");
|
||||
ASSERT_NE(front, nullptr);
|
||||
ASSERT_TRUE(front->start(action("DetectWallReflectors"), robot::Time(10.0)));
|
||||
auto tick = rig.feed(front, 10.3, 10.3, "tilted_laser");
|
||||
EXPECT_EQ(tick.status, ActionStatus::kFailed);
|
||||
EXPECT_NE(tick.message.find("tilt"), std::string::npos);
|
||||
auto* wrong = rig.registry.find("DetectWallWrong");
|
||||
ASSERT_NE(wrong, nullptr);
|
||||
ASSERT_TRUE(wrong->start(action("DetectWallWrong"), robot::Time(10.0)));
|
||||
tick = rig.feed(wrong, 10.4, 10.4, "rear_laser", "/b_scan2");
|
||||
EXPECT_EQ(tick.status, ActionStatus::kFailed);
|
||||
EXPECT_NE(tick.message.find("opposite"), std::string::npos);
|
||||
EXPECT_FALSE(rig.hasOutput(kTarget));
|
||||
}
|
||||
|
||||
TEST(WallReflectorAction, AmbiguousSceneNeverSucceeds)
|
||||
{
|
||||
Rig rig;
|
||||
ASSERT_TRUE(rig.loaded);
|
||||
auto* handler = rig.registry.find("DetectWallReflectors");
|
||||
ASSERT_NE(handler, nullptr);
|
||||
ASSERT_TRUE(handler->start(action("DetectWallReflectors"), robot::Time(10.0)));
|
||||
wall_scan_sim::World world;
|
||||
world.tapes = {{-0.4, 0.05}, {0.0, 0.05}, {0.4, 0.05}};
|
||||
auto tick = rig.feed(handler, 10.3, 10.3, "front_laser", "/f_scan", true, world);
|
||||
EXPECT_EQ(tick.status, ActionStatus::kRunning);
|
||||
EXPECT_NE(tick.message.find("ambiguous"), std::string::npos);
|
||||
tick = handler->update(robot::Time(15.1));
|
||||
EXPECT_EQ(tick.status, ActionStatus::kFailed);
|
||||
EXPECT_NE(tick.message.find("ambiguous"), std::string::npos);
|
||||
EXPECT_FALSE(rig.hasOutput(kTarget));
|
||||
}
|
||||
|
||||
TEST(WallReflectorAction, CancelAndPauseResumeDiscardOldSamples)
|
||||
{
|
||||
Rig rig;
|
||||
ASSERT_TRUE(rig.loaded);
|
||||
auto* handler = rig.registry.find("DetectWallReflectors");
|
||||
ASSERT_NE(handler, nullptr);
|
||||
ASSERT_TRUE(handler->start(action("DetectWallReflectors"), robot::Time(10.0)));
|
||||
EXPECT_EQ(rig.feed(handler, 10.3, 10.3).status, ActionStatus::kRunning);
|
||||
handler->cancel();
|
||||
EXPECT_EQ(handler->update(robot::Time(10.4)).status, ActionStatus::kFailed);
|
||||
EXPECT_FALSE(rig.hasOutput(kTarget));
|
||||
|
||||
ASSERT_TRUE(handler->start(action("DetectWallReflectors"), robot::Time(20.0)));
|
||||
EXPECT_EQ(rig.feed(handler, 20.3, 20.3).status, ActionStatus::kRunning);
|
||||
EXPECT_EQ(rig.feed(handler, 20.4, 20.4).status, ActionStatus::kRunning);
|
||||
handler->pause(robot::Time(20.45));
|
||||
handler->resume(robot::Time(21.0));
|
||||
auto tick = rig.feed(handler, 21.1, 21.1);
|
||||
EXPECT_EQ(tick.status, ActionStatus::kRunning);
|
||||
EXPECT_FALSE(rig.hasOutput(kTarget));
|
||||
tick = rig.feed(handler, 21.3, 20.4);
|
||||
EXPECT_NE(tick.message.find("before settle"), std::string::npos);
|
||||
tick = rig.happy(handler, 21.0);
|
||||
ASSERT_EQ(tick.status, ActionStatus::kSucceeded) << tick.message;
|
||||
}
|
||||
|
||||
TEST(WallReflectorAction, FailedSecondRunDoesNotReplacePreviousTf)
|
||||
{
|
||||
Rig rig;
|
||||
ASSERT_TRUE(rig.loaded);
|
||||
auto* handler = rig.registry.find("DetectWallReflectors");
|
||||
ASSERT_NE(handler, nullptr);
|
||||
ASSERT_TRUE(handler->start(action("DetectWallReflectors"), robot::Time(10.0)));
|
||||
ASSERT_EQ(rig.happy(handler).status, ActionStatus::kSucceeded);
|
||||
const auto original = rig.output(kTarget);
|
||||
ASSERT_TRUE(handler->start(action("DetectWallReflectors"), robot::Time(20.0)));
|
||||
wall_scan_sim::World empty;
|
||||
empty.tapes.clear();
|
||||
auto tick = rig.feed(handler, 20.3, 20.3, "front_laser", "/f_scan", true, empty);
|
||||
EXPECT_NE(tick.message.find("insufficient_candidates"), std::string::npos);
|
||||
tick = handler->update(robot::Time(25.1));
|
||||
EXPECT_EQ(tick.status, ActionStatus::kFailed);
|
||||
EXPECT_NE(tick.message.find("insufficient_candidates"), std::string::npos);
|
||||
const auto retained = rig.output(kTarget);
|
||||
EXPECT_DOUBLE_EQ(retained.transform.translation.x, original.transform.translation.x);
|
||||
EXPECT_DOUBLE_EQ(retained.transform.translation.y, original.transform.translation.y);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
#ifdef WALL_REFLECTOR_DETECTION_ACTION_TEST_CONFIG_DIR
|
||||
setenv("PNKX_NAV_CORE_CONFIG_DIR", WALL_REFLECTOR_DETECTION_ACTION_TEST_CONFIG_DIR, 1);
|
||||
#endif
|
||||
#ifdef WALL_REFLECTOR_DETECTION_ACTION_TEST_LIBRARY_DIR
|
||||
setenv("PNKX_NAV_CORE_LIBRARY_PATH", WALL_REFLECTOR_DETECTION_ACTION_TEST_LIBRARY_DIR, 1);
|
||||
#endif
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
Reference in New Issue
Block a user