20 #define BOOST_TEST_STATIC_LINK 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" 46 orientation[0] = euler2Quaternion(-90, 0.0, 0.0);
47 orientation[1] = euler2Quaternion(-90, 0.0, 0.0);
49 std::string* types =
new std::string[nHp];
51 types[1] =
"PlateDeep";
53 int elementsPerHp[2] = { 3, 1 };
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++) {
60 asr_msgs::AsrAttributedPoint element;
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;
68 pose.position.y = curLocation[1];
69 pose.position.z = curLocation[2];
71 element.type = types[idx];
72 element.identifier = std::to_string(idx);
74 apc.request.point_cloud.elements.push_back(element);
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);
90 if (!mSetPointCloudClient.call(apc.request, apc.response)) {
91 ROS_ERROR(
"Could not set initial point cloud.");
94 asr_next_best_view::GetAttributedPointCloud gpc;
95 if (!mGetPointCloudClient.call(gpc)) {
96 ROS_ERROR(
"Could not get initial point cloud.");
102 geometry_msgs::Pose initialPose =
setup();
106 rateViewportsClient = mNodeHandle->serviceClient<asr_next_best_view::RateViewports>(
"/nbv/rate_viewports");
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");
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);
121 if (!rateViewportsClient.
call(rateViewports.request, rateViewports.response)) {
122 ROS_ERROR(
"Something went wrong in rate viewports");
125 asr_next_best_view::RatedViewport ratedViewport = rateViewports.response.sortedRatedViewports[0];
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");
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);
138 variationPose = nbv.response.viewport.pose;
139 variationPose.position.x -= variation;
140 rateViewports.request.viewports.push_back(variationPose);
142 variationPose = nbv.response.viewport.pose;
143 variationPose.position.y += variation;
144 rateViewports.request.viewports.push_back(variationPose);
146 variationPose = nbv.response.viewport.pose;
147 variationPose.position.y -= variation;
148 rateViewports.request.viewports.push_back(variationPose);
150 variationPose = nbv.response.viewport.pose;
151 variationPose.position.x += 2.0 * variation;
152 rateViewports.request.viewports.push_back(variationPose);
154 variationPose = nbv.response.viewport.pose;
155 variationPose.position.x -= 2.0 * variation;
156 rateViewports.request.viewports.push_back(variationPose);
158 variationPose = nbv.response.viewport.pose;
159 variationPose.position.y += 2.0 * variation;
160 rateViewports.request.viewports.push_back(variationPose);
162 variationPose = nbv.response.viewport.pose;
163 variationPose.position.y -= 2.0 * variation;
164 rateViewports.request.viewports.push_back(variationPose);
166 requestObjectTypes = {
"Smacks"};
167 rateViewports.request.object_type_name_list = requestObjectTypes;
169 if (!rateViewportsClient.
call(rateViewports.request, rateViewports.response)) {
170 ROS_ERROR(
"Something went wrong in rate viewports");
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");
179 for (asr_next_best_view::RatedViewport viewport : rateViewports.response.sortedRatedViewports) {
180 ROS_INFO_STREAM(viewport);
184 rateViewports = RateViewports();
185 variationPose = nbv.response.viewport.pose;
186 variationPose.position.x += variation;
187 rateViewports.request.viewports.push_back(variationPose);
189 requestObjectTypes = {};
190 rateViewports.request.object_type_name_list = requestObjectTypes;
192 if (!rateViewportsClient.
call(rateViewports.request, rateViewports.response)) {
193 ROS_ERROR(
"Something went wrong in rate viewports");
198 rateViewports = RateViewports();
200 if (!rateViewportsClient.
call(rateViewports.request, rateViewports.response)) {
201 ROS_ERROR(
"Something went wrong in rate viewports");
211 test_suite* evaluation = BOOST_TEST_SUITE(
"Evaluation NBV");
216 if (boost::iequals(argv[1],
"silent") || boost::iequals(argv[1],
"s")) {
224 framework::master_test_suite().add(evaluation);
geometry_msgs::Pose setup()
Eigen::Matrix< Precision, 3, 1 > SimpleVector3
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)
virtual ~RateViewportsTest()
#define ROS_INFO_STREAM(args)
Eigen::Quaternion< Precision > SimpleQuaternion
ROSCPP_DECL bool waitForService(const std::string &service_name, int32_t timeout)
RateViewportsTest(bool silent)