ed_sensor_integration
test_laser_segmenter.cpp
Go to the documentation of this file.
1 #include <gtest/gtest.h>
2 #include <math.h>
3 #include <iostream>
4 #include <opencv2/highgui/highgui.hpp>
5 
6 // ROS
7 #include <ros/console.h>
8 #include <ros/package.h>
9 
10 // TU/e Robotics
11 #include <ed/entity.h>
12 #include <ed/world_model.h>
13 #include <ed/models/model_loader.h>
14 #include <ed/update_request.h>
15 #include <ed/rendering.h>
16 #include <ed/uuid.h>
18 #include <geolib/Shape.h>
20 #include "tue/config/loaders/sdf.h"
21 
22 // ED sensor integration
23 #include <ed/laser/updater.h>
24 
25 const double MAX_POSITION_ERROR = 0.05;
26 const double MAX_YAW_ERROR_DEGREES = 5.0;
27 
28 void moveFurnitureObject(const ed::UUID& id, const geo::Pose3D& new_pose, ed::WorldModel& wm)
29 {
30  ed::UpdateRequest request;
31  request.setPose(id, new_pose);
32  wm.update(request);
33 }
34 
35 
36 class LaserSegmenterTest : public ::testing::Test {
37 protected:
38  void SetUp() override
39  {
40  ROS_DEBUG_STREAM("Setting up... ");
41  extendPath("ED_MODEL_PATH");
42  extendPath("GAZEBO_MODEL_PATH");
43  extendPath("GAZEBO_RESOURCE_PATH");
44  }
45 
46  void extendPath(const std::string& name)
47  {
48  if (const char* original_path = ::getenv(name.c_str()))
49  original_env_values_[name] = original_path;
50  else
51  original_env_values_[name] = nullptr;
52  std::string package_path = ros::package::getPath("ed_sensor_integration");
53  std::string new_path = package_path + "/test";
54  if (original_env_values_[name])
55  {
56  new_path += ":";
57  new_path += original_env_values_[name];
58  }
59  ROS_INFO_STREAM("New " << name << ": " << new_path);
60  ::setenv(name.c_str(), new_path.c_str(), 1);
61  }
62 
63  void TearDown() override
64  {
65  ROS_DEBUG_STREAM("Tearing down... ");
66  for (auto it = original_env_values_.begin(); it != original_env_values_.end(); it++)
67  {
68  if(it->second)
69  ::setenv(it->first.c_str(), it->second, 1);
70  else
71  ::unsetenv(it->first.c_str());
72  }
73  }
74 
76 };
77 
78 
80 {
81  ROS_INFO_STREAM("Starting testsuite");
82 
83  std::string path = ros::package::getPath("ed_sensor_integration");
84  path += "/test/test_laser_model.sdf";
85 
86  ed::UpdateRequest request;
88 
89  ed::WorldModel world_model;
90  world_model.update(request);
91 
92  // create updater
93  LaserUpdater updater;
94  uint num_beams = 1000;
95  updater.world_association_distance_ = 0.4;
96  updater.min_segment_size_pixels_ = 5;
97  updater.segment_depth_threshold_ = 0.2;
98  updater.min_cluster_size_ = 0.1;
99  updater.max_cluster_size_ = 3.0;
100  updater.fit_entities_ = false;
101  updater.max_gap_size_ = 10;
102  updater.configureLaserModel(num_beams, -2.0, 2.0 , 0.01, 30.0);
103 
104  std::vector<double> sensor_ranges(num_beams, 0);
105  geo::Pose3D test_pose(0.0, 0.0, 0.2, 0.0, 0.0, 0.0);
106 
107  updater.renderWorld(test_pose, world_model, sensor_ranges);
108 
110  double timestamp = 0.0;
111 
112  ed::WorldModel empty_world;
113  updater.update(empty_world, sensor_ranges, test_pose, timestamp, req);
114 
115  int n_entities_found = req.updated_entities.size();
116  EXPECT_EQ(n_entities_found, 3) << "3 entities in world, updater found " << n_entities_found;
117 }
118 
119 
120 int main(int argc, char **argv)
121 {
122  testing::InitGoogleTest(&argc, argv);
123  return RUN_ALL_TESTS();
124 }
LaserSegmenterTest
Definition: test_laser_segmenter.cpp:36
uuid.h
ed::UpdateRequest
std::string
updater.h
update_request.h
LaserUpdater::min_cluster_size_
double min_cluster_size_
Definition: laser/updater.h:88
std::vector< double >
transform_cache.h
LaserUpdater::segment_depth_threshold_
double segment_depth_threshold_
Definition: laser/updater.h:87
LaserUpdater::world_association_distance_
double world_association_distance_
Definition: laser/updater.h:86
LaserUpdater::min_segment_size_pixels_
uint min_segment_size_pixels_
Definition: laser/updater.h:85
Shape.h
LaserSegmenterTest::original_env_values_
std::map< std::string, const char * > original_env_values_
Definition: test_laser_segmenter.cpp:75
geo::Transform3T
LaserSegmenterTest::extendPath
void extendPath(const std::string &name)
Definition: test_laser_segmenter.cpp:46
iostream
ed::WorldModel::update
void update(const UpdateRequest &req)
LaserUpdater::max_cluster_size_
double max_cluster_size_
Definition: laser/updater.h:89
LaserUpdater::configureLaserModel
void configureLaserModel(uint num_beams, double angle_min, double angle_max, double range_min, double range_max)
configure the LRF model based on a laserscan message
Definition: laser/updater.h:56
LaserUpdater::update
void update(const ed::WorldModel &world, std::vector< double > &sensor_ranges, const geo::Pose3D &sensor_pose, const double timestamp, ed::UpdateRequest &req)
update update the worldmodel based on a novel laserscan message.
Definition: laser/updater.cpp:278
LaserSegmenterTest::SetUp
void SetUp() override
Definition: test_laser_segmenter.cpp:38
sdf.h
LaserUpdater::fit_entities_
bool fit_entities_
Definition: laser/updater.h:90
std::string::c_str
T c_str(T... args)
reader_writer.h
ed::UpdateRequest::setPose
void setPose(const UUID &id, const geo::Pose3D &pose)
LaserSegmenterTest::TearDown
void TearDown() override
Definition: test_laser_segmenter.cpp:63
ed::UUID
rendering.h
LaserUpdater::renderWorld
void renderWorld(const geo::Pose3D &sensor_pose, const ed::WorldModel &world, std::vector< double > &model_ranges)
render the worldmodel as would be seen by the lrf.
Definition: laser/updater.cpp:451
req
string req
main
int main(int argc, char **argv)
Definition: test_laser_segmenter.cpp:120
LaserUpdater::max_gap_size_
uint max_gap_size_
Definition: laser/updater.h:91
std::map< std::string, const char * >
ed::WorldModel
world_model.h
std::map::begin
T begin(T... args)
TEST_F
TEST_F(LaserSegmenterTest, testCase)
Definition: test_laser_segmenter.cpp:79
LaserUpdater
Definition: laser/updater.h:17
std::map::end
T end(T... args)
entity.h
moveFurnitureObject
void moveFurnitureObject(const ed::UUID &id, const geo::Pose3D &new_pose, ed::WorldModel &wm)
Definition: test_laser_segmenter.cpp:28
MAX_POSITION_ERROR
const double MAX_POSITION_ERROR
Definition: test_laser_segmenter.cpp:25
ed::models::LoadType::FILE
@ FILE
ed::models::loadModel
bool loadModel(const LoadType load_type, const std::string &source, ed::UpdateRequest &req)
model_loader.h
MAX_YAW_ERROR_DEGREES
const double MAX_YAW_ERROR_DEGREES
Definition: test_laser_segmenter.cpp:26