PerformanceTest.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 #include <dynamic_reconfigure/IntParameter.h>
26 #include <chrono>
27 #include <fstream>
28 
29 using namespace asr_next_best_view;
30 using namespace boost::unit_test;
31 using namespace dynamic_reconfigure;
32 
33 class PerformanceTest : public BaseTest {
34 
35 public:
37  }
38 
39  virtual ~PerformanceTest() {}
40 
41  void iterationTest() {
42  ros::NodeHandle nh;
43 
44  // where results are written to
45  std::string testResultPath;
46  nh.getParam("/test/testResultFilePath", testResultPath);
47 
48  // get number of threads per test run from launch file/param
49  std::vector<int> nThreadsPerTestRun;
50  nh.getParam("/test/nThreads", nThreadsPerTestRun);
51 
52  asr_next_best_view::ResetCalculator reca;
53  std::chrono::time_point<std::chrono::system_clock> start, end;
54 
55  double totalTimeNBV, totalTimeUpdate;
56  SimpleVector3* hp = new SimpleVector3[15];
57  hp[0] = SimpleVector3(3.09807621388, 21.7942286312,1.32);
58  hp[1] = SimpleVector3(3.96410161747, 21.2942286309,1.32);
59  hp[2] = SimpleVector3(4.83012702105, 20.7942286305,1.32);
60  hp[3] = SimpleVector3(5.69615242463, 20.2942286302,1.32);
61  hp[4] = SimpleVector3(6.56217782822, 19.7942286298,1.32);
62  hp[5] = SimpleVector3(7.4282032318, 19.2942286295,1.32);
63  hp[6] = SimpleVector3(8.29422863538, 18.7942286291,1.32);
64  hp[7] = SimpleVector3(9.16025403897, 18.2942286288,1.32);
65  hp[8] = SimpleVector3(10.0262794426, 17.7942286284,1.32);
66  hp[9] = SimpleVector3(10.8923048461, 17.2942286281,1.32);
67  hp[10] = SimpleVector3(11.7583302497, 16.7942286277,1.32);
68  hp[11] = SimpleVector3(12.6243556533, 16.2942286274,1.32);
69  hp[12] = SimpleVector3(13.4903810569, 15.794228627,1.32);
70  hp[13] = SimpleVector3(14.3564064605, 15.2942286267,1.32);
71  hp[14] = SimpleVector3(15.2224318641, 14.7942286267,1.32);
72 
73  for (unsigned int i = 0; i < nThreadsPerTestRun.size(); i++) {
74  // run whole test with nThreads
75  int nThreads = nThreadsPerTestRun[i];
76 
77  // file where results are written to
78  std::string fileName = testResultPath + "_" + std::to_string(nThreads) + "_threads.csv";
79  std::ofstream file(fileName, std::ios::out | std::ios::trunc);
80  file << "HP,SampleSize,TotalNBV,AvgNBV,TotalUpd,AvgUpd" << std::endl;
81  ROS_INFO_STREAM("Writing to " << testResultPath);
82 
83  // change nThreads used to rate using dynParams
84  Reconfigure reconf;
85  IntParameter nThreadsParam;
86  nThreadsParam.name = "nRatingThreads";
87  nThreadsParam.value = nThreads;
88  reconf.request.config.ints.clear();
89  reconf.request.config.ints.push_back(nThreadsParam);
90  mDynParametersClient.call(reconf.request, reconf.response);
91  ROS_INFO_STREAM("nThreads set to " << nThreads);
92 
93 
94  ROS_INFO("Generating clusters");
95  // clusters
96  for(unsigned int sampleSize = 50; sampleSize<=400; sampleSize+=50)
97  {
98 
99  for(unsigned int hpSize = 1; hpSize <= 15; hpSize++)
100  {
101  int countNBV = 0;
102  int countUpdate = 0;
103  totalTimeNBV = 0;
104  totalTimeUpdate = 0;
105  SetAttributedPointCloud apc;
106 
107  SimpleQuaternion* orientation = new SimpleQuaternion[hpSize];
108  for(unsigned int i=0; i<hpSize; i++){ orientation[i] = euler2Quaternion(-90, 100.0, 0.0);}
109 
110  std::string* types = new std::string[hpSize];
111  for(unsigned int i=0; i<hpSize; i++){types[i] = "Smacks";}
112 
113 
114  std::map<std::string, std::vector<asr_msgs::AsrAttributedPoint>* > objectPointCloudsMap;
115 
116  for (std::size_t idx = 0; idx < hpSize; idx++) {
117 
118  if(objectPointCloudsMap.find(types[idx]) == objectPointCloudsMap.end())
119  {
120  objectPointCloudsMap[types[idx]]= new std::vector<asr_msgs::AsrAttributedPoint>();
121  }
122  for (std::size_t cnt = 0; cnt < sampleSize; cnt++)
123  {
124  SimpleVector3 randomVector;
125  randomVector = MathHelper::getRandomVector(hp[idx], SimpleVector3(.1, .1, 0.01));
126 
127  asr_msgs::AsrAttributedPoint element;
128 
129  geometry_msgs::Pose pose;
130  pose.orientation.w = orientation[idx].w();
131  pose.orientation.x = orientation[idx].x();
132  pose.orientation.y = orientation[idx].y();
133  pose.orientation.z = orientation[idx].z();
134  pose.position.x = randomVector[0];
135  pose.position.y = randomVector[1];
136  pose.position.z = randomVector[2];
137 
138  element.type = types[idx];
139  element.pose = pose;
140  objectPointCloudsMap[types[idx]]->push_back(element);
141  apc.request.point_cloud.elements.push_back(element);
142  }
143  }
144  std::cout << "point cloud size " << apc.request.point_cloud.elements.size() << std::endl;
145 
146 
147  // reset calculator before each test
148  mResetCalculatorClient.call(reca.request, reca.response);
149 
150  ROS_INFO("set initial pose");
151  geometry_msgs::Pose initialPose;
152  initialPose.position.x = 1.64;
153  initialPose.position.y = 22.73;
154  initialPose.position.z = 1.32;
155 
156  initialPose.orientation.w = 0.964072111801;
157  initialPose.orientation.x = 0.0;
158  initialPose.orientation.y = 0.0;
159  initialPose.orientation.z = -0.265640665651;
160  this->setInitialPose(initialPose);
161 
162  //ros::Duration(5).sleep();
163  // Set point cloud
164  if (!mSetPointCloudClient.call(apc.request, apc.response))
165  {
166  ROS_ERROR("Could not set initial point cloud");
167  }
168  ros::Rate r(2);
169  asr_next_best_view::GetNextBestView nbv;
170  nbv.request.current_pose = initialPose;
171  //ViewportPointCloudPtr viewportPointCloudPtr(new ViewportPointCloud());
172  bool setPointCloud = false;
173  int x = 1;
174  std::cout << "Cluster : " << hpSize << ", SamplingSize " << sampleSize << std::endl;
175  while(ros::ok()) {
176  if(apc.request.point_cloud.elements.size() == 0)
177  {
178  ROS_ERROR("No elements were found");
179  break;
180  }
181  else if(setPointCloud)
182  {
183  setPointCloud = false;
184  if (!mSetPointCloudClient.call(apc.request, apc.response))
185  {
186  ROS_ERROR("Could not set point cloud");
187  break;
188  }
189  }
190 
191  ROS_INFO_STREAM("Calculating NBV #"<< x);
192  start = std::chrono::system_clock::now();
193  if (!mGetNextBestViewClient.call(nbv.request, nbv.response)) {
194  ROS_ERROR("Something went wrong in next best view");
195  break;
196  }
197  end = std::chrono::system_clock::now();
198  countNBV ++;
199  std::chrono::duration<double> elapsed_seconds = end-start;
200  totalTimeNBV += elapsed_seconds.count();
201 
202  if (!nbv.response.found) {
203  ROS_ERROR("No NBV found");
204  break;
205  }
206 
207  asr_next_best_view::UpdatePointCloud upc_req;
208  upc_req.request.object_type_name_list = nbv.response.viewport.object_type_name_list;
209  upc_req.request.pose_for_update = nbv.response.viewport.pose;
210 
211  start = std::chrono::system_clock::now();
212  if(!mUpdatePointCloudClient.call(upc_req)) {
213  ROS_ERROR("Update Point Cloud failed!");
214  break;
215  }
216  end = std::chrono::system_clock::now();
217  countUpdate++;
218  elapsed_seconds = end-start;
219  totalTimeUpdate += elapsed_seconds.count();
220  x++;
221  if (x > 10)
222  {
223  break;
224  }
225 
226  nbv.request.current_pose = nbv.response.viewport.pose;
227  ros::spinOnce();
228  ros::Duration(0.5).sleep();
229  }
230  file << hpSize << "," << sampleSize << ",";
231  if (countNBV > 0)
232  {
233  file << totalTimeNBV << "," << totalTimeNBV /(double)countNBV << ",";
234  std::cout << "Total time NBV : " << totalTimeNBV << std::endl;
235  std::cout << "Average time NBV : " << totalTimeNBV /(double)countNBV << std::endl;
236  }
237  else
238  {
239  file << "0,0,";
240  }
241  if (countUpdate > 0)
242  {
243  file << totalTimeUpdate << "," << totalTimeUpdate / (double)countUpdate << std::endl;
244  std::cout << "Total time update : " << totalTimeUpdate << std::endl;
245  std::cout << "Average time update : " << totalTimeUpdate / (double)countUpdate << std::endl;
246  }
247  else
248  {
249  file << "0,0" << std::endl;
250  }
251  std::cout << "Iteration count : " << countNBV << " / " << countUpdate << std::endl;
252  }
253  }
254  file.close();
255  }
256  }
257 };
258 
259 test_suite* init_unit_test_suite( int argc, char* argv[] ) {
260  ros::init(argc, argv, "nbv_test");
261  ros::start();
262 
263  test_suite* evaluation = BOOST_TEST_SUITE("Evaluation NBV");
264 
266 
267  evaluation->add(BOOST_CLASS_TEST_CASE(&PerformanceTest::iterationTest, testPtr));
268 
269  framework::master_test_suite().add(evaluation);
270 
271  return 0;
272 }
273 
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)
virtual ~PerformanceTest()
test_suite * init_unit_test_suite(int argc, char *argv[])
#define ROS_INFO(...)
ROSCPP_DECL bool ok()
TFSIMD_FORCE_INLINE const tfScalar & x() const
#define ROS_INFO_STREAM(args)
bool getParam(const std::string &key, std::string &s) const
Eigen::Quaternion< Precision > SimpleQuaternion
Definition: typedef.hpp:67
ROSCPP_DECL void spinOnce()
#define ROS_ERROR(...)


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