20 #define BOOST_TEST_STATIC_LINK 22 #include <boost/test/included/unit_test.hpp> 25 #include <dynamic_reconfigure/IntParameter.h> 45 std::string testResultPath;
46 nh.
getParam(
"/test/testResultFilePath", testResultPath);
49 std::vector<int> nThreadsPerTestRun;
50 nh.
getParam(
"/test/nThreads", nThreadsPerTestRun);
52 asr_next_best_view::ResetCalculator reca;
53 std::chrono::time_point<std::chrono::system_clock> start, end;
55 double totalTimeNBV, totalTimeUpdate;
73 for (
unsigned int i = 0; i < nThreadsPerTestRun.size(); i++) {
75 int nThreads = nThreadsPerTestRun[i];
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;
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);
96 for(
unsigned int sampleSize = 50; sampleSize<=400; sampleSize+=50)
99 for(
unsigned int hpSize = 1; hpSize <= 15; hpSize++)
105 SetAttributedPointCloud apc;
108 for(
unsigned int i=0; i<hpSize; i++){ orientation[i] = euler2Quaternion(-90, 100.0, 0.0);}
110 std::string* types =
new std::string[hpSize];
111 for(
unsigned int i=0; i<hpSize; i++){types[i] =
"Smacks";}
114 std::map<std::string, std::vector<asr_msgs::AsrAttributedPoint>* > objectPointCloudsMap;
116 for (std::size_t idx = 0; idx < hpSize; idx++) {
118 if(objectPointCloudsMap.find(types[idx]) == objectPointCloudsMap.end())
120 objectPointCloudsMap[types[idx]]=
new std::vector<asr_msgs::AsrAttributedPoint>();
122 for (std::size_t cnt = 0; cnt < sampleSize; cnt++)
125 randomVector = MathHelper::getRandomVector(hp[idx],
SimpleVector3(.1, .1, 0.01));
127 asr_msgs::AsrAttributedPoint element;
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];
138 element.type = types[idx];
140 objectPointCloudsMap[types[idx]]->push_back(element);
141 apc.request.point_cloud.elements.push_back(element);
144 std::cout <<
"point cloud size " << apc.request.point_cloud.elements.size() << std::endl;
148 mResetCalculatorClient.call(reca.request, reca.response);
151 geometry_msgs::Pose initialPose;
152 initialPose.position.x = 1.64;
153 initialPose.position.y = 22.73;
154 initialPose.position.z = 1.32;
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);
164 if (!mSetPointCloudClient.call(apc.request, apc.response))
166 ROS_ERROR(
"Could not set initial point cloud");
169 asr_next_best_view::GetNextBestView nbv;
170 nbv.request.current_pose = initialPose;
172 bool setPointCloud =
false;
174 std::cout <<
"Cluster : " << hpSize <<
", SamplingSize " << sampleSize << std::endl;
176 if(apc.request.point_cloud.elements.size() == 0)
181 else if(setPointCloud)
183 setPointCloud =
false;
184 if (!mSetPointCloudClient.call(apc.request, apc.response))
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");
197 end = std::chrono::system_clock::now();
199 std::chrono::duration<double> elapsed_seconds = end-start;
200 totalTimeNBV += elapsed_seconds.count();
202 if (!nbv.response.found) {
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;
211 start = std::chrono::system_clock::now();
212 if(!mUpdatePointCloudClient.call(upc_req)) {
216 end = std::chrono::system_clock::now();
218 elapsed_seconds = end-start;
219 totalTimeUpdate += elapsed_seconds.count();
226 nbv.request.current_pose = nbv.response.viewport.pose;
230 file << hpSize <<
"," << sampleSize <<
",";
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;
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;
249 file <<
"0,0" << std::endl;
251 std::cout <<
"Iteration count : " << countNBV <<
" / " << countUpdate << std::endl;
263 test_suite* evaluation = BOOST_TEST_SUITE(
"Evaluation NBV");
269 framework::master_test_suite().add(evaluation);
Eigen::Matrix< Precision, 3, 1 > SimpleVector3
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
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
ROSCPP_DECL void spinOnce()