pose_helper_test.cpp
Go to the documentation of this file.
1 
18 #include "gtest/gtest.h"
19 #include "ros/ros.h"
20 #include "helper/pose_helper.hpp"
21 
22 #include <math.h>
23 #include <boost/shared_ptr.hpp>
24 #include <boost/thread/thread.hpp>
25 #include <boost/date_time/posix_time/posix_time.hpp>
26 #include <eigen3/Eigen/Geometry>
27 
28 #include "asr_robot_model_services/GetDistance.h"
29 
30 #define EPSILON 0.001
31 
32 using namespace directSearchWS;
33 
34 class PoseHelperSetup: public ::testing::Test {
35 
36 public:
37 
39  boost::thread t;
40 
41  PoseHelperSetup() : n(ros::this_node::getName()) {
42  }
43 
44  void SetUp() {
45  n.setParam("distanceFunc", 2);
46  n.setParam("/nbv/ncp", 0.4);
47  n.setParam("/nbv/fcp", 1.5);
48  n.setParam("viewCenterPositionDistanceThreshold", 0.17);
49  n.setParam("/nbv/mHypothesisUpdaterAngleThreshold", 45.0);
50 
52  }
53 
54  void TearDown() {
55  }
56 
58  }
59 };
60 
61 
62 TEST_F(PoseHelperSetup, CalcDistPositionEucl) {
63  n.setParam("distanceFunc", 2);
65  PoseHelperPtr poseHelperPtr = PoseHelper::getInstance();
66 
67  geometry_msgs::Pose pose1;
68  geometry_msgs::Pose pose2;
69 
70  EXPECT_DOUBLE_EQ(0.0, poseHelperPtr->calculateDistance(pose1, pose2));
71 
72  // orientation should not change anything
73  pose1.orientation.x = 0.444;
74  pose2.orientation.w = -0.666;
75 
76  EXPECT_DOUBLE_EQ(0.0, poseHelperPtr->calculateDistance(pose1, pose2));
77 
78  pose2.position.x = 13.33;
79  pose2.position.y = -14.55;
80 
81  EXPECT_NEAR(19.733, poseHelperPtr->calculateDistance(pose1, pose2), EPSILON);
82 
83  pose1.position.x = -13.33;
84  pose1.position.y = -14.55;
85 
86  EXPECT_DOUBLE_EQ(26.66, poseHelperPtr->calculateDistance(pose1, pose2));
87 }
88 
89 TEST_F(PoseHelperSetup, CalcAngularDistanceInRad) {
90  PoseHelperPtr poseHelperPtr = PoseHelper::getInstance();
91 
92  geometry_msgs::Pose pose1;
93  pose1.orientation.w = 1.0;
94  geometry_msgs::Pose pose2;
95  pose2.orientation.w = 1.0;
96  EXPECT_NEAR(0.0, poseHelperPtr->calcAngularDistanceInRad(pose1, pose2), EPSILON);
97 
98  // position should not change anything
99  pose1.position.x = 13.33;
100  pose2.position.y = -14.55;
101  EXPECT_NEAR(0.0, poseHelperPtr->calcAngularDistanceInRad(pose1, pose2), EPSILON);
102 
103  // rotate x: 180°
104  pose2.orientation.w = 0.0;
105  pose2.orientation.x = 1.0;
106  EXPECT_NEAR(180.0 * M_PI / 180.0, poseHelperPtr->calcAngularDistanceInRad(pose1, pose2), EPSILON);
107 
108  // rotate x: 90° and y: -90°
109  pose2.orientation.w = 0.5;
110  pose2.orientation.x = 0.5;
111  pose2.orientation.y = -0.5;
112  pose2.orientation.z = -0.5;
113  EXPECT_NEAR(120.0 * M_PI / 180.0, poseHelperPtr->calcAngularDistanceInRad(pose1, pose2), EPSILON);
114 }
115 
116 TEST_F(PoseHelperSetup, CheckViewCenterPointsAreApproxEquale) {
117  PoseHelperPtr poseHelperPtr = PoseHelper::getInstance();
118 
119  geometry_msgs::Pose pose1;
120  pose1.orientation.w = 1.0;
121  geometry_msgs::Pose pose2;
122  pose2.orientation.w = 1.0;
123  EXPECT_TRUE(poseHelperPtr->checkViewCenterPointsAreApproxEquale(pose1, pose2));
124 
125  // 0.95 is viewCenterDistance and 0.16 is distance between viewpoints < viewCenterPositionDistanceThreshold ~= 0.176
126  // rotate z: arctan(0.16/0.95) == 9.56° < 60° == mHypothesisUpdaterAngleThreshold
127  pose2.orientation.w = 0.997;
128  pose2.orientation.z = 0.083;
129  EXPECT_TRUE(poseHelperPtr->checkViewCenterPointsAreApproxEquale(pose1, pose2));
130 
131  // 0.95 is viewCenterDistance and 0.19 is distance between viewpoints > viewCenterPositionDistanceThreshold ~= 0.176
132  // rotate z: arctan(0.19/0.95) == 11.31° < 60° == mHypothesisUpdaterAngleThreshold
133  pose2.orientation.w = 0.995;
134  pose2.orientation.z = 0.099;
135  EXPECT_FALSE(poseHelperPtr->checkViewCenterPointsAreApproxEquale(pose1, pose2));
136 
137  // 0.95 is viewCenterDistance
138  pose2.position.x = 0.95;
139  pose2.position.y = -0.95;
140  // rotate z: 90° > 60° == mHypothesisUpdaterAngleThreshold
141  pose2.orientation.w = 0.707;
142  pose2.orientation.z = 0.707;
143  EXPECT_FALSE(poseHelperPtr->checkViewCenterPointsAreApproxEquale(pose1, pose2));
144 
145  // 0.95 is viewCenterDistance
146  pose2.position.x = 0.95 * 2;
147  pose2.position.y = 0.0;
148  // rotate z: 180°
149  pose2.orientation.w = 0.0;
150  pose2.orientation.z = 1.0;
151  EXPECT_FALSE(poseHelperPtr->checkViewCenterPointsAreApproxEquale(pose1, pose2));
152 }
153 
154 
155 bool getDistance(asr_robot_model_services::GetDistance::Request &req, asr_robot_model_services::GetDistance::Response &res) {
156  return true;
157 }
158 
160 
163  ros::ServiceServer service_GetDistance = n.advertiseService("/asr_robot_model_services/GetDistance", getDistance);
164  while (true) {
165  ros::spinOnce();
166  hasAdvertised = true;
167  boost::this_thread::sleep(boost::posix_time::milliseconds(10));
168  }
169  return 0;
170 }
171 
172 TEST_F(PoseHelperSetup, ResetInstance) {
173  n.setParam("distanceFunc", 2);
175  PoseHelperPtr poseHelperPtr = PoseHelper::getInstance();
176 
177  geometry_msgs::Pose pose1;
178  geometry_msgs::Pose pose2;
179 
180  pose2.position.x = 1.0;
181  pose2.position.y = 0.0;
182 
183  EXPECT_NEAR(1.0, poseHelperPtr->calculateDistance(pose1, pose2), EPSILON);
184 
185  n.setParam("distanceFunc", 1);
187 
188  hasAdvertised = false;
189  boost::thread t = boost::thread(advertiseService);
190  while (!hasAdvertised) {}
191 
192  EXPECT_NEAR(0.0, poseHelperPtr->calculateDistance(pose1, pose2), EPSILON);
193  t.interrupt();
194  t.join();
195 
196 }
197 
198 
ros::NodeHandle n
std::string getName(void *handle)
ROSCPP_DECL const std::string & getName()
bool getDistance(asr_robot_model_services::GetDistance::Request &req, asr_robot_model_services::GetDistance::Response &res)
ServiceServer advertiseService(const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T *obj)
int advertiseService()
#define EPSILON
static boost::shared_ptr< PoseHelper > getInstance()
Definition: pose_helper.cpp:28
bool hasAdvertised
TEST_F(PoseHelperSetup, CalcDistPositionEucl)
ROSCPP_DECL void spinOnce()
void setParam(const std::string &key, const XmlRpc::XmlRpcValue &v) const


asr_direct_search_manager
Author(s): Borella Jocelyn, Karrenbauer Oliver, Meißner Pascal
autogenerated on Wed Jan 8 2020 03:15:41