SingleSceneTest.cpp
Go to the documentation of this file.
1 
20 #define BOOST_TEST_STATIC_LINK
21 
22 #include <boost/test/included/unit_test.hpp>
23 
25 
26 using namespace next_best_view;
27 using namespace boost::unit_test;
28 
29 class SingleSceneTest : public BaseTest {
30 
31 public:
33  }
34 
35  virtual ~SingleSceneTest() {}
36 
37  void iterationTest() {
38  asr_next_best_view::GetAttributedPointCloud gpc;
39  asr_next_best_view::SetAttributedPointCloud apc;
40 
41  ROS_INFO("Generating point cloud");
42 
43  int hpSize = 4;
44  SimpleVector3* hp = new SimpleVector3[hpSize];
45  hp[0] = SimpleVector3(-1.35357105732, 1.06068396568,0.8);
46  hp[1] = SimpleVector3(-1.05733001232, 1.06068396568, 0.8);
47  hp[2] = SimpleVector3(-1.03866374493, 0.772554755211, 0.8);
48  hp[3] = SimpleVector3(-1.35400700569, 0.420550823212, 0.8);
49 
50  SimpleQuaternion* orientation = new SimpleQuaternion[hpSize];
51  orientation[0] = euler2Quaternion(-90, 180.0, 0.0);
52  orientation[1] = euler2Quaternion(-90, 180.0, 0.0);
53  orientation[2] = euler2Quaternion(-90, -90.0, 0.0);
54  orientation[3] = euler2Quaternion(-90, 0.0, 0.0);
55 
56  std::string* types = new std::string[hpSize];
57  types[0] = "Knaeckebrot";
58  types[1] = "VitalisSchoko";
59  types[2] = "Cup";
60  types[3] = "Cup";
61 
62  std::string* ids = new std::string[hpSize];
63  ids[0] = "1";
64  ids[1] = "2";
65  ids[2] = "000100000100";
66  ids[3] = "100000000100";
67 
68  int sampleSize = 1;
69  std::map<std::string, std::vector<asr_msgs::AsrAttributedPoint>* > objectPointCloudsMap;
70 
71  for (std::size_t idx = 0; idx < (std::size_t)hpSize; idx++) {
72 
73  if(objectPointCloudsMap.find(types[idx]) == objectPointCloudsMap.end())
74  {
75  objectPointCloudsMap[types[idx]]= new std::vector<asr_msgs::AsrAttributedPoint>();
76  }
77  for (std::size_t cnt = 0; cnt < (std::size_t)sampleSize; cnt++) {
78  SimpleVector3 randomVector;
79  randomVector = MathHelper::getRandomVector(hp[idx], SimpleVector3(.05, .05, 0.01));
80 
81  asr_msgs::AsrAttributedPoint element;
82 
83  geometry_msgs::Pose pose;
84  pose.orientation.w = orientation[idx].w();
85  pose.orientation.x = orientation[idx].x();
86  pose.orientation.y = orientation[idx].y();
87  pose.orientation.z = orientation[idx].z();
88  pose.position.x = randomVector[0];
89  pose.position.y = randomVector[1];
90  pose.position.z = randomVector[2];
91 
92  element.type = types[idx];
93  element.pose = pose;
94  element.identifier = ids[idx];
95  objectPointCloudsMap[types[idx]]->push_back(element);
96  apc.request.point_cloud.elements.push_back(element);
97  }
98  }
99 
100  ROS_INFO("Setting initial pose");
101  geometry_msgs::Pose initialPose;
102  initialPose.position.x = -0.974955737591;
103  initialPose.position.y = -0.157173499465;
104  initialPose.position.z = 1.32;
105 
106  initialPose.orientation.w = 0.718685498907;
107  initialPose.orientation.x = 0.0;
108  initialPose.orientation.y = 0.0;
109  initialPose.orientation.z = 0.695335281472;
110  this->setInitialPose(initialPose);
111 
112  // Set point cloud
113  mSetPointCloudClient.call(apc.request, apc.response);
114  ros::Rate r(2);
115  asr_next_best_view::GetNextBestView nbv;
116  nbv.request.current_pose = initialPose;
117  bool setPointCloud = false;
118  int x = 1;
119  while(ros::ok()) {
120  if(apc.request.point_cloud.elements.size() == 0)
121  {
122  ROS_ERROR("No elements were found");
123  break;
124  }
125  else if(setPointCloud)
126  {
127  setPointCloud = false;
128  if (!mSetPointCloudClient.call(apc.request, apc.response))
129  {
130  ROS_ERROR("Could not set point cloud");
131  break;
132  }
133  }
134 
135  ROS_INFO_STREAM("Calculating NBV #"<< x);
136  if (!mGetNextBestViewClient.call(nbv.request, nbv.response)) {
137  ROS_ERROR("Something went wrong in next best view");
138  break;
139  }
140 
141  ROS_INFO_STREAM("Name list size " << nbv.response.viewport.object_type_name_list.size());
142 
143  if (nbv.response.viewport.object_type_name_list.size() > 0)
144  {
145  mGetPointCloudClient.call(gpc);
146  apc.request.point_cloud.elements.clear();
147  apc.request.point_cloud.elements.insert(apc.request.point_cloud.elements.end(), gpc.response.point_cloud.elements.begin(), gpc.response.point_cloud.elements.end());
148 
149  for(unsigned int i=0;i<nbv.response.viewport.object_type_name_list.size();i++)
150  {
151  std::vector<asr_msgs::AsrAttributedPoint> temp;
152  ROS_INFO_STREAM("Type: " << nbv.response.viewport.object_type_name_list[i]);
153  for (std::vector<asr_msgs::AsrAttributedPoint>::iterator it = apc.request.point_cloud.elements.begin(); it != apc.request.point_cloud.elements.end(); ++it)
154  {
155 
156  if ((nbv.response.viewport.object_type_name_list[i].compare(it->type)) != 0)
157  {
158  temp.push_back(*it);
159  }
160  }
161  apc.request.point_cloud.elements.clear();
162  apc.request.point_cloud.elements.insert(apc.request.point_cloud.elements.end(), temp.begin(), temp.end());
163  setPointCloud = true;
164  }
165  }
166  else
167  {
168  break;
169  }
170 
171  if (!nbv.response.found) {
172  ROS_ERROR("No NBV found");
173  break;
174  }
175 
176  asr_next_best_view::UpdatePointCloud upc_req;
177  upc_req.request.object_type_name_list = nbv.response.viewport.object_type_name_list;
178  upc_req.request.pose_for_update = nbv.response.viewport.pose;
179 
180  if(!mUpdatePointCloudClient.call(upc_req)) {
181  ROS_ERROR("Update Point Cloud failed!");
182  break;
183  }
184 
185  x++;
186 
187  nbv.request.current_pose = nbv.response.viewport.pose;
188 
189  ros::spinOnce();
190  waitForEnter();
191  ros::Duration(2).sleep();
192  }
193  }
194 };
195 
196 test_suite* init_unit_test_suite( int argc, char* argv[] ) {
197  ros::init(argc, argv, "nbv_test");
198  ros::start();
199 
200  test_suite* evaluation = BOOST_TEST_SUITE("Evaluation NBV");
201 
203 
204  evaluation->add(BOOST_CLASS_TEST_CASE(&SingleSceneTest::iterationTest, testPtr));
205 
206  framework::master_test_suite().add(evaluation);
207 
208  return 0;
209 }
210 
ROSCPP_DECL void start()
Eigen::Matrix< Precision, 3, 1 > SimpleVector3
Definition: typedef.hpp:53
bool sleep() const
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
this namespace contains all generally usable classes.
#define ROS_INFO(...)
ROSCPP_DECL bool ok()
static SimpleVectorX getRandomVector(const SimpleVectorX &mean, const SimpleVectorX &standardDeviation)
Definition: MathHelper.cpp:104
TFSIMD_FORCE_INLINE const tfScalar & x() const
#define ROS_INFO_STREAM(args)
virtual ~SingleSceneTest()
Eigen::Quaternion< Precision > SimpleQuaternion
Definition: typedef.hpp:67
ROSCPP_DECL void spinOnce()
#define ROS_ERROR(...)
test_suite * init_unit_test_suite(int argc, char *argv[])


asr_next_best_view
Author(s): Aumann Florian, Borella Jocelyn, Heller Florian, Meißner Pascal, Schleicher Ralf, Stöckle Patrick, Stroh Daniel, Trautmann Jeremias, Walter Milena, Wittenbeck Valerij
autogenerated on Thu Jan 9 2020 07:20:18