RateViewportsTest.cpp
Go to the documentation of this file.
1 
20 #define BOOST_TEST_STATIC_LINK
21 
22 #include <boost/test/included/unit_test.hpp>
24 #include "asr_next_best_view/GetAttributedPointCloud.h"
25 #include "asr_next_best_view/RateViewports.h"
26 #include "asr_next_best_view/RatedViewport.h"
27 
28 using namespace asr_next_best_view;
29 using namespace boost::unit_test;
30 
31 class RateViewportsTest : public BaseTest {
32 public:
33  RateViewportsTest(bool silent) : BaseTest (true, silent) { }
34 
35  virtual ~RateViewportsTest() {}
36 
37  geometry_msgs::Pose setup() {
38  ROS_INFO("Generate clusters");
39  // number of clusters
40  int nHp = 2;
41  SimpleVector3* location = new SimpleVector3[nHp];
42  location[0] = SimpleVector3(-0.43232, 0.6958, 0.7211);
43  location[1] = SimpleVector3(-0.283309, 0.710407, 0.718543);
44 
45  SimpleQuaternion* orientation = new SimpleQuaternion[nHp];
46  orientation[0] = euler2Quaternion(-90, 0.0, 0.0);
47  orientation[1] = euler2Quaternion(-90, 0.0, 0.0);
48 
49  std::string* types = new std::string[nHp];
50  types[0] = "Smacks";
51  types[1] = "PlateDeep";
52 
53  int elementsPerHp[2] = { 3, 1 };
54 
55  SetAttributedPointCloud apc;
56  for (std::size_t idx = 0; idx < (std::size_t)nHp; idx++) {
57  for (std::size_t cnt = 0; cnt < (std::size_t)elementsPerHp[idx]; cnt++) {
58  SimpleVector3 curLocation = location[idx];
59 
60  asr_msgs::AsrAttributedPoint element;
61 
62  geometry_msgs::Pose pose;
63  pose.orientation.w = orientation[idx].w();
64  pose.orientation.x = orientation[idx].x();
65  pose.orientation.y = orientation[idx].y();
66  pose.orientation.z = orientation[idx].z();
67  pose.position.x = curLocation[0] - 0.1 * cnt; // put smacks in row next to each other
68  pose.position.y = curLocation[1];
69  pose.position.z = curLocation[2];
70 
71  element.type = types[idx];
72  element.identifier = std::to_string(idx);
73  element.pose = pose;
74  apc.request.point_cloud.elements.push_back(element);
75  }
76  }
77 
78  ROS_INFO("Setting initial pose");
79  geometry_msgs::Pose initialPose;
80  initialPose.position.x = -0.383223;
81  initialPose.position.y = 0.157997;
82  initialPose.position.z = 1.32;
83  initialPose.orientation.x = -0.17266;
84  initialPose.orientation.y = 0.2115588;
85  initialPose.orientation.z = 0.60825979;
86  initialPose.orientation.w = 0.74528563;
87  this->setInitialPose(initialPose);
88 
89  // set PointCloud
90  if (!mSetPointCloudClient.call(apc.request, apc.response)) {
91  ROS_ERROR("Could not set initial point cloud.");
92  }
93 
94  asr_next_best_view::GetAttributedPointCloud gpc;
95  if (!mGetPointCloudClient.call(gpc)) {
96  ROS_ERROR("Could not get initial point cloud.");
97  }
98  return initialPose;
99  }
100 
101  void test() {
102  geometry_msgs::Pose initialPose = setup();
103 
104  ros::ServiceClient rateViewportsClient;
105  ros::service::waitForService("/nbv/rate_viewports", -1);
106  rateViewportsClient = mNodeHandle->serviceClient<asr_next_best_view::RateViewports>("/nbv/rate_viewports");
107 
108  // get nbv
109  asr_next_best_view::GetNextBestView nbv;
110  if (!mGetNextBestViewClient.call(nbv.request, nbv.response)) {
111  ROS_ERROR("Something went wrong in next best view");
112  return;
113  }
114 
115  asr_next_best_view::RateViewports rateViewports;
116  std::vector<std::string> requestObjectTypes = { "Smacks" };
117  rateViewports.request.object_type_name_list = requestObjectTypes;
118  rateViewports.request.current_pose = initialPose;
119  rateViewports.request.viewports.push_back(nbv.response.viewport.pose);
120 
121  if (!rateViewportsClient.call(rateViewports.request, rateViewports.response)) {
122  ROS_ERROR("Something went wrong in rate viewports");
123  return;
124  }
125  asr_next_best_view::RatedViewport ratedViewport = rateViewports.response.sortedRatedViewports[0];
126  ROS_INFO_STREAM("nbv: " << nbv.response);
127  ROS_INFO_STREAM("ratedView: " << ratedViewport);
128  BOOST_CHECK_MESSAGE(rateViewports.request.viewports.size() == rateViewports.response.sortedRatedViewports.size(), "ratedViewports should be equal");
129  BOOST_CHECK_MESSAGE(ratedViewport.object_type_name_list.size() == requestObjectTypes.size(), "object_type_name_list was modified");
130 
131  // generate multiple poses in a + shape around nbv
132  double variation = 0.1;
133  rateViewports = RateViewports();
134  geometry_msgs::Pose variationPose = nbv.response.viewport.pose;
135  variationPose.position.x += variation;
136  rateViewports.request.viewports.push_back(variationPose);
137 
138  variationPose = nbv.response.viewport.pose;
139  variationPose.position.x -= variation;
140  rateViewports.request.viewports.push_back(variationPose);
141 
142  variationPose = nbv.response.viewport.pose;
143  variationPose.position.y += variation;
144  rateViewports.request.viewports.push_back(variationPose);
145 
146  variationPose = nbv.response.viewport.pose;
147  variationPose.position.y -= variation;
148  rateViewports.request.viewports.push_back(variationPose);
149 
150  variationPose = nbv.response.viewport.pose;
151  variationPose.position.x += 2.0 * variation;
152  rateViewports.request.viewports.push_back(variationPose);
153 
154  variationPose = nbv.response.viewport.pose;
155  variationPose.position.x -= 2.0 * variation;
156  rateViewports.request.viewports.push_back(variationPose);
157 
158  variationPose = nbv.response.viewport.pose;
159  variationPose.position.y += 2.0 * variation;
160  rateViewports.request.viewports.push_back(variationPose);
161 
162  variationPose = nbv.response.viewport.pose;
163  variationPose.position.y -= 2.0 * variation;
164  rateViewports.request.viewports.push_back(variationPose);
165 
166  requestObjectTypes = {"Smacks"};
167  rateViewports.request.object_type_name_list = requestObjectTypes;
168 
169  if (!rateViewportsClient.call(rateViewports.request, rateViewports.response)) {
170  ROS_ERROR("Something went wrong in rate viewports");
171  return;
172  }
173 
174  ratedViewport = rateViewports.response.sortedRatedViewports[0];
175  BOOST_CHECK_MESSAGE(rateViewports.request.viewports.size() == rateViewports.response.sortedRatedViewports.size(), "ratedViewports should be equal");
176  BOOST_CHECK_MESSAGE(ratedViewport.object_type_name_list.size() == requestObjectTypes.size(), "object_type_name_list was modified");
177 
178  ROS_INFO_STREAM("rated viewports:");
179  for (asr_next_best_view::RatedViewport viewport : rateViewports.response.sortedRatedViewports) {
180  ROS_INFO_STREAM(viewport);
181  }
182 
183  // empty object_type_name_list
184  rateViewports = RateViewports();
185  variationPose = nbv.response.viewport.pose;
186  variationPose.position.x += variation;
187  rateViewports.request.viewports.push_back(variationPose);
188 
189  requestObjectTypes = {};
190  rateViewports.request.object_type_name_list = requestObjectTypes;
191 
192  if (!rateViewportsClient.call(rateViewports.request, rateViewports.response)) {
193  ROS_ERROR("Something went wrong in rate viewports");
194  return;
195  }
196 
197  // empty viewports
198  rateViewports = RateViewports();
199 
200  if (!rateViewportsClient.call(rateViewports.request, rateViewports.response)) {
201  ROS_ERROR("Something went wrong in rate viewports");
202  return;
203  }
204  }
205 };
206 
207 test_suite* init_unit_test_suite(int argc, char* argv[]) {
208  ros::init(argc, argv, "nbv_test");
209  ros::start();
210 
211  test_suite* evaluation = BOOST_TEST_SUITE("Evaluation NBV");
212 
213  bool silent = false;
214  if (argc >= 2) {
215  // caseinsensitive comparison
216  if (boost::iequals(argv[1], "silent") || boost::iequals(argv[1], "s")) {
217  silent = true;
218  }
219  }
221 
222  evaluation->add(BOOST_CLASS_TEST_CASE(&RateViewportsTest::test, testPtr));
223 
224  framework::master_test_suite().add(evaluation);
225 
226  return 0;
227 }
228 
229 
230 
231 
ROSCPP_DECL void start()
geometry_msgs::Pose setup()
Eigen::Matrix< Precision, 3, 1 > SimpleVector3
Definition: typedef.hpp:53
test_suite * init_unit_test_suite(int argc, char *argv[])
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
bool call(MReq &req, MRes &res)
#define ROS_INFO(...)
#define ROS_INFO_STREAM(args)
Eigen::Quaternion< Precision > SimpleQuaternion
Definition: typedef.hpp:67
#define ROS_ERROR(...)
ROSCPP_DECL bool waitForService(const std::string &service_name, int32_t timeout)
RateViewportsTest(bool silent)


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