36 #include <geometry_msgs/PoseArray.h> 37 #include <geometry_msgs/PoseWithCovarianceStamped.h> 39 #include <gtest/gtest.h> 43 inline geometry_msgs::PoseWithCovarianceStamped generatePoseWithCov(
44 const float y,
const float y_var,
const float var_measure = 0.0)
46 geometry_msgs::PoseWithCovarianceStamped pose;
47 pose.header.frame_id =
"map";
49 pose.pose.pose.position.y = y;
50 pose.pose.pose.orientation.w = 1.0;
51 pose.pose.covariance[6 * 0 + 0] = var_measure;
52 pose.pose.covariance[6 * 1 + 1] = y_var;
53 pose.pose.covariance[6 * 2 + 2] = var_measure;
54 pose.pose.covariance[6 * 3 + 3] = var_measure;
55 pose.pose.covariance[6 * 4 + 4] = var_measure;
56 pose.pose.covariance[6 * 5 + 5] = var_measure;
59 std::pair<float, float> getMean(
const std::vector<geometry_msgs::Pose>& poses)
62 for (
const geometry_msgs::Pose p : poses)
69 for (
const geometry_msgs::Pose p : poses)
71 root_mean += std::pow(p.position.y - mean, 2);
73 root_mean /= poses.size();
75 return std::pair<float, float>(mean, root_mean);
79 TEST(Landmark, Measurement)
81 geometry_msgs::PoseArray::ConstPtr poses;
83 const boost::function<void(const geometry_msgs::PoseArray::ConstPtr&)> cb_pose =
84 [&poses](
const geometry_msgs::PoseArray::ConstPtr&
msg) ->
void 92 nh.
advertise<geometry_msgs::PoseWithCovarianceStamped>(
"initialpose", 1,
true);
94 nh.
advertise<geometry_msgs::PoseWithCovarianceStamped>(
"mcl_measurement", 1,
true);
97 pub_init.
publish(generatePoseWithCov(2.0, 1.0));
100 for (
int i = 0; i < 100; i++)
111 ASSERT_TRUE(static_cast<bool>(poses));
112 for (
const geometry_msgs::Pose p : poses->poses)
114 ASSERT_FLOAT_EQ(p.position.x, 0.0f);
115 ASSERT_FLOAT_EQ(p.position.z, 0.0f);
116 ASSERT_FLOAT_EQ(p.orientation.x, 0.0f);
117 ASSERT_FLOAT_EQ(p.orientation.y, 0.0f);
118 ASSERT_FLOAT_EQ(p.orientation.z, 0.0f);
119 ASSERT_FLOAT_EQ(p.orientation.w, 1.0f);
121 const std::pair<float, float> mean_init = getMean(poses->poses);
122 ASSERT_NEAR(mean_init.first, 2.0f, 0.1f);
123 ASSERT_NEAR(mean_init.second, 1.0f, 0.1f);
126 pub_landmark.publish(generatePoseWithCov(2.6, 1.0, 1000.0 * 1000.0));
130 ASSERT_TRUE(static_cast<bool>(poses));
131 for (
const geometry_msgs::Pose p : poses->poses)
133 ASSERT_FLOAT_EQ(p.position.x, 0.0f);
134 ASSERT_FLOAT_EQ(p.position.z, 0.0f);
135 ASSERT_FLOAT_EQ(p.orientation.x, 0.0f);
136 ASSERT_FLOAT_EQ(p.orientation.y, 0.0f);
137 ASSERT_FLOAT_EQ(p.orientation.z, 0.0f);
138 ASSERT_FLOAT_EQ(p.orientation.w, 1.0f);
140 const std::pair<float, float> mean_measured = getMean(poses->poses);
141 ASSERT_NEAR(mean_measured.first, 2.3f, 0.1f);
142 ASSERT_NEAR(mean_measured.second, 0.5f, 0.1f);
145 int main(
int argc,
char** argv)
147 testing::InitGoogleTest(&argc, argv);
150 return RUN_ALL_TESTS();
void publish(const boost::shared_ptr< M > &message) const
TEST(Landmark, Measurement)
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
ROSCPP_DECL void spinOnce()
int main(int argc, char **argv)