33 #include <nav_msgs/Odometry.h> 34 #include <sensor_msgs/Imu.h> 38 #include <gtest/gtest.h> 51 nav_msgs::Odometry& odom_raw,
52 sensor_msgs::Imu& imu)
57 for (
int i = 0; i < 100 &&
ros::ok(); ++i)
69 nav_msgs::Odometry& odom_raw,
70 sensor_msgs::Imu& imu,
71 const float dt,
const int steps)
81 odom_raw.pose.pose.orientation =
84 tf2::Quaternion(tf2::Vector3(0.0, 0.0, 1.0), dt * odom_raw.twist.twist.angular.z));
90 tf2::Quaternion(tf2::Vector3(0.0, 0.0, 1.0), dt * imu.angular_velocity.z));
92 const double yaw =
tf2::getYaw(odom_raw.pose.pose.orientation);
93 odom_raw.pose.pose.position.x +=
cos(yaw) * dt * odom_raw.twist.twist.linear.x;
94 odom_raw.pose.pose.position.y +=
sin(yaw) * dt * odom_raw.twist.twist.linear.x;
106 nav_msgs::Odometry& odom_raw,
107 sensor_msgs::Imu& imu,
127 void cbOdom(
const nav_msgs::Odometry::ConstPtr& msg)
137 const float dt = 0.02;
138 const int steps = 100;
140 nav_msgs::Odometry odom_raw;
141 odom_raw.header.frame_id =
"odom";
142 odom_raw.pose.pose.orientation.w = 1;
144 sensor_msgs::Imu imu;
145 imu.header.frame_id =
"base_link";
146 imu.orientation.w = 1;
147 imu.linear_acceleration.z = 9.8;
152 odom_raw.twist.twist.linear.x = 0.5;
153 ASSERT_TRUE(
run(odom_raw, imu, dt, steps));
155 odom_raw.twist.twist.linear.x = 0.0;
159 ASSERT_NEAR(
odom_->pose.pose.position.x, 1.0, 1e-3);
160 ASSERT_NEAR(
odom_->pose.pose.position.y, 0.0, 1e-3);
161 ASSERT_NEAR(
odom_->pose.pose.position.z, 0.0, 1e-3);
165 imu.angular_velocity.z = M_PI * 0.25;
166 odom_raw.twist.twist.angular.z = imu.angular_velocity.z * 1.1;
167 ASSERT_TRUE(
run(odom_raw, imu, dt, steps));
169 imu.angular_velocity.z = 0;
170 odom_raw.twist.twist.angular.z = 0;
175 ASSERT_NEAR(
odom_->pose.pose.position.x, 1.0, 1e-2);
176 ASSERT_NEAR(
odom_->pose.pose.position.y, 0.0, 1e-2);
177 ASSERT_NEAR(
odom_->pose.pose.position.z, 0.0, 1e-2);
181 odom_raw.twist.twist.linear.x = 0.5;
182 ASSERT_TRUE(
run(odom_raw, imu, dt, steps));
184 odom_raw.twist.twist.linear.x = 0.0;
188 ASSERT_NEAR(
odom_->pose.pose.position.x, 1.0, 5e-2);
189 ASSERT_NEAR(
odom_->pose.pose.position.y, 1.0, 5e-2);
190 ASSERT_NEAR(
odom_->pose.pose.position.z, 0.0, 5e-2);
196 const std::string ns_postfix(GetParam());
199 const float dt = 0.02;
200 const int steps = 100;
202 nav_msgs::Odometry odom_raw;
203 odom_raw.header.frame_id =
"odom";
204 odom_raw.pose.pose.orientation.w = 1;
206 sensor_msgs::Imu imu;
207 imu.header.frame_id =
"base_link";
208 imu.orientation.y =
sin(-M_PI / 4);
209 imu.orientation.w =
cos(-M_PI / 4);
210 imu.linear_acceleration.x = -9.8;
215 odom_raw.twist.twist.linear.x = 0.5;
216 ASSERT_TRUE(
run(odom_raw, imu, dt, steps));
218 odom_raw.twist.twist.linear.x = 0.0;
222 ASSERT_NEAR(
odom_->pose.pose.position.x, 0.0, 1e-3);
223 ASSERT_NEAR(
odom_->pose.pose.position.y, 0.0, 1e-3);
224 ASSERT_NEAR(
odom_->pose.pose.position.z, 1.0, 1e-3);
229 const std::string ns_postfix(GetParam());
232 const float dt = 0.02;
233 const int steps = 100;
235 nav_msgs::Odometry odom_raw;
236 odom_raw.header.frame_id =
"odom";
237 odom_raw.pose.pose.orientation.w = 1;
239 sensor_msgs::Imu imu;
240 imu.header.frame_id =
"base_link";
241 imu.orientation.y =
sin(-M_PI / 4);
242 imu.orientation.w =
cos(-M_PI / 4);
243 imu.linear_acceleration.x = -9.8;
248 odom_raw.twist.twist.linear.x = 0.5;
249 ASSERT_TRUE(
run(odom_raw, imu, dt, steps));
251 odom_raw.twist.twist.linear.x = 0.0;
255 ASSERT_NEAR(
odom_->pose.pose.position.z, 1.0 - 1.0 / M_E, 5e-2);
260 ::testing::Values(
"",
"_old_param"));
262 int main(
int argc,
char** argv)
264 testing::InitGoogleTest(&argc, argv);
265 ros::init(argc, argv,
"test_track_odometry");
267 return RUN_ALL_TESTS();
nav_msgs::Odometry::ConstPtr odom_
TEST_P(TrackOdometryTest, ZFilterOff)
void publish(const boost::shared_ptr< M > &message) const
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)
ros::Subscriber sub_odom_
int main(int argc, char **argv)
TEST_F(TrackOdometryTest, OdomImuFusion)
void fromMsg(const A &, B &b)
void initializeTrackOdometry(nav_msgs::Odometry &odom_raw, sensor_msgs::Imu &imu)
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
void stepAndPublish(nav_msgs::Odometry &odom_raw, sensor_msgs::Imu &imu, const float dt)
double getYaw(const A &a)
INSTANTIATE_TEST_CASE_P(TrackOdometryTestInstance, TrackOdometryTest,::testing::Values("","_old_param"))
INLINE Rall1d< T, V, S > cos(const Rall1d< T, V, S > &arg)
ROSCPP_DECL void spinOnce()
void cbOdom(const nav_msgs::Odometry::ConstPtr &msg)
INLINE Rall1d< T, V, S > sin(const Rall1d< T, V, S > &arg)
bool run(nav_msgs::Odometry &odom_raw, sensor_msgs::Imu &imu, const float dt, const int steps)
void initializeNode(const std::string &ns)